// =========================================================================== // Copyright 2018 Autodesk, Inc. All rights reserved. // // Use of this software is subject to the terms of the Autodesk license // agreement provided at the time of installation or download, or which // otherwise accompanies this software in either electronic or hard copy form. // =========================================================================== // // // Creation Date: 13 April 1997 // // // Procedure Name: // ChaSkeletonsMenu // // Description: // Create the RIGGING->Skeletons menu // // Input Arguments: // parent to parent the menu to. // // Return Value: // None. // global proc int MCmatch(string $name, string $match1, string $match2) { string $match = match($match1,$name); if (size($match)) return 1; $match = match($match2,$name); if (size($match)) return 1; return 0; } global proc string jointLabel_uiToMel( string $ui ) { string $result = $ui; string $left = (uiRes( "n_joint.a_sd_enum_kPuppetLeft" )); string $right = (uiRes( "n_joint.a_sd_enum_kPuppetRight" )); string $center = (uiRes( "n_joint.a_sd_enum_kPuppetCenter" )); string $noside = (uiRes( "n_joint.a_sd_enum_kPuppetNoSide" )); string $root = (uiRes( "n_joint.a_typ_enum_kPuppetPartPelvis" )); string $hip = (uiRes( "n_joint.a_typ_enum_kPuppetPartHip" )); string $knee = (uiRes( "n_joint.a_typ_enum_kPuppetPartKnee" )); string $foot = (uiRes( "n_joint.a_typ_enum_kPuppetPartFoot" )); string $toe = (uiRes( "n_joint.a_typ_enum_kPuppetPartToe" )); string $spine = (uiRes( "n_joint.a_typ_enum_kPuppetPartBack" )); string $neck = (uiRes( "n_joint.a_typ_enum_kPuppetPartNeck" )); string $head = (uiRes( "n_joint.a_typ_enum_kPuppetPartHead" )); string $collar = (uiRes( "n_joint.a_typ_enum_kPuppetPartCollar" )); string $shoulder = (uiRes( "n_joint.a_typ_enum_kPuppetPartShoulder" )); string $elbow = (uiRes( "n_joint.a_typ_enum_kPuppetPartElbow" )); string $hand = (uiRes( "n_joint.a_typ_enum_kPuppetPartHand" )); string $finger = (uiRes( "n_joint.a_typ_enum_kPuppetPartFinger" )); string $thumb = (uiRes( "n_joint.a_typ_enum_kPuppetPartThumb" )); string $none = (uiRes( "n_joint.a_typ_enum_kPuppetPartNone" )); string $index = (uiRes( "n_joint.a_typ_enum_kPuppetPartIndex" )); string $middle = (uiRes( "n_joint.a_typ_enum_kPuppetPartMiddle" )); string $ring = (uiRes( "n_joint.a_typ_enum_kPuppetPartRing" )); string $pinky = (uiRes( "n_joint.a_typ_enum_kPuppetPartPinky" )); string $extrafinger = (uiRes( "n_joint.a_typ_enum_kPuppetPartExtraFinger" )); string $bigtoe = (uiRes( "n_joint.a_typ_enum_kPuppetPartBigToe" )); string $indextoe = (uiRes( "n_joint.a_typ_enum_kPuppetPartIndexToe" )); string $middletoe = (uiRes( "n_joint.a_typ_enum_kPuppetPartMiddleToe" )); string $ringtoe = (uiRes( "n_joint.a_typ_enum_kPuppetPartRingToe" )); string $pinkytoe = (uiRes( "n_joint.a_typ_enum_kPuppetPartPinkyToe" )); string $extratoe = (uiRes( "n_joint.a_typ_enum_kPuppetPartExtraToe" )); string $other = (uiRes( "n_joint.a_typ_enum_kPuppetPartOther" )); string $propA = (uiRes( "n_joint.a_typ_enum_kPuppetPartPropA" )); string $propB = (uiRes( "n_joint.a_typ_enum_kPuppetPartPropB" )); string $propC = (uiRes( "n_joint.a_typ_enum_kPuppetPartPropC" )); if( $ui == $left ) { $result = "Left"; } else if( $ui == $right ) { $result = "Right"; } else if( $ui == $center ) { $result = "Center"; } else if( $ui == $noside ) { $result = "None"; } else if( $ui == $root ) { $result = "Root"; } else if( $ui == $hip ) { $result = "Hip"; } else if( $ui == $knee ) { $result = "Knee"; } else if( $ui == $foot ) { $result = "Foot"; } else if( $ui == $toe ) { $result = "Toe"; } else if( $ui == $spine ) { $result = "Spine"; } else if( $ui == $neck ) { $result = "Neck"; } else if( $ui == $head ) { $result = "Head"; } else if( $ui == $collar ) { $result = "Collar"; } else if( $ui == $shoulder ) { $result = "Shoulder"; } else if( $ui == $elbow ) { $result = "Elbow"; } else if( $ui == $hand ) { $result = "Hand"; } else if( $ui == $finger ) { $result = "Finger"; } else if( $ui == $thumb ) { $result = "Thumb"; } else if( $ui == $none ) { $result = "None"; } else if( $ui == $index ) { $result = "IndexFinger"; } else if( $ui == $middle ) { $result = "MiddleFinger"; } else if( $ui == $ring ) { $result = "RingFinger"; } else if( $ui == $pinky ) { $result = "PinkyFinger"; } else if( $ui == $extrafinger ) { $result = "ExtraFinger"; } else if( $ui == $bigtoe ) { $result = "BigToe"; } else if( $ui == $indextoe ) { $result = "IndexToe"; } else if( $ui == $middletoe ) { $result = "MiddleToe"; } else if( $ui == $ringtoe ) { $result = "RingToe"; } else if( $ui == $pinkytoe ) { $result = "PinkyToe"; } else if( $ui == $extratoe ) { $result = "FootThumb"; } else if( $ui == $other ) { $result = "Other"; } else if( $ui == $propA ) { $result = "PropA"; } else if( $ui == $propB ) { $result = "PropB"; } else if( $ui == $propC ) { $result = "PropC"; } else { uiToMelMsg( "jointLabel_uiToMel", $ui, 1 ); } return $result; } proc labelListBasedOnNames(string $list[]) { for ($listItem in $list) { string $buffer[]; tokenize($listItem,"|",$buffer); string $item = $buffer[size($buffer)-1]; int $labelInfo[] = jointLabelInfoForString($item); int $type = $labelInfo[0]; int $side = $labelInfo[1]; if ($type != -1) { string $typeCmd = ("setAttr "+$listItem+".type "+$type); evalEcho $typeCmd; } if ($side != -1) { string $sideCmd = ("setAttr "+$listItem+".side "+$side); evalEcho $sideCmd; } } } global proc labelJointsBasedOnNames() { string $jnts[] = `ls -sl -dag -type joint`; if (size($jnts) == 0) { error (uiRes("m_ChaSkeletonsMenu.kSelectJointsToLabel")); } labelListBasedOnNames($jnts); } global proc renameJointsBasedOnTypes() { string $jnts[] = `ls -sl -dag -type joint`; if (size($jnts) == 0) { error (uiRes("m_ChaSkeletonsMenu.kSelectJointsToRename")); } int $ii; string $jnt; int $jntCount = size($jnts); for ($ii = $jntCount-1; $ii >= 0; $ii--) { $jnt = $jnts[$ii]; string $side = `getAttr -asString ($jnt+".side")`; string $part = `getAttr -asString ($jnt+".type")`; string $newName = jointLabel_uiToMel($side)+jointLabel_uiToMel($part); if( ($side != (uiRes("n_joint.a_sd_enum_kPuppetNoSide"))) && ($part != (uiRes("n_joint.a_typ_enum_kPuppetPartNone"))) ) { $newName = `rename $jnt $newName`; } } } global proc retargetingSideLabel(string $side) // // Description: // Set the "Side" attribute on the selected objects. // { int $setSomething = 0; if ($side == "Center") { string $sel[] = `ls -sl -type joint`; for ($obj in $sel) { setAttr ($obj+".side") 0; $setSomething = 1; } } else { int $sideNum; if ($side == "Left") { $sideNum = 1; } else if ($side == "Right") { $sideNum = 2; } else { $sideNum = 3; /* "None" */ } string $sel[] = `ls -sl -dag -type joint`; for ($obj in $sel) { setAttr ($obj+".side") $sideNum; $setSomething = 1; } } if (0 == $setSomething) { error (uiRes("m_ChaSkeletonsMenu.kMustSelectJointsToLabel")); } } global proc retargetLabelType(string $type, int $dag) { int $label; int $labelCenter = false; if ($type == "Root") { $labelCenter = true; $label = 1; } else if ($type == "Hip") { $label = 2; } else if ($type == "Knee") { $label = 3; } else if ($type == "Foot") { $label = 4; } else if ($type == "Toe") { $label = 5; } else if ($type == "Spine") { $labelCenter = true; $label = 6; } else if ($type == "Neck") { $labelCenter = true; $label = 7; } else if ($type == "Head") { $labelCenter = true; $label = 8; } else if ($type == "Collar") { $label = 9; } else if ($type == "Shoulder") { $label = 10; } else if ($type == "Elbow") { $label = 11; } else if ($type == "Hand") { $label = 12; } else if ($type == "Finger") { $label = 13; } else if ($type == "Thumb") { $label = 14; } else if ($type == "None") { $label = 0; $labelCenter = true; } else if ($type == "Index") { $label = 19; } else if ($type == "Middle") { $label = 20; } else if ($type == "Ring") { $label = 21; } else if ($type == "Pinky") { $label = 22; } else if ($type == "ExtraFinger") { $label = 23; } else if ($type == "BigToe") { $label = 24; } else if ($type == "IndexToe") { $label = 25; } else if ($type == "MiddleToe") { $label = 26; } else if ($type == "RingToe") { $label = 27; } else if ($type == "PinkyToe") { $label = 28; } else if ($type == "ExtraToe" || $type == "FootThumb") { $label = 29; } else { error (uiRes("m_ChaSkeletonsMenu.kRetargetInvType")); } if ($labelCenter) { retargetingSideLabel("Center"); } string $cmd = "ls -sl -type joint"; if ($dag) { $cmd += " -dag"; } string $sel[] = eval($cmd); for ($obj in $sel) { setAttr ($obj+".type") $label; } } global proc labelLimb(string $selObj, string $limb) { int $topLabel, $midLabel, $endLabel, $digitLabel; if ($limb == "Leg") { $topLabel = 2; /* "Hip" */ $midLabel = 3; /* "Knee" */ $endLabel = 4; /* "Foot" */ $digitLabel = 5; /* "Toe" */ } else if ($limb == "Arm") { $topLabel = 10; /* "Shoulder" */ $midLabel = 11; /* "Elbow" */ $endLabel = 12; /* "Hand" */ $digitLabel = 13; /* "Finger" */ } else { string $errorStr = (uiRes("m_ChaSkeletonsMenu.kInvalidLimb")); error `format -s $limb $errorStr`; } // Shoulder or Hip // setAttr ($selObj+".type") $topLabel; string $jntsBelow[] = `ls -sl -dag -type joint $selObj`; if ($limb == "Leg") { int $currLabel = $topLabel; for ($jj = 1; $jj < size($jntsBelow); $jj++) { string $buffer[]; tokenize($jntsBelow[$jj],"|",$buffer); string $currJnt = $buffer[size($buffer)-1]; if (! MCmatch($currJnt,"Roll","roll")) { if ($currLabel != $digitLabel) { $currLabel++; } } setAttr ($jntsBelow[$jj]+".type") $currLabel; } } else { int $onElbow = 1; int $onHands = 0; int $currLabel = $topLabel; int $numJntsBelow = size($jntsBelow); for ($jj = 1; $jj < $numJntsBelow; $jj++) { string $buffer[]; tokenize($jntsBelow[$jj],"|",$buffer); string $currJnt = $buffer[size($buffer)-1]; if (MCmatch($currJnt,"Roll","roll")) { setAttr ($jntsBelow[$jj]+".type") $currLabel; continue; } string $rels[] = `listRelatives -type joint $jntsBelow[$jj]`; if ($currLabel == $midLabel) { if ((size($rels) > 1) || MCmatch($currJnt,"Hand","hand") || MCmatch($currJnt,"Wrist","wrist")) { $currLabel++; } } else if ($currLabel != $digitLabel) { $currLabel++; } setAttr ($jntsBelow[$jj]+".type") $currLabel; } // If we are still on the elbow, it means there was never a // branch (i.e. no fingers) // if ($onElbow) { if ($numJntsBelow == 3) { setAttr ($jntsBelow[2]+".type") $endLabel; } else if ($numJntsBelow > 3) { for ($jj = 2; $jj < $numJntsBelow; $jj++) { if ($onElbow) { string $testForElbow = match("lbow",$jntsBelow[$jj]); if (0 == size($testForElbow)) { $onElbow = 0; setAttr ($jntsBelow[$jj]+".type") $endLabel; } } else { setAttr ($jntsBelow[$jj]+".type") $digitLabel; } } } } } } global proc retargetingLimbLabel(string $limb) // // Description: // Set the "Type" attributes on the selected limb. // { string $sel[] = `ls -sl -type joint`; if (size($sel) == 0) { if ($limb == "Leg") { error (uiRes("m_ChaSkeletonsMenu.kMustSelectHip")); } else if ($limb == "Arm") { error (uiRes("m_ChaSkeletonsMenu.kMustSelectShoulder")); } else { error (uiRes("m_ChaSkeletonsMenu.kNoSelJoints")); } } int $dag = 0; if ($limb == "Leg" || $limb == "Arm") { for ($selObj in $sel) { labelLimb($selObj,$limb); } } else { if ($limb == "Thumb" || $limb == "Index" || $limb == "Middle" || $limb == "Ring" || $limb == "Pinky" || $limb == "ExtraFinger" || $limb == "BigToe" || $limb == "IndexToe" || $limb == "MiddleToe" || $limb == "RingToe" || $limb == "PinkyToe" || $limb == "FootThumb" || $limb == "ExtraToe") { $dag = 1; } retargetLabelType($limb, $dag); } } global proc ChaSkeletonsMenu( string $parent ) { setParent -menu $parent; if( `menu -q -ni $parent` != 0 ) { // // Menu is built already - just update check boxes and return // // check to validate Enable and Snap Solver checkbox menuItem -e -cb `ikSystem -q -sn` globalSnapEnableItem; menuItem -e -enable (!`ikSystem -q -allowRotation`) globalSnapEnableItem; return; } string $cmd; if (`isTrue "KinematicsUIExists"`) { menuItem -divider true -dividerLabel (uiRes("m_ChaSkeletonsMenu.kToolsDivider")); $cmd = "JointTool"; menuItem -rtc $cmd createSkeletonItem; $cmd = "JointToolOptions"; menuItem -optionBox true -i "kinJoint.png" -annotation (getRunTimeCommandAnnotation($cmd)) -c $cmd skeletonDialogItem; $cmd = "InsertJointTool"; menuItem -rtc $cmd insertJointItem; $cmd = "MirrorJoint"; menuItem -dmc "performMirrorJoint 2" -rtc $cmd mirrorJointItem; $cmd = "MirrorJointOptions"; menuItem -optionBox true -i "kinMirrorJoint_S.png" -annotation (getRunTimeCommandAnnotation($cmd)) -c $cmd mirrorJointOptionItem; $cmd = "OrientJoint"; menuItem -dmc "performJointOrient 2" -rtc $cmd orientJointItem; $cmd = "OrientJointOptions"; menuItem -optionBox true -annotation (getRunTimeCommandAnnotation($cmd)) -image "orientJoint.png" -c $cmd orientJointOptionItem; $cmd = "RemoveJoint"; menuItem -ltVersion 2017 -echoCommand true -rtc $cmd removeJointItem; $cmd = "ConnectJoint"; menuItem -ltVersion 2017 -dmc "performConnectJoint 2" -rtc $cmd connectJointItem; $cmd = "ConnectJointOptions"; menuItem -optionBox true -i "kinConnect.png" -annotation (getRunTimeCommandAnnotation($cmd)) -c $cmd connectJointOptionItem; $cmd = "DisconnectJoint"; menuItem -echoCommand true -ltVersion 2017 -rtc $cmd disconnectJointItem; $cmd = "RerootSkeleton"; menuItem -echoCommand true -rtc $cmd rerootSkeleton; menuItem -label (uiRes("m_ChaSkeletonsMenu.kJointLabelling")) -aob true -sm true -to true; menuItem -label (uiRes("m_ChaSkeletonsMenu.kAddFBIKLabels")) -sm true -to true fbikLabelItem; menuItem -rtc "FBIKLabelLeft" -echoCommand true; menuItem -rtc "FBIKLabelRight" -echoCommand true; menuItem -rtc "FBIKLabelCenter" -echoCommand true; menuItem -d true; menuItem -rtc "FBIKLabelNone" -echoCommand true; menuItem -rtc "FBIKLabelArm" -echoCommand true; menuItem -rtc "FBIKLabelLeg" -echoCommand true; menuItem -d true; menuItem -rtc "FBIKLabelCollar" -echoCommand true; menuItem -rtc "FBIKLabelElbow" -echoCommand true; menuItem -rtc "FBIKLabelFoot" -echoCommand true; menuItem -rtc "FBIKLabelHand" -echoCommand true; menuItem -rtc "FBIKLabelHead" -echoCommand true; menuItem -rtc "FBIKLabelHip" -echoCommand true; menuItem -rtc "FBIKLabelKnee" -echoCommand true; menuItem -rtc "FBIKLabelNeck" -echoCommand true; menuItem -rtc "FBIKLabelRoot" -echoCommand true; menuItem -rtc "FBIKLabelShoulder" -echoCommand true; menuItem -rtc "FBIKLabelSpine" -echoCommand true; menuItem -d true; menuItem -rtc "FBIKLabelThumb" -echoCommand true; menuItem -rtc "FBIKLabelIndex" -echoCommand true; menuItem -rtc "FBIKLabelMiddleFinger" -echoCommand true; menuItem -rtc "FBIKLabelRingFinger" -echoCommand true; menuItem -rtc "FBIKLabelPinky" -echoCommand true; menuItem -rtc "FBIKLabelExtraFinger" -echoCommand true; menuItem -rtc "FBIKLabelFingerBase" -echoCommand true; menuItem -d true; menuItem -rtc "FBIKLabelBigToe" -echoCommand true; menuItem -rtc "FBIKLabelIndexToe" -echoCommand true; menuItem -rtc "FBIKLabelMiddleToe" -echoCommand true; menuItem -rtc "FBIKLabelRingToe" -echoCommand true; menuItem -rtc "FBIKLabelPinkyToe" -echoCommand true; menuItem -rtc "FBIKLabelFootThumb" -echoCommand true; menuItem -rtc "FBIKLabelToeBase" -echoCommand true; setParent -menu ..; menuItem -rtc "ToggleSelectedLabels"; menuItem -rtc "ShowAllLabels"; menuItem -rtc "HideAllLabels"; menuItem -rtc "RenameJointsFromLabels" renameJointsMenu; menuItem -rtc "LabelBasedOnJointNames" labelJointsMenu; setParent -menu ..; menuItem -divider true -dividerLabel (uiRes("m_ChaSkeletonsMenu.kIKDivider")); $cmd = "IKHandleTool"; menuItem -ltVersion "2015" -rtc $cmd createHandleItem; $cmd = "IKHandleToolOptions"; menuItem -optionBox true -i "kinHandle.png" -annotation (getRunTimeCommandAnnotation($cmd)) -c $cmd handleDialogItem; if( `licenseCheck -mode "edit" -type "complete"` ) { $cmd = "IKSplineHandleTool"; menuItem -ltVersion 2016 -rtc $cmd createSplineHandleItem; $cmd = "IKSplineHandleToolOptions"; menuItem -optionBox true -i "kinSplineHandle.png" -annotation (getRunTimeCommandAnnotation($cmd)) -c $cmd handleSplineDialogItem; } $cmd = "SetPreferredAngle"; menuItem -ltVersion "2015" -dmc "performSetPrefAngle 2" -rtc $cmd setPrefAngleItem; $cmd = "SetPreferredAngleOptions"; menuItem -optionBox true -annotation (getRunTimeCommandAnnotation($cmd)) -c $cmd setPrefAngleOptionItem; $cmd = "AssumePreferredAngle"; menuItem -ltVersion "2015" -dmc "performAssumePrefAngle 2" -rtc $cmd assumePrefAngleItem; $cmd = "AssumePreferredAngleOptions"; menuItem -optionBox true -annotation (getRunTimeCommandAnnotation($cmd)) -c $cmd assumePrefAngleOptionItem; menuItem -d true -ld false; $cmd = "ToggleIKHandleSnap"; menuItem -ltVersion "2015" -cb `ikSystem -q -sn` -enable (! `ikSystem -q -allowRotation`) -echoCommand true -rtc $cmd globalSnapEnableItem; $cmd = "ToggleIKAllowRotation"; menuItem -ltVersion "2015" -cb `ikSystem -q -allowRotation` -echoCommand true -rtc $cmd; $cmd = "EnableSelectedIKHandles"; menuItem -ltVersion "2015" -echoCommand true -rtc $cmd enableIKHandlesItem; $cmd = "DisableSelectedIKHandles"; menuItem -ltVersion "2015" -echoCommand true -rtc $cmd disableIKHandlesItem; menuItem -d true -longDivider false; $cmd = "QuickRigEditor"; menuItem -rtc $cmd -version "2017" quickRigWindowItem; $cmd = "HIKCharacterControlsTool"; menuItem -to true -rtc $cmd hikWindowItem; setParent -m ..; } }