// =========================================================================== // 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 sets up the skinCluster Smooth Weights option box // // Input Arguments: // None. // // Return Value: // None. // proc setOptionVars (int $forceFactorySettings) { if ( $forceFactorySettings || !`optionVar -exists scSmoothWeights` ) optionVar -floatValue scSmoothWeights 0.0; if ( $forceFactorySettings || !`optionVar -exists scSmoothWeightIterations` ) optionVar -intValue scSmoothWeightIterations 5; if ( $forceFactorySettings || !`optionVar -exists scSmoothPreview` ) optionVar -intValue scSmoothPreview 0; if ( $forceFactorySettings || !`optionVar -exists scSmoothObeyMaxInfluences` ) optionVar -intValue scSmoothObeyMaxInfluences 1; } // // Procedure Name: // smoothSkinWeightsSetup // // 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 smoothSkinWeightsSetup (string $parent, int $forceFactorySettings) { // Retrieve the option settings // setOptionVars( $forceFactorySettings ); setParent $parent; // Query the optionVar's and set the values into the controls // // if (`floatSliderGrp -exists scSmoothWeightsSlider`) floatSliderGrp -edit -value `optionVar -query scSmoothWeights` scSmoothWeightsSlider; if (`intSliderGrp -exists scSmoothWeightsIterations`) intSliderGrp -edit -value `optionVar -query scSmoothWeightIterations` scSmoothWeightsIterations; if (`checkBoxGrp -exists previewCheckBox`) checkBoxGrp -e -v1 `optionVar -query scSmoothPreview` previewCheckBox; if (`checkBoxGrp -exists obeyMaxInfluencesCheckBox`) checkBoxGrp -e -v1 `optionVar -query scSmoothObeyMaxInfluences` obeyMaxInfluencesCheckBox; // If preview is used obeyMaxInfluences is ignored. Make sure this is reflected in the UI. int $preview = `optionVar -query scSmoothPreview`; checkBoxGrp -e -enable ( $preview == false ) obeyMaxInfluencesCheckBox ; } // // Procedure Name: // smoothSkinWeightsCallback // // 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 smoothSkinWeightsCallback (string $parent, int $doIt) { setParent $parent; if (`floatSliderGrp -exists scSmoothWeightsSlider`) optionVar -floatValue scSmoothWeights `floatSliderGrp -query -value scSmoothWeightsSlider`; if (`intSliderGrp -exists scSmoothWeightIterations`) optionVar -intValue scSmoothWeightIterations `intSliderGrp -query -value scSmoothWeightIterations`; if (`checkBoxGrp -exists previewCheckBox`) optionVar -intValue scSmoothPreview `checkBoxGrp -query -v1 previewCheckBox`; if (`checkBoxGrp -exists obeyMaxInfluencesCheckBox`) optionVar -intValue scSmoothObeyMaxInfluences `checkBoxGrp -query -v1 obeyMaxInfluencesCheckBox`; if ($doIt) { performSmoothSkinWeights false; addToRecentCommandQueue "performSmoothSkinWeights false" "SmoothSkinWeights"; } } global proc smoothSkinWeightsOptions () { // Name of the command for this option box // string $commandName = "smoothSkinWeights"; // Build the option box "methods" // 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("skinCluster"); // 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`; floatSliderGrp -label (uiRes("m_performSmoothSkinWeights.kSmoothTolerance")) -annotation (uiRes("m_performSmoothSkinWeights.kSmoothToleranceAnnotation")) -minValue 0.0 -maxValue 100.0 -pre 4 scSmoothWeightsSlider; intSliderGrp -label (uiRes("m_performSmoothSkinWeights.kSmoothIterations")) -annotation (uiRes("m_performSmoothSkinWeights.kSmoothIterationsAnnotation")) -cc "optionVar -intValue scSmoothWeightIterations `intSliderGrp -query -value scSmoothWeightsIterations`" -minValue 0 -maxValue 100 scSmoothWeightsIterations; checkBoxGrp -label (uiRes("m_performSmoothSkinWeights.kSmoothPreview")) -annotation (uiRes("m_performSmoothSkinWeights.kSmoothPreviewAnnotation")) -v1 0 -cc "checkBoxGrp -e -enable ( #1 == false ) obeyMaxInfluencesCheckBox" previewCheckBox; checkBoxGrp -label (uiRes("m_performSmoothSkinWeights.kSmoothObeyMaxInfluences")) -annotation (uiRes("m_performSmoothSkinWeights.kSmoothObeyMaxInfluencesAnnotation")) -v1 0 obeyMaxInfluencesCheckBox; // 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 -label (uiRes("m_performSmoothSkinWeights.kSmooth")) -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_performSmoothSkinWeights.kSmoothSkinWeightsOptions")); // Step 8: Customize the 'Help' menu item text. // ============================================ // setOptionBoxHelpTag( "SmoothSkinWeights" ); // Step 9: Set the current values of the option box. // ================================================= // eval (($setup + " " + $parent + " " + 0)); // Step 10: Show the option box. // ============================= // showOptionBox(); } proc string assembleCmd () { string $cmd; setOptionVars( false ); $cmd = "doSmoothSkinWeightsArgList 3 { " + "\"" + `optionVar -query scSmoothWeights` + "\", " + "\"" + `optionVar -query scSmoothWeightIterations` + "\", " + "\"" + `optionVar -query scSmoothPreview` + "\", " + "\"" + `optionVar -query scSmoothObeyMaxInfluences` + "\" " + " };"; return $cmd; } global proc string performSmoothSkinWeights (int $action) // The action variable means // 0 - do the command // 1 - show the option box // 2 - return the drag command { string $cmd = ""; switch ($action) { case 0: // Execute the command // Retrieve the option settings // setOptionVars (false); // Get the command and print it in the command window $cmd = `assembleCmd`; // Execute the command with the option settings evalEcho($cmd); break; case 1: // Do the option box smoothSkinWeightsOptions; break; case 2: // Return the drag string // Retrieve the option settings // setOptionVars (false); // Get the command $cmd = `assembleCmd`; break; } return $cmd; }