- Enhancing the IK Limb Controls
- Upgrading the Legs and Feet
- Creating Advanced Head and Torso Controls
Upgrading the Legs and Feet
You'll follow the same basic process just used for the advanced arm to create all the advanced rig controls for the leg and feet: node creation, hierarchy setup, connections, and channel cleaning. For the advanced leg controls, you should again add skeletons to the upper legs and knees to improve deformations when the limbs twist and bend. Simply apply the same setup and connection techniques as used on the upper arms. A new setup technique, however, will be shown for creating a rolling foot control, which will be useful whenever the character is animated to walk.
Adding Advanced IK Feet Controls
To upgrade the controls for the feet, you need to add locators and IK handles to the basic foot rig. Creating controls for rolling the foot through the heel, ball, and toe (otherwise known as a foot-roll rig), requires adding two new IK handles to each foot skeleton and inserting several group node pivots into the hierarchy.
To add an IK based foot-roll rig to the left FK foot skeleton:
- Begin by disconnecting the basic foot hierarchy. In the Hypergraph drag the left foot root and IK handle nodes with the middle mouse button onto an empty area. This detaches them from the left leg icon. It is a good idea to also detach the polygon foot bones from the parent foot joints, so they don't shift when you add IK to the skeleton.
- To add two IK solvers to the foot skeleton, choose Skeleton > IK Handle tool
, and make sure that the standard RP solver is selected in the options. The IK Handle tool is used to add IK to an existing FK skeleton. To add the first IK solver, in Right view, click the left-foot root followed by the ball joint. Name the resulting IK handle located at the ball of the foot lfBallIk.
- Add a second IK handle to the same skeleton by activating the tool again, and click the left-foot ball joint followed by the end joint. Name the resulting IK handle at the end of the foot lfToeIk. Notice that the two IK solvers have not overlapped, so there won't be any conflicts between the constraints. You'll parent the two IK handles under three new locators that will be used as the main pivots for the foot-roll rig.
- Choose Create > Locator to manually create each locator, and place them at the heel, ball, and toe of the foot. Use FIGURE 4.17 as a guide for placing the heel locator where the heel of the foot touches the ground, which is where the foot should pivot from when rolling backward, and for placing the other two locators on the ball and end joints. Name the locators lfHeelRoll, lfBallRoll, and lfToeRoll.
Figure 4.17 Place three main locators at the heel, ball of the foot, and toe to create the pivots for a rolling foot control.
- Parent the locators between the left leg icon and the foot skeleton in the following order: lfHeelRoll, lfToeRoll, and lfBallRoll. Parent the two new IK handles under the lfBallRoll locator, and parent the original leg IK handle under the lfToeRoll locator (see FIGURE 4.18). Make sure that you re-parent the polygon bones under the appropriate foot joints, and then rotate the locators to test out the controls.
Figure 4.18 Here is the hierarchy setup for the standard foot-roll control. The more advanced version on the example rig inserts more locators to create additional pivots for the foot.
- Repeat steps 1 through 5 of the process on the other foot. Mirroring a whole hierarchy can be problematic.
This foot-roll rig is a variation of the "reverse foot-roll" setup that has been common in the animation industry for many years. However, even though the foot-roll rig has all the controls needed to animate a rolling foot, it can be further enhanced by adding more locators or group nodes as pivots. For instance, you may have noticed that even though you have a pivot located at the ball of the foot, because of the way it is parented you cannot wiggle the toe joints. Instead, the toes stay still while the foot rotates upward, which is the direct result of the "reverse" parenting of the nodes.
Creating additional controls just involves thinking about how the three locators are moving, and then inserting new locators or group nodes to extend that movement. For instance, in addition to the standard pivots at the ankle and ball of the foot, try adding a pivot to rotate the foot at the outer edge. Some experimentation would show that such a node would need to be parented above the lfHeelRoll locator in the hierarchy, as would a node that will be used to rotate the foot at the ankle. On the other hand, a node that is intended to wiggle the toes should be inserted in the hierarchy below the lfToeRoll locator and above the left leg IK handle and left foot root joint.
Driving and Cleaning the IK Foot Controls
As with the advanced arm controls, the advanced leg controls must also be driven using math expressions, node connections, or SDKs. The foot-roll controls can be entirely driven by custom channels on the leg icon using SDKs. You'll create a custom channel named footroll to drive the three locators created in the last section. After driving the foot to roll, clean the leg icon by locking and hiding the scaling channels, and set the transform manipulator as default.
To drive the left foot-roll rig with SDKs:
- Create a custom channel on the leg icon by choosing Channels > Attributes > Add Attribute in the Channel Box. Set the limits for your footRoll channel to minimum –5 and maximum 10, with a default setting of 0.
- In the Set Driven Key dialog box, load the leg icon's custom footRoll channel as the driver, and load the lfHeelRoll locator's rotateX channel as the driven. Set two SDKs on the heel locator to roll backward about 35 degrees when the footRoll channel is manipulated from 0 to –5.
- Load the lfBallRoll locator, and drive its rotateX channel to rotate upward about 30 degrees when the footRoll channel is manipulated from 0 to 5.
- Move the footRoll channel to 10, and rotate the ball of the foot locator back down about 10 degrees to uncompress the foot. To complete the roll up onto the toes at 10 on the footRoll channel, load the lfToeRoll locator and set a driven key on the rotateX channel at about 30 degrees.
- To test the control, set the driver channel back to 0, and scrub the channel. You should see the foot roll back onto the heel at –5, up onto the ball of the foot at 5, and up onto the toe at 10 with a slight decompression at the ball (see FIGURE 4.19). Of course, if you added other pivots for the foot and toes to your foot controls, make sure that you create driver channels on the foot icon and drive those pivots as well.
Figure 4.19 Create custom channels to drive the foot-roll pivots, as well as other pivots on the advanced foot rig.
MEL Scripting the Advanced Controls
Writing MEL code for the advanced controls involves all the commands and techniques used in the basic scripts, plus new commands for connecting channels and editing attributes. You can find most of these commands by doing the rigging tasks in the interface, and then examining the history in the Script Editor. Remember to always look up new commands in the MEL Command Reference to streamline the code by using available flags. For instance, after connecting channels with SDKs in the interface, the code in the History field will contain many select, setAttr, and rotate commands as you manipulate the driver and driven channels. The code will look something like this:
select -r cm:lfArm_icon ; select -r cm:lfArmTurn_bindJt ; setDrivenKeyframe -currentDriver lfArm_icon.armTurn lfArmTurn_bindJt.rotateX; // 1 // select -r lfArm_icon ; setAttr "lfArm_icon.armTurn" 10; select -r lfArmTurn_bindJt ; rotate -r -os 36.379451 0 0 ; select -r lfArm_icon ; setDrivenKeyframe -currentDriver lfArm_icon.armTurn lfArmTurn_bindJt.rotateX; // 1 // setAttr "lfArm_icon.armTurn" -10; select -r lfArmTurn_bindJt ; rotate -r -os -115.024388 0 0 ; setDrivenKeyframe -currentDriver lfArm_icon.armTurn lfArmTurn_bindJt.rotateX; // 1 // select -r lfArm_icon ; setAttr "lfArm_icon.armTurn" 0; setAttr "lfArm_icon.armTurn" -10;
You can consolidate all of this code into three SDK commands simply by adding the flags to set the driver and driven values, which is –dv, or driver value, and –v, or value (which specifies the driven value). Loops and procedures further streamline the code in the advanced scripts. Here is a simplified example:
//Set SDKs to create forearm twist controls: setDrivenKeyframe -cd "lfArm_icon.armTurn" -dv 0 -v 0 "lfArmTurn_bindJt.rotateX"; setDrivenKeyframe -cd "lfArm_icon.armTurn" -dv 10 -v 35 "lfArmTurn_bindJt.rotateX"; setDrivenKeyframe -cd "lfArm_icon.armTurn" -dv -10 -v -115 "lfArmTurn_bindJt.rotateX";
The advanced controls also require connecting channels using math expressions. Maya sees a math expression as a string, so you specify the expression using the string flag on the expression command. Since most expressions have multiple lines, it is advisable to store them in separate string variables that can be combined. Be careful to avoid breaking long strings onto multiple lines, as this will cause an "unterminated string" error. Also be aware that names won't be hard-coded in the advanced scripts, so names stored in variables and arrays will further break up the expression string. Here is one example of using MEL to declare an expression:
//Expression for twisting the upper arm joints: string $exp1 = "lfNewUpArm_rootJt.rx = 0 + (lfArm_ctrlRt.rx / 3);\n"; string $exp2 = "lfNewUpArm1_bindJt.rx = 0 + (lfArm_ctrlRt.rx / 2); \n"; string $exp3 = "lfNewUpArm2_bindJt.rx = 0 + (lfArm_ctrlRt.rx); \n "; expression -name "newUpArms_exp" -string ($exp1 + $exp2 + $exp3);
Creating direct node connections in the advanced scripts is basically the same as described in "Driving the Upper Arm Twisting," earlier in this chapter. You run createNode commands to create utility nodes, and then use the connectAttr commands to connect these nodes to other transform channels. In addition, you'll use setAttr commands extensively to set how the utility nodes affect the connections. You'll use similar setAttr commands to lock and hide attributes, and set default manipulators. As a final step, you'll use a transformLimits command in the process of cleaning up icons to set limits on the icon transform channels. All of this will, of course, be organized into procedures with arguments for all the node names and values.