/* -------------------- RigSetup V.1.0 Copyright (C) 2005: Nikita Pavlov http://www.andrew.cmu.edu/user/nyp Skeleton tools are a continuation of work by: Neel Kar http://www.andrew.cmu.edu/~nkar -------------------- LICENSE: YOU MAY MAKE MODIFICATIONS AT YOUR OWN RISK FOR YOUR OWN PURPOSES. PLEASE CONTACT THE AUTHOR FIRST IF YOU WANT THE MODIFICATIONS/ADD-ONS TO BE INCLUDED IN THIS DISTRIBUTION. This program is free software and is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. -------------------- Usage: - Drag and drop the script into Maya to open the interface. - Click on "Build Skeleton" to create the basic rig. - Position the bones based on your character geometry and click "Mirror Joints" to create the other half of the skeleton. - Click on "Build IK" to create the IK for your skeleton. - Click on "Build Helpers" to create helper geometry and driven keys for your skeleton. -------------------- History: v.1.0: Adapted Neel's skeleton code. Created IK and Helper creation. */ global proc RigSetupUI( ) { //If such a window already exists, destroy it. if ( `window -exists bonecorrectionUI ` ) deleteUI bonecorrectionUI ; //Create the window. window -title "Auto Rig Setup v.1.0" -wh 200 500 -menuBar true bonecorrectionUI ; menu -label "About" ; menuItem -label "About" -c "showAbout()"; string $tabs = `tabLayout -innerMarginWidth 5 -innerMarginHeight 5`; string $skeletonTab = `columnLayout -adjustableColumn true`; frameLayout -label "Generate" -labelAlign "center" -collapsable true -borderStyle "in"; columnLayout -adjustableColumn true; radioButtonGrp -numberOfRadioButtons 3 -labelArray3 "1" "2" "3" -label "Fingers: " -select 1 -columnWidth4 80 40 40 40 bFingers; button -l "Build Skeleton" -c "makeSkeleton" -w 150; button -l "Mirror Joints" -c "mirrorJoints" -w 150; setParent ..; setParent ..; frameLayout -label "Scaling" -labelAlign "center" -collapsable true -borderStyle "in"; columnLayout -adjustableColumn true; floatFieldGrp -label "Scale percentage" -nf 1 -v1 1.0 number1; button -l "Scale Skeleton" -c "scaleSkeleton" -w 150; setParent ..; setParent ..; //End of the column. setParent..; // Create the IK tab. string $ikTab = `columnLayout -adjustableColumn true`; frameLayout -label "Generate" -labelAlign "center" -collapsable true -borderStyle "in"; columnLayout -adjustableColumn true; //checkBoxGrp -numberOfCheckBoxes 1 -label1 "Inverse Foot" -v1 1; checkBoxGrp -numberOfCheckBoxes 1 -label1 "Legs" -v1 1 bLegs; checkBoxGrp -numberOfCheckBoxes 1 -label1 "Arms" -v1 1 bArms; checkBoxGrp -numberOfCheckBoxes 1 -label1 "Spine" -v1 1 bSpine; button -l "Build IK" -c "makeIK" -w 150; setParent ..; setParent ..; //End of the column. setParent..; // Create the Helpers tab. string $helpersTab = `columnLayout -adjustableColumn true`; frameLayout -label "Generate" -labelAlign "center" -collapsable true -borderStyle "in"; columnLayout -adjustableColumn true; checkBoxGrp -numberOfCheckBoxes 1 -label1 "Arms and Legs" -v1 1 bIKControllers; checkBoxGrp -numberOfCheckBoxes 1 -label1 "Torso" -v1 1 bTorsoHelpers; checkBoxGrp -numberOfCheckBoxes 1 -label1 "Head" -v1 1 bHeadHelpers; //checkBoxGrp -numberOfCheckBoxes 1 -label1 "Driven Keys" -v1 1; button -l "Build Helpers" -c "makeHelpers" -w 150; setParent ..; setParent ..; setParent; // Set the tabs. tabLayout -edit -tabLabel $skeletonTab "Skeleton" $tabs; tabLayout -edit -tabLabel $ikTab "IK" $tabs; tabLayout -edit -tabLabel $helpersTab "Helpers" $tabs; //Show it. showWindow bonecorrectionUI ; } RigSetupUI; global proc makeSkeleton() { select -cl; // Create the spine joint -p 0 1.22059 0.14998 -n BackRoot; joint -p 0 1.43859 0.0711292 -n Back1; joint -e -zso -oj xyz BackRoot; joint -p 0 1.653696 0.0711292 -n Back2; joint -e -zso -oj xyz Back1; joint -p 0 1.845 0.124 -n Back3; joint -e -zso -oj xyz Back2; joint -p 0 2.0091 0.201001 -n BackEnd; joint -e -zso -oj xyz Back3; joint -p 0 2.106504 0.219555 -n NeckRoot; joint -e -zso -oj xyz BackEnd; //joint -p 0 2.273483 0.228831 -n NeckEnd; //joint -e -zso -oj xyz NeckRoot; // Create the head (temporarily connected to the neck) joint -p 0 2.375526 0.256661 -n HeadRoot; joint -e -zso -oj xyz NeckRoot; joint -p 0 3.010972 0.344788 -n HeadEnd; joint -e -zso -oj xyz HeadRoot; select -cl; // Create the left hip bones. //joint -p 0.121257 1.228372 0 -n LeftHipRoot; //joint -p 0.331927 1.298595 0 -n LeftHipEnd; //joint -e -zso -oj xyz LeftHipRoot; //select -cl; // Create the left leg joint -p 0 1.284985 0.089573 -n LeftLegRoot; joint -p 0 0.763163 0.268345 -n LeftLegKnee; joint -e -zso -oj xyz LeftLegRoot; joint -p 0 0.681024 0.268345 -n LeftLegLow; joint -e -zso -oj xyz LeftLegKnee; joint -p 0 0.39363 0.159037 -n LeftFootAnkle; joint -e -zso -oj xyz LeftLegLow; joint -p 0 0.118485 0.3895 -n LeftFootBall; joint -e -zso -oj xyz LeftFootAnkle; joint -p 0 0.0596938 0.86924 -n LeftFootToe; joint -e -zso -oj xyz LeftFootBall; select -r LeftLegRoot; move -r 0.335503 0 0 ; parent LeftLegRoot BackRoot; select -r LeftFootAnkle; rotate -r -ws 0 13.225053 0 ; select -cl ; // Create inverse heel (just the placeholder for now) joint -p 0.308054 0.0526989 -0.107052 -n LeftInverseHeel; parent LeftInverseHeel LeftFootAnkle; select -cl; // Create left shoulder blade (clavicle) joint -p 0.135838 2.043289 0 -n LeftClavicleRoot; joint -p 0.305154 1.965686 0 -n LeftClavicleEnd; joint -e -zso -oj xyz LeftClavicleRoot; select -r LeftClavicleRoot; move -r 0 -0.0184173 0.105242 ; // Parent it to BackEnd select -r LeftClavicleRoot ; select -tgl BackEnd ; parent; select -cl; // Create left arm joint -p 0.471924 1.989051 0 -n LeftArmRoot; joint -p 1.326089 2.021025 0 -n LeftArmElbow; joint -e -zso -oj xyz LeftArmRoot; joint -p 2.070629 2.021025 0 -n LeftArmWrist; joint -e -zso -oj xyz LeftArmElbow; //joint -p 2.121172 2.021025 0.115379 -n LeftHandRoot; //joint -e -zso -oj xyz LeftArmEnd; joint -p 2.260498 2.021025 0.0893714 -n LeftArmHand; joint -e -zso -oj xyz LeftArmWrist; select -r LeftArmRoot ; move -r 0 0 0.139704 ; parent LeftArmRoot LeftClavicleEnd; select -r LeftArmElbow ; move -r 0 0 -0.076612 ; select -r LeftArmWrist ; move -r -0.0405593 0 0.0540791 ; select -r LeftArmHand ; move -r 0.0204345 0 -0.120749 ; select -cl ; // Get the number of fingers. int $numFingers = `radioButtonGrp -q -select bFingers`; // Create middle finger. // This is used for creating other fingers, so it must be made. // If it's unnecessary (i.e., 2 finger hand), we delete it later. joint -p 2.288363 0 0.0912291 -n LeftFinger2_Root; joint -p 2.349667 0 0.0912291 -n LeftFinger2_Mid1; joint -e -zso -oj xyz LeftFinger2_Root; joint -p 2.425831 0 0.0968021 -n LeftFinger2_Mid2; joint -e -zso -oj xyz LeftFinger2_Mid1; joint -p 2.492708 0 0.120952 -n LeftFinger2_End; joint -e -zso -oj xyz LeftFinger2_Mid2; select -r LeftFinger2_Root; move -r 0 2.011319 0 ; // Parent the finger to the palm. parent LeftFinger2_Root LeftArmHand; if ($numFingers >= 2) { // Create top finger. select -r LeftFinger2_Root; duplicate -rr; rename "LeftFinger2_Root1" "LeftFinger1_Root"; rename "LeftFinger1_Root|LeftFinger2_Mid1" "LeftFinger1_Mid1"; rename "LeftFinger1_Mid1|LeftFinger2_Mid2" "LeftFinger1_Mid2"; rename "LeftFinger1_Mid2|LeftFinger2_End" "LeftFinger1_End"; select -r LeftFinger1_Root; move -r 0 0.0795783 0 ; move -r -0.00324809 0 0 ; select -r LeftFinger1_Mid1 ; move -r -0.0146164 0 0 ; select -r LeftFinger1_Mid2 ; move -r -0.0162405 0 0 ; select -r LeftFinger1_End ; move -r -0.00974428 0 0 ; select -r LeftFinger1_Root ; rotate -r -ws 0 0 9.454071 ; select -cl ; // Create bottom finger. select -r LeftFinger1_Root ; duplicate -rr; move -r -0.0113683 -0.14454 0 ; rotate -r -ws 0 0 -20.716536 ; select -r LeftFinger1_Root1|LeftFinger1_Mid1 ; move -r -0.00649618 0 0 ; select -r LeftFinger1_Root1|LeftFinger1_Mid1 ; select -r LeftFinger1_Root1|LeftFinger1_Mid1|LeftFinger1_Mid2 ; move -r -0.00324809 0 0 ; select -r LeftFinger1_Root1|LeftFinger1_Mid1|LeftFinger1_Mid2|LeftFinger1_End ; move -r -0.00324809 0.00162405 0 ; rename "LeftFinger1_Root1" "LeftFinger3_Root"; rename "LeftFinger3_Root|LeftFinger1_Mid1" "LeftFinger3_Mid1"; rename "LeftFinger3_Mid1|LeftFinger1_Mid2" "LeftFinger3_Mid2"; rename "LeftFinger3_Mid2|LeftFinger1_End" "LeftFinger3_End"; select -cl; //parent LeftFinger1_Root LeftFinger3_Root LeftArmHand; } if ($numFingers == 2) delete LeftFinger2_Root; // Create thumb. joint -p 2.156424 2.101207 0 -n LeftThumb_Root; joint -p 2.16323 2.181511 0 -n LeftThumb_Mid; joint -e -zso -oj xyz LeftThumb_Root; joint -p 2.195896 2.265897 0 -n LeftThumb_End; joint -e -zso -oj xyz LeftThumb_Mid; select -r LeftThumb_Root; move -r 0 0 0.0930636 ; parent LeftThumb_Root LeftArmHand; select -cl; print "\nPlease adjust the existing bone structure to match the joints of your skeleton.\n"; print "Do not rename or reparent any of the existing joints.\n"; print "When you are finished adjusting the joints, run the next script, \"Rig2.mel\".\n\n"; print "First stage finished. Please see the script editor for further instructions.\n"; } // End makeSkeleton. global proc makeBoxDummy(string $name) { curve -d 1 -p -0.5 0.5 0.5 -p 0.5 0.5 0.5 -p 0.5 -0.5 0.5 -p 0.5 0.5 0.5 -p 0.5 0.5 -0.5 -p 0.5 -0.5 -0.5 -p 0.5 0.5 -0.5 -p -0.5 0.5 -0.5 -p -0.5 -0.5 -0.5 -p -0.5 0.5 -0.5 -p -0.5 0.5 0.5 -p -0.5 -0.5 0.5 -p -0.5 -0.5 -0.5 -p 0.5 -0.5 -0.5 -p 0.5 -0.5 0.5 -p -0.5 -0.5 0.5 -k 0 -k 1 -k 2 -k 3 -k 4 -k 5 -k 6 -k 7 -k 8 -k 9 -k 10 -k 11 -k 12 -k 13 -k 14 -k 15 -n $name; } global proc makeArrowDummy(string $name) { // Create a four-arrow curve for aim constraints. curve -d 1 -p -1 1 0 -p -1 3 0 -p -2 3 0 -p 0 5 0 -p 2 3 0 -p 1 3 0 -p 1 1 0 -p 3 1 0 -p 3 2 0 -p 5 0 0 -p 3 -2 0 -p 3 -1 0 -p 1 -1 0 -p 1 -3 0 -p 2 -3 0 -p 0 -5 0 -p -2 -3 0 -p -1 -3 0 -p -1 -1 0 -p -3 -1 0 -p -3 -2 0 -p -5 0 0 -p -3 2 0 -p -3 1 0 -p -1 1 0 -k 0 -k 1 -k 2 -k 3 -k 4 -k 5 -k 6 -k 7 -k 8 -k 9 -k 10 -k 11 -k 12 -k 13 -k 14 -k 15 -k 16 -k 17 -k 18 -k 19 -k 20 -k 21 -k 22 -k 23 -k 24 -n $name; scale -r 0.0658911 0.0658911 0.0658911 ; makeIdentity -apply true -t 1 -r 1 -s 1; select -cl; } // Called internally when setting up the driven keys for the fingers. // The parameter must be either "Left" or "Right". global proc setHandDrivenKeys(string $side) { // Orient finger joints. select -r LeftArmHand ; joint -e -oj xyz -secondaryAxisOrient yup -ch -zso; select -r RightArmHand ; joint -e -oj xyz -secondaryAxisOrient yup -ch -zso; // Set driven key for wrist waving. eval ( "setAttr " + $side + "HandDummy.WristWave 0"); eval ( "setAttr " + $side + "WristWave.rotateZ 0"); eval ( "setDrivenKeyframe -cd " + $side + "HandDummy.WristWave " + $side + "WristWave.rotateZ"); eval ( "setAttr " + $side + "HandDummy.WristWave 10"); if ($side == "Left") eval ( "setAttr " + $side + "WristWave.rotateZ 45"); else eval ( "setAttr " + $side + "WristWave.rotateZ -45"); eval ( "setDrivenKeyframe -cd " + $side + "HandDummy.WristWave " + $side + "WristWave.rotateZ"); eval ( "setAttr " + $side + "HandDummy.WristWave -10"); if ($side == "Left") eval ( "setAttr " + $side + "WristWave.rotateZ -45"); else eval ( "setAttr " + $side + "WristWave.rotateZ 45"); eval ( "setDrivenKeyframe -cd " + $side + "HandDummy.WristWave " + $side + "WristWave.rotateZ"); eval ( "setAttr " + $side + "HandDummy.WristWave 0"); // Set driven key for wrist shaking. eval ( "setAttr " + $side + "HandDummy.WristShake 0"); eval ( "setAttr " + $side + "WristShake.rotateY 0"); eval ( "setDrivenKeyframe -cd " + $side + "HandDummy.WristShake " + $side + "WristShake.rotateY"); eval ( "setAttr " + $side + "HandDummy.WristShake 10"); if ($side == "Left") eval ( "setAttr " + $side + "WristShake.rotateY 90"); else eval ( "setAttr " + $side + "WristShake.rotateY -90"); eval ( "setDrivenKeyframe -cd " + $side + "HandDummy.WristShake " + $side + "WristShake.rotateY"); eval ( "setAttr " + $side + "HandDummy.WristShake -10"); if ($side == "Left") eval ( "setAttr " + $side + "WristShake.rotateY -90"); else eval ( "setAttr " + $side + "WristShake.rotateY 90"); eval ( "setDrivenKeyframe -cd " + $side + "HandDummy.WristShake " + $side + "WristShake.rotateY"); eval ( "setAttr " + $side + "HandDummy.WristShake 0"); // Set driven key for wrist twisting. // This is anatomically incorrect, but for our simplified solution it will do. eval ( "setAttr " + $side + "HandDummy.WristTwist 0"); eval ( "setAttr " + $side + "ArmIK.rotateX 0"); eval ( "setDrivenKeyframe -cd " + $side + "HandDummy.WristTwist " + $side + "ArmIK.rotateX"); eval ( "setAttr " + $side + "HandDummy.WristTwist 10"); if ($side == "Left") eval ( "setAttr " + $side + "ArmIK.rotateX -90"); else eval ( "setAttr " + $side + "ArmIK.rotateX -90"); eval ( "setDrivenKeyframe -cd " + $side + "HandDummy.WristTwist " + $side + "ArmIK.rotateX"); eval ( "setAttr " + $side + "HandDummy.WristTwist -10"); if ($side == "Left") eval ( "setAttr " + $side + "ArmIK.rotateX 90"); else eval ( "setAttr " + $side + "ArmIK.rotateX 90"); eval ( "setDrivenKeyframe -cd " + $side + "HandDummy.WristTwist " + $side + "ArmIK.rotateX"); eval ( "setAttr " + $side + "HandDummy.WristTwist 0"); // Set driven key for thumb curling eval ( "setAttr " + $side + "HandDummy.CurlThumb 0"); eval ( "setAttr " + $side + "Thumb_Root.rotateZ 0"); eval ( "setAttr " + $side + "Thumb_Root.rotateY 0"); eval ( "setAttr " + $side + "Thumb_Mid.rotateZ 0"); eval ( "setDrivenKeyframe -cd " + $side + "HandDummy.CurlThumb " + $side + "Thumb_Root.rotateZ"); eval ( "setDrivenKeyframe -cd " + $side + "HandDummy.CurlThumb " + $side + "Thumb_Root.rotateY"); eval ( "setDrivenKeyframe -cd " + $side + "HandDummy.CurlThumb " + $side + "Thumb_Mid.rotateZ"); eval ( "setAttr " + $side + "HandDummy.CurlThumb 10"); eval ( "setAttr " + $side + "Thumb_Root.rotateZ -80"); if ($side == "Left") eval ( "setAttr " + $side + "Thumb_Root.rotateY -40"); else eval ( "setAttr " + $side + "Thumb_Root.rotateY 40"); eval ( "setAttr " + $side + "Thumb_Mid.rotateZ -80"); eval ( "setDrivenKeyframe -cd " + $side + "HandDummy.CurlThumb " + $side + "Thumb_Root.rotateZ"); eval ( "setDrivenKeyframe -cd " + $side + "HandDummy.CurlThumb " + $side + "Thumb_Root.rotateY"); eval ( "setDrivenKeyframe -cd " + $side + "HandDummy.CurlThumb " + $side + "Thumb_Mid.rotateZ"); eval ( "setAttr " + $side + "HandDummy.CurlThumb -10"); eval ( "setAttr " + $side + "Thumb_Root.rotateZ 30"); if ($side == "Left") eval ( "setAttr " + $side + "Thumb_Root.rotateY 20"); else eval ( "setAttr " + $side + "Thumb_Root.rotateY -20"); eval ( "setAttr " + $side + "Thumb_Mid.rotateZ 10"); eval ( "setDrivenKeyframe -cd " + $side + "HandDummy.CurlThumb " + $side + "Thumb_Root.rotateZ"); eval ( "setDrivenKeyframe -cd " + $side + "HandDummy.CurlThumb " + $side + "Thumb_Root.rotateY"); eval ( "setDrivenKeyframe -cd " + $side + "HandDummy.CurlThumb " + $side + "Thumb_Mid.rotateZ"); eval ( "setAttr " + $side + "HandDummy.CurlThumb 0"); // Set driven key for first finger curling if ((`objExists LeftFinger1_Root` && $side == "Left") || (`objExists RightFinger1_Root` && $side == "Right")) { eval ( "setAttr " + $side + "HandDummy.CurlFinger1 0"); eval ( "setAttr " + $side + "Finger1_Root.rotateY 0"); eval ( "setAttr " + $side + "Finger1_Mid1.rotateY 0"); eval ( "setAttr " + $side + "Finger1_Mid2.rotateY 0"); eval ( "setDrivenKeyframe -cd " + $side + "HandDummy.CurlFinger1 " + $side + "Finger1_Root.rotateY"); eval ( "setDrivenKeyframe -cd " + $side + "HandDummy.CurlFinger1 " + $side + "Finger1_Mid1.rotateY"); eval ( "setDrivenKeyframe -cd " + $side + "HandDummy.CurlFinger1 " + $side + "Finger1_Mid2.rotateY"); eval ( "setAttr " + $side + "HandDummy.CurlFinger1 10"); if ($side == "Left") { eval ( "setAttr " + $side + "Finger1_Root.rotateY -80"); eval ( "setAttr " + $side + "Finger1_Mid1.rotateY -60"); eval ( "setAttr " + $side + "Finger1_Mid2.rotateY -40"); } else { eval ( "setAttr " + $side + "Finger1_Root.rotateY 80"); eval ( "setAttr " + $side + "Finger1_Mid1.rotateY 60"); eval ( "setAttr " + $side + "Finger1_Mid2.rotateY 40"); } eval ( "setDrivenKeyframe -cd " + $side + "HandDummy.CurlFinger1 " + $side + "Finger1_Root.rotateY"); eval ( "setDrivenKeyframe -cd " + $side + "HandDummy.CurlFinger1 " + $side + "Finger1_Mid1.rotateY"); eval ( "setDrivenKeyframe -cd " + $side + "HandDummy.CurlFinger1 " + $side + "Finger1_Mid2.rotateY"); eval ( "setAttr " + $side + "HandDummy.CurlFinger1 -10"); if ($side == "Left") { eval ( "setAttr " + $side + "Finger1_Root.rotateY 20"); eval ( "setAttr " + $side + "Finger1_Mid1.rotateY 0"); eval ( "setAttr " + $side + "Finger1_Mid2.rotateY 20"); } else { eval ( "setAttr " + $side + "Finger1_Root.rotateY -20"); eval ( "setAttr " + $side + "Finger1_Mid1.rotateY 0"); eval ( "setAttr " + $side + "Finger1_Mid2.rotateY -20"); } eval ( "setDrivenKeyframe -cd " + $side + "HandDummy.CurlFinger1 " + $side + "Finger1_Root.rotateY"); eval ( "setDrivenKeyframe -cd " + $side + "HandDummy.CurlFinger1 " + $side + "Finger1_Mid1.rotateY"); eval ( "setDrivenKeyframe -cd " + $side + "HandDummy.CurlFinger1 " + $side + "Finger1_Mid2.rotateY"); eval ( "setAttr " + $side + "HandDummy.CurlFinger1 0"); } // Set driven key for second finger curling if ((`objExists LeftFinger2_Root` && $side == "Left") || (`objExists RightFinger2_Root` && $side == "Right")) { eval ( "setAttr " + $side + "HandDummy.CurlFinger2 0"); eval ( "setAttr " + $side + "Finger2_Root.rotateY 0"); eval ( "setAttr " + $side + "Finger2_Mid1.rotateY 0"); eval ( "setAttr " + $side + "Finger2_Mid2.rotateY 0"); eval ( "setDrivenKeyframe -cd " + $side + "HandDummy.CurlFinger2 " + $side + "Finger2_Root.rotateY"); eval ( "setDrivenKeyframe -cd " + $side + "HandDummy.CurlFinger2 " + $side + "Finger2_Mid1.rotateY"); eval ( "setDrivenKeyframe -cd " + $side + "HandDummy.CurlFinger2 " + $side + "Finger2_Mid2.rotateY"); eval ( "setAttr " + $side + "HandDummy.CurlFinger2 10"); if ($side == "Left") { eval ( "setAttr " + $side + "Finger2_Root.rotateY -80"); eval ( "setAttr " + $side + "Finger2_Mid1.rotateY -60"); eval ( "setAttr " + $side + "Finger2_Mid2.rotateY -40"); } else { eval ( "setAttr " + $side + "Finger2_Root.rotateY 80"); eval ( "setAttr " + $side + "Finger2_Mid1.rotateY 60"); eval ( "setAttr " + $side + "Finger2_Mid2.rotateY 40"); } eval ( "setDrivenKeyframe -cd " + $side + "HandDummy.CurlFinger2 " + $side + "Finger2_Root.rotateY"); eval ( "setDrivenKeyframe -cd " + $side + "HandDummy.CurlFinger2 " + $side + "Finger2_Mid1.rotateY"); eval ( "setDrivenKeyframe -cd " + $side + "HandDummy.CurlFinger2 " + $side + "Finger2_Mid2.rotateY"); eval ( "setAttr " + $side + "HandDummy.CurlFinger2 -10"); if ($side == "Left") { eval ( "setAttr " + $side + "Finger2_Root.rotateY 20"); eval ( "setAttr " + $side + "Finger2_Mid1.rotateY 0"); eval ( "setAttr " + $side + "Finger2_Mid2.rotateY 20"); } else { eval ( "setAttr " + $side + "Finger2_Root.rotateY -20"); eval ( "setAttr " + $side + "Finger2_Mid1.rotateY 0"); eval ( "setAttr " + $side + "Finger2_Mid2.rotateY -20"); } eval ( "setDrivenKeyframe -cd " + $side + "HandDummy.CurlFinger2 " + $side + "Finger2_Root.rotateY"); eval ( "setDrivenKeyframe -cd " + $side + "HandDummy.CurlFinger2 " + $side + "Finger2_Mid1.rotateY"); eval ( "setDrivenKeyframe -cd " + $side + "HandDummy.CurlFinger2 " + $side + "Finger2_Mid2.rotateY"); eval ( "setAttr " + $side + "HandDummy.CurlFinger2 0"); } // Set driven key for third finger curling if ((`objExists LeftFinger3_Root` && $side == "Left") || (`objExists RightFinger3_Root` && $side == "Right")) { eval ( "setAttr " + $side + "HandDummy.CurlFinger3 0"); eval ( "setAttr " + $side + "Finger3_Root.rotateY 0"); eval ( "setAttr " + $side + "Finger3_Mid1.rotateY 0"); eval ( "setAttr " + $side + "Finger3_Mid2.rotateY 0"); eval ( "setDrivenKeyframe -cd " + $side + "HandDummy.CurlFinger3 " + $side + "Finger3_Root.rotateY"); eval ( "setDrivenKeyframe -cd " + $side + "HandDummy.CurlFinger3 " + $side + "Finger3_Mid1.rotateY"); eval ( "setDrivenKeyframe -cd " + $side + "HandDummy.CurlFinger3 " + $side + "Finger3_Mid2.rotateY"); eval ( "setAttr " + $side + "HandDummy.CurlFinger3 10"); if ($side == "Left") { eval ( "setAttr " + $side + "Finger3_Root.rotateY -80"); eval ( "setAttr " + $side + "Finger3_Mid1.rotateY -60"); eval ( "setAttr " + $side + "Finger3_Mid2.rotateY -40"); } else { eval ( "setAttr " + $side + "Finger3_Root.rotateY 80"); eval ( "setAttr " + $side + "Finger3_Mid1.rotateY 60"); eval ( "setAttr " + $side + "Finger3_Mid2.rotateY 40"); } eval ( "setDrivenKeyframe -cd " + $side + "HandDummy.CurlFinger3 " + $side + "Finger3_Root.rotateY"); eval ( "setDrivenKeyframe -cd " + $side + "HandDummy.CurlFinger3 " + $side + "Finger3_Mid1.rotateY"); eval ( "setDrivenKeyframe -cd " + $side + "HandDummy.CurlFinger3 " + $side + "Finger3_Mid2.rotateY"); eval ( "setAttr " + $side + "HandDummy.CurlFinger3 -10"); if ($side == "Left") { eval ( "setAttr " + $side + "Finger3_Root.rotateY 20"); eval ( "setAttr " + $side + "Finger3_Mid1.rotateY 0"); eval ( "setAttr " + $side + "Finger3_Mid2.rotateY 20"); } else { eval ( "setAttr " + $side + "Finger3_Root.rotateY -20"); eval ( "setAttr " + $side + "Finger3_Mid1.rotateY 0"); eval ( "setAttr " + $side + "Finger3_Mid2.rotateY -20"); } eval ( "setDrivenKeyframe -cd " + $side + "HandDummy.CurlFinger3 " + $side + "Finger3_Root.rotateY"); eval ( "setDrivenKeyframe -cd " + $side + "HandDummy.CurlFinger3 " + $side + "Finger3_Mid1.rotateY"); eval ( "setDrivenKeyframe -cd " + $side + "HandDummy.CurlFinger3 " + $side + "Finger3_Mid2.rotateY"); eval ( "setAttr " + $side + "HandDummy.CurlFinger3 0"); } // Set driven key for spreading the fingers if ((`objExists LeftFinger1_Root` && $side == "Left") || (`objExists RightFinger1_Root` && $side == "Right")) { eval ( "setAttr " + $side + "HandDummy.SpreadAllFingers 0"); eval ( "setAttr " + $side + "Finger1_Root.rotateZ 0"); eval ( "setDrivenKeyframe -cd " + $side + "HandDummy.SpreadAllFingers " + $side + "Finger1_Root.rotateZ"); eval ( "setAttr " + $side + "HandDummy.SpreadAllFingers 10"); eval ( "setAttr " + $side + "Finger1_Root.rotateZ 40"); eval ( "setDrivenKeyframe -cd " + $side + "HandDummy.SpreadAllFingers " + $side + "Finger1_Root.rotateZ"); eval ( "setAttr " + $side + "HandDummy.SpreadAllFingers -10"); eval ( "setAttr " + $side + "Finger1_Root.rotateZ -15"); eval ( "setDrivenKeyframe -cd " + $side + "HandDummy.SpreadAllFingers " + $side + "Finger1_Root.rotateZ"); eval ( "setAttr " + $side + "HandDummy.SpreadAllFingers 0"); } if ((`objExists LeftFinger2_Root` && `objExists LeftFinger1_Root` && $side == "Left") || (`objExists RightFinger2_Root` && `objExists RightFinger1_Root` && $side == "Right")) { eval ( "setAttr " + $side + "HandDummy.SpreadAllFingers 0"); eval ( "setAttr " + $side + "Finger2_Root.rotateZ 0"); eval ( "setDrivenKeyframe -cd " + $side + "HandDummy.SpreadAllFingers " + $side + "Finger2_Root.rotateZ"); eval ( "setAttr " + $side + "HandDummy.SpreadAllFingers 10"); eval ( "setAttr " + $side + "Finger2_Root.rotateZ 0"); eval ( "setDrivenKeyframe -cd " + $side + "HandDummy.SpreadAllFingers " + $side + "Finger2_Root.rotateZ"); eval ( "setAttr " + $side + "HandDummy.SpreadAllFingers -10"); eval ( "setAttr " + $side + "Finger2_Root.rotateZ 0"); eval ( "setDrivenKeyframe -cd " + $side + "HandDummy.SpreadAllFingers " + $side + "Finger2_Root.rotateZ"); eval ( "setAttr " + $side + "HandDummy.SpreadAllFingers 0"); } if ((`objExists LeftFinger3_Root` && $side == "Left") || (`objExists RightFinger3_Root` && $side == "Right")) { eval ( "setAttr " + $side + "HandDummy.SpreadAllFingers 0"); eval ( "setAttr " + $side + "Finger3_Root.rotateZ 0"); eval ( "setDrivenKeyframe -cd " + $side + "HandDummy.SpreadAllFingers " + $side + "Finger3_Root.rotateZ"); eval ( "setAttr " + $side + "HandDummy.SpreadAllFingers 10"); eval ( "setAttr " + $side + "Finger3_Root.rotateZ -40"); eval ( "setDrivenKeyframe -cd " + $side + "HandDummy.SpreadAllFingers " + $side + "Finger3_Root.rotateZ"); eval ( "setAttr " + $side + "HandDummy.SpreadAllFingers -10"); eval ( "setAttr " + $side + "Finger3_Root.rotateZ 15"); eval ( "setDrivenKeyframe -cd " + $side + "HandDummy.SpreadAllFingers " + $side + "Finger3_Root.rotateZ"); eval ( "setAttr " + $side + "HandDummy.SpreadAllFingers 0"); } } global proc mirrorJoints() { // Mirror the arms and legs. select -r LeftLegRoot ; mirrorJoint -mirrorYZ -mirrorBehavior -searchReplace "Left" "Right"; select -r LeftClavicleRoot; mirrorJoint -mirrorYZ -mirrorBehavior -searchReplace "Left" "Right"; // The fingers need adjusting after the mirroring. if (`objExists RightFinger1_Root`) { select -r RightFinger1_Root.rotateAxis ; rotate -r -os -180 0 0 ; } if (`objExists RightFinger2_Root`) { select -r RightFinger2_Root.rotateAxis ; rotate -r -os -180 0 0 ; } if (`objExists RightFinger3_Root`) { select -r RightFinger3_Root.rotateAxis ; rotate -r -os -180 0 0 ; } select -cl; } // Run this AFTER mirroring the joints! global proc orientJoints() { select -r BackRoot ; // Orient joints. joint -e -oj none -ch -zso; // Freeze transformations. makeIdentity -apply true -t 1 -r 1 -s 1; select -cl; print "Joints oriented.\n"; } global proc makeLegsIK() { // Create the left leg IK. select -cl ; select -r LeftFootAnkle.rotatePivot ; select -add LeftLegRoot.rotatePivot ; ikHandle -s sticky -n LeftFootAnkleIK; // Create the right leg IK. select -r RightFootAnkle.rotatePivot ; select -add RightLegRoot.rotatePivot ; ikHandle -s sticky -n RightFootAnkleIK; // BEFORE parenting the IKs, create the knee aim controller. makeArrowDummy("LeftKneeAim"); makeArrowDummy("RightKneeAim"); // Position the knee aim at the left knee bone. // You can't just take its position, since it's relative // to the hip bone. Therefore, we duplicate and unparent it. select -cl; $tmpKnee = `duplicate -rr LeftLegKnee`; rename $tmpKnee "LeftLegKneeTmp"; parent -w LeftLegKneeTmp; $lKneePos = `getAttr LeftLegKneeTmp.translate`; setAttr "LeftKneeAim.translateX" $lKneePos[0]; setAttr "LeftKneeAim.translateY" $lKneePos[1]; setAttr "LeftKneeAim.translateZ" $lKneePos[2]; delete LeftLegKneeTmp; // Repeat with the right knee bone. $tmpKnee = `duplicate -rr RightLegKnee`; rename $tmpKnee "RightLegKneeTmp"; parent -w RightLegKneeTmp; $rKneePos = `getAttr RightLegKneeTmp.translate`; setAttr "RightKneeAim.translateX" $rKneePos[0]; setAttr "RightKneeAim.translateY" $rKneePos[1]; setAttr "RightKneeAim.translateZ" $rKneePos[2]; delete RightLegKneeTmp; // Offset the left knee aim in the direction of the pole vector. float $lpv[] = `getAttr LeftFootAnkleIK.poleVector`; vector $lpvec = `unit <<$lpv[0], $lpv[1], $lpv[2]>>`; float $lparray[] = { $lpvec.x, $lpvec.y, $lpvec.z }; move -r $lparray[0] $lparray[1] $lparray[2] LeftKneeAim; makeIdentity -apply true -t 1 -r 1 -s 1 LeftKneeAim; // Repeat with the right knee aim. float $rpv[] = `getAttr RightFootAnkleIK.poleVector`; vector $rpvec = `unit <<$rpv[0], $rpv[1], $rpv[2]>>`; float $rparray[] = { $rpvec.x, $rpvec.y, $rpvec.z }; move -r $rparray[0] $rparray[1] $rparray[2] RightKneeAim; makeIdentity -apply true -t 1 -r 1 -s 1 RightKneeAim; // Connect the knee aims. select -r LeftKneeAim ; select -tgl LeftFootAnkleIK ; poleVectorConstraint -weight 1; select -r RightKneeAim ; select -tgl RightFootAnkleIK ; poleVectorConstraint -weight 1; select -cl; makeInverseFootIK(); } global proc makeInverseFootIK() { // Unparent the inverse heel. parent -w LeftInverseHeel; // Create the inverse foot bone structure. select -r LeftFootAnkle ; duplicate -rr; // Rename and unparent the new joints. rename "LeftFootAnkle1" "LeftFootAnkleInverse"; select -r LeftFootAnkleInverse; parent -w; select -r LeftFootAnkleInverse|LeftFootBall ; rename "LeftFootAnkleInverse|LeftFootBall" "LeftFootBallInverse"; parent -w; select -r LeftFootBallInverse|LeftFootToe ; rename "LeftFootBallInverse|LeftFootToe" "LeftFootToeInverse"; parent -w; // Reparent the joints in reverse order. select -r LeftFootAnkleInverse ; select -tgl LeftFootBallInverse ; parent; select -r LeftFootBallInverse ; select -tgl LeftFootToeInverse ; parent; select -r LeftFootToeInverse ; select -tgl LeftInverseHeel ; parent; // Delete the other inverse heel, and // mirror the geometry to the other side. delete RightInverseHeel; select -r LeftInverseHeel; mirrorJoint -mirrorYZ -mirrorBehavior -searchReplace "Left" "Right"; // Create the left foot IK. select -r LeftFootToe.rotatePivot ; select -add LeftFootBall.rotatePivot ; ikHandle -s sticky -n LeftFootToeIK; select -r LeftFootBall.rotatePivot ; select -add LeftFootAnkle.rotatePivot ; ikHandle -s sticky -n LeftFootBallIK; // Create the right foot IK. select -r RightFootToe.rotatePivot ; select -add RightFootBall.rotatePivot ; ikHandle -s sticky -n RightFootToeIK; select -r RightFootBall.rotatePivot ; select -add RightFootAnkle.rotatePivot ; ikHandle -s sticky -n RightFootBallIK; // Parent IKs to the inverse left foot. parent LeftFootToeIK LeftFootToeInverse; parent LeftFootBallIK LeftFootBallInverse; if (`objExists "LeftFootAnkleIK"`) parent LeftFootAnkleIK LeftFootAnkleInverse; select -cl ; // Parent IKs to the inverse right foot. parent RightFootToeIK RightFootToeInverse; parent RightFootBallIK RightFootBallInverse; if (`objExists "RightFootAnkleIK"`) parent RightFootAnkleIK RightFootAnkleInverse; select -cl ; print "Finished building leg IK.\n"; } global proc makeArmsIK() { // Create IK for clavicles. select -r LeftClavicleEnd.rotatePivot ; select -add LeftClavicleRoot.rotatePivot ; ikHandle -s sticky -n LeftClavicleIK; makeIdentity -apply true -t 1 -r 1 -s 1; select -r RightClavicleEnd.rotatePivot ; select -add RightClavicleRoot.rotatePivot ; ikHandle -s sticky -n RightClavicleIK; makeIdentity -apply true -t 1 -r 1 -s 1; // Create IK for arms. select -r LeftArmWrist.rotatePivot ; select -add LeftArmRoot.rotatePivot ; ikHandle -s sticky -n LeftArmIK; select -r RightArmWrist.rotatePivot ; select -add RightArmRoot.rotatePivot ; ikHandle -s sticky -n RightArmIK; // Create IK for hands. select -r LeftArmHand.rotatePivot ; select -add LeftArmWrist.rotatePivot ; ikHandle -s sticky -n LeftHandIK; parent LeftHandIK LeftArmIK; makeIdentity -apply true -t 1 -r 1 -s 1 -n 0; select -r RightArmHand.rotatePivot ; select -add RightArmWrist.rotatePivot ; ikHandle -s sticky -n RightHandIK; parent RightHandIK RightArmIK; makeIdentity -apply true -t 1 -r 1 -s 1 -n 0; // Create left hand pad groups. //float $lHandPos[] = `getAttr LeftHandRoot.translate`; //select -r LeftHandRoot ; //makeIdentity -apply true -t 1 -r 1 -s 1; //group -n LeftWristShake; //xform -os -piv $lHandPos[0] $lHandPos[1] $lHandPos[2]; //group -n LeftWristWave; //xform -os -piv $lHandPos[0] $lHandPos[1] $lHandPos[2]; // Create right hand pad groups. //float $rHandPos[] = `getAttr RightHandRoot.translate`; //select -r RightHandRoot ; //makeIdentity -apply true -t 1 -r 1 -s 1; //group -n RightWristShake; //xform -os -piv $rHandPos[0] $rHandPos[1] $rHandPos[2]; //group -n RightWristWave; //xform -os -piv $rHandPos[0] $rHandPos[1] $rHandPos[2]; select -cl; // Create elbow IK pole vector targets. makeArrowDummy("LeftElbowAim"); makeArrowDummy("RightElbowAim"); // Position the elbow aim at the left elbow bone. // You can't just take its position, since it's relative // to the shoulder bone. Therefore, we duplicate and unparent it. select -cl; $tmpElbow = `duplicate -rr LeftArmElbow`; rename $tmpElbow "LeftArmElbowTmp"; parent -w LeftArmElbowTmp; $lElbowPos = `getAttr LeftArmElbowTmp.translate`; setAttr "LeftElbowAim.translateX" $lElbowPos[0]; setAttr "LeftElbowAim.translateY" $lElbowPos[1]; setAttr "LeftElbowAim.translateZ" $lElbowPos[2]; delete LeftArmElbowTmp; // Repeat with the right elbow aim. $tmpElbow = `duplicate -rr RightArmElbow`; rename $tmpElbow "RightArmElbowTmp"; parent -w RightArmElbowTmp; $rElbowPos = `getAttr RightArmElbowTmp.translate`; setAttr "RightElbowAim.translateX" $rElbowPos[0]; setAttr "RightElbowAim.translateY" $rElbowPos[1]; setAttr "RightElbowAim.translateZ" $rElbowPos[2]; delete RightArmElbowTmp; // Offset the left elbow aim. float $lpv[] = `getAttr LeftArmIK.poleVector`; vector $lpvec = `unit <<$lpv[0], $lpv[1], $lpv[2]>>`; float $lparray[] = { $lpvec.x, $lpvec.y, $lpvec.z }; move -r $lparray[0] $lparray[1] $lparray[2] LeftElbowAim; //move -r $lpvec.x $lpvec.y $lpvec.z LeftElbowAim; makeIdentity -apply true -t 1 -r 1 -s 1 LeftElbowAim; // Offset the right elbow aim. float $rpv[] = `getAttr RightArmIK.poleVector`; vector $rpvec = `unit <<$rpv[0], $rpv[1], $rpv[2]>>`; float $rparray[] = { $rpvec.x, $rpvec.y, $rpvec.z }; move -r $rparray[0] $rparray[1] $rparray[2] RightElbowAim; makeIdentity -apply true -t 1 -r 1 -s 1 RightElbowAim; // Connect the elbow aims with the elbow IKs. select -r LeftElbowAim ; select -tgl LeftArmIK ; poleVectorConstraint -weight 1; select -r RightElbowAim ; select -tgl RightArmIK ; poleVectorConstraint -weight 1; select -cl; print "Finished building arm IK.\n"; } global proc makeSpineIK() { if (`objExists curve1`) rename curve1 renamed_curve1; // Create an IK spline with 6 cv's. select -r Back1.rotatePivot ; select -add BackEnd.rotatePivot ; ikHandle -sol ikSplineSolver -ns 3; rename curve1 SpineCurve; // Create a cluster. select -r SpineCurve.cv[0:5] ; newCluster " -envelope 1 -n SpineCluster"; // Weigh the curve cv's. select -r SpineCurve.cv[0:5] ; percent -v 0.0 SpineCluster SpineCurve.cv[0] ; percent -v 0.1 SpineCluster SpineCurve.cv[1] ; percent -v 0.2 SpineCluster SpineCurve.cv[2] ; percent -v 0.4 SpineCluster SpineCurve.cv[3] ; percent -v 0.8 SpineCluster SpineCurve.cv[4] ; percent -v 1.0 SpineCluster SpineCurve.cv[5] ; // Move the cluster's pivot to the bottom of the spine. select -r Back1; duplicate -rr; parent -w Back4; float $tmpSpinePos[] = `getAttr Back4.translate`; move $tmpSpinePos[0] $tmpSpinePos[1] $tmpSpinePos[2] SpineClusterHandle.scalePivot SpineClusterHandle.rotatePivot ; delete Back4; // Lock the cluster from moving and scaling. setAttr -lock true "SpineClusterHandle.tx"; setAttr -lock true "SpineClusterHandle.ty"; setAttr -lock true "SpineClusterHandle.tz"; setAttr -lock true "SpineClusterHandle.sx"; setAttr -lock true "SpineClusterHandle.sy"; setAttr -lock true "SpineClusterHandle.sz"; select -cl; print "Finished building spine IK.\n"; } global proc makeIKControllers() { // Create foot dummies. I don't know how to figure out its scale, // so for now, just vertex-edit it if it doesn't match. :) curve -d 1 -p 0.313157 0.100989 -0.187662 -p -0.286752 0.100989 -0.183199 -p -0.286752 -0.0526989 -0.183199 -p -0.286752 0.100989 -0.183199 -p -0.209138 0.100989 1.145582 -p -0.209138 -0.0526989 1.145582 -p -0.209138 0.100989 1.145582 -p 0.249606 0.100989 1.259702 -p 0.249606 -0.0526989 1.259702 -p 0.249606 0.100989 1.259702 -p 0.526521 0.100989 1.011503 -p 0.526521 -0.0526989 1.011503 -p 0.526521 0.100989 1.011503 -p 0.313157 0.100989 -0.187662 -p 0.313157 -0.0526989 -0.187662 -p -0.286752 -0.0526989 -0.183199 -p -0.209138 -0.0526989 1.145582 -p 0.249606 -0.0526989 1.259702 -p 0.526521 -0.0526989 1.011503 -p 0.313157 -0.0526989 -0.187662 -k 0 -k 1 -k 2 -k 3 -k 4 -k 5 -k 6 -k 7 -k 8 -k 9 -k 10 -k 11 -k 12 -k 13 -k 14 -k 15 -k 16 -k 17 -k 18 -k 19 -n LeftFootDummy; float $leftHeelPos[] = `getAttr LeftInverseHeel.translate`; setAttr LeftFootDummy.tx $leftHeelPos[0]; setAttr LeftFootDummy.ty $leftHeelPos[1]; setAttr LeftFootDummy.tz $leftHeelPos[2]; // Duplicate left foot dummy to the right select -cl ; select -r LeftFootDummy ; duplicate -rr; rename "LeftFootDummy1" "RightFootDummy"; float $rightHeelPosX = -$leftHeelPos[0]; setAttr "RightFootDummy.translateX" $rightHeelPosX; setAttr "RightFootDummy.scaleX" -1; // Freeze transformations on the dummies. select -r RightFootDummy ; makeIdentity -apply true -t 1 -r 1 -s 1; select -r LeftFootDummy ; makeIdentity -apply true -t 1 -r 1 -s 1; // Parent foot dummies to the inverse heels. select -r LeftInverseHeel ; select -tgl LeftFootDummy ; parent; select -r RightInverseHeel ; select -tgl RightFootDummy ; parent; select -cl ; // Add toe and ball rotation attributes to the dummies. select -r LeftFootDummy ; addAttr -ln ToeRotate -at double -min -10 -max 10 -dv 0 |LeftFootDummy ; setAttr -e -keyable true |LeftFootDummy.ToeRotate; addAttr -ln BallRotate -at double -min -10 -max 10 -dv 0 |LeftFootDummy ; setAttr -e -keyable true |LeftFootDummy.BallRotate; select -r RightFootDummy ; addAttr -ln ToeRotate -at double -min -10 -max 10 -dv 0 |RightFootDummy ; setAttr -e -keyable true |RightFootDummy.ToeRotate; addAttr -ln BallRotate -at double -min -10 -max 10 -dv 0 |RightFootDummy ; setAttr -e -keyable true |RightFootDummy.BallRotate; select -cl; // Set the driven key for LeftToeRotate. // (10 => -60 degrees z, -10 => 50 degrees z.) setAttr "LeftFootDummy.ToeRotate" 0; setAttr "LeftFootToeInverse.rotateZ" 0; setDrivenKeyframe -cd LeftFootDummy.ToeRotate LeftFootToeInverse.rotateZ; setAttr "LeftFootDummy.ToeRotate" 10; setAttr "LeftFootToeInverse.rotateZ" -60; setDrivenKeyframe -cd LeftFootDummy.ToeRotate LeftFootToeInverse.rotateZ; setAttr "LeftFootDummy.ToeRotate" -10; setAttr "LeftFootToeInverse.rotateZ" 50; setDrivenKeyframe -cd LeftFootDummy.ToeRotate LeftFootToeInverse.rotateZ; setAttr "LeftFootDummy.ToeRotate" 0; // Set the driven key for LeftFootBallRotate. // (10 => -60 degrees z, -10 => 50 degrees z.) setAttr "LeftFootDummy.BallRotate" 0; setAttr "LeftFootBallInverse.rotateZ" 0; setDrivenKeyframe -cd LeftFootDummy.BallRotate LeftFootBallInverse.rotateZ; setAttr "LeftFootDummy.BallRotate" 10; setAttr "LeftFootBallInverse.rotateZ" -60; setDrivenKeyframe -cd LeftFootDummy.BallRotate LeftFootBallInverse.rotateZ; setAttr "LeftFootDummy.BallRotate" -10; setAttr "LeftFootBallInverse.rotateZ" 50; setDrivenKeyframe -cd LeftFootDummy.BallRotate LeftFootBallInverse.rotateZ; setAttr "LeftFootDummy.BallRotate" 0; // Set the driven key for RightToeRotate. // (10 => -60 degrees z, -10 => 50 degrees z.) setAttr "RightFootDummy.ToeRotate" 0; setAttr "RightFootToeInverse.rotateZ" 0; setDrivenKeyframe -cd RightFootDummy.ToeRotate RightFootToeInverse.rotateZ; setAttr "RightFootDummy.ToeRotate" 10; setAttr "RightFootToeInverse.rotateZ" -60; setDrivenKeyframe -cd RightFootDummy.ToeRotate RightFootToeInverse.rotateZ; setAttr "RightFootDummy.ToeRotate" -10; setAttr "RightFootToeInverse.rotateZ" 50; setDrivenKeyframe -cd RightFootDummy.ToeRotate RightFootToeInverse.rotateZ; setAttr "RightFootDummy.ToeRotate" 0; // Set the driven key for RightFootBallRotate. // (10 => -50 degrees z, -10 => 30 degrees z.) setAttr "RightFootDummy.BallRotate" 0; setAttr "RightFootBallInverse.rotateZ" 0; setDrivenKeyframe -cd RightFootDummy.BallRotate RightFootBallInverse.rotateZ; setAttr "RightFootDummy.BallRotate" 10; setAttr "RightFootBallInverse.rotateZ" -60; setDrivenKeyframe -cd RightFootDummy.BallRotate RightFootBallInverse.rotateZ; setAttr "RightFootDummy.BallRotate" -10; setAttr "RightFootBallInverse.rotateZ" 50; setDrivenKeyframe -cd RightFootDummy.BallRotate RightFootBallInverse.rotateZ; setAttr "RightFootDummy.BallRotate" 0; // Create the controller for both feet and make the feet controllers its children. spaceLocator -p 0 0 0 -n BothFeet; move -r 0 0 1.262427; scale -r 0.25 0.25 0.25 ; makeIdentity -apply true -t 1 -r 1 -s 0; select -r RightFootDummy ; select -tgl LeftFootDummy ; select -tgl BothFeet ; parent; // Move the pivot of the two-feet controller to the origin. move 0 0 0 BothFeet.scalePivot BothFeet.rotatePivot ; // Create left hand dummy controller. float $lIKPos[] = `getAttr LeftArmIK.translate`; makeBoxDummy("LeftHandDummy"); move -r $lIKPos[0] $lIKPos[1] $lIKPos[2]; scale -r 0.15 0.4 0.4 ; // Create custom attributes. select -r LeftHandDummy ; addAttr -ln WristWave -at double -min -10 -max 10 -dv 0 LeftHandDummy; setAttr -e -keyable true LeftHandDummy.WristWave; addAttr -ln WristShake -at double -min -10 -max 10 -dv 0 LeftHandDummy; setAttr -e -keyable true LeftHandDummy.WristShake; addAttr -ln WristTwist -at double -min -10 -max 10 -dv 0 LeftHandDummy; setAttr -e -keyable true LeftHandDummy.WristTwist; addAttr -ln CurlThumb -at double -min -10 -max 10 -dv 0 LeftHandDummy; setAttr -e -keyable true LeftHandDummy.CurlThumb; if (`objExists LeftFinger1_Root`) { addAttr -ln CurlFinger1 -at double -min -10 -max 10 -dv 0 LeftHandDummy; setAttr -e -keyable true LeftHandDummy.CurlFinger1; } if (`objExists LeftFinger2_Root`) { addAttr -ln CurlFinger2 -at double -min -10 -max 10 -dv 0 LeftHandDummy; setAttr -e -keyable true LeftHandDummy.CurlFinger2; } if (`objExists LeftFinger3_Root`) { addAttr -ln CurlFinger3 -at double -min -10 -max 10 -dv 0 LeftHandDummy; setAttr -e -keyable true LeftHandDummy.CurlFinger3; } // Spread the fingers only if there is more than 1 finger // (in which case finger1 is guaranteed to exist). if (`objExists LeftFinger1_Root`) { addAttr -ln SpreadAllFingers -at double -min -10 -max 10 -dv 0 LeftHandDummy; setAttr -e -keyable true LeftHandDummy.SpreadAllFingers; } // Duplicate it to the right hand. duplicate -rr; rename "LeftHandDummy1" "RightHandDummy"; // Position the right hand dummy controller. float $rIKPos[] = `getAttr RightArmIK.translate`; setAttr RightHandDummy.tx $rIKPos[0]; setAttr RightHandDummy.ty $rIKPos[1]; setAttr RightHandDummy.tz $rIKPos[2]; // Parent the IK to the left hand dummy. makeIdentity -apply true -t 1 -r 1 -s 1 LeftHandDummy; parent LeftArmIK LeftHandDummy; select -cl; // Parent the IK to the right hand dummy. makeIdentity -apply true -t 1 -r 1 -s 1 RightHandDummy; parent RightArmIK RightHandDummy; select -cl; // Create padding groups for the hand IK. // IK will do the twisting at the top level. select -r LeftHandIK; group -n LeftWristShake; xform -os -piv 0 0 0; group -n LeftWristWave; xform -os -piv 0 0 0; select -r RightHandIK; group -n RightWristShake; xform -os -piv 0 0 0; group -n RightWristWave; xform -os -piv 0 0 0; // Set up driven keys for the hands. setHandDrivenKeys("Left"); setHandDrivenKeys("Right"); // Parent aim constraints to corresponding dummy nodes. parent LeftKneeAim LeftFootDummy; parent RightKneeAim RightFootDummy; parent LeftElbowAim LeftHandDummy; parent RightElbowAim RightHandDummy; print "Finished building arm and leg helpers.\n"; } global proc makeHeadHelpers() { // Create head dummy. select -cl; makeBoxDummy("HeadDummy"); scale -r 0.5 0.2 0.5 ; select -r NeckRoot; duplicate -rr; parent -w; $tmpNeckPos = `getAttr NeckRoot1.translate`; move -r $tmpNeckPos[0] $tmpNeckPos[1] $tmpNeckPos[2] HeadDummy; makeIdentity -apply true -t 1 -r 1 -s 1 HeadDummy; delete NeckRoot1; parent HeadDummy NeckRoot; // Create head padding groups. select -r HeadRoot; group -n HeadNod; xform -os -piv 0 0 0; group -n HeadTilt; xform -os -piv 0 0 0; group -n HeadTwist; xform -os -piv 0 0 0; select -cl; // Add custom attributes to the head dummy to rotate the neck. select -r HeadDummy ; addAttr -ln HeadTwist -at double -min -10 -max 10 -dv 0 HeadDummy; setAttr -e -keyable true HeadDummy.HeadTwist; addAttr -ln HeadTilt -at double -min -10 -max 10 -dv 0 HeadDummy; setAttr -e -keyable true HeadDummy.HeadTilt; addAttr -ln HeadNod -at double -min -10 -max 10 -dv 0 HeadDummy; setAttr -e -keyable true HeadDummy.HeadNod; select -cl ; // Create driven keys for twisting the head. setAttr "HeadDummy.HeadTwist" 0; setAttr "HeadTwist.rotateX" 0; setDrivenKeyframe -cd HeadDummy.HeadTwist HeadTwist.rotateX; setAttr "HeadDummy.HeadTwist" 10; setAttr "HeadTwist.rotateX" -90; setDrivenKeyframe -cd HeadDummy.HeadTwist HeadTwist.rotateX; setAttr "HeadDummy.HeadTwist" -10; setAttr "HeadTwist.rotateX" -90; setDrivenKeyframe -cd HeadDummy.HeadTwist HeadTwist.rotateX; setAttr "HeadDummy.HeadTwist" 0; // Create driven keys for tilting the head. setAttr "HeadDummy.HeadTilt" 0; setAttr "HeadTilt.rotateY" 0; setDrivenKeyframe -cd HeadDummy.HeadTilt HeadTilt.rotateY; setAttr "HeadDummy.HeadTilt" 10; setAttr "HeadTilt.rotateY" -50; setDrivenKeyframe -cd HeadDummy.HeadTilt HeadTilt.rotateY; setAttr "HeadDummy.HeadTilt" -10; setAttr "HeadTilt.rotateY" 50; setDrivenKeyframe -cd HeadDummy.HeadTilt HeadTilt.rotateY; setAttr "HeadDummy.HeadTilt" 0; // Create driven keys for nodding the head. setAttr "HeadDummy.HeadNod" 0; setAttr "HeadNod.rotateZ" 0; setDrivenKeyframe -cd HeadDummy.HeadNod HeadNod.rotateZ; setAttr "HeadDummy.HeadNod" 10; setAttr "HeadNod.rotateZ" -70; setDrivenKeyframe -cd HeadDummy.HeadNod HeadNod.rotateZ; setAttr "HeadDummy.HeadNod" -10; setAttr "HeadNod.rotateZ" 70; setDrivenKeyframe -cd HeadDummy.HeadNod HeadNod.rotateZ; setAttr "HeadDummy.HeadNod" 0; // Freeze the head box in place. select -r HeadDummy ; makeIdentity -apply true -t 1 -r 1 -s 1 -n 0; setAttr -lock true -keyable false "HeadDummy.tx"; setAttr -lock true -keyable false "HeadDummy.ty"; setAttr -lock true -keyable false "HeadDummy.tz"; setAttr -lock true -keyable false "HeadDummy.rx"; setAttr -lock true -keyable false "HeadDummy.ry"; setAttr -lock true -keyable false "HeadDummy.rz"; setAttr -lock true -keyable false "HeadDummy.sx"; setAttr -lock true -keyable false "HeadDummy.sy"; setAttr -lock true -keyable false "HeadDummy.sz"; setAttr -keyable false "HeadDummy.v"; print "Finished building head helpers.\n"; select -cl; } global proc makeTorsoHelpers() { // Create "UpperBody" letter control. select -cl; textCurves -f "Arial|h-11|w400|c0" -t "U" -n UpperBodyGroup; select -r "curve1"; parent -w; rename "curve1" "UpperBody"; //CenterPivot; scale -r -0.25 0.25 0.25 ; rotate -r 0 45 0; // Move it just behind the back root. $backRootPos = `getAttr BackRoot.translate`; move -r $backRootPos[0] $backRootPos[1] $backRootPos[2] UpperBody; move -r -1.2 0 -1.2 UpperBody; makeIdentity -apply true -t 1 -r 1 -s 1 UpperBody; delete UpperBodyGroupShape; // Move the upper body's pivot to the back root. select -r UpperBody; move $backRootPos[0] $backRootPos[1] $backRootPos[2] UpperBody.scalePivot UpperBody.rotatePivot ; select -cl; // Create "Shoulders" letter control. select -cl; textCurves -ch 0 -f "Arial|h-11|w400|c0" -t "S" -n ShouldersGroup; select -r "curve1"; parent -w; rename "curve1" "Shoulders"; //CenterPivot; //makeIdentity -apply true -t 1 -r 1 -s 1 Shoulders; scale -r 0.25 0.25 0.25 ; rotate -r 0 -45 0; // Move it into position, slightly offset behind the body. move -r $backRootPos[0] $backRootPos[1] $backRootPos[2] Shoulders; move -r 1.2 0 -1.2 Shoulders; makeIdentity -apply true -t 1 -r 1 -s 1 Shoulders; delete ShouldersGroupShape; // Parent the hips to the upper body controls. parent BackRoot UpperBody; // Parent the shoulders to the top of the spine. parent Shoulders BackEnd; makeIdentity -apply true -t 1 -r 1 -s 1 Shoulders; // Parent arms and clavicles to the shoulder controls. select -r LeftClavicleIK ; select -tgl RightClavicleIK ; select -tgl Shoulders ; parent; setAttr -lock true "Shoulders.rx"; setAttr -lock true "Shoulders.ry"; setAttr -lock true "Shoulders.rz"; setAttr -lock true "Shoulders.sx"; setAttr -lock true "Shoulders.sy"; setAttr -lock true "Shoulders.sz"; // Create the root rig control. circle -c 0 0 0 -nr 0 1 0 -sw 360 -r 1 -d 3 -ut 0 -tol 0.01 -s 8 -ch 1 -n Rig; move -r $backRootPos[0] $backRootPos[1] $backRootPos[2] Rig; makeIdentity -apply true -t 1 -r 1 -s 1 Rig; // Parent the feet to the rig. if (`objExists BothFeet`) parent BothFeet Rig; parent UpperBody Rig; // Parent the hand dummies to the rig. if (`objExists LeftHandDummy`) parent LeftHandDummy Rig; if (`objExists RightHandDummy`) parent RightHandDummy Rig; // Add custom attributes to the upper body to rotate the spine. select -r UpperBody ; addAttr -ln BackTwist -at double -min -10 -max 10 -dv 0 UpperBody; setAttr -e -keyable true UpperBody.BackTwist; addAttr -ln BackBend -at double -min -10 -max 10 -dv 0 UpperBody; setAttr -e -keyable true UpperBody.BackBend; addAttr -ln BackBow -at double -min -10 -max 10 -dv 0 UpperBody; setAttr -e -keyable true UpperBody.BackBow; select -cl; // Set driven keys for back bending. setAttr "UpperBody.BackBend" 0; setAttr "SpineClusterHandle.rotateZ" 0; setDrivenKeyframe -cd UpperBody.BackBend SpineClusterHandle.rotateZ; setAttr "UpperBody.BackBend" 10; setAttr "SpineClusterHandle.rotateZ" -60; setDrivenKeyframe -cd UpperBody.BackBend SpineClusterHandle.rotateZ; setAttr "UpperBody.BackBend" -10; setAttr "SpineClusterHandle.rotateZ" 60; setDrivenKeyframe -cd UpperBody.BackBend SpineClusterHandle.rotateZ; setAttr "UpperBody.BackBend" 0; // Set driven keys for back bowing. setAttr "UpperBody.BackBow" 0; setAttr "SpineClusterHandle.rotateX" 0; setDrivenKeyframe -cd UpperBody.BackBow SpineClusterHandle.rotateX; setAttr "UpperBody.BackBow" 10; setAttr "SpineClusterHandle.rotateX" 80; setDrivenKeyframe -cd UpperBody.BackBow SpineClusterHandle.rotateX; setAttr "UpperBody.BackBow" -10; setAttr "SpineClusterHandle.rotateX" -60; setDrivenKeyframe -cd UpperBody.BackBow SpineClusterHandle.rotateX; setAttr "UpperBody.BackBow" 0; // Set driven keys for back twisting. Note that this modifies the joints // directly rather than using the spline IK. setAttr "UpperBody.BackTwist" 0; setAttr "Back1.rotateX" 0; setAttr "Back2.rotateX" 0; setAttr "Back3.rotateX" 0; setDrivenKeyframe -cd UpperBody.BackTwist Back1.rotateX; setDrivenKeyframe -cd UpperBody.BackTwist Back2.rotateX; setDrivenKeyframe -cd UpperBody.BackTwist Back3.rotateX; setAttr "UpperBody.BackTwist" 10; setAttr "Back1.rotateX" 30; setAttr "Back2.rotateX" 30; setAttr "Back3.rotateX" 40; setDrivenKeyframe -cd UpperBody.BackTwist Back1.rotateX; setDrivenKeyframe -cd UpperBody.BackTwist Back2.rotateX; setDrivenKeyframe -cd UpperBody.BackTwist Back3.rotateX; setAttr "UpperBody.BackTwist" -10; setAttr "Back1.rotateX" -30; setAttr "Back2.rotateX" -30; setAttr "Back3.rotateX" -40; setDrivenKeyframe -cd UpperBody.BackTwist Back1.rotateX; setDrivenKeyframe -cd UpperBody.BackTwist Back2.rotateX; setDrivenKeyframe -cd UpperBody.BackTwist Back3.rotateX; setAttr "UpperBody.BackTwist" 0; // Hide the cluster. setAttr "SpineClusterHandle.visibility" off; print "Finished building torso helpers.\n"; select -cl; } global proc makeIK() { orientJoints(); int $bMakeLegsIK = `checkBoxGrp -q -v1 bLegs`; int $bMakeArmsIK = `checkBoxGrp -q -v1 bArms`; int $bMakeSpineIK = `checkBoxGrp -q -v1 bSpine`; if ($bMakeLegsIK == 1) makeLegsIK(); if ($bMakeArmsIK == 1) makeArmsIK(); if ($bMakeSpineIK == 1) makeSpineIK(); } global proc makeHelpers() { int $bMakeIKControllers = `checkBoxGrp -q -v1 bIKControllers`; int $bMakeTorsoHelpers = `checkBoxGrp -q -v1 bTorsoHelpers`; int $bMakeHeadHelpers = `checkBoxGrp -q -v1 bHeadHelpers`; if ($bMakeIKControllers == 1) makeIKControllers(); if ($bMakeTorsoHelpers == 1) makeTorsoHelpers(); if ($bMakeHeadHelpers == 1) makeHeadHelpers(); } global proc showAbout() { if (`window -exists showAbout`){ deleteUI -window showAbout; } window -t "About" -width 435 -height 350 -minimizeButton false -maximizeButton false showAbout; formLayout -numberOfDivisions 100 aboutForm; scrollLayout aboutScroll; columnLayout; string $text; text -l "Automated Rig Setup Tool v.1.0\nNikita Pavlov\n10.10.2005\nwww.andrew.cmu.edu/user/nyp\n\n" -align left; //text -l "about:\n" -align left; //$text = "A tool to generate a fast mocap skeleton and then making symmetric operations. \n\n"; //text -l $text -align left; setParent ..; setParent ..; button -l "Close" -height 25 -c "deleteUI -window showAbout;" cBn; int $lmargin = 3; int $rmargin = 3; formLayout -e -attachForm aboutScroll "left" $lmargin -attachForm aboutScroll "top" 6 -attachForm aboutScroll "right" $rmargin -attachControl aboutScroll "bottom" 4 cBn -attachForm cBn "left" $lmargin -attachForm cBn "right" $rmargin -attachForm cBn "bottom" 5 aboutForm ; showWindow showAbout; } global proc scaleSkeleton( ) { float $scale = `floatFieldGrp -q -v1 number1`; string $rootNode[] = `ls -sl`; if (size($rootNode) == 0) { error "You did not select a joint"; } else { string $type[] = `listAnimatable -type`; if ($type[0]!="joint") { error "Object is not a joint"; } } string $childs[] = `listRelatives -fullPath -children -type joint -allDescendents $rootNode[0]`; for( $child in $childs ) { float $pos[] = `joint -query -relative -position $child`; $pos[0] *= $scale; $pos[1] *= $scale; $pos[2] *= $scale; joint -edit -relative -position $pos[0] $pos[1] $pos[2] $child; } } global proc templateRight( ) { setAttr "rclavicle.template" 1; setAttr "rhipjoint.template" 1; } global proc untemplateRight( ) { setAttr "rclavicle.template" 0; setAttr "rhipjoint.template" 0; }