// =========================================================================== // 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: 24 April 1997 // // Description: // This script provides an option box dialog for the blendShape command. // // Input Arguments: // boolean showOptionBox true - show the option box dialog // false - just execute the command // // Return Value: // None. // // // Procedure Name: // setOptionVars // // Description: // Initialize the option values. // // Input Arguments: // Whether to set the options to default values. // // Return Value: // None. // proc setOptionVars(int $forceFactorySettings) { if ($forceFactorySettings || !`optionVar -exists blendShapeAddTgtWt`) { optionVar -floatValue blendShapeAddTgtWt 1; } if ($forceFactorySettings || !`optionVar -exists blendShapeAddBetween`) { optionVar -intValue blendShapeAddBetween 0; } if ($forceFactorySettings || !`optionVar -exists blendShapeAddTop`) { optionVar -intValue blendShapeAddTop 1; } } // // Procedure Name: // blendShapeAddSetup // // Description: // Update the state of the option box UI to reflect the option values. // // Input Arguments: // parent - Top level parent layout of the option box UI. // Required so that UI object names can be // successfully resolved. // // forceFactorySettings - Whether the option values should be set to // default values. // // Return Value: // None. // global proc blendShapeAddSetup(string $parent, int $forceFactorySettings) { // Retrieve the option settings setOptionVars ($forceFactorySettings); setParent $parent; // Query the optionVar's and set the values into the controls checkBoxGrp -edit -v1 0 bsSpec; textFieldGrp -e -tx "" bsNode; optionMenuGrp -e -enable 0 bsList; textFieldGrp -e -enable 0 bsNode; float $wt=`optionVar -q blendShapeAddTgtWt`; floatSliderGrp -e -v $wt bstWt; $val = `optionVar -query blendShapeAddBetween`; checkBoxGrp -edit -v1 $val bsInbetweenWidget; floatSliderGrp -e -enable $val bstWt; textFieldGrp -e -enable $val inBetweenIndex; $val = `optionVar -query blendShapeAddTop`; checkBoxGrp -edit -v1 $val blendShapeAddTgtTopWidget; } // // Procedure Name: // blendShapeAddCallback // // Description: // Update the option values with the current state of the option box UI. // // Input Arguments: // parent - Top level parent layout of the option box UI. Required so // that UI object names can be successfully resolved. // // doIt - Whether the command should execute. // // Return Value: // None. // global proc blendShapeAddCallback(string $parent, int $doIt) { setParent $parent; // Set the optionVar's from the control values, and then perform the // command float $env = `floatSliderGrp -q -v bstWt`; optionVar -floatValue blendShapeAddTgtWt $env; $val= `checkBoxGrp -q -v1 bsInbetweenWidget`; optionVar -intValue blendShapeAddBetween $val; $val= `checkBoxGrp -q -v1 blendShapeAddTgtTopWidget`; optionVar -intValue blendShapeAddTop $val; if ($doIt) { performBlendShapeAdd 0; addToRecentCommandQueue "performBlendShapeAdd 0" "BlendShapeAdd"; } } // // Procedure Name: // blendShapeAddOptions // // Description: // Construct the option box UI. Involves accessing the standard option // box and customizing the UI accordingly. // // Input Arguments: // None. // // Return Value: // None. // proc blendShapeAddOptions() { if( !`exists doBlendShapeAddTargetPostDeformer`) source "doBlendShapeAddTargetPostDeformer.mel"; // Name of the command for this option box. // string $commandName = "blendShapeAdd"; // Build the option box actions. // string $callback = ($commandName + "Callback"); string $setup = ($commandName + "Setup"); // STEP 1: 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; // STEP 2: Pass the command name to the option box. // ================================================= // // Any default option box behaviour based on the command name is set // up with this call. For example, updating the 'Help' menu item with // the name of the command. // setOptionBoxCommandName("blendShape"); // STEP 3: Activate the default UI template. // ========================================== // // Activate the default UI template so that the layout of this // option box is consistent with the layout of the rest of the // application. // setUITemplate -pushTemplate DefaultTemplate; // STEP 4: Create option box contents. // =================================== // // This, of course, will vary from option box to option box. // Turn on the wait cursor. // waitCursor -state 1; tabLayout -tabsVisible 0 -scrollable 1; string $parent = `columnLayout -adjustableColumn 1`; checkBoxGrp -numberOfCheckBoxes 1 -label (uiRes("m_performBlendShapeAdd.kSpecifyNode")) -label1 "" -v1 0 -on1 "specifyBlendShapeCallback 1" -ofc "specifyBlendShapeCallback 0" bsSpec; textFieldGrp -enable 0 -label (uiRes("m_performBlendShapeAdd.kBlendShapeNode")) -tx "" bsNode; // Create an option menu listing existing blendShapes // optionMenuGrp -enable 0 -label (uiRes("m_performBlendShapeAdd.kExistingNodes")) -cc "textFieldGrp -e -tx `optionMenuGrp -q -v bsList` bsNode" bsList; // add all the blendShapes to the menu // int $pp; string $bnArray[]; $bnArray = `ls -type blendShape`; int $bnCount = size($bnArray); if ($bnCount > 0) { for ($pp = 0; $pp < $bnCount; $pp++) { menuItem -label $bnArray[$pp]; } } else { menuItem -label (uiRes("m_performBlendShapeAdd.kNoBlendShapeSelected")) ; } separator; checkBoxGrp -numberOfCheckBoxes 1 -label (uiRes("m_performBlendShapeAdd.kAddInBetweenTarget")) -label1 "" -v1 0 -on1 "floatSliderGrp -e -enable 1 bstWt;textFieldGrp -e -enable 1 inBetweenIndex;" -offCommand "floatSliderGrp -e -enable 0 bstWt;textFieldGrp -e -enable 0 inBetweenIndex" bsInbetweenWidget; textFieldGrp -enable 0 -label (uiRes("m_performBlendShapeAdd.kTargetIndex")) -tx "" inBetweenIndex; floatSliderGrp -enable 0 -label (uiRes("m_performBlendShapeAdd.kInBetweenWeight")) -field true -v 1 -min -10 -max 10 bstWt; separator; checkBoxGrp -label (uiRes("m_performBlendShapeAdd.kTargetShapeOptions")) -label1 (uiRes("m_performBlendShapeAdd.kCheckTopology")) -numberOfCheckBoxes 1 -v1 0 blendShapeAddTgtTopWidget; separator; checkBoxGrp -label (uiRes("m_performBlendShapeAdd.kEnablePostDeformerMode")) -label1 "" -v1 0 -on1 "optionMenuGrp -e -enable 1 bsPostDeformerModeList" -ofc "optionMenuGrp -e -enable 0 bsPostDeformerModeList" bsEnablePostDeformerModeCBG; optionMenuGrp -enable 0 -label "" -changeCommand("postDeformerModeCB") bsPostDeformerModeList; menuItem -label (uiRes("m_performBlendShapeAdd.kPDMTangentSpace")) ; menuItem -label (uiRes("m_performBlendShapeAdd.kPDMTransformSpace")) ; textFieldButtonGrp -label (uiRes("m_performBlendShapeAdd.kTransformName")) -editable true -buttonLabel (uiRes("m_performBlendShapeAdd.kUseSelected")) -text "" -cw 3 100 -buttonCommand("transformNameButtonCB(\"bsTransformNameFBGrp\")") bsTransformNameFBGrp; textFieldButtonGrp -e -enable 0 bsTransformNameFBGrp; // Turn off the wait cursor. // waitCursor -state 0; // Step 5: Deactivate the default UI template. // =========================================== // setUITemplate -popTemplate; // Step 6: Customize the buttons. // ============================== // // Provide more descriptive labels for the buttons. This is not // necessary, but in some cases, for example, a button labelled // 'Create' may be more meaningful to the user than one labelled // 'Apply'. // // Disable those buttons that are not applicable to the option box. // // Attach actions to those buttons that are applicable to the option // box. Note that the 'Close' button has a default action attached // to it that will hide the window. If a a custom action is // attached to the 'Close' button then be sure to call the 'hide the // option box' procedure within the custom action so that the option // box is hidden properly. // 'Apply' button. // string $applyBtn = getOptionBoxApplyBtn(); button -edit -command ($callback + " " + $parent + " " + 1) $applyBtn; // 'Save' button. // string $saveBtn = getOptionBoxSaveBtn(); button -edit -command ($callback + " " + $parent + " " + 0 + "; hideOptionBox") $saveBtn; // 'Reset' button. // string $resetBtn = getOptionBoxResetBtn(); button -edit -command ($setup + " " + $parent + " " + 1) $resetBtn; // Step 7: Set the option box title. // ================================= // setOptionBoxTitle (uiRes("m_performBlendShapeAdd.kAddBlendShapeTargetOptions")); // Step 8: Customize the 'Help' menu item text. // ============================================ // setOptionBoxHelpTag( "EditBlendShapeAdd" ); // Step 9: Set the current values of the option box. // ================================================= // eval (($setup + " " + $parent + " " + 0)); // Step 10: Show the option box. // ============================= // showOptionBox(); } // // Procedure Name: // blendShapeAddHelp // // Description: // Return a short description about this command. // // Input Arguments: // None. // // Return Value: // string. // proc string blendShapeAddHelp() { return " Command: blendShape"; } // // Procedure Name: // assembleCmd // // Description: // Construct the command that will apply the option box values. // // Input Arguments: // None. // proc string assembleCmd() { string $cmd; setOptionVars(false); $cmd = "doBlendShape"; // This is add mode = 1 int $radio = 1; int $tween = `optionVar -query blendShapeAddBetween`; int $top = `optionVar -query blendShapeAddTop`; int $bsp=0; if (`checkBoxGrp -exists bsSpec`) { $bsp = `checkBoxGrp -query -v1 bsSpec`; } string $bsn = "\"\""; if (`textFieldGrp -exists bsNode`) { $bsn=`textFieldGrp -query -tx bsNode`; if ($bsn=="") $bsn="\"\""; } string $bstn="\"\""; if ($tween && `textFieldGrp -exists inBetweenIndex`) { $bstn=`textFieldGrp -query -tx inBetweenIndex`; if ($bstn!="") $tween = $bstn; if (! $tween) { error( (uiRes("m_performBlendShapeAdd.kInvalidTarget"))); } $bstn="\"\""; } int $bstp = $tween;; float $bstw=`optionVar -query blendShapeAddTgtWt`; int $bsPostDeformerEnabled = 0; if (`checkBoxGrp -exists bsEnablePostDeformerModeCBG`) { $bsPostDeformerEnabled = `checkBoxGrp -query -v1 bsEnablePostDeformerModeCBG`; } if ($bsPostDeformerEnabled == 0) { $cmd += (" " + $radio + " " + $tween + " " + $top + " " + $bsp + " " + $bsn + " " + $bstp + " " + $bstn + " " + $bstw + " 0"); } else { int $bsPostDeformer = -1; string $transformName = "\"\""; if (`optionMenuGrp -exists bsPostDeformerModeList`) { $bsPostDeformer = `optionMenuGrp -query -select bsPostDeformerModeList` -1; if($bsPostDeformer == 1) { if (`textFieldButtonGrp -exists bsTransformNameFBGrp`) $transformName = `textFieldButtonGrp -q -text bsTransformNameFBGrp`; } } $cmd = "doBlendShapeAddTargetPostDeformer " + $bsn + " " + $top + " " + $bsPostDeformer + " " + $transformName; } return $cmd; } // // Procedure Name: // performBlendShapeAdd // // Description: // Perform the blendShapeAdd 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 blendShapeAdd command with the current // option box values. // // Input Arguments: // 0 - Execute the command. // 1 - Show the option box dialog. // 2 - Return the command. // global proc string performBlendShapeAdd(int $action) { string $cmd = ""; switch ($action) { // Execute the command. // case 0: // Get the command. // $cmd = `assembleCmd`; // Execute the command with the option settings. // eval($cmd); break; // Show the option box. // case 1: blendShapeAddOptions; break; // Return the command string. // case 2: // Get the command. // $cmd = `assembleCmd`; break; } return $cmd; }