Tuesday, March 04, 2008

Rigging an Arm and the Palm

The basics
Hi to all, its satyajit aka metalloid again. Today I am going to tell you how to setup a human arm and how to hook it up with the custom controllers. To start lets first talk something about the hierarchy, what does this “hierarchy” mean? To tell you it simply means a chain, you all must have seen a chain u pull one of its pieces and the whole things follows well the hierarchy is somewhat similar, you see your family tree for example, you will see branches, just imagine it you move your grand parents, the whole thing beneath it follows but yr great grand parents don’t they’ll stay in place, this is a hierarchy. Take the case of workers in office, there is a President then a VP then Managers then employees, this is another hierarchy. A hierarchy basically means a setup that has a flow in a specific direction and a governance policy that controls the subordinate entities of the hierarchy. Now lets talk in terms of animation a hierarchy is a simple collection of objects in a parent child relationship in which the child object is bound to follow the parent object and yet have its own movements and rotations but if the parent moves/rotates/scales it will make the child follow in equal proportions.
Let’s move on a bit further in our expedition and talk about kinematics. What the hell? One more jargon? Are u nuts? No friends I am not, its not all that difficult to understand and its important too for rigging, ok so what is kinematics? it means the study of motion or here we refer it to as motion. You must have seen a lot of things moving around you, if not then go to a place called the “ROAD” there you will find ample examples. So when a body or an object is moving it has a certain energy called “KINETIC ENERGY(KE)” and when you lift an object up against gravity the energy it possess is called “POTENTIAL ENERGY(PE)”, but the catch here is that the sum total of KE and PE is always a constant in any moving object. Or if we put it in a equation KE+PE=Constant and by the way which in English means as the kinetic energy increases the potential energy decreases and vice versa. The best example to illustrate this example is a pendulum. When it reaches the ends its speed (KE) is minimum and the PE is maximum and in the centre when its speed (ke) is maximum and the pe is minimum.
Remember as the KE increases the PE decreases and vice versa.
Now you all must be wondering why I told you all this, actually I was preparing you for what’s about to come. It’s time to get nasty, get ready. When we talk about hierarchy it brings in the concept of IK(inverse kinematics) and FK(forward kinematics). Look at a human body, its bone structure is divided into 6 main segments or partitions: The spine, the hands, the limbs and the neck+head. Suppose you suspend a human by his spine and move him, when you move the spine the whole thing follows, this is FK. Tie the hands to another pole and then move, you’ll see that the hand is fixed there and is not following when the spine is moved and yet its position in the bone hierarchy is below than the collar bone or the humorous bone, this is IK. In English it means “if the parent is moved and the child follows this kind of setups is called an FK setup” and “if the parent is moved and the child does not follow then its IK setup. I hope you all have understood a little of ik and fk, and if you didn’t don’t worry, you’ll get plenty of practical to do.



The Prerequisites
Now coming to the hand setup, I suppose that you all are familiar to 3DS max interface and rigging tools. Without wasting anymore time I am getting to the nitty gritty of rigging. Go to the motion panel rollout or under the animation menu you’ll find bones, click it and press the “Create bone” button. Create a couple of bones in the hierarchy like shown in the figure below and be sure to rename the bones properly. And remember this thing very carefully always start and end the creation of a bone chain in one viewport only, never start creating the bone chain in one viewport and finish it in another, of course when you intend to use that chain as an ik setup for ik create the chain however it pleases you, show your creativity and make a design (mess :D). You’ll have to take this precaution because the ik works in a plane like XY, XZ or YZ suppose if you create a bone in top viewport with a bend that bend will be used by the ik solver to calculate. There is one more thing that you need to understand about the bones. Every intersection of bones is called a joint and a joint can either be a “Ball joint” or a “Hinge joint”, understand the difference, a ball joint can rotate in all the axis but a hinge joint can rotate in only one axis. For example some hinge joints in body: the shoulder, neck, wrist, pelvis, ankle and some hinge joints: the ankle, the knee, the knuckles of fingers. You know what does it mean when a hinge joint starts rotating in more than one axis, guess……….., it means its time to see the doctor, you have a broken bone in your body, just kidding. But remember never create bones in multiple viewports when you intend to use them in an IK setup.

The Nitty Gritty
Create this setup



Add an HI IK from the upper bone to fore arm bone this will make the hand go to and fro, the next fig will show the full bone setup.


Here you are seeing the yellow colored bones these bones are called the twist bones. The fore arm bone will not be used in skinning the twist bones will be used for that. The twist of the twist bones will be like a gradient from the first to the last one, it would be like this the one close to the palm will rotate more than the one in the middle which in turn will rotate more than the one close to the elbow. Its pretty easy till this but what makes a good rig great is the flexibility that it provides. With this setup I can only a couple of gestures to the fingers. In order to do that we’ll have to modify the hierarchy, I’ll illustrate it in the next figure.


This is the modified hierarchy but the difference is hard to notice so take a look at the next fig.


This fig will illustrate my point in a much better way, watch the first from left hierarchy, just bones and now take a look at the other one, you’ll see the helpers(point) between successive bones it gives us one more transform node to work with. Now you can wire these helpers the way you fell like and if you want one more gesture add another set of helpers (transformation nodes) above these, this way you’ll get 3 transform nodes to work with, it means three different gestures.
I hope that this much is clear, next we’ll see how to make yr own interface i.e. u can add yr own custom controls e.g. rollouts, spinners, sliders, buttons, dropdown combos and lot of other things. First of all you’ll need to make a control node in which you will add all the custom attributes, but before you do that make sure that you add a modifier named “Attribute holder” this will give you an empty modifier without any input options or interface, its not compulsory to do you can even add attributes on objects base level but that will make it a little messy, all the predefined attributes and the custom attributes at the same place but it wont effect the functionality of the attributes, its just a an organization method, just to make the work area look clean. Next I’ll tell you the commands:


To add a custom attribute you first need to declare the attributes, its more like a collection of parameters which will provide the variables or the values to hook up our scene objects.

To define a custom attribute a variable is needed that we will later add to the object’s modifier
Syntax:

=attributes
(
parameters rollout:
(
param1 type:# ui:(,…)
param2 type:# ui:(,…)
.
.
.
)
rollout “Rollout Tag”
(
ui
ui
.
.
.
)
)

Now to add this created custom attribute type the following line and before this select the object you want to add the custom attribute to:
$ symbol indicates the selected object and when more than one object is selected the objects can be accessed as $[1], $[2], $[3]….$[n], it depends upon the selection order. Suppose you have 5 boxes in the scene named as box1, box2…box5 and you selected them in the order box5, box3, box4, box2 and box1, now when you type $[2] and hit enter it’ll return “box3” and when you hit $[4] it’ll return “box2” and so on. I hope this is enough to illustrate the $ thing.

Here: $[1] = box5
$[2] = box3
$[3] = box4
$[4] = box2
$[5] = box1

The statement to add the created custom attribute to the selected object is:
custAttributes.add $.modifiers[1]


An example to illustrate the above code fragment:

clearListener()
cb=attributes footCon
(
parameters paraF rollout:rollF
(
toeR type:#angle ui:(fr_sp,fr_sl)
ballR type:#angle ui:(bj_sp,bj_sl)
toeW type:#angle ui:(tw_sp,tw_sl)
ffrt type:#angle ui:(ft_sp,ft_sl)

)
rollout rollF "Toe Control"
(
spinner fr_sp "" range:[0.00,45.00,0.00]
slider fr_sl "Toe Rotate" range:[00.00,45.00,0.00]

spinner bj_sp "" range:[0.00,45.00,0.00]
slider bj_sl "Ball Rotate" range:[00.00,45.00,0.00]

spinner tw_sp "" range:[0.00,45.00,0.00]
slider tw_sl "Toe Wiggle" range:[00.00,45.00,0.00]

spinner ft_sp "" range:[0.00,45.00,0.00]
slider ft_sl "Foot from Toe Rotate" range:[00.00,45.00,0.00]

)


)


custAttributes.add $.modifiers[1] cb
My work here is almost done, I have told you how to create and add custom attributes, how to modify the hierarchy to add one more pivot that you can hook up to another controller. If you use this technique wisely the opportunities are endless. You can make and do anything. Plus there is one more thing I need to tell you all, there is an attribute called the “pen attribute holder” and its available free over the Internet. Its just like attribute holder plus it has a great advantage, you can make poses of the controllers you create in the pen attribute holder and save them, this way you can just make a fist pose and save it and whenever you need to make the fist you wont have to tweak each and single controller just do it by activating the saved preset. This saves a hell lot of time. Anyway I leave it up to you to find and explore this. I wont tell you all, you also have to do something on your own but I’ll always be there to help and guide you but its you how have to walk the path, I can only point it out to you.
This a screenshot of custom created attributes for hands that I made.
this is how the custom attributes will look, cool isn’t it? Take my word for it, it will take you a little while to get through this but once you are, you’ll be happy.
Now only the part is left where I explain how to put all of this together to make a working rig.
I’ll just write the steps, follow these first to make the setup, once you are through fell free to use your creativity to modify and add to it. Its your imagination and imagination knows no boundary.

Steps:
  1. create the basic hand setup,
  2. create the twist bones,
  3. create the palm bone,
  4. create the fingers,
  5. select all the three palm bones and make them child to the fore arm bone
  6. modify the hierarchy of the fingers like the way I told you, insert helper in between and make sure to match the pivots of the helpers with that of the bone its parent of, first add just one helper, in later stages you may add as many as you feel needed, since its your first try so make it simple,
  7. link the bones to the helper to create the hierarchy shown in the schematic view fig,
  8. wire the desired rotations of the helpers to the other helpers, this way you will get the curl or whatever gestures you desire and yet the bones will be free to rotate. Here I need to elaborate more: understand this carefully when I inserted the helpers in the hierarchy there was a purpose behind it I did it so that I can wire the helpers instead of directly wiring the bones so that I have the bones transformations free, if I want one more gesture I can again modify the hierarchy by inserting more helpers and again wiring them with some other controller. This way I will have different gestures on the same bone chain and yet my bones will be free to transform. If you get through this point you have done it all, for the hand.

Well this is it, now you know everything to create the hand setup, my mail id is satyajit.das84@gmail.com feel free to contact me when in need, I’ll be more than happy to help. Rigging is not something that you can do as much as you want, once started you’ll have to see it through, you cant stop in between because until you get everything right; your model will not work properly and if you can do a little scripting then it’s a great advantage. It makes rigging lot easier and quick, doing things manually takes a lot of time and is also not precise because human beings make mistakes and that’s what makes them intelligent where as computers don’t make mistakes that’s why they are stupid. Make mistakes, lots of mistakes and learn from them but never repeat them. Always make new ones.

Defeat is a better teacher than victory.

See ya all until next time.
Take care
Happy rigging

1 comment:

Arvin said...

nice tips..keep updating..:)