Orienting joints

Orienting your joints is very important if you want to have your joints rotate in predictable ways. When you create a back for example you want all of the local axis to work in the same way so that all of the back joints will bend in the same direction when rotated.

1. Start by creating two joints. Go to the animation menu set. Skeleton->joint tool option make sure that create IK handle is unchecked.
2. For this example lets start with two joints. Create two joints by clicking in any view in two different places.
3. Go to the component mode and click on the question mark icon miscellaneous. This will make the local axis for the joints visible.(figure 1)
4. Switch back to object mode and then move the second joint you created. Switch back to component mode and notice that the local axis in no longer pointed at the second joint.(figure 2)
5. So we are going to change the local axis of this joint so that it points at the child joint. This is helpful because often times you don't place the joints in the correct place the first time and you want to be able to move the joints to where they work best. Once all of the joints are aligned correctly with one axis pointing up and the other pointing down to the next joint you will have a cleaner rig and then applying transformations to the skeleton like scaling becomes easy.
6. What you are going to do is make the second joint an aim constraint for the first joint. First upparent the second (child joint) from the first one so there is no longer a joint connecting the two joint nodes.
7. Create a locator and snap it to the first joint (hit w for the move tool then middle mouse drag while holding the v tool to point snap it to the joint) Move the locator in the y direction only so that it is directly above the first joint (parent or root joint) See figure 3.
8. Now you are going to reset the orientations on the parent joint. Open the Attribute editor and make sure that under transform attributes the rotate transforms are all 0 0 0 and that under joint the joint orientation are set to 0 0 0.
9. Select the two joints (child first and then the parent). Select the create aim constraint dialog box and match the selections in figure 4. You are going to want the up vector to be z and the aim vector to be y so set the vector to 0 1 0 for the aim and 0 0 1 for the up axis. There is no real reason for this just that you should keep them consistent throughout your work. You should see the joint has changed its orientation to point at the child joint. Select the joints and Go to Display -> component display -> local rotation axis. Now move the child joint around and watch the parent joint's local axis follow the child joint.
10. Go to the outline and remove the aim constraint. Delete the locator and re parent the child to the parent joint. Now open the attribute editor and copy the transform attributes for the rotate xyz to the joint orientation xyz and zero out the rotate transforms after copying them (setAttr joint1.jox 'getAttr joint1.rx' setAttr joint1.joy 'getAttr joint1.ry'; setAttr joint1.joz 'getAttr joint1.rz'; ). You now have an oriented joint, notice that the joint can be scaled by translating the child in the y direction.
11. This is time consuming so there is a script that you can run and use to quickly orient the joints. jsOrientJointUI.mel
Download these Mel scripts and place them in the "My Documents\maya\5.0\scripts" directory. These scripts will then be loaded when you start up maya and are necessary for these tutorials. If you have already done this in a different tutorial disregard these steps.

endName

jsChannelCtrl

jsConstObj

jsCreateCreature

jsDefineCreature

jsGetShape

jsListCreatures

jsMovIn

jsMovOut

jsOrientJoint

jsOrientJointUI

PickWalk

jsRenameWindow

jsRotateOrder

jsScaleJointsByCurve

jsUnlockTransforms

12. To show how the script works start by creating a collection of joints that could be a back bone(figure 5). Make sure that auto joint orient is being used (its xyz by default which works). Select the top of the hierarchy and go to Edit->select Hierarchy. This selects all of the joints. Rotate the joints just to see how they move. Notice that they do not all rotate the same way in a predictable fashion. This is because Maya's auto joint orient doesn't know which way is up for the joints. Make sure all of the joints are selected again and go to display->component display->local rotation axis. Notice that the axis flip as the joints curve.
13. Open the script in your script editor and run it by hitting cntl enter or the number pad enter. Type in jsOrientJointUI in the script editor window. This will open up a window with two buttons. Now select each joint of the backbone in turn and orient them so that the z axis points consistently throughout the back.