// =========================================================================== // 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. // =========================================================================== // // Description: // This script provides an option box dialog for the bakeDeformer command. // // Input Arguments: // int action 0 - execute the command // 1 - show the option box dialog // 2 - return the command string // // Return Value: // None. // global int $bakeDeformer_selectionIt; global int $bakeDeformer_selectionSize; global string $bakeDeformer_selection[]; proc selectionIt(string $selection[]) { global int $bakeDeformer_selectionIt; global int $bakeDeformer_selectionSize; global string $bakeDeformer_selection[]; $bakeDeformer_selection = $selection; $bakeDeformer_selectionIt = 0; $bakeDeformer_selectionSize = size($bakeDeformer_selection); } proc string selectionIt_Next() { global int $bakeDeformer_selectionIt; global int $bakeDeformer_selectionSize; global string $bakeDeformer_selection[]; string $object = ""; if($bakeDeformer_selectionIt < $bakeDeformer_selectionSize) { $object = $bakeDeformer_selection[$bakeDeformer_selectionIt]; $bakeDeformer_selectionIt += 1; } return $object; } proc int isJoint(string $object) { return `objectType -isType "joint" $object`; } proc string getShape(string $object) { string $shapes[] = `listRelatives -shapes $object`; return $shapes[0]; } proc int isShape(string $object) { string $children[] = `listRelatives -path -shapes $object`; if(size($children) <= 0) { return false; } return `objectType -isType "mesh" $children[0]`; } proc string getSelectedMesh(string $selection[]) { selectionIt($selection); string $object = ""; while( ($object = selectionIt_Next()) != "" ) { if(isShape($object)) { string $shape = getShape($object); string $meshParent[] = `listRelatives -parent $shape`; return $meshParent[0]; } } return ""; } proc string getSelectedSkeleton(string $selection[]) { selectionIt($selection); string $object = ""; while( ($object = selectionIt_Next()) != "" ) { if(isJoint($object)) { return $object; } } return ""; } proc string[] getSelectedObjects() { return `ls -selection -type transform`; //get selected joints & shapes } proc resetOptionVars (int $forceFactorySettings) { if ($forceFactorySettings || !`optionVar -exists performBakeDeformerMaxInfluences`) optionVar -intValue performBakeDeformerMaxInfluences 3; if ($forceFactorySettings || !`optionVar -exists performBakeDeformerSrcMesh`) optionVar -stringValue performBakeDeformerSrcMesh ""; if ($forceFactorySettings || !`optionVar -exists performBakeDeformerSrcSkeleton`) optionVar -stringValue performBakeDeformerSrcSkeleton ""; if ($forceFactorySettings || !`optionVar -exists performBakeDeformerDstMesh`) optionVar -stringValue performBakeDeformerDstMesh ""; if ($forceFactorySettings || !`optionVar -exists performBakeDeformerDstSkeleton`) optionVar -stringValue performBakeDeformerDstSkeleton ""; } proc loadFields (string $parent) { setParent $parent; int $nameInfluences = `optionVar -q performBakeDeformerMaxInfluences`; intSliderGrp -e -value $nameInfluences bakeDeformerMaxInfluences; string $val = `optionVar -q performBakeDeformerSrcMesh`; textFieldGrp -e -text $val bakeDeformerSrcMesh; $val = `optionVar -q performBakeDeformerSrcSkeleton`; textFieldGrp -e -text $val bakeDeformerSrcSkeleton; $val = `optionVar -q performBakeDeformerDstMesh`; textFieldGrp -e -text $val bakeDeformerDstMesh; $val = `optionVar -q performBakeDeformerDstSkeleton`; textFieldGrp -e -text $val bakeDeformerDstSkeleton; } global proc bakeDeformerSetup (string $parent, int $forceFactorySettings) { resetOptionVars($forceFactorySettings); loadFields($parent); } global proc saveOptionVars(string $parent) { setParent $parent; string $save = (uiRes("m_performBakeDeformer.kDefaultCreaseSetNameeey")); print ( $save ); int $maxInfluences = `intSliderGrp -q -value bakeDeformerMaxInfluences`; optionVar -intValue performBakeDeformerMaxInfluences $maxInfluences; string $val = `textFieldGrp -q -text bakeDeformerSrcMesh`; optionVar -stringValue performBakeDeformerSrcMesh $val; $val = `textFieldGrp -q -text bakeDeformerSrcSkeleton`; optionVar -stringValue performBakeDeformerSrcSkeleton $val; $val = `textFieldGrp -q -text bakeDeformerDstMesh`; optionVar -stringValue performBakeDeformerDstMesh $val; $val = `textFieldGrp -q -text bakeDeformerDstSkeleton`; optionVar -stringValue performBakeDeformerDstSkeleton $val; } global proc bakeDeformerCallback(string $parent, int $doIt) { saveOptionVars($parent); performBakeDeformer(0); } global proc bakeDeformerCallback_srcButton() { string $selection[] = getSelectedObjects(); string $srcMeshName = getSelectedMesh($selection); string $srcSkeletonName = getSelectedSkeleton($selection); textFieldGrp -e -text $srcMeshName bakeDeformerSrcMesh; textFieldGrp -e -text $srcSkeletonName bakeDeformerSrcSkeleton; } global proc bakeDeformerCallback_dstButton() { string $selection[] = getSelectedObjects(); string $dstMeshName = getSelectedMesh($selection); string $dstSkeletonName = getSelectedSkeleton($selection); textFieldGrp -e -text $dstMeshName bakeDeformerDstMesh; textFieldGrp -e -text $dstSkeletonName bakeDeformerDstSkeleton; } // // Procedure Name: // bakeDeformerOptions // // Description: // Construct the option box UI. Involves accessing the standard option // box and customizing the UI accordingly. // // Input Arguments: // None. // // Return Value: // None. // proc bakeDeformerOptions() { string $commandName = "bakeDeformer"; string $callback = ($commandName + "Callback"); string $setup = ($commandName + "Setup"); // Get the option box. // // The value returned is the name of the layout to be used as // the parent for the option box UI. // string $layout = getOptionBox(); setParent $layout; setUITemplate -pushTemplate OptionBoxTemplate; setOptionBoxCommandName($commandName); string $parent = `columnLayout -adjustableColumn 1`; // Define the UI. // string $meshL10N = (uiRes("m_performBakeDeformer.kBakeDeformerMesh")); string $skeletonL10N = (uiRes("m_performBakeDeformer.kBakeDeformerSkeleton")); button -label (uiRes("m_performBakeDeformer.kBakeDeformerSource")) -command ($callback + "_srcButton") bakeDeformerSrcButton; textFieldGrp -label $meshL10N -text "" bakeDeformerSrcMesh; textFieldGrp -label $skeletonL10N -text "" bakeDeformerSrcSkeleton; button -label (uiRes("m_performBakeDeformer.kBakeDeformerDestination")) -command ($callback + "_dstButton") bakeDeformerDstButton; textFieldGrp -label $meshL10N -text "" bakeDeformerDstMesh; textFieldGrp -label $skeletonL10N -text "" bakeDeformerDstSkeleton; separator; intSliderGrp -label (uiRes("m_performBakeDeformer.kBakeDeformerMaxInfluences")) -field true -minValue 1 -maxValue 50 bakeDeformerMaxInfluences; setUITemplate -popTemplate; loadFields($parent); string $applyBtn = getOptionBoxApplyBtn(); button -edit -command ($callback + " " + $parent + " " + 0) $applyBtn; string $saveBtn = getOptionBoxSaveBtn(); button -edit -command ("saveOptionVars " + $parent) $saveBtn; string $resetBtn = getOptionBoxResetBtn(); button -edit -command ($setup + " " + $parent + " " + 1) $resetBtn; setOptionBoxTitle (uiRes("m_performBakeDeformer.kBakeDeformerTool")); setOptionBoxHelpTag( "bakeDeformerTool" ); bakeDeformerSetup($parent, 0); // Show the option box. // showOptionBox(); } // // Procedure Name: // assembleCmd // // Description: // Construct the command that will apply the option box values. // // Input Arguments: // None. // // Return Value: // None. // proc string assembleCmd() { string $srcMeshName = `textFieldGrp -q -text bakeDeformerSrcMesh`; string $srcSkeletonName = `textFieldGrp -q -text bakeDeformerSrcSkeleton`; string $dstMeshName = `textFieldGrp -q -text bakeDeformerDstMesh`; string $dstSkeletonName = `textFieldGrp -q -text bakeDeformerDstSkeleton`; int $maxInfluences = `intSliderGrp -q -value bakeDeformerMaxInfluences`; string $cmd = "bakeDeformer"; if($srcMeshName != "") { $cmd += " -srcMeshName " + $srcMeshName; } if($srcSkeletonName != "") { $cmd += " -srcSkeletonName " + $srcSkeletonName; } if($dstMeshName != "") { $cmd += " -dstMeshName " + $dstMeshName; } if($dstSkeletonName != "") { $cmd += " -dstSkeletonName " + $dstSkeletonName; } $cmd += " -maxInfluences " + $maxInfluences; return $cmd; } // // Procedure Name: // performBakeDeformer // // Description: // Perform the bakeDeformer command using the corresponding // option values. This procedure will also show the option box // window if necessary as well as construct the command string // that will invoke the bakeDeformer command with the current // option box values. // // Input Arguments: // 0 - Execute the command. // 1 - Show the option box dialog. // 2 - Return the command. // // Return Value: // None. // global proc string performBakeDeformer(int $action) { string $cmd = ""; switch ($action) { // Execute the command. // case 0: $cmd = assembleCmd(); evalEcho($cmd); break; // Show the option box. // case 1: bakeDeformerOptions(); break; // Return the command string. // case 2: $cmd = assembleCmd(); break; } return $cmd; }