FK IK switching
Now we will create the constraints to drive the main leg chain with either the FK or the IK leg chain. Select, in this order, l_upperLeg_FK_jnt, l_upperLeg_IK_jnt, l_upperLeg_jnt and go Constrain > Orient (Options). Make sure Constrain axes is set to All and hit Apply. Then select, in this order l_lowerLeg_FK_jnt, l_ lowerLeg _IK_jnt, l_ lowerLeg _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.
Now that the original leg chain is following both the FK and IK joints, let's use SDKs to go between the 2 modes. Select the 4 orientConstraint nodes that we just created (you will find them under l_upperLeg_jnt, l_lowerLeg_jnt, l_ankleTwist_jnt and l_ball_jnt) and go Animate > Set Driven Key > Set. This should load the constraint nodes into the Driven window. Now select the fkIkSwitch_ctrl and hit Load Driver. Set the L Leg attribute to 0 (FK mode) on the fkIkSwitch. Then select the l_upperLeg_jnt_OrientConstraint1 node in the Driven portion of the SDK window. In the Channel Box, set L upper Leg FK Jnt W0 to 1 and L upper Leg IK Jnt W1 to 0. Do the same for the remaining 3 constraint nodes. Once all the FK W0 have been set to 1 and the IK W1 nodes have been set to 0, highlight L Leg in the top-right window of the SDK tool and highlight the weight attributes on the bottom-left window of the SDK tool. Then, hit Key on the SDK window. Now, simply set the L Leg attribute to 1 on the fkIkSwitch_ctrl, set all the W0 to 0 and the W1 to 1 on all the constraint nodes and hit Key once more.
Setting up the FK IK switching using the Set Driven Key tool
Attaching the leg to the hip
Rather than parenting the leg chains directly under the hip joint, I want to keep them separate. That way, should I need to re-work any part of the rig, I can do so without disturbing other regions. So we are going to stick with using constraints to bring everything together. Select in this order, l_upperLeg_FK_jnt, l_upperLeg_IK_jnt, l_upperLeg_jnt and go Constrain > Point. Now select the newly created pointConstraint node (this will live under l_upperLeg_jnt) and go Animate > Set Driven Key > Set to load into the Driven portion of the SDK tool. Select fkIkSwitch_ctrl and click Load Driver. Set the L Leg attribute on the fkIkSwitch_ctrl to 0 (FK mode), the L Upper Leg FK jnt W0 to 1 and L Upper Leg IK jnt W0 to 0 on the pointConstraint node. In the SDK tool, highlight L _Leg on the top-right window and both weight attributes on the bottom-right window. Then hit Key on the SDK tool. Then set the value to 1 for the L Leg attribute on the fkIkStwitch_ctrl and reverse the weight values on the pointConstraint node. Hit Key once more on the SDK tool.
Using the Set Driven Key tool to control the pointConstraint node
Now, select in this order, l_upperLegDrive_IK_jnt, l_upperLeg_IK_jnt and go Constrain > Point. We now need a control that will be used to attach the IK leg to the hip. Select l_elbow_ctrl_offset, hit Ctrl+D to duplicate it and then Shift+P to un-parent it from its current location. Use the Search and Replace Names tool to rename _elbow to _hip_IK. Select l_hip_IK_ctrl_offset and parent it under l_upperLeg_IK_jnt. Zero out the translate and rotate values in the Channel Box for l_hip_IK_ctrl_offset and then un-parent it (Shift+P). In component mode (F8), edit its shape and position to make it more easily selectable. Now, in this order, select l_hip_IK_ctrl, l_upperLegDrive_IK_jnt and go Constrain > Point. Then, simply select l_hip_IK_ctrl_offset and parent it under hip_FK_ctrl. You can hide l_hip_IK_ctrl if you wish.
Let's take care of the FK leg next. Select in this order, l_upperLeg_FK_ctrl, l_upperLeg_FK_jnt and go Constrain > Point. Job done.
The addition of the l_hip_IK_ctrl; used to attach the IK leg to the hip control
Adding the twist joint
To create the twisting of the leg, we will create the same expression as we did for the arm. Open up the Expression Editor by going Windows > Animation Editors and create the following expression:
l_upperLegTwistA_jnt.rotateY = l_lowerLeg_jnt.rotateY * .25;
l_upperLegTwistB_jnt.rotateY = l_lowerLeg_jnt.rotateY * . 5;
l_upperLegTwistC_jnt.rotateY = l_lowerLeg_jnt.rotateY * .75;
l_lowerLegTwistA_jnt.rotateY = l_ankleTwist_jnt.rotateY * .25 * -1;
l_lowerLegTwistB_jnt.rotateY = l_ankleTwist_jnt.rotateY * . 5 * -1;
l_lowerLegTwistC_jnt.rotateY = l_ankleTwist_jnt.rotateY * .75 * -1;
Hit Create and then rename the expression l_legTwist_expr. The * -1 will make sure that the twisting of the lower leg does not go in the wrong direction. Select the l_lowerLeg_FK_ctrl and set the Rotate Order to YZX to reduce any funny business as we twist the lower leg. Let's now hook the knee twist up for the IK control. Open up the Connection Editor (Window > General Editor > Connection Editor) and load the l_leg_IK_ctrl into the left-hand side. Now load l_lowerLeg_IK_jnt into the right-hand side and connect kneeTwist (left-hand side) to rotateY (right-hand side).
Using the Expression Editor to drive the leg twist joints
Cleaning up the leg rig
A bit of housework now. Select all the joint chains for the legs and l_leg_IK_ctrl_offset. Hit Ctrl+G to group them together and then rename this group l_leg_rig_grp. Open up l_leg_rig_grp, select all the joint chains in there and hit Ctrl+G to group them. Rename that group l_leg_jnt_grp. The last thing to do is color code the controls using the Drawing Overrides. All you need to do now is mirror the joints over and create the rig for the right-hand side.
Both legs in place and the Outliner cleaned up
Jahirul's previous rigging tutorials can be found here:
Maya rigging: Introduction to rigging
Maya rigging: Introduction to rigging a human torso
Maya rigging: Introduction to rigging the neck and the head
Maya rigging: Introduction to rigging the shoulder and the arms
Maya rigging: Introduction to rigging the hands
Check out Jahirul's site