You are on page 1of 42

Chapter 1 | This Issue

Planning your Rig

Chapter 2 | Next Issue


Knowing your Tools

Chapter 3 | June Issue 058


Rig Creation Part 1

Chapter 4 | July Issue 059


Rig Creation Part 2

Chapter 5 | August Issue 060


Facial Rigging

Chapter 6 | September Issue 061


Scripting

The aim of these tutorials is to show and explain how you might tackle rigging your 3D character for animation. These tutorials will give help and advice to novices and experts who are looking to build on their rigging skills or approach rigging for the first time. The series gives a detailed step by step guide as to how to approach rigging but also shows us how to tackle common problems and issues that regularly occur even in a professional environment. The artists will be reflecting on working in the industry as well as talking us through their individual approaches to creating the best rigs possible.

- Free Model
This download includes The Model Used Within This Tutorial

Introduction to Rigging Chapter 1: Planning your Rig Introduction to Rigging: 1 - Planning your Rig
Software Used: Maya

Chapter Overview
Welcome to the Introduction to Rigging tutorial series for Maya. Throughout these lessons for beginners, you will discover some basic technical concepts that will get you started in the fun and crazy world of rigging! And at the end, we will rig a complete biped character and leave with a short introduction on scripting, to automate simple tasks. In this first chapter we almost wont be using the software itself first things first! Anyone can follow a tutorial and get things working, but you cant rely on tutorials forever, right? Youve got to understand what you are doing! So were going to explain a little about how character riggers think, and how to optimize your work from the very start of the process in just about any kind of job. Are you ready? Lets do this! everything thats in your mind, like some crazy, hungry monkey, before planning your rig! Like with almost everything in life, if you dont plan before taking action you will most likely have a hard time trying to get things working! The process of building a character rig can be really complex, so its a good idea to write a task list to avoid skipping important steps (Fig.01). Pro Tip: First, lets play a little with our character and try to imagine how we can get good deformations. Good practice is to take screenshots from your model and draw over them. Try to figure out the ideal location of the skeleton, controls and pivots based in your characters proportions. Dont worry about this now; we will help you throughout this chapter (Fig.02). Good practice in Maya is to use Groups (Any Mode > Edit > Group). Your rig must be as simple as possible. It doesnt matter whether youre working on a simple cartoon character or on a badass realistic creature: keep thinking in terms of solutions! They will come to you more easily when your rig and workflow are organized (Fig.03). Please, try to rename all objects, geometries, curve controls, nodes, etc. To sum up: everything you create and may have to use later.

Planning
Before taking any action, here is something you should always remember: Do not try to create

Naming
There are lots of object types in the 3D world, so its easy to mix them up or delete what you shouldnt when youre on a tight schedule or working on really large scenes. Be careful to always name all of your objects, whilst keeping the names as clean and understandable as possible. A simple pipeline only uses prefixes and suffixes for all nodes (objects in your Maya scene).

Organization
In the rigging world, being organized is essential! Organization helps you to create easy-to-understand and up-to-date setups.

www.3dcreativemag.com

page 75

Issue 056 April 2010

Chapter 1: Planning your Rig Introduction to Rigging


The main idea here is team integration. When another person opens up your scene, they should be able to edit it easily if everything is correctly organized. Remember: please work with care in order to avoid unnecessary work for others and for yourself! A simple yet efficient approach is to use three letters from the name of the character as a prefix, and also three letters from the node type as a suffix. And a good idea is to use underscores to make the names more readable. If applicable, indicate the node side using just one letter (L for left and R for right). Try to use underscores only when prefixing and suffixing, make the object name cleaner by separating words using capital letters between them (l_greenColoredEyeball_jnt, for example) (Fig.04). Before you start your rig, take some time to look at the real world, as well as movie and image references. By doing this, you will most certainly have a clearer idea of what objectives to meet and how to achieve them (Fig.05). our joints in the best way we possibly can this always ensures good rigging results! We will quickly cover some deformation facts and limits, establishing those imaginary mass blocks to better understand how the deformation works in each area. Try to compare it to your own body to better understand how the rig should work.

References
Whenever rigging creatures, be they humanoid, alien, animal, robotic, or whatever, always look for anatomy references in books and on the internet. Having knowledge about anatomy is a very important basis for creating good skeletons and muscle deformations.

Basic Anatomy
Lets now discuss a little about some of the basic aspects of anatomy so we can position

www.3dcreativemag.com

page 76

Issue 056 April 2010

Introduction to Rigging Chapter 1: Planning your Rig

Spine
The center of gravity (or center of mass) of a character is located in the spine, near the navel (wed usually consider the waist joint as the root joint of all the hierarchy). When building the chest, be aware that its the body part that deforms the least, while the abdomen is the most flexible region of the spine (Fig.06).

Head & Neck


We can divide the head and the neck into two main rotation points: one for the neck located in the base of the cervical vertebrae region, and the other for the head located at the base of the skull (Fig.07).

Arms & Clavicles


The clavicle is very important in order to get good arm movements, because the shoulder doesnt rotate more than on a horizontal line. With the clavicle, this limit can be surpassed, but remember that the clavicle bone doesnt rotate on its own axis (the one pointing to the shoulder). There is no limit on the shoulders rotation, but the elbow can only rotate on one axis (using the biceps and triceps muscles). The wrist bone also cannot rotate on its axis point. The relationship between the elbow and the wrist is very interesting because of the radius and ulna bones; they cross when the forearm rotates so that the wrist region rotates, keeping the elbow fixed (Fig.08).

www.3dcreativemag.com

page 77

Issue 056 April 2010

Chapter 1: Planning your Rig Introduction to Rigging Hands


Basically, we can consider that there are three phalanx bones for each of the five fingers in the human hand. None of these bones rotate on their axis point. The starting base of a phalanx can rotate on two axes, but the middle and last phalanges cannot (Fig.09).

Legs
The leg joint can rotate in all directions, and its possible to rotate the ankle with it together, as if in a group. The knee just rotates in one direction, whilst the toes on the feet are similar to the fingers on the hand (with three phalanx bones for each), except that the toes only have two phalanges each (Fig.10). Pro Tip: Remember to base your rigging on good anatomy whenever you can, but dont let it imprison your creativity! Sometimes we need to create mechanics that are different to realistic and natural anatomy in order to achieve the desired effects and deformations. Feel free to diversify using your creativity to get the best solutions for your needs.

In Closing
Thats it for this lesson! Be sure to draw and study a lot of anatomy and deformations! In the next chapter we will dive into Maya our 3D software of choice to put our knowledge into practice! Thats right, in the next part we will test our planning on the real thing! A brief overview will show you how the software works and explain some of its main tools that are used for the rigging process, and we will also discover some tips and tricks on general rigging so you can speed up your workflow.

Richard Kazuo & Danilo Pinheiro


For more from these artists visit http://riggerman.animationblogspot.com/ http://nilouco.blogspot.com or contact richardyzo@gmail.com nilouco@gmail.com

www.3dcreativemag.com

page 78

Issue 056 April 2010

Chapter 1 | April Issue 056


Planning your Rig

Chapter 2 | This Issue


Knowing your Tools

Chapter 3 | Next Issue


Rig Creation Part 1

Chapter 4 | July Issue 059


Rig Creation Part 2

Chapter 5 | August Issue 060


Facial Rigging

Chapter 6 | September Issue 061


Scripting

The aim of these tutorials is to show and explain how you might tackle rigging your 3D character for animation. These tutorials will give help and advice to novices and experts who are looking to build on their rigging skills or approach rigging for the first time. The series gives a detailed step by step guide as to how to approach rigging but also shows us how to tackle common problems and issues that regularly occur even in a professional environment. The artists will be reflecting on working in the industry as well as talking us through their individual approaches to creating the best rigs possible.

- Free Model
This download includes The Model Used Within This Tutorial

Introduction to Rigging Chapter 2: Knowing your Tools Introduction to Rigging: 2 - Knowing your Tools
Software Used: Maya

Chapter Overview
In this chapter we will explain a little about Mayas architecture and take a look at some useful tools for the rigging process in order to get the best out of them. You will also see some tips and tricks on general rigging that will help you speed-up your rigging process a lot.

Concepts
When we work with rigging we need to think: what can we do to bring this character to life, whilst keeping it simple and clean? Rigging is a technical process that stands between modeling and animation and our responsibility is to create simple and easily understandable controls for the animators, while keeping the pipeline clean and straightforward as possible to achieve what we need. That is why it is very important to look for references in real-life or other CG sources. A good knowledge about anatomy and movement is essential! We need to understand a little about programming too, some processes can be very repetitive and scripting these tiring parts will make your work a lot quicker and fun. If you use Maya, you should learn a little about MEL and Python scripting. But dont worry about all of these topics right now! We will see all of them in the tutorials. an empty group. The visual representation of the object you are moving is called Shape. To see this clearly open up a new scene, take a look into your Outliner and check (Display > Shapes). Click on the plus sign on the left of the top camera object and you will see it has a transform (the white box) and a shape (the camera icon) (Fig.01). Please note you cannot move the shape without the transform, its Mayas way to keep track of where your object is in your scene. Now, I just said we cant move the shape without the transform, but that is not entirely true to meshes. You can move around geometry vertices without moving its transform, we will call this kind of movement deformation of components. Note that you cannot deform a camera, because its shape doesnt have components. Only edit shapes if you know what you are doing! That can lead to undesired deformations and weird pivots. So, summing it up, Transformation is when we edit (translate, rotate or scale) entire objects. Deformation is when we edit (translate, rotate or scale) components of a mesh (Fig.02).

Transformation and Deformation


Ok, the first thing we should be aware of is how the things you see in Mayas viewport work. We wont go too technical here. For starters, this is what you need to be aware of - Every object in Maya that you can move around in the viewport has a Transform Node. These nodes are there even when you cannot see them, for example:

www.3dcreativemag.com

page 113

Issue 057 May 2010

Chapter 2: Knowing your Tools Introduction to Rigging

In a practical example, you would use transformation to move around an entire ball and deformation to squash and stretch the components of this ball.

* Aim Constraint: constrains only the rotation of the object to make it always aim to the targets; * Scale Constraint: constrains only the scaling of the object (Fig.03);

riggers! The main goal of working with joints is to put them on the right position of the character in order to get the best deformations when the joint is transformed... that is how joints work; they are used to drive components of meshes. Simply put, you move a joint and it moves components of a mesh that are bound to this joint. Do not worry if you do not understand, we will talk about skinning in a moment (Fig.04). Tip: (Joints) = When creating a linear joint hierarchy using Joint Tool (Animation >>

Constraints:
Sometimes in Maya we need to make an object follow another in translation, rotation, scale, for example making it always face the target, etc... These can be done using constraints. To create a constraint, first select the target object (the one who will lead), then select the constrained object (the one who will follow the lead) and click on the desired type of constraint from the menu (Animation >> Constrain). By default, constraints override your objects transform values to match the target values but you can also create an offset in your constraint by checking the Maintain Offset checkbox in any constraint option box. * Point Constraint: constrains only the translation of the object using its own pivot point; * Orient Constraint: constrains only the rotation of the object using its own pivot point; * Parent Constraint: constrains only the translation and rotation of the object using the targets pivot point;

Joints
Joints are hierarchical deformers that makes the skeletal structure for our models possible. They are very flexible and we can use them for lots of different characters, animals and creatures as we like. By far the most used object for us

www.3dcreativemag.com

page 114

Issue 057 May 2010

Introduction to Rigging Chapter 2: Knowing your Tools


Skeleton > Joint Tool) snap on the grid (pressing X), move joints in only one direction (using move manipulator option Along rotation axis) and rotate it to put in the desired angle. This way you create joint chains in only one axis and avoid future orientation problems (Fig.05).

Skinning
Smooth Bind Skin (Animation >> Skin > Bind Skin > Smooth Bind) is used to drive your geometry using joints. It creates a skin Cluster deformer in the input history of the geometry making it possible for our joints to be used as deformers of our character model (Fig.06). We will take a look at the skinning process in detail in the next chapter.

Deformers
There are a lot of deformers in Maya. Each deformer has an attribute named Envelope that we can use to weigh the deformation applied. We will list some of the main ones that are used in rigging, but do not be satisfied with only these below, go ahead to try others too: Cluster It is a center point to modify geometries or selected vertices from a geometry. Create it by selecting a mesh or points of a mesh and going to (Animation > Create Deformers > Cluster), it will create a little C letter, our cluster Handle manipulator. This works almost the same as joints with the advantage of having a localized and easily adjustable effect. We can optimize this effect by painting its weight using (Animation >> Edit Deformers > Paint Cluster Weights Tool) (Fig.07).

www.3dcreativemag.com

page 115

Issue 057 May 2010

Chapter 2: Knowing your Tools Introduction to Rigging

Blend Shapes This allows us to model our own deformations anyway we want and toggle them as needed. We will see this topic in detail in chapter 5 (Fig.08). Lattice This deformer creates a box shape with points around geometries or selected points of geometries. Edit these points to deform the associated model. Create a lattice deformer by

selecting entire objects or components of them and going to (Animation >> Create Deformers > Lattice). Change the lattice S/T/U divisions for more resolution in X/Y/Z in order to get more precise deformations. The deformer also creates a lattice Base object (look at Outliner Panel) to define a starting location to calculate the deformations (Fig.09).

we have seen until now work? They need a start and an end position to points and simply send them from one point to another, in a straight line. Non-linear deformers do not calculate the deformation this way. Youll notice each of them has a unique method of editing your meshes points. Main Nonlinear Deformers, very useful for

There are also the non-linear deformers. Why non-linear? Remember how all the deformers

cartoon rigging projects: Bend + The bend deformer literally bends your

www.3dcreativemag.com

page 116

Issue 057 May 2010

Introduction to Rigging Chapter 2: Knowing your Tools

points in an arc. You can define its position and orientation by transforming the bend Handle manipulator. The Curvature attribute is used to measure the bending power and Low and High Bounds are used to change the boundaries of

the deformation. Create a bend deformer by selecting meshes or points of meshes and then clicking on (Animation >> Create Deformers > Nonlinear > Bend) (Fig.10).

Squash + The squash deformer will squash (or stretch) your geometry vertices while maintaining its volume. A squash Handle manipulator will be applied to selected meshes or points by going to (Animation >> Create Deformers > Nonlinear > Squash). You can move this handle around to the position where you get the best squash deformation for your needs. Edit its Factor attribute value in order to squash or stretch your geometry amongst other editable attributes (Fig.11). Now that you know some tricks, you are ready to get busy! In the next chapter we will start rigging our ET character by creating its skeleton hierarchy, go deeper into the skinning process and see a little more about blend shapes. Until then, practice a lot and get yourself comfortable with Maya!

Richard Kazuo & Danilo Pinheiro


For more from these artists visit http://riggerman.animationblogspot.com/ http://nilouco.blogspot.com or contact richardyzo@gmail.com nilouco@gmail.com

www.3dcreativemag.com

page 117

Issue 057 May 2010

Chapter 1 | April Issue 056


Planning your Rig

Chapter 2 | May Issue 057


Knowing your Tools

Chapter 3 | This Issue


Rig Creation Part 1

Chapter 4 | Next Issue


Rig Creation Part 2

Chapter 5 | August Issue 060


Facial Rigging

Chapter 6 | September Issue 061


Scripting

The aim of these tutorials is to show and explain how you might tackle rigging your 3D character for animation. These tutorials will give help and advice to novices and experts who are looking to build on their rigging skills or approach rigging for the first time. The series gives a detailed step by step guide as to how to approach rigging but also shows us how to tackle common problems and issues that regularly occur even in a professional environment. The artists will be reflecting on working in the industry as well as talking us through their individual approaches to creating the best rigs possible.

- Free Models
This download includes The Models Used Within This Tutorial

Introduction to Rigging Chapter 3: Rig Creation Part 1 Introduction to Rigging: 3 - Rig Creation - Part 1
Software Used: Maya

Chapter Overview
This time we are finally getting down to business! We will start to create the skeleton hierarchy of our character while giving a deeper explanation to the skinning process. At the very end, we will take a peek on some blendshape targets for our ET character. Enough said, lets rig!

Joint Outlining
Now it is time to use our planned material from previous lessons to create the characters skeleton. Use the side, front, top and persp viewports to create these structures: the last joint in the hierarchy and for helping Spine: the root joint of a biped character must be the first lower spine, the waist. From then on you will need to create up to three joints until the chest area. Name them as spineA_jnt, spineB_ jnt and spineC_jnt. After that build another five joints for the neck_jnt, head_jnt, jaw_jnt, chin_jnt and chin_end. (Fig.01) TIP (joint Ends) = We do not use the joints suffixed _end as skinned influences. We only create them to help us visualize the rotation of Leg: now we can start with another separated joint hierarchy from top to bottom, but this time we will concentrate only on the left side because we will mirror the limbs from left to right later on. So, create six joints named as following: l_leg_ jnt, l_upKnee_jnt, l_lowKnee_jnt, l_ankle_jnt, l_foot_jnt, l_foot_end. Note the l_ prefix, that means left side. We will replace that for r_ when we mirror these and other limbs. Arm: for the arms we will use five joints that can be: the l_clavicle_jnt, l_shoulder_jnt, l_upElbow_ jnt, l_lowElbow_jnt and l_wrist_jnt. (Fig.03) TIP (Forearm Twist) = This technique is for a simple forearm twist: duplicate the wrist joint (Any Mode >> Edit > Duplicate) and move it along the chain (in our case, the X direction) until it is 1/3 of the distance of the low Elbow. Rename it as forearm_jnt and delete its child wrist joint. This is a simple yet very useful way to mimic the forearm twisting, when we rotate our hands. For now we wont actually be setting the forearm rig, we will take a look into its expression in the next chapter! (Fig.04) TIP (knee/elbow) = We use two joints as knee (or elbow) in order to get better deformations. These parts are very complex in real-life, so we need two joints to reach almost 180 degrees of rotation while minimizing volume loss. (Fig.02) Maya calculate the starting skin weights.

www.3dcreativemag.com

page 85

Issue 058 June 2010

Chapter 3: Rig Creation Part 1

Introduction to Rigging

Hand: lets create four joints for each finger, such as: l_thumbA_jnt, l_thumbB_jnt, l_ thumbC_jnt, l_thumb_end. Parent finger joints to the l_wrist_jnt. (Fig.05)

the command (Any Mode >> Modify > Freeze Transformations). This way you will be able to return to the default joint positions (bind pose) when you paint skin weights.

vertices with the command and value currently set for the selected joint. A technique that we use is to repaint all of the character model again. It may seem hard to do sometimes, but this way you can get better results instead of trying to repair the original skin weights generated by the software. Lets do this by activating Replace paint mode with the Value of 1 for the waist! After you block it, also paint value 1 for spineA to all faces of the mesh that are above this joint. When you have the two white blocks, hold the weights of all other joints except spineA and waist. Now press 3 or 4 times the Flood button with the Smooth option selected. Look at what you should have: a nice smooth blending between these two joints while the other joints do not influence this area - they were held. Continue by holding the waist joint and unholding spineB, then block influences between spineA and spineB areas, lock and smooth. Repeat this process for all adjacent joints. (Fig.07) TIP (skinning) = You can rotate joints when painting to see if your weights are good. When you are finished, just reset their rotations to zero! Concentrate in painting the skin values for only one side of the character, as we can

Mirroring
Now, we can parent the clavicle joint to the spineC and then do the mirroring using (Animation >> Skeleton > Mirror Joint) . Look at the options for this command, we should search for l_ (left side) and replace for r_ (right side) while mirroring in YZ mirror across. Do the same for the l_leg_jnt parented to the waist. (Fig.06)

Skinning in Action
Now lets put these joints into action! Freeze the joints transformations, select your model and all of your joints except those named _end and apply the Smooth Bind Skin by going to (Animation >> Skin > Bind Skin > Smooth Bind). Go to the option box and mark these options: Bind to Selected joints, Max influences 3, Maintain Max Influences off. Maya will then create a default skinCluster with point weight values that we can refine using the artisan brush (Animation >> Skin > Edit Smooth Skin > Paint Skin Weights Tool). When you look the mesh with this tool activated, you will see that it is painted black, white and gray. Do not worry, it is all right. These colors are showing you the weights values for joints (black = 0, white = 1 and gray = values between 0 and 1). This means that: the whiter the region is, the more the currently selected joint will affect your mesh. With this tool, we can replace, add, scale or smooth influences for each deformer joint. The button Toggle Hold Weights on Selected can be used to lock the selected joint for modifications and the button Flood paints all

Skinning Theory
Ok, in a moment we will start the skinning process to actually drive our mesh using our created joints - but before that we need to understand what this is all about. We will be using the smooth bind command, it allows you to deform a mesh using one or more joints by creating a skinCluster deformer in your mesh. Smooth means that you can have more than one joint driving the position of a single point of your mesh. So the skin Cluster lets joints drive points in a mesh and for each point the rules for which the joint is to follow is completely open for us to edit (either by numeric values or painting the values directly in the mesh). TIP (Skinning) = Reset joint rotations before applying the skin Cluster. To do this preserving your joint hierarchy, select all joints and use

www.3dcreativemag.com

page 86

Issue 058 June 2010

Introduction to Rigging Chapter 3: Rig Creation Part 1


mirror weights from one side to another using (Animation >> Skin > Edit Smooth Skin > Mirror Skin Weights).

Secondary Deformations
If you want to get better deformations while animating your character, you should create secondary deformations as corrective blendshape targets to simulate muscles and interactive anatomy that will be automatically controlled. This technique is simple: just duplicate the original model and deform it to what you need, when you use it as a target then link its blendshape slider to a controller. We usually connect the rotation of a specific joint to values of the blend shape slider using Set Driven Keys (Animation >> Set Driven Key > Set...). Let us see an example. Look at the picture to get the idea: (Fig.08) Here we created an inflated biceps blendshape. This target is controlled by the lowElbow joints rotation Y value. We then use SDK to tell Maya: when the rotation Y of the joint is 0, the value of the slider of the blendshape is also 0. When the rotation Y of the joint is -30, the value of the blendshape will be 1. Simple, isnt it? TIP (secondary deformation) = Always think in volume preservation. You can use secondary deformations in any part of the character that you need. So try to do it for the main muscles of your character like elbows, knees, belly volume, etc. That is it for this lesson! Try to skin the joints in different positions to better understand how the smooth skinning works in order to get the best deformations possible! Also model and test a lot of targets for your character to learn this properly! These are valuable assets in any riggers workflow, remember that! :) Now that the entire joint hierarchy is created and the skin weights are nicely adjusted, in the next chapter we will see some rigging tricks to create IK/FK blending, reverse foot controls, forearm twist and create the actual controllers that the animators will use. See you then!

Richard Kazuo & Danilo Pinheiro


For more from these artists visit http://riggerman.animationblogspot.com/ http://nilouco.blogspot.com or contact richardyzo@gmail.com nilouco@gmail.com

www.3dcreativemag.com

page 87

Issue 058 June 2010

Chapter 1 | April Issue 056


Planning your Rig

Chapter 2 | May Issue 057


Knowing your Tools

Chapter 3 | June Issue 058


Rig Creation Part 1

Chapter 4 | This Issue


Rig Creation Part 2

Chapter 5 | Next Issue


Facial Rigging

Chapter 6 | September Issue 061


Scripting

The aim of these tutorials is to show and explain how you might tackle rigging your 3D character for animation. These tutorials will give help and advice to novices and experts who are looking to build on their rigging skills or approach rigging for the first time. The series gives a detailed step by step guide as to how to approach rigging but also shows us how to tackle common problems and issues that regularly occur even in a professional environment. The artists will be reflecting on working in the industry as well as talking us through their individual approaches to creating the best rigs possible.

- Free Models
This download includes The Models Used Within This Tutorial

Introduction to Rigging Chapter 4: Rig Creation Part 2 Introduction to Rigging: 4 - Rig Creation - Part 2
Software used: Maya

Chapter Overview
In this chapter we will build the rig setups using the joints we created in our last lesson and add control curves for the animators to use (after all, no one likes to have to select the actual joints when animating - sometimes this will not even work and break the rig).

Controls
Now its time to set up controls to move the skeleton. We usually create CV curves as controls and modify the shapes by editing components to make them more intuitive for the animators (Fig.01). We should also add attributes to them in the ChannelBox panel (ChannelBox > Edit > Add Attribute) to get powerful results as we will see next (Fig.02). To zeroOut an object you just have to: - Create an empty group. - Translate and rotate the group to the same position and rotation of your object (you can do this by creating a parentConstraint to snap the group to the object and then delete the constraint). - When they are both on top of each other, TIP (zeroOut): Notice this is not the same as freezing the transform (that aligns the object to the world). Keep the zeroOut process in mind, as it is the key to easily creating correctly oriented controls and we will be using it a lot in this chapter. parent the object to the group. - Voil, your object now has zero values without freezing and without losing its orientation. Transformations). But notice that when you freeze a control curve, its orientations will jump back to the worlds axis. Thats a problem. Most of the time we dont want to lose the controls orientation. Thats where we use the zeroOut process.

zeroOut
When creating our controls we must make them clean and simple, which means all controls by default cannot have any transform value. We can nullify these values by freezing the transformations (Any Mode > Modify > Freeze

Master Control
This will be our global control for the character rig. You can use the default circle or create a CV curve shaped like a character, it is up to you. Name this curve Master_ctrl and add one attribute named EXTRAS as the only displayable label for our attributes. All the curve controls we will be creating must be in a group inside of the Master_ctrl so the entire rig will behave properly (Fig.03).

www.3dcreativemag.com

page 85

Issue 059 July 2010

Chapter 4: Rig Creation Part 2

Introduction to Rigging

The Spine Rig


To create the spine rig we will build curve controllers for each joint to be driven with parentConstraints. Starting from the root_jnt up to the spineC_jnt, name them as hips_ctrl, spineA_ctrl, spineB_ctrl and spineC_ctrl and align them to the joints and zeroOut. Now parent the spine curves so they form a hierarchy (spineA > spineB > spineC) and finish by parenting the spineA_ctrl and the hips_ctrl under another curve called cog_ctrl. This will be our Center Of Gravity control, so we can move the entire spine using only one curve (Fig.04). To finish, create a group with these curves named controls_grp and parent it to the Master_ctrl. hierarchy by parenting the chins zeroOut group to the jaw curve, the jaws zeroOut group to the head curve, the heads zeroOut group to the neck curve and finally the necks zeroOut group to the spineC_ctrl created earlier (Fig.05). Start by duplicating the shoulder joint and renaming its _jnt suffix to _fk. Do the same for all its children joints. Repeat the process but now rename the suffixes as _ik. Delete the forearm and finger joints from the newly created _ik and _fk hierarchies. (You should end up with a four joint chain, starting on the shoulder and ending on the wrist) NOTE: The joints are separated for your better understanding - the chains must be exactly on top of each other. the arms, but the same technique can also be used for the legs.

Neck, Head and Jaw


Now lets create curves to control the neck, head, jaw and chin. To make it easier for the animators to see and select the controls, edit the components (control vertices) of the curves. We usually start with circles and first align them to their respective joints before remodeling to the desired shape. When you are done shaping, zeroOut each one of the curves, create parentConstraints to make the curves drive their respective joints and then put them in a

IK/FK Blend limbs


Sometimes animators need to use Forward Kinematics (FK) and Inverse Kinematics (IK) in the same scene. Luckily, we can blend these two techniques in our rig - bringing lots of advantages. At the first contact it can be a little complex, but do not worry, it gets easy when we understand the simple idea behind the concepts. We will only explain how to set up a blend for

www.3dcreativemag.com

page 86

Issue 059 July 2010

Introduction to Rigging Chapter 4: Rig Creation Part 2

TIP (duplicate_IK/FK): Renaming is simple using the Search and Replace Names command (Any Mode > Modify > Search and Replace Names...). Try to use it (Fig.06)! Now lets constrain all the joints on these three hierarchies. Follow these steps for each joint of the chain we want to blend:

Remember to do this only once for each joint in the _jnt chain; this will make our _jnt chain follow both the _ik and the _fk chains though the orientConstraint. If you move the joints around you will see that they follow both chains equally. We will now create an attribute to control these influences. For all limbs we will add a float attribute called

Go to the Hypergraph panel (Any Mode > Window > Hypergraph), create a reverseNode (in Hypergraph > Rendering > Create Render Node > Utilities tab > Reverse) and connect the blend attribute from the Master_ctrl curve on its inputX. Now, connect the outputX attribute of the reverseNode on all of the (IK-W1) of the orientConstraints. Look at the image sequence for a better comprehension (Fig.07). TIP (direct connections): Directly connecting attributes can be a cleaner alternative to driven keys or expressions, as they evaluate real-time and do not create animation curves.

- First select a _fk joint. - Add its corresponding _ik joint to the selection. - Finish by adding the corresponding _jnt joint and applying an orientConstraint (Animation > Constrain > Orient).

(limb)_ikFkBlend (for example: l_arm_ ikFkBlend for the left arm), with min value 0 and max value 1 to the Master_ctrl curve. Connect this attribute on every (FK-W0) of the orientConstraints we just created (the constraint nodes should be right under the _jnt joints).

www.3dcreativemag.com

page 87

Issue 059 July 2010

Chapter 4: Rig Creation Part 2


Do the same for the leg joints too, but do not do anything with the feet joints as we will take care of them further on.

Introduction to Rigging

IK handles creation
This is an important step. If you skip this, your IK chains will be useless! Now that we have created the chains we can create our ikHandles (Animation > Skeleton > IK Handle Tool) to get the inverse kinematics behaviour from our joints. - For the arms, create a rotate plane (ikRPsolver as the current solver) for both sides starting in the l_shoulder_ik joint and ending on the l_wrist_ik joint. - For the legs, create the rotate plane ikHandles starting in the l_leg_ik joint and ending on the l_ankle_ik joint. - For the feet, create two single chain solvers (ikSCsolver). One starting in the l_ankle_jnt and ending on the l_foot_jnt and the other one starting at the l_foot_jnt and ending at the l_foot_end. Name them as l_foot_ikh and l_toe_ikh. - Do this on the left and right sides of the limbs and feet. - Group all the ikHandles in a single group named ikHandles_grp.

Clavicle Control
Since the clavicle doesnt need to have an Ik to Fk blending, just create a simple curve oriented like the joint, zeroOut and parentConstraint the clavicle_jnt to your control on both sides like so (Fig.08). To finish, just parent the zeroOut groups of both clavicles to the spineC_ctrl.

and driving the correspondent joint with a parentConstraint. There will be three controls (shoulder, elbow and wrist) that must be parented to the clavicle controller. As for the IK chain, create only a control for the wrist (aligned and oriented to the wrist joint) that will orientConstraint it; also pointContraint the corresponding ikHandle of the limb to the controller. ZeroOut the curve and parent it to the controls_grp (Fig.09). TIP (ik/FK_visibility): You can set drivenKeys on joints and control visibilities when switching between IK and FK mode.

Arms Controls
To drive these two newly created chains, create controls as you wish - use the same process as the head/neck controls using zeroOuts to pseudo-freeze your controls. For the FK chain, create a control for each joint (except for the elbow, that will have only one control as we skip the second joint), parented hierarchically

www.3dcreativemag.com

page 88

Issue 059 July 2010

Introduction to Rigging Chapter 4: Rig Creation Part 2 Forearm Twist


To simulate our radius and ulna bones in the arms, we will use the l_forearm_jnt. Start by creating a curve to control the forearm twisting named as l_forearmTwist_ctrl and position it on top of the l_forearm_jnt. ParentConstraint the control to the lowElbow joint and lock and hide all of its attributes (ChannelBox > Channels > Lock and Hide Selected). We wont be animating its position; to keep our rig organized, put this control on the controls_grp. Ok, now lets do an expression to connect the forearm controls rotation X to drive the rotation X of the wrist joint. Add an attribute to the forearm control curve named autoRotateIntensity as float with min value 0, max value 1 and default value 0.5. Do this for the right arm joint too. Now, go to the Channel Box menu Edit and choose Expression. Another way to do this is by going to (Any Mode > Window > General Editor > Expression Editor). In this panel, write the expression below: l_forearm_jnt.rotateX = l_wrist_jnt.rotateX * l_forearmTwist_ctrl.autoRotateIntensity; r_forearm_jnt.rotateX = r_wrist_jnt.rotateX * r_forearmTwist_ctrl.autoRotateIntensity; (Fig.10). TIP (forearm_expression): Notice we are creating only one expression to control both forearm twists, so create the other side control before applying the expression to avoid errors! - Create a curve and snap its position and rotation as the same as the finger joint. - ZeroOut the curve to nullify transform values while still maintaining its orientated as the joint. - Now just constrain the respective joint to its curve and parent the base curves (that control the first joint of the finger) to the controls_grp; To make the finger curves follow the rig, when you have created the controls for one hand, group all of them and parentConstraint to the wrist_jnt so it is always following the hand, no matter the IK/FK blending (Fig.11). TIP (rig_Fingers): This process is easier to do using a MELscript, which we will cover in Chapter 6 of this tutorial. For each finger you should: If we need to control multiple fingers at the same time, we can create more groups above them and set driven keys.

Fingers
The simplest way to rig fingers is to create a curve for each one of the joints. Align and orient, zeroOut them in a hierarchy (like the spine controls) and then parentConstraint the joint to the corresponding curve.

Legs Controls
Ok, now that the arms are complete, lets quickly create the legs controls. Its the same process except for the IK control - you might want to orient it to the world (with just a little bit offset on the Y axis to follow the foot angle) so that the translate Y of the controller is facing upwards. (Fig.12)

www.3dcreativemag.com

page 89

Issue 059 July 2010

Chapter 4: Rig Creation Part 2


The FK controls go parented in the hips_ctrl and the IK controls in the controls_grp. Also do not forget to pointConstraint the legs ikHandles to the IK controllers, but do not create the orientConstraint to the ankle joint because the foot does not work like the hand.

Introduction to Rigging

Reverse Foot
Sometimes we must think beyond the real anatomy because movements in real world are very complex and difficult to reproduce in 3D. That is why we must fake some processes: lets take a look at the Reverse Foot setup that is used to get good foot control. Create a hierarchy of four joints, then rename and dispose them on top of the original foot chain, as in Fig.13 (start by the Base joint and end with the Ankle joint). The idea is to create an inverted chain that will drive the bones in the reverse order. To make our foot joints follow this new chain; just pointConstraint the l_foot_ikh we created earlier to the l_footReverseHeel_jxt. Before going on, lets create a control to move the toe independently, only one curve for both IK/FK modes named l_toe_ctrl. Create and align it to the toe joint then zeroOut. Parent the group to the controls_grp and parentConstraint it to the l_footReverseTip_jxt so it is always following the foot. ParentConstraint the l_toe_ikh to this control and now both our feet ikHandles are being controled. - Connect the reversed blending attribute Group the reverse joints we just created as l_footReverse_grp - this will act as our hand. (reverse_l_leg.outputX) to the feet ikHandles ikBlend attributes (l_foot_ikh.ikBlend only! ParentConstraint it to both the FK and IK foot controls, do not forget to also make the blending connections to switch who is driving the group accordingly. While youre at it, notice that the foot FK motion is still not completely right. To fix it, just follow these two steps for both feet:

www.3dcreativemag.com

page 90

Issue 059 July 2010

Introduction to Rigging Chapter 4: Rig Creation Part 2

Leave l_toe_ikh.ikBlend always as 1). - Now remember the ikHandles_grp? Group the scattered l_foot_ikh, l_toe_ikh and l_leg_ikh ikHandles into a group called l_foot_ ikh_grp and parentConstraint it to follow its corresponding reverse foot group - in this case, l_footReverse_grp. If you followed these steps correctly, when you rotate the reversed chain, the heel now raises without losing ground contact!

IK Twisting Controls
Now that we have created all of our IK controls, lets add an attribute to control the limbs orientations: the twist attribute. This little fellow will play the part of our polevector. As an attribute, there are less controls floating around and since it works in angles, not in translation aiming like the polevector,, it is much more intuitive and clean to animate. Ok, so create a float attribute on each arm and leg IK control, and make a direct connection to the twist attribute of their respective ikHandles. To finish, select those four ikHandles and in the channelBox, set their polevector X, Y and Z values to zero - this will free the movement, reducing the flipping effect to almost none.

following the rig. We will see this is the next lesson! For now, you can group these and parentConstraint to the head joint. Phew! We have come to the end of this extensive lesson and now you can almost say your character is fully rigged and ready to be animated! Now, how about giving him more emotion through facial expressions? Thats what we are going to study in our next lesson. Until then, practice what you have learned in this lesson - how about trying to come up with a solution for an automatic clavicle setup using Constraints, Expressions and Set Driven Keys!

Reverse Foot Attributes


Lets add float attributes without min and max values to the foot IK controller, which will drive the rotation of the respective reverse foot joints for the animators to use. Lets name them: Raise Tip, Swivel Tip, Raise Heel, Swivel Heel, Raise Foot and Swivel Foot. The connections are always the same. Connect the attribute to the corresponding joint using the Connection Editor panel (Any Mode > Window > General Editors > Connection Editor). For example (Fig.14): Raise Tip > footReverseTip_jxt.rotateZ Swivel Tip > footReverseTip_jxt.rotateY Raise Heel > footReverseHeel_jxt.rotateZ Swivel Heel > footReverseHeel_jxt.rotateY

Richard Kazuo & Danilo Pinheiro


For more from these artists visit: http://riggerman.animationblogspot.com/ http://nilouco.blogspot.com Or contact: richardyzo@gmail.com nilouco@gmail.com

Wrapping Up
To finish our entire rig, group the root_jnt, l_footReverse_grp and r_footReverse_grp as joints_grp and parent this group and the ikHandles_grp to the Master_ctrl. You can hide these two groups, leaving only the geometry and the controls visible - and now our setup is also scalable! You will notice the eyes and teeth are still not

- Free Models
This download includes The Models Used Within This Tutorial

www.3dcreativemag.com

page 91

Issue 059 July 2010

Chapter 1 | April Issue 056


Planning your Rig

Chapter 2 | May Issue 057


Knowing your Tools

Chapter 3 | June Issue 058


Rig Creation Part 1

Chapter 4 | July Issue 059


Rig Creation Part 2

Chapter 5 | This Issue


Facial Rigging

Chapter 6 | Next Issue


Scripting

The aim of these tutorials is to show and explain how you might tackle rigging your 3D character for animation. These tutorials will give help and advice to novices and experts who are looking to build on their rigging skills or approach rigging for the first time. The series gives a detailed step by step guide as to how to approach rigging but also shows us how to tackle common problems and issues that regularly occur even in a professional environment. The artists will be reflecting on working in the industry as well as talking us through their individual approaches to creating the best rigs possible.

- Free Models
This download includes The Models Used Within This Tutorial

Introduction to Rigging Chapter 5: Facial Rigging Introduction to Rigging: 5 - Facial Rigging


Software used: Maya be difficult to achieve some facial expressions using any other deformer. TIP (blendShape target editing) = Remember to never freeze the transformations of your copies, otherwise they will offset the overall position of the mesh when deformed.

Chapter Overview
In this chapter, we will learn how to build a simple yet powerful facial rig. We will explain how to do facial expressions using blending shapes and get more advanced results using joints for local deformations of the face. It is easy and fun (Fig.01).

Facial Blend Shapes


Please try to make your rig as simple as possible as we can get pretty good results for facial animation using only basic blend shapes and combining some of them (hence, the blending). To help you build a good blend shape system look at the images in this chapter. There are a lot of ways to modify your original model to create your blend shape targets, so feel free to use the Deformation tools you want because there is not only one way to do this. These are the main targets for a simple facial rigging (Fig.02).

Blendshape theory
Sometimes deforming meshes by just painting influences can be tiring and time consuming. Instead we can model the desired deformation and then apply it to our mesh using the blendShape deformer. By duplicating our model and deforming it using any modeling tool, we have the ability to make these deformations show up whenever we want by applying them as blendShape targets. To create a blendShape deformer, select two meshes that have the same topology (same number and order of points - do this by duplicating the geometry), edit the copy as desired and then select it and the original model (in this order) and go to (Animation > Create Deformers > Blend Shape). You will get a blendShape deformer with an attribute that does the transition from one geometry to another; you decide how much influence to use in the channelBox. This works pretty much the same as joint skinning. Each point has a starting position (the default mesh) and an end position that is weighted by an envelope multiplier. You can even create exaggerated deformations or input negative values if you need, just take care not to overuse this feature and get ugly deformations. The blendShape technique is widely used for facial rigging for its speed and for when it would

www.3dcreativemag.com

page 87

Issue 060 August 2010

Chapter 5: Facial Rigging


TIP (get blendShapes) = Use deformers like clusters and lattices or simply move, rotate and scale vertices, edges or faces to get the blend shapes. You can also select the model and press the 3 keyboard key to make it smoother and easy to see the final result of your blendShapes. Try it (Fig.03).

Introduction to Rigging

Modeling the targets


We usually model the blendShape targets using the Move tool with the Soft Selection and Reflection options turned on to edit vertices. Hold the B button and drag on the viewport to change the radius of this manipulator (Fig.04). TIP (model blendShapes) = You can also model the targets using another modeling software other than Maya; just make sure you export and import the mesh correctly without changing its position and point order. will not be affected by the deformer. Duplicate the tempToBS and rename it as mouth_LSmile, if you painted the right side of the smile target as zero, for example. Flood paint the entire mesh as value 1 again and then paint the other side off; Duplicate the mesh as mouth_RSmile; Repeat this process for all sliders you may think useful. The List of Input Operations window will be Do not forget to delete the tempToBS copy after getting all the sided targets (Fig.05). opened. To edit that order click and drag the middle mouse button in the name of the deformer and release the button below another node. The Blend Shape node must be below the Skin Cluster node! Do this process if you forget to turn the Front of Chain on while creating your blendShape deformer (Fig.06). TIP (inputOrder) = Now, it is really very important to know what sequential order of input deformers are been applied in the character model. Depending on how the order is input we can have problems, so verify this with care. We can change this order by right-clicking and holding the right mouse button over the model and selecting Inputs > All Inputs...

Breaking the symmetry


Usually we create perfect symmetrical deformations, and sometimes we need to have them separated by left and right sides to break this symmetric feeling. To do this easily, duplicate the original model and rename it as a temporary copy like tempToBS. Apply all blend shapes created on this new temporary copy by selecting all of them first and then the tempToBS geometry. Finish by creating the blendShape deformer. Look at the Blend Shape Editor (Any Mode > Window > Animation Editors > Blend Shape) to see sliders that you can use to control the intensity of each blend shape respectively. Now, when you select the tempToBS copy and use the Paint Blend Shape Weight tool (Animation > Edit Deformers > Paint Blend Shape Weights tool) you are able to choose what regions of the mesh will receive the deformation from the blend shape. This is what we are going to do to separate the sides: Set value 0 for the desired blend shape slider and paint one side off - the side that

Wrapping up
The process of creating blendShapes can be made parallel with the body rigging and then brought together at this point. Our next step is to associate the modeled targets to the rigged model. Lets do this by selecting all blend shape targets and lastly select the rigged model geometry (ett_body_geo) and apply the blendShape deformer using the command (Animation > Create Deformers > Blend Shape), we usually use it with Check Topology turned off and in the Advanced configuration tab of the deformer, use Front of Chain as the Deformation Order.

www.3dcreativemag.com

page 88

Issue 060 August 2010

Introduction to Rigging Chapter 5: Facial Rigging

Creating controls for the targets


Finally we can create sliders as controls for your blend shapes. These sliders can control single or multiple channels and have horizontal (X) and/or vertical (Y) freedom to be used. Create a nurbs circle (Any Mode > Create > NURBS Primitives > Circle), and in the nurbs create history modify the Degree attribute to Linear, Section to 4, Normal Y to 0 and Normal Z as 1, then rotate the circle 45 in Z axis and delete the history (Any Mode > Edit > Delete by type > History). We can now use this circle as a boundary background of our slider. Remember to edit its vertices to obtain a space delimiter for the slider, shape it like a box and turn on the Template option box in Object Display of the nurbsCircleShape node and rename it as *_sld_bg. Now create a nurbs circle, rename it as *_sld_ ctrl, limit its translation X and Z to zero and the translate Y to min 0 and max 1. This object will be a vertical and unilateral slider. If you want to create a square control, limit the translate X to min -1 and max 1. Usually, we position these sliders on the top of the head and group them as a child of the head_ctrl. In the end, create simple texts (Any Mode > Create > Text) to label this sliders (Fig.07). To connect this slider to the blend shape, you can use setDrivenKeys (Animation > Animate > Set Driven Key > Set) or maybe direct connecting attributes (Any Mode > Window > General Editors > Connection Editor) (Fig.08).

www.3dcreativemag.com

page 89

Issue 060 August 2010

Chapter 5: Facial Rigging

Introduction to Rigging

Facial Joints
If you need more control over a specific facial area of your character you can create joints to do this. Start by creating a single joint at the origin of the scene (Animation > Skeleton > Joint Tool); you can do this by holding the X key to snap on the grid, clicking at the center and pressing Enter. Create a nurbs curve to be the control of this joint and scaleConstraint and parentConstraint the joint to it. Group the control and move it to the desired position on the face snapping to points holding the V key of the keyboard. Repeat these steps for additional joints and do not forget to name them properly (Fig.09). To make the controls follow the head lets group these control groups and parentConstraint them to the head joint, jaw joint or another part to the facial rig. Remember to put this group under controls_grp to keep our scene clean and organized. Do the same to the joints we just created, group them and parent under joints_grp. Now, to deform the face with these new joints we need to add them as an influence of the skinned geometry mesh. So, select all the facial joints and the character model (face) and add the influences (Animation > Skin > Edit Smooth Skin > Add Influence). You can now paint the skin influences of the facial joints using (Animation > Skin > Edit Smooth Skin > Paint Skin Weights tool) and getting the values from the head and jaw joints (Fig.10). on the chin joint. Skin these joints to the tongue geometry and create nurbs curves shapes parented to the chin_ctrl to control these joints. It is really simple (Fig.11).

Teeth
The rigging of teeth is just geometries in groups that will receive parentConstraints by curves following the head_ctrl (for the upTooth) and to the chin_ctrl (for lowTooth).

Tongue
You can rig a simple tongue by creating three joints and parenting them

www.3dcreativemag.com

page 90

Issue 060 August 2010

Introduction to Rigging Chapter 5: Facial Rigging

Eyes
Animators prefer eyes that aim towards a look at control for characters. So what we do is create two circles, one in front of each eye, and create another one as a father of these so we can move the two eyes together. After that, we just create aimConstraints selecting the eye controls and lastly the eye geometry group and choosing the command (Animation Mode >> Constrain > Aim).

Lets create two layers to further organize things: One for the characters geometry called ett_L_geo - you can put this layer in reference mode so the animators do not accidentally select the mesh; And another one for the character controls called ett_L_ctrl - you can put the entire controls_grp in this layer. If you followed our organization correctly, just

back to where you still understand what you are doing and continue. This is the key to learning while having fun and without frustrations. We hope you liked these lessons and got motivated to study even more! See you in the next chapter, where we will take a look into scripting - something every hardcore rigger should know to help speed and efficiency in any kind of production.

Finally, the last thing to do is to group the eye_ctrl named as eye_ctrl_grp and parent it to the head_ctrl. Please remember the eye geometries must be in a group that is parentContrained and scaleConstrained to the head_ctrl (Fig.12).

hide the joints_grp to make all the joints unreachable. It is simple as that.

Richard Kazuo & Danilo Pinheiro


For more from these artists visit: http://riggerman.animationblogspot.com/ http://nilouco.blogspot.com Or contact them at: richardyzo@gmail.com nilouco@gmail.com

Conclusion
All right! We pretty much reached the end of the rigging part of our series as the next chapter will only cover scripting, so make sure to leave nothing behind! Remember to always keep things simple and organized. Build up your understanding of the basics and try to come up with more complex solutions little by little. If you get mixed up, go

Wrapping up
We have come to the end of our rig. Everything is working nicely and now we just have to hide some things from the animators to avoid them moving and keyframing what they are not supposed to.

- Free Models
This download includes The Models Used Within This Tutorial

www.3dcreativemag.com

page 91

Issue 060 August 2010

Chapter 1 | April Issue 056


Planning your Rig

Chapter 2 | May Issue 057


Knowing your Tools

Chapter 3 | June Issue 058


Rig Creation Part 1

Chapter 4 | July Issue 059


Rig Creation Part 2

Chapter 5 | August Issue 060


Facial Rigging

Chapter 6 | This Issue


Scripting

The aim of these tutorials is to show and explain how you might tackle rigging your 3D character for animation. These tutorials will give help and advice to novices and experts who are looking to build on their rigging skills or approach rigging for the first time. The series gives a detailed step by step guide as to how to approach rigging but also shows us how to tackle common problems and issues that regularly occur even in a professional environment. The artists will be reflecting on working in the industry as well as talking us through their individual approaches to creating the best rigs possible.

Introduction to Rigging Chapter 6: Scripting Introduction to Rigging: 6 - Scripting


Software used: Maya

Chapter Overview
In this last chapter we will look at scripting for Maya. Even if you are an animator or modeler, knowing a little about scripting can help you in ways you could never imagine! We can identify the best cases for using scripting by analyzing when you repeat certain tasks, like keyframing sets of controllers or duplicating meshes for symmetry modeling. In rigging this can also be used, but in larger scales. Good examples are the automation of the creation of rigs that are always set up in the same manner, like a reverse foot or when you need to constrain a large quantity of objects while maintaining a certain set of rules.

The Script Editor


So lets get started. This window will be your best friend when it comes to scripting! Open it up by accessing (Any Mode > Window > General Editors > Script Editor). Maya (version 8.5 or higher) comes with MEL (Maya Embedded Language) and Python scripting languages; you can choose which one to use in the script editor. While MEL is better integrated with Maya, Python has the advantage of being a language that is widely used in CG softwares and thus makes it very efficient in cross-program scripts and in code reuse. For simplicity, we will use MEL script in our examples (Fig.01). TIP (info on any Maya command) = If you ever need to know what a command does or what flags it expects, just hit F1 to see Mayas help documents. Go to Technical Documentation > Commands (or CommandsPython) to see all available commands. Or you can use the Quick Help function on the Script Editors window. Just highlight the desired command on the script editor, right click it to open up a Marking Menu and select Quick Help (Fig.02). So basically, whatever you do while working in Maya will be logged as a command in the Script Editor. That means whenever you need to do repetitive tasks you can run a line of code multiple times and there are functions that will TIP (using variables) = Remember to always declare (create) your variables before using them. You can create your own variable names, If you did everything correctly, a sphere by the name of ball will be created. Try to assign another value for the $sphereName variable and run the script again! Open up the Script Editor Type in: string $sphereName = ball; Press Control+Enter on your keyboard to execute and then type: sphere -name $sphereName; For instance, lets create a nurbs sphere by typing sphere into the MEL tab in the script editor and then pressing the Ctrl+Enter keys on the keyboard - this will run your command and create the sphere. Now, lets use a flag to pass a parameter to the command. Type in sphere -radius 10 and see what happens! help you to do different things each time the command is used.

Variables
To help us make things dynamic, the variables exist. Variables store information that we can use in programming and as the name says, their value can vary. Lets create and use a variable to better understand the concept:

Scripting Theory
To start understanding how scripting works in Maya, you can think about it this way: Everything you do in Maya by clicking with your mouse is actually a shortcut to a command. That command is logged into the script editor window where you can see it, copy and most of the times run it again, changing parameters (we call them flags) if needed.

www.3dcreativemag.com

page 69

Issue 061 September 2010

Chapter 6: Scripting
just do not forget to use the dollar sign ($) at the start of its name! For example: $myName, $numberOfJoints, $currentFrame, etc... (Fig.03) 3. Finally the float variables, that are also used only for numbers, but contain only fractional numbers like 1.0, 3.96, -560.34 and so on. TIP (casting variables) = You can force some variables to show as another type by casting. You do this by writing the wanted data type name and then enclosing a variable or value in parenthesis right after that. Try writing print (int(4.5)); in the script editor.

Introduction to Rigging
create an integer array, you cannot populate it with a string or a float number. To store and access data to the array you work with an index identifier, pretty much like an unique number in a queue; the order the elements that are being stored in the array is the order you will call it later (please remember that array indexes always starts at zero!). Do not worry about this now, things will get clear when we put it into practice. To create an array, just put a pair of square brackets after the data type. For example: string $names[], int $numbers[], float $decimals[], etc. To populate arrays use a pair of braces encapsulating your data and separate them with commas, like so: string $names[] = {Julie, Florence, Yuki}; int $numbers[] = {1, -2, 4, -8}, float $decimals[] = {1.34, 5.0005, -0.4498}, etc.

Variable Data Types


There are lots of variable types in MEL; they exist to categorize data so the script does not try to perform any operation using variables that Maya cannot understand or execute. For example, you can subtract numbers, but can you subtract letters? As there are several data types, we will be only be looking at three in this tutorial: 1. We just declared $sphereName as a string variable - this kind of variable can contain any text, including numbers, white spaces and special characters like a tab or a return line; 2. There is also the int variables that are used for numbers and can only contain whole, non-decimal numbers like 1, 2, 4, 180, -30, and so on;

Arrays
Sometimes we need to deal with a large amount of data and using lots of variables can be troublesome. For these cases there is a different variable type with the ability to easily organize, access and manipulate data. They are called arrays. A single array can contain multiple strings, integers, vectors, you name it - but only one type of data at a time. That means if you

Loops
Now that you know the basics about variables and arrays, lets take a look at loops. Loops, as the name suggests, are used to repeatedly execute a piece of code several times. Combine this with the power of an array and you will get yourself a new best friend! For a simple introduction, lets execute this for loop, like so: int $numberArray[] = {1,2,3,4,5}; for ($i in $numberArray) { print $i; }; You will get the following result: 12345. Simple, right? You must be wondering about that $i variable over there... its simply our index variable. You can name it as you wish and you dont need to declare it before entering the loop (unless you want to keep track of its last value). So, every time the code between the braces finish it goes back to the top, gets the next data value in queue and repeats all over

www.3dcreativemag.com

page 70

Issue 061 September 2010

Introduction to Rigging Chapter 6: Scripting


again, changing the value of the $i variable dynamically. To understand, take a look at this next piece of code that is a bit more complex: string $namesArray[] = {John Doe, Dude, Bob}; for ($name in $namesArray) { print (Hello! My name is + $name + . Nice to meet you!\n); }; TIP (printing to a new line) = Notice the \n at the end of the print string. That is a special character used in strings that makes Maya continue printing in a new line to prevent concatenation, as happened in our first numberArray example. Other special characters include \t for tabbing and \b to create a nice little... bullet thingy (Fig.04).

Conditionals
Ok, so far we can work on really simple and repetitive scripts. But what if you need something more complex like adding some choice-making to them? Meet the conditionals. Conditionals allow your code to choose how to act based on any rule you write - better than that, they prevent your scripts from breaking or even your software from crashing, just by checking if certain conditions are met. If not, you can make the action cease and display an error message or even continue through another route. For instance: string $selectedObjects[] = `ls -sl`; if (`objectType $selectedObjects[0]` == joint ){ print You have selected a joint! As a prize, you win a polyCube!\n; polyCube; } else { print There is no joint selected! Bad, bad user!\n; } Now take a look at this other kind of conditional which can be very useful: TIP (capturing return values) = Notice the grave accent (`) symbols surrounding the ls command of the first conditional example. In MEL they are used to indicate that you want to get and use the return value(s) of that command. In other words, every object name that is listed using the ls -sl command will be automatically put inside the $selectedObjects When run, this code creates five spheres on top of each other. The while conditional also works as a loop - in this case, the conditional worked as a counter since at the end of every iteration, it was checking to see if the statement was still true. When its not true anymore, the loop stops running. }; int $numberOfSpheres = 5; int $i = 0; while ($i < $numberOfSpheres){ sphere; $i++; NOTE: Its important that you declare the variable that will capture the return value(s) as the right data type, otherwise you may get a data type error. Check the Maya Commands reference to see the expected return type for each function. array that we can use later in a loop, for instance.

Procedures
When your script starts to get bigger, it also starts to get troublesome to edit variables whenever you need to debug it. Using procedures we can run several lines of code using a single command, easily feeding data to it at the same time. Some more features were added to our last script, take a look at the procedure below:

www.3dcreativemag.com

page 71

Issue 061 September 2010

Chapter 6: Scripting
proc createSpheres(string $sphereName, int $numberOfSpheres, float $positionOffset){ int $i = 0; while ($i < $numberOfSpheres){ sphere -name ($sphereName + ($i+1) ); setAttr .translateX ($positionOffset*$i); $i++; }; }; After running the code above, nothing will happen. That is because we only declared the createSphere command. Lets run it by typing: createSpheres(ball, 5, 3); You will notice five spheres with the name ball were created separated by the same amount of units we wrote as the $positionOffset value. Much easier, right? Its like creating your own commands and defining your own flags (Fig.05). NOTE: In the rest of the chapter we will look at a couple of scripts and try to explain how they work as much as possible. Until now we have only seen the tools you can use to accomplish certain tasks. But like in real life you can use tools the way you want to build anything and most of the times there is not only one way to do things. So keep in mind you can (and must) change whatever you see fit in the code in order to experiment and understand. Remember! Your best friend in any situation is the Maya Commands Help documents, accessible by pressing F1 inside Maya. If you get stuck in a tricky part, try searching for similar scripts on the internet and learn by looking at other peoples code. Now lets create our zeroOut group - since we cannot set its position and orientation at creation, lets just give it a name. The same as the object, but with a suffix: string $zeroOutGroup = `group -name ($selectedObjects[0] + _grp)`; The only way to get the selected object in Maya is by using the ls -sl command, so lets use it! Since it returns an array, we should capture the results as so: string $selectedObjects[] = `ls -sl`; Lets see this line by line. } TIP (comments) = You can comment lines in your script so it is easier to organize and debug; just add two slash (//) symbols at the beginning proc zeroOut(){ //get the object //create the group and name it //snap the groups position to the object //parent the object to the group creating our procedure with pseudo-code, so that we have a good guideline to follow:

Introduction to Rigging

string $selectedObjects[] = `ls -sl`; string $zeroOutGroup = `group -empty -name ($selectedObjects[0] + _grp)`; string $constraint[] = `parentConstraint $selectedObjects[0] $zeroOutGroup`; delete $constraint; parent $selectedObjects[0] $zeroOutGroup; } Ta-daaa! To test it, select any object and type zeroOut at the command line!

of a commented line. To comment multiple lines, use a slash with an asterisk (/*) to start the comment and an asterisk with a slash to end the comment (*/).

The Create Finger Controls Procedure


Going a bit further in complexity, with all this brilliant knowledge we have seen so far, we can create a MEL script to automate the rigging process of fingers controls, so lets code: // declare variables: string $mirror[] = {l_, r_}; string $jointNames[] = {thumb, index, middle, ring}; string $hierarchy[] = {A, B, C}; // run loops to create curve controls:

With our group created, we need to snap the position and orientation of the group to be the same as the object. The easiest way is to parentConstraint it (then get rid of the constraint): string $constraint = `parentConstraint $selectedObjects[0] $zeroOutGroup`; delete $constraint; And now, for the finishing touch: parent $selectedObjects[0] $zeroOutGroup; Put it all together in order and you should get: proc zeroOut(){

for ($side in $mirror) { for ($jntName in $jointNames) { for ($hier in $hierarchy) { string $control[] = `circle -ch off -r 0.4 -nr 1 0 0 -d 1 -name ($side+$jntName+$hier+_ ctrl)`; parentConstraint -name tempToDelete ($side+$jntName+$hier+_jnt) $control[0]; delete tempToDelete; select -r $control[0]; zeroOut(); // call zeroOut procedure // control joints by control curves: parentConstraint $control[0] ($side+$jntName+$hier+_jnt);

The ZeroOut Procedure


Alright! Now lets test some of our gained knowledge to create a script! Something simple and yet very, very useful... a zeroOut procedure. Ok, so what we need is to create a group to zero all the transformations of any selected object without moving its location. Lets start by

www.3dcreativemag.com

page 72

Issue 061 September 2010

Introduction to Rigging Chapter 6: Scripting


}; // parent curve controls in hierarchy: parent ($side+$jntName+B_ctrl_grp) ($side+$jntName+A_ctrl); parent ($side+$jntName+C_ctrl_grp) ($side+$jntName+B_ctrl); }; // put all inside a control group: group -n ($side+hand_fingerControls_grp) ($side+thumbA_ctrl_grp) ($side+indexA_ctrl_ grp) ($side+middleA_ctrl_grp) ($side+ringA_ ctrl_grp); }; (Fig.06) To run this code, you have to create all the necessary joints, like l_thumbA_jnt, l_thumbB_jnt, l_thumbC_jnt, l_indexA_jnt, and so on... Some interesting things to notice in this code are: TIP (your first steps on automatic rigging) = this code can be put into a procedure to be called inside an automatic rigging solution! Versatility is the key! Take for example Danilo Pinheiros Auto Rig script, this tool can rig a character like the ETotal in less than an hour! (Fig.07) Like we continuously repeated across our lessons, this is only the start of your rigging studies. Keep up the rhythm and do not forget to always think about the reasons why you are doing something. Try to always be organized and simple - do not follow tutorials blindly. And last but not least, try to always have fun while you are at it - it is the key to learn faster and better! Danilo and Richard signing off now, see you next time! The code is limited to four fingers in the $jntNames array and three joints (A, B and C) on the $hierarchy array. Can you make it work with more joints and fingers? A tip: store the controls names in an extra array. Three nested loops: that creates even shorter code! The script for the left and right sides is the same, so why not run everything twice only changing the prefix? We declared arrays at the start of the code to loop over them - imagine writing the same code over and over for each joint, it would be a waste of effort and a lot harder to debug.

The End
In the next chapt.. wait a minute. This is the end of the Maya Introduction to Rigging Series! Well, we hope that you enjoyed it and learned a lot, because we sure did! Our concern was to create good lessons (not too simple and not too complex) that could get anyone started on rigging: a fun and rewarding experience!

Richard Kazuo & Danilo Pinheiro


For more from these artists visit: http://riggerman.animationblogspot.com/ http://nilouco.blogspot.com Or contact them at: richardyzo@gmail.com nilouco@gmail.com

www.3dcreativemag.com

page 73

Issue 061 September 2010

You might also like