Search the wiki
06. Rigging the leg
Before we begin though, spend a few minutes cleaning up your latest scene, unless you have done so already. I ended up deleting a few stray empty group nodes that were hanging around, and also used the Layers to partition the joints from the geometry.
001. Create the leg joints
For the leg, we’ll be creating two main joint chains: one for the leg itself and one for the foot. This will allow us to create a clean twisting motion from the ankle with just the one axis. It’s a similar thinking to what we have done with the torso.
Jump into the Side view, go Skeleton > Joint Tool and create a 3 joint chain. Place the first joint around the region where the great trochanter of the femur would sit, then the next joint at the knee and finally, a third joint at the ankle. Add a slight bend to the knee as this will make it easier for the IK to calculate how the leg should flex. Switch to the Front view next, and line the root joint up with the crease that runs from the ASIS to the pubic symphysis.
Select the root joint now and go Skeleton > Orient Joint (Options). Set the Primary Axis to Y. The Secondary Axis to Z, the Secondary Axis World Orientation to Z (-) and hit Apply. Make sure to rotate the legs joints to check that the orientations have been set correctly. Rename the joints from root to tip as follows: l_femur_jnt, l_tibiaFibula_jnt and l_legEnd_jnt.
Next, jump back into the Side view and create a single joint. Rename this joint l_ankleTwist_jnt. With the new joint selected, hold the V key and snap its position to the end of the leg chain. Then rotate the joint 180 degrees on the X-axis so Y points downwards like our existing leg chain, and then go Modify > Freeze Transformations to zero out the rotation value. To make it easier to select this joint, increase its radius in the Channel Box.
Lastly, we’ll create the joints for the foot. Activate the Joint Tool once more, hold down the V key, and create a root joint at the same position as the l_ankleTwist_jnt. Then create a second joint at the ball of the foot, and finally add a joint at the end of the toes. I place the joint at the ball of the foot pretty close to the ground, as I find it means I get a more pleasing result during deformation. I also hold down the Shift key when creating the final joint in the chain, as this will create a straight joint. From root to tip, rename the joints as follows: l_tarsals_jnt, l_ball_jnt and l_toeEnd_jnt. With l_tarsals_jnt selected, go Skeleton > Orient Joint Tool. The settings should be set from beforehand, so simply hit Apply.
Now parent l_tarsals_jnt under l_ankleTwist_jnt. Then select l_ankleTwist_jnt and rotate it on the Y-axis so it sits within the geometry of the foot better. When in place, freeze the transformations. Lastly, parent l_ankleTwist_jnt under l_legEnd_jnt.
002. Create the FK, IK and twist joints
To create the FK joint chain, duplicate the l_femur_jnt and then go Modify > Search and Replace. Set the Search for to _jnt and the Replace with to _fk_jnt. Then delete the 1 that will be present on the end of l_femur_fk_jnt. Repeat the same step to create the IK joint chain.
For now, select both the FK and the IK joint chain and hide them (Ctrl + H) so we can create the twist joints. Load up the trusty Joint Splitter tool once more, set l_femur_jnt as the Start Joint, set the Jnt Qty to 3 and hit Split Joints. Then select l_patella_jnt and split that joint with the same settings. Next parent the twist joints of the upper leg to l_femur_jnt and the twist joints of the lower leg to l_patella_jnt, like we did for the arm. Make sure that l_legEnd_jnt is parented back under l_patella_jnt.
With the twist joints parented correctly, rename the twist joints of the upper leg l_femurTwist1_jnt, l_femurTwist2_jnt and l_femurTwist3_jnt. For the twist joints of the lower leg, rename them as so: l_patellaTwist1_jnt, l_patellaTwist2_jnt and l_patellaTwist3_jnt.
With all the joints created, create the low-res mesh and parent each relevant slice to the relevant joint. Follow the same techniques to do this as we have used for the torso, the head and the arms. Remember to delete the history from the slices and rename the geometry appropriately.
003. FK IK blending
Let’s now create the setup so that our original joint chain will be driven by either the FK or the IK joint chain, and again, we will do this using constraints and Set Driven Keys.
Select, in this order, l_femur_fk_jnt, l_femur_ik_jnt, l_femur_jnt and go Constrain > Orient (Options). Set the Constrain axes to All and hit Apply. If something pops then the joints are not aligned correctly and will need to be looked at. If nothing pops, then we are good to go. Select, in this order l_patella_fk_jnt, l_patella_ik_jnt, l_patella_jnt and go Constrain > Orient. In this order, select l_ankleTwist_fk_jnt, l_ankleTwist_ik_jnt, l_ankleTwist_jnt, and again apply the orient constraint. Lastly, select in this order l_ball_fk_jnt, l_ball_ik_jnt, l_ball_jnt and go Constrain > Orient.
The original leg chain will now follow both the FK and IK joints with equal weighting. Let’s use SDKs to go between the 2 joint chains. In the Outliner, select the 4 orientConstraint nodes that were just created (you will find them under l_femur_jnt, l_patella_jnt, l_ankleTwist_jnt and l_ball_jnt) and go Animate > Set Driven Key > Set. The constraint nodes should be placed into the Driven box. Now select the fkIk_ctrl and hit Load Driver. Set the L Leg attribute to 0 (FK enabled) on the fkIk_ctrl.
Then select the l_femur_jnt_OrientConstraint1 node in the Driven box of the SDK window, and in the Channel Box set L Femur Fk Jnt W0 to 1 (FK enabled), and L Femur Ik Jnt W1 to 0 (IK disabled). Do the same for the remaining 3 constraint nodes so that all the Fk Jnt W0 attributes are set to 1 and the Ik Jnt W1 attributes are set to 0. Back in the SDK window, highlight L Leg in the top-right box, highlight l_femur_jnt_OrientConstraint1 in the bottom-left box and highlight both L Femur Fk Jnt W0 and L Femur Ik Jnt W1 in the bottom-right box. With everything highlighted, hit Key on the SDK window, and then do the same for the remaining three constraint nodes.
When you have set the first key for all the constraint nodes, simply set the L Leg attribute to 1 (IK enabled)on the fkIk_ctrl, set all the W0 to 0 (FK disabled) and the W1 to 1 (IK enabled) on all the constraint nodes, and hit Key once more. Make sure to rotate the FK and IK joint chains to see if they are driving the leg correctly and that you can switch between the modes before moving on.
004. Create the FK controls
We’ll now create the controls for the FK leg. As we won’t need to work with the original leg chain and the IK leg chain, select them both and hit Ctrl + H to hide them. Then select l_femur_fk_jnt, l_patella_fk_jnt, l_ankleTwist_fk_jnt and l_ball_fk_jnt. Open up the Script Editor and load the createControls.py script into a Python tab. Make sure the following lines read as below and then execute the script:
|16||ctrl = cmds.circle( nr=(0, 1, 0), r=5, n=ctrlName)|
|21||cmds.orientConstraint(ctrl, s, mo=0)|
You can now switch to component mode and edit the shapes and the position of the controls. Next we need to create the FK control hierarchy. First parent l_ball_fk_ctrl_offset under l_ankleTwist_fk_ctrl. Then parent l_ankleTwist_fk_ctrl_offset under l_patella_fk_ctrl. Next parent l_ l_patella_fk_ctrl_offset under l_femur_fk_ctrl. Lastly, parent l_femur_fk_ctrl_offset under hip_fk_ctrl.
005. Create the IK controls
Now hide the FK joint chain and un-hide the IK joint chain by selecting it in the Outliner and hitting Shift + H.
Let’s now add the IK handle that will drive the IK leg. Go Skeleton > IK Handle Tool (Options) and set the Current solver to Rotate-Plane Solver. Then in the Outliner, click on l_femur_ik_jnt, hold down the Ctrl key and LMB click on l_legEnd_ik_jnt. Select the IK handle now, and rename it to l_leg_ik.
Now I’d like two controls for the IK leg: one for the knee and one for the ankle, much like the setup we have for the arm. We could create two new controls for this but instead, I’ve selected both l_arm_ik_ctrl_offset and l_elbow_ik_ctrl_offset and hit Ctrl + D to duplicate them. I’ve then used the Search and Replace tool to rename the hierarchy for l_arm_ik_ctrl to l_leg_ik_ctrl, and l_elbow_ik_ctrl to l_knee_ik_ctrl.
Next we need to position to controls into the correct place. Let’s start with the l_leg_ik_ctrl. Start by selecting l_leg_ik_ctrl_offset, hold down the V key and snap it to the same position as l_leg_ik. You can now parent l_leg_ik under l_leg_ik_ctrl. Switch to component mode and then reshape the control around the foot.
For the knee control, we will tackle it in the same way we did for the elbow. Select in this order: l_femur_ik_jnt, l_patella_ik_jnt, l_legEnd_ik_jnt and then l_knee_ctrl_offset. Then go Constrain > Point (Options). Make sure Maintain Offset is disabled and then hit Apply. Now select in this order: l_patella_ik_jnt, l_knee_ik_ctrl_offset, and go Constrain > Aim.
Jump into the Outliner now and delete the two constraint nodes living under l_knee_ik_ctrl_offset. With the Move tool active, make sure you are in Object mode and then translate the l_knee_ik_ctrl_offset nodes out in front of the character. Now select l_knee_ik_ctrl, Ctrl-select l_leg_ik in the Outliner, and go Constrain > Pole Vector.
Let’s now add the ability to twist the knee from the l_leg_ik_ctrl. Select l_leg_ik_ctrl and in the Channel Box, go Edit > Modify Attribute. Select elbowTwist in the Attributes box and set the New name to kneeTwist. With l_leg_ik_ctrl selected, go Windows > Connection Editor. This should load the control into the Outputs field. Select l_leg_ik and hit Reload Right to drop it into the Inputs field. Highlight kneeTwist on the left-side column and twist on the right-hand column.
006. A bit of a clean up
We now want to connect the leg to the rest of the rig. Select all three leg chains: l_femur_jnt, l_femur_fk_jnt, l_femur_ik_jnt and parent them under hip_fk_jnt. Then select l_femur_fk_ctrl_offset, and parent it under hip_fk_ctrl.
Now I want to add an expression that will twist the lower leg, much like the forearm twist. Open up the Expression Editor and create the following expression:
l_patellaTwist1_jnt.rotateY = l_ankleTwist.rotateY *.15;
l_patellaTwist2_jnt.rotateY = l_ankleTwist.rotateY *.35;
l_patellaTwist3_jnt.rotateY = l_ankleTwist.rotateY *.55
Rename this expression l_tibiaFibula_twist_expr.
007. Using annotations
Let’s clean up the Outliner now. Select both l_leg_ik_ctrl_offset and l_knee_ik_ctrl_offset, hit Ctrl + G to group them together and rename that group l_leg_ik_ctrl. Then parent l_leg_ik_ctrl under rig_ctrl_grp.
Now let’s create a visual aid between the position of the knee and the knee control. There are many ways to do this, but I find that using Annotations works well and is pretty easy to set up.
Start by selecting l_knee_ik_ctrl, go Create > Annotation, and when the dialog box pops up, call it l_knee_ctrl. This will create a locator and an annotation node with a line created between the two. Select the annotationLocator from the Outliner and point snap it to the l_patella_ik_jnt. Then take the annotation node, parent it under l_knee_ik_ctrl, and zero out the Translate and Rotate values to snap it into the correct place. Now take the annotationLocator and parent it under l_patella_ik_jnt.
Select the annotation node now, and rename it l_knee_annotation. In the Attribute Editor, I also decided to delete the l_knee_ctrl from the Text field. I’ll leave it up to you if you’d like to do the same or not. I just didn’t want it on display in the viewport. Then under the transform node for l_knee_annotation, set the Display type to Template so it cannot be selected. If you now translate the knee control, the visual line will help to indicate the direction in which the knee is pointing.
Do the same for the right leg, the elbows and the eyes if you wish, and then we will move on
to the foot.