////////////////////////////////////////////////////// //kfHIK_Mapping ////////////////////////// //Written by Kiel Figgins //www.3dfiggins.com ////////////////////////// //Use to map KF Rigs to Maya's Human IK setup ////////////////////////// //Version History ////////////////////////// //1.01 (10-01-2019) - Adjusted for maya 2014 version of HIK which had limited limb twist joints //1.00 (09-30-2019) - Orginal version ////////////////////////// //Coming Soon /* Online Resources https://mayastation.typepad.com/maya-station/2010/07/hik-and-mel-commands.html https://mayastation.typepad.com/maya-station/2011/04/maya-2012-hik-menus-and-mel-commands-part-1.html https://forums.autodesk.com/t5/maya-animation-and-rigging/hik-scripting-and-ui-do-not-produce-same-results/td-p/5684408 https://knowledge.autodesk.com/support/maya-lt/learn-explore/caas/CloudHelp/cloudhelp/2017/ENU/MayaLT/files/GUID-48C5DC90-DE2C-4A08-A52A-3A5294B1ED2F-htm.html https://knowledge.autodesk.com/support/maya/learn-explore/caas/CloudHelp/cloudhelp/2018/ENU/Maya-CharacterAnimation/files/GUID-D8B0FEDE-C651-4B88-8DAA-C1EA73F7D538-htm.html whatIs hikCustomRigAssignEffector; whatIs hikCreateDefinition; whatIs setCharacterObject; whatIs RetargeterValidateMapping; whatIs RetargeterAddMapping; Steps (links to vids from brad) -open rig file -make joints visible in in viewport -set Xray joints as preference in viewport -select world control, set jointVis to 1 -set limb pinners to FK (older version will need to manually turn on fk control shapes) -set FK Arms to T pose (could script this), legs too by raising body con? -open HumanIK Tab HIKCharacterControlsTool; -click create character definition string $charName = "Character1"; hikCreateCharacter($charName); hikUpdateCharacterList(); hikSelectDefinitionTab(); -bone mapping (see below, will need to toggle/refresh ui to see results) -update mapping ui hikUpdateContextualUI; -click create custom rig button hikCreateCustomRig($charName); -assign fk controls(see below) -save scene as *_HIK.ma Apply Example Mocap -set character dropdown to none -click apply animation example -set frame range to 138 -set character dropdown to Character1(custom rig) -set source dropdown to Dummy_Fight */ global proc kfHIK_Mapping() { if (`window -q -ex kfHIK_MappingWin`) { showWindow kfHIK_MappingWin ; return ; } window -w 230 -h 600 -t "HIK" -tlb true kfHIK_MappingWin ; formLayout mainSaveForm ; //UI pieces text -l "1. Open Rig File" txHIK_Open; button -l "Help" -w 30 -ann "" -c ("kfHIK_Instruct();") -bgc .1 .5 .9 btnHIK_Help; button -l "2. Prep Rig ." -w 110 -ann "" -c ("kfHIK_Tpose();") btnHIK_Prep; button -l "3. Create HIK ." -w 110 -ann "" -c ("kfHIK_Create();") btnHIK_Create; button -l "4. Save *_HIK File ." -w 110 -ann "" -c ("kfHIK_Save();") btnHIK_Save; separator -style "in" -h 3 sepHIK_A; button -l "Load Mocap Steps" -w 110 -ann "" -c ("kfHIK_Load();") btnHIK_Load; //UI FormLayout formLayout -e -af txHIK_Open "top" 10 -an txHIK_Open "bottom" -af txHIK_Open "left" 5 -an txHIK_Open "right" -af btnHIK_Help "top" 5 -an btnHIK_Help "bottom" -ac btnHIK_Help "left" 5 txHIK_Open -an btnHIK_Help "right" -ac btnHIK_Prep "top" 5 btnHIK_Help -an btnHIK_Prep "bottom" -af btnHIK_Prep "left" 5 -an btnHIK_Prep "right" -ac btnHIK_Create "top" 8 btnHIK_Prep -an btnHIK_Create "bottom" -af btnHIK_Create "left" 5 -an btnHIK_Create "right" -ac btnHIK_Save "top" 8 btnHIK_Create -an btnHIK_Save "bottom" -af btnHIK_Save "left" 5 -an btnHIK_Save "right" -ac sepHIK_A "top" 5 btnHIK_Save -an sepHIK_A "bottom" -af sepHIK_A "left" 0 -af sepHIK_A "right" 0 -ac btnHIK_Load "top" 8 sepHIK_A -an btnHIK_Load "bottom" -af btnHIK_Load "left" 5 -an btnHIK_Load "right" mainSaveForm ; showWindow kfHIK_MappingWin ; //Resize the main window window -e -widthHeight 120 165 kfHIK_MappingWin; }//end of proc kfHIK_Mapping //////////////////// //UI Specific Procs global proc kfHIK_Save() { //get the file type string $fileKind[] = `file -q -type`; //Determine ma(9) or mb(10) int $fileExt = size($fileKind[0]); //Working with file type string $fileEnder; string $fileEndType; if($fileExt == 9) { $fileEnder = ".ma"; $fileEndType = "mayaAscii"; } else { $fileEnder = ".mb"; $fileEndType = "mayaBinary"; } //get just the name and extenstion string $theFile = `file -q -sceneName`; if(`size($theFile)` != 0) { //minus the extension string $theFileName = `basenameEx($theFile)`; //get the number of characters in file name and extension int $theFileCount = size($theFileName); //for finding out the path string $fullPath = `file -q -sn`; //getting rid of the file name and extension int $thePath = (size($fullPath) - ($theFileCount + 3)); //just the path string $justPath = startString($fullPath, $thePath); file -rename ($justPath + $theFileName + "_HIK" + $fileEnder); file -save -type $fileEndType; print ("\n\nHuman IK File saved\n\n"); } else { //scene error, path not found SaveSceneAs; } }//end of proc global proc kfHIK_Load() { string $findWorld[] = `ls ("CTRL_*_World")`; string $charName = `substituteAllString $findWorld[0] "CTRL_" ""`; $charName = `substituteAllString $charName "_World" ""`; $charName = ($charName + "_HIK"); //Open HumanIK Tab HIKCharacterControlsTool; //Set Timeline playbackOptions -min 0 -max 138 ; //Open Script Editor ScriptEditor; print ("\n\nApply Example Mocap\n-set character dropdown to none\n-click Import Animation Example\n-set frame range to 138\n-set character dropdown to " + $charName + "(custom rig)\n-set source dropdown to Dummy_Fight"); }//end of proc global proc kfHIK_Create() { string $findWorld[] = `ls ("CTRL_*_World")`; string $charName = `substituteAllString $findWorld[0] "CTRL_" ""`; $charName = `substituteAllString $charName "_World" ""`; $charName = ($charName + "_HIK"); //Open HumanIK Tab HIKCharacterControlsTool; //Create character definition hikCreateCharacter($charName); hikUpdateCharacterList(); hikSelectDefinitionTab(); //Skeleton mapping setCharacterObject($findWorld[0],$charName,0,0); setCharacterObject("sp_Spine_5_Pelvis",$charName,49,0); setCharacterObject("sp_Spine_4_Hips",$charName,1,0); setCharacterObject("sp_Spine_3_Waist",$charName,8,0); setCharacterObject("sp_Spine_2_Ribs",$charName,23,0); setCharacterObject("sp_Spine_1_Ribcage",$charName,24,0); setCharacterObject("L_Arm_Collar",$charName,18,0); setCharacterObject("R_Arm_Collar",$charName,19,0); setCharacterObject("j_L__Arm_00",$charName,9,0); setCharacterObject("j_R__Arm_00",$charName,12,0); setCharacterObject("j_L__Arm_05",$charName,10,0); setCharacterObject("j_R__Arm_05",$charName,13,0); setCharacterObject("L_Arm_Wrist",$charName,11,0); setCharacterObject("R_Arm_Wrist",$charName,14,0); int $oldHIK = catch(setCharacterObject("j_L__Arm_01",$charName,176,0)); if($oldHIK) { setCharacterObject("j_L__Arm_02","Adventurer_HIK",45,0); setCharacterObject("j_R__Arm_02","Adventurer_HIK",47,0); setCharacterObject("j_L__Arm_07","Adventurer_HIK",46,0); setCharacterObject("j_R__Arm_07","Adventurer_HIK",48,0); } else { setCharacterObject("j_L__Arm_01",$charName,176,0); setCharacterObject("j_R__Arm_01",$charName,178,0); setCharacterObject("j_L__Arm_02",$charName,184,0); setCharacterObject("j_R__Arm_02",$charName,186,0); setCharacterObject("j_L__Arm_03",$charName,192,0); setCharacterObject("j_R__Arm_03",$charName,194,0); setCharacterObject("j_L__Arm_04",$charName,200,0); setCharacterObject("j_R__Arm_04",$charName,202,0); setCharacterObject("j_L__Arm_06",$charName,177,0); setCharacterObject("j_R__Arm_06",$charName,179,0); setCharacterObject("j_L__Arm_07",$charName,185,0); setCharacterObject("j_R__Arm_07",$charName,187,0); setCharacterObject("j_L__Arm_08",$charName,193,0); setCharacterObject("j_R__Arm_08",$charName,195,0); setCharacterObject("j_L__Arm_09",$charName,201,0); setCharacterObject("j_R__Arm_09",$charName,203,0); } setCharacterObject("j_Neck_10",$charName,20,0); setCharacterObject("j_Neck_09",$charName,32,0); setCharacterObject("j_Neck_08",$charName,33,0); setCharacterObject("j_Neck_07",$charName,34,0); setCharacterObject("j_Neck_06",$charName,35,0); setCharacterObject("j_Neck_05",$charName,36,0); setCharacterObject("j_Neck_04",$charName,37,0); setCharacterObject("j_Neck_03",$charName,38,0); setCharacterObject("j_Neck_02",$charName,39,0); setCharacterObject("j_Neck_01",$charName,40,0); setCharacterObject("Skull",$charName,15,0); setCharacterObject("j_L__Leg_00",$charName,2,0); setCharacterObject("j_R__Leg_00",$charName,5,0); setCharacterObject("j_L__Leg_05",$charName,3,0); setCharacterObject("j_R__Leg_05",$charName,6,0); setCharacterObject("L_Leg_Ankle",$charName,4,0); setCharacterObject("R_Leg_Ankle",$charName,7,0); setCharacterObject("L_Leg_Toe",$charName,16,0); setCharacterObject("R_Leg_Toe",$charName,17,0); if($oldHIK) { setCharacterObject("j_L__Leg_02","Adventurer_HIK",41,0); setCharacterObject("j_R__Leg_02","Adventurer_HIK",43,0); setCharacterObject("j_L__Leg_07","Adventurer_HIK",42,0); setCharacterObject("j_R__Leg_07","Adventurer_HIK",44,0); } else { setCharacterObject("j_L__Leg_01",$charName,172,0); setCharacterObject("j_R__Leg_01",$charName,174,0); setCharacterObject("j_L__Leg_02",$charName,180,0); setCharacterObject("j_R__Leg_02",$charName,182,0); setCharacterObject("j_L__Leg_03",$charName,188,0); setCharacterObject("j_R__Leg_03",$charName,190,0); setCharacterObject("j_L__Leg_04",$charName,196,0); setCharacterObject("j_R__Leg_04",$charName,198,0); setCharacterObject("j_L__Leg_06",$charName,173,0); setCharacterObject("j_R__Leg_06",$charName,175,0); setCharacterObject("j_L__Leg_07",$charName,181,0); setCharacterObject("j_R__Leg_07",$charName,183,0); setCharacterObject("j_L__Leg_08",$charName,189,0); setCharacterObject("j_R__Leg_08",$charName,191,0); setCharacterObject("j_L__Leg_09",$charName,197,0); setCharacterObject("j_R__Leg_09",$charName,199,0); } hikUpdateContextualUI; //Create custom rig button hikCreateCustomRig($charName); //Define FK controls string $retargeter = RetargeterGetName( $charName ); RetargeterAddMapping( $retargeter, "Head", "R", "CTRL_Head", "15" ); RetargeterAddMapping( $retargeter, "Head", "T", "CTRL_Head", "15" ); RetargeterAddMapping( $retargeter, "Neck", "R", "CTRL_Neck_Pivot", "20" ); RetargeterAddMapping( $retargeter, "Spine2", "R", "CTRL_Chest", "1000" ); RetargeterAddMapping( $retargeter, "Spine2", "T", "CTRL_Chest", "1000" ); RetargeterAddMapping( $retargeter, "Spine1", "T", "CTRL_Spine_Ribs", "23" ); RetargeterAddMapping( $retargeter, "Spine", "T", "CTRL_Spine_Waist", "8" ); RetargeterAddMapping( $retargeter, "Hips", "T", "CTRL_Body", "1" ); RetargeterAddMapping( $retargeter, "Hips", "R", "CTRL_Body", "1" ); RetargeterAddMapping( $retargeter, "LeftUpLeg", "R", "CTRL_FK_L__Hip", "2" ); RetargeterAddMapping( $retargeter, "LeftLeg", "R", "CTRL_FK_L__Knee", "3" ); RetargeterAddMapping( $retargeter, "LeftFoot", "R", "CTRL_FK_L__Ankle", "4" ); RetargeterAddMapping( $retargeter, "RightUpLeg", "R", "CTRL_FK_R__Hip", "5" ); RetargeterAddMapping( $retargeter, "RightLeg", "R", "CTRL_FK_R__Knee", "6" ); RetargeterAddMapping( $retargeter, "RightFoot", "R", "CTRL_FK_R__Ankle", "7" ); RetargeterAddMapping( $retargeter, "LeftShoulder", "R", "CTRL_L__Collar", "18" ); RetargeterAddMapping( $retargeter, "LeftArm", "R", "CTRL_FK_L__Shoulder", "9" ); RetargeterAddMapping( $retargeter, "LeftForeArm", "R", "CTRL_FK_L__Elbow", "10" ); RetargeterAddMapping( $retargeter, "LeftHand", "R", "CTRL_FK_L__Wrist", "11" ); RetargeterAddMapping( $retargeter, "RightShoulder", "R", "CTRL_R__Collar", "19" ); RetargeterAddMapping( $retargeter, "RightArm", "R", "CTRL_FK_R__Shoulder", "12" ); RetargeterAddMapping( $retargeter, "RightForeArm", "R", "CTRL_FK_R__Elbow", "13" ); RetargeterAddMapping( $retargeter, "RightHand", "R", "CTRL_FK_R__Wrist", "14" ); hikUpdateCustomRigUI(); print ("\n\nSUCCESS: HIK Created\n\n"); }//end of proc global proc kfHIK_Tpose() { //HIK Rig TPose float $maxVal[] = `attributeQuery -node "CTRL_L__WristPinner" -max "IKFK"`; setAttr "CTRL_L__WristPinner.IKFK" $maxVal[0]; setAttr "CTRL_R__WristPinner.IKFK" $maxVal[0]; setAttr "CTRL_L__FootPinner.IKFK" $maxVal[0]; setAttr "CTRL_R__FootPinner.IKFK" $maxVal[0]; group -em; string $null[] = `ls -sl`; delete `pointConstraint L_Leg_Ankle $null`; float $tyOrg = `getAttr ($null[0] + ".ty")`; delete $null; kfHIK_Tpose_Set("CTRL_FK_L__Shoulder", 0, 1, 0); kfHIK_Tpose_Set("CTRL_FK_L__Elbow", 0, -1, 0); kfHIK_Tpose_Set("CTRL_FK_L__Wrist", 0, 0, 0); kfHIK_Tpose_Set("CTRL_FK_R__Shoulder", 180, -1, 0); kfHIK_Tpose_Set("CTRL_FK_R__Elbow", 180, 1, 0); kfHIK_Tpose_Set("CTRL_FK_R__Wrist", 180, 0, 0); kfHIK_Tpose_Set("CTRL_FK_L__Hip", 0, -1, -90); kfHIK_Tpose_Set("CTRL_FK_L__Knee", 0, 1, -90); kfHIK_Tpose_Set("CTRL_FK_L__Ankle", 0, 0, 0); kfHIK_Tpose_Set("CTRL_FK_L__Toe", 0, 0, 0); kfHIK_Tpose_Set("CTRL_FK_R__Hip", 180, 1, 90); kfHIK_Tpose_Set("CTRL_FK_R__Knee", 180, -1, 90); kfHIK_Tpose_Set("CTRL_FK_R__Ankle", 180, 0, 0); kfHIK_Tpose_Set("CTRL_FK_R__Toe", 180, 0, 0); group -em; string $null[] = `ls -sl`; delete `pointConstraint L_Leg_Ankle $null`; float $tyNew = `getAttr ($null[0] + ".ty")`; delete $null; float $offset = ($tyOrg - $tyNew); setAttr "CTRL_Body.ty" $offset; //Hide old controls if($maxVal[0] == 10) { setAttr "CTRL_L__WristPinner.ViewIKCtrls" 0; setAttr "CTRL_L__WristPinner.ViewPoleLines" 0; setAttr "CTRL_L__WristPinner.ViewFKCtrls" 1; setAttr "CTRL_R__WristPinner.ViewIKCtrls" 0; setAttr "CTRL_R__WristPinner.ViewPoleLines" 0; setAttr "CTRL_R__WristPinner.ViewFKCtrls" 1; setAttr "CTRL_L__FootPinner.ViewIKCtrls" 0; setAttr "CTRL_L__FootPinner.ViewFKCtrls" 1; setAttr "CTRL_L__FootPinner.ViewPoleLines" 0; setAttr "CTRL_R__FootPinner.ViewIKCtrls" 0; setAttr "CTRL_R__FootPinner.ViewFKCtrls" 1; setAttr "CTRL_R__FootPinner.ViewPoleLines" 0; } print "\n\nSUCCESS: Rig in TPose\n\n"; }//end of proc global proc kfHIK_Tpose_Set(string $con, float $rx, float $ry, float $rz) { group -em; string $null[] = `ls -sl`; setAttr ($null[0] + ".rx") $rx; setAttr ($null[0] + ".ry") $ry; setAttr ($null[0] + ".rz") $rz; delete `orientConstraint $null $con`; delete $null; }//end of proc /////////////////////////////////////////////////////////////// //Instructions global proc kfHIK_Instruct() { if (`window -q -ex kfHIK_InstructWin`) { showWindow kfHIK_InstructWin ; return ; } window -w 850 -h 500 -t "HumanIK Instructions" kfHIK_InstructWin ; formLayout mainSaveForm ; //UI pieces scrollField -w 100 -h 100 -wordWrap true -tx ( "HumanIK Mapping for AnimRigs - by Kiel Figgins - KielFiggins22@gmail.com - 3dFiggins.com" + "\n\n" + "For instructions with screenshots, visit 3dFiggins.com/Store/Support/HumanIK" + "\n\n" + "HumanIK Matching" + "\n" + "-----------------------------------------------------" + "\n" + "1. Open the rig file" + "\n" + "2. Click 'Prep Rig' button." + "\n" + "(This sets the T pose and limbs to FK. If you want to map your own HIK setup, you can stil use this feature to set the pose)" + "\n" + "(If you do want to do you own mapping, set the jointVis to 1 on the World control, and use those joints in the mapping)" + "\n" + "3. Click 'Create HIK' button." + "\n" + "4. Click 'Save HIK File' button." + "\n" + "(This is to save the character mapping, that you can then use the *_HIK file when referencing into your animation scene)" + "\n\n" + "Once you bake the HIK mocap/animation back to the actual rig, the results will be on the FK limb controls." + "\n" + "You can use the IKFK script at 3dFiggins.com/Store/Support/IKFK to bake the animation back and forth from FK to IK" ) -ed 0 scrollHIK_Instruct; //UI FormLayout formLayout -e -af scrollHIK_Instruct "top" 5 -af scrollHIK_Instruct "bottom" 5 -af scrollHIK_Instruct "left" 5 -af scrollHIK_Instruct "right" 5 mainSaveForm ; showWindow kfHIK_InstructWin; //Resize the main window window -e -widthHeight 925 280 kfHIK_InstructWin; }//end of proc