// =========================================================================== // 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 is the mirror deformer weight option box dialogs. // // Input Arguments: // None. // // Return Value: // None. // global proc string mirrorDeformerWeightsSelectedDeformer() { string $def = ""; if (`textScrollList -exists mirrorDeformerDeformersList`) { string $sel[] = `textScrollList -q -si mirrorDeformerDeformersList`; if (size($sel) > 0) $def = $sel[0]; } return $def; } proc buildDeformerList(string $deformers[]) { if (size($deformers) <= 1) return; // Create a separator separator -height 20; // If the scrollList has not been created yet, create it. // Otherwise, clear it. if (!`textScrollList -q -ex mirrorDeformerDeformersList` ) { columnLayout -columnAttach "left" 50 -columnWidth 300; text -height 20 -label (uiRes("m_performMirrorDeformerWeights.kSelectMirroredWeightsDeformer")); textScrollList -width 300 -height 100 mirrorDeformerDeformersList; setParent ..; } else textScrollList -e -ra mirrorDeformerDeformersList; string $deformer; for ($deformer in $deformers) textScrollList -e -append $deformer -sc "mirrorDeformerWeightsSelectedDeformer" mirrorDeformerDeformersList; // Select the first item. textScrollList -e -sii 1 mirrorDeformerDeformersList; } proc setOptionVars (int $forceFactorySettings) { if ($forceFactorySettings || !`optionVar -exists mirrorDeformerAxis`) { optionVar -stringValue mirrorDeformerAxis "YZ"; } if ($forceFactorySettings || !`optionVar -exists mirrorInverse`) { optionVar -intValue mirrorInverse 1; } if ( $forceFactorySettings || !`optionVar -exists mirrorDeformerWeightsSurfaceAssociationOption` ) optionVar -intValue mirrorDeformerWeightsSurfaceAssociationOption 1; if ( $forceFactorySettings || !`optionVar -exists mirrorDeformerWeightsCreate` ) optionVar -intValue mirrorDeformerWeightsCreate 1; } // // Procedure Name: // mirrorDeformerWeightsSetup // // 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 mirrorDeformerWeightsSetup (string $parent, int $forceFactorySettings) { // Retrieve the option settings // setOptionVars( $forceFactorySettings ); setParent $parent; string $mode = `optionVar -query mirrorDeformerAxis`; if ($mode == "XY") { radioButtonGrp -edit -select 1 mirrorDeformerAxisWidget; checkBoxGrp -e -label1 (uiRes("m_performMirrorDeformerWeights.kDfrmPositivetoNegativeZ")) mirrorInverseWidget; } else if ($mode == "YZ") { radioButtonGrp -edit -select 2 mirrorDeformerAxisWidget; checkBoxGrp -e -label1 (uiRes("m_performMirrorDeformerWeights.kDfrmPositivetoNegativeX")) mirrorInverseWidget; } else { radioButtonGrp -edit -select 3 mirrorDeformerAxisWidget; checkBoxGrp -e -label1 (uiRes("m_performMirrorDeformerWeights.kDfrmPositivetoNegativeY")) mirrorInverseWidget; } int $objectCentered = `optionVar -query mirrorInverse`; checkBoxGrp -edit -value1 $objectCentered mirrorInverseWidget; int $create = `optionVar -query mirrorDeformerWeightsCreate`; checkBoxGrp -edit -value1 $create mirrorDeformerWeightsCreateWidget; int $value; // Set the state of the check box to that of the variable smoothCopyWeights // if (`radioButtonGrp -exists mirrorDeformerWeightsSurfaceAssociationMenu1`) { int $value = `optionVar -q mirrorDeformerWeightsSurfaceAssociationOption`; if( $value > 0) radioButtonGrp -e -select 1 ("mirrorDeformerWeightsSurfaceAssociationMenu" + $value); } } // // Procedure Name: // mirrorDeformerWeightsCallback // // 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 mirrorDeformerWeightsCallback (string $parent, int $doIt) { setParent $parent; string $mode; if (`radioButtonGrp -query -select mirrorDeformerAxisWidget` == 1) { $mode = "XY"; } else if (`radioButtonGrp -query -select mirrorDeformerAxisWidget` == 2) { $mode = "YZ"; } else { $mode = "XZ"; } optionVar -stringValue mirrorDeformerAxis $mode; // inverse int $invertIt = `checkBoxGrp -query -value1 mirrorInverseWidget`; optionVar -intValue mirrorInverse $invertIt; // create int $create = `checkBoxGrp -query -value1 mirrorDeformerWeightsCreateWidget`; optionVar -intValue mirrorDeformerWeightsCreate $create; // Remember the values of the surface associations // $value = 1; for( $i = 1; $i < 4; $i++) if( `radioButtonGrp -q -select ("mirrorDeformerWeightsSurfaceAssociationMenu" + $i)`) $value = $i; optionVar -intValue mirrorDeformerWeightsSurfaceAssociationOption $value; if ($doIt) { performMirrorDeformerWeights false; addToRecentCommandQueue "performMirrorDeformerWeights false" "MirrorDeformerWeights"; } } proc string mirrorDeformerWeightsWidgets( string $parent ) { setParent $parent; string $tabForm = `columnLayout -adjustableColumn true`; // Mode string $strValZ = uiRes("m_performMirrorSkinWeights.kPositivetoNegativeZ"); string $strValX = uiRes("m_performMirrorSkinWeights.kPositivetoNegativeX"); string $strValY = uiRes("m_performMirrorSkinWeights.kPositivetoNegativeY"); radioButtonGrp -label (uiRes("m_performMirrorDeformerWeights.kDfrmMirrorAcross")) -numberOfRadioButtons 3 -label1 (uiRes("m_performMirrorDeformerWeights.kDfrmXY")) -label2 (uiRes("m_performMirrorDeformerWeights.kDfrmYZ")) -label3 (uiRes("m_performMirrorDeformerWeights.kDfrmXZ")) -cc1 ("checkBoxGrp -e -label1 \"" + $strValZ + "\" mirrorInverseWidget") -cc2 ("checkBoxGrp -e -label1 \"" + $strValX + "\" mirrorInverseWidget") -cc3 ("checkBoxGrp -e -label1 \"" + $strValY + "\" mirrorInverseWidget") mirrorDeformerAxisWidget; // Invert checkBoxGrp -label (uiRes("m_performMirrorDeformerWeights.kDfrmDirection")) -label1 (uiRes("m_performMirrorDeformerWeights.kDfrmPositivetoNegative")) -numberOfCheckBoxes 1 mirrorInverseWidget; // Create checkBoxGrp -label (uiRes("m_performMirrorDeformerWeights.kDfrmCreate")) -numberOfCheckBoxes 1 mirrorDeformerWeightsCreateWidget; separator; radioButtonGrp -numberOfRadioButtons 1 -label (uiRes("m_performMirrorDeformerWeights.kDfrmSurfaceAssociation")) -label1 (uiRes("m_performMirrorDeformerWeights.kDfrmClosestPoint")) -select 1 mirrorDeformerWeightsSurfaceAssociationMenu1; radioButtonGrp -numberOfRadioButtons 1 -label1 (uiRes("m_performMirrorDeformerWeights.kDfrmRayCast")) -shareCollection mirrorDeformerWeightsSurfaceAssociationMenu1 mirrorDeformerWeightsSurfaceAssociationMenu2; radioButtonGrp -numberOfRadioButtons 1 -label1 (uiRes("m_performMirrorDeformerWeights.kDfrmClosestComponent")) -shareCollection mirrorDeformerWeightsSurfaceAssociationMenu1 mirrorDeformerWeightsSurfaceAssociationMenu3; // Get the list of deformers attached to the selected objects. If two objects // are selected, the list will consist of the deformers common to both objects. string $currentSelection[] = `ls -selection`; int $selSize = size($currentSelection); if ($selSize > 0) { if ($selSize == 1) { string $allDeformers[] = findRelatedDeformer($currentSelection[0]); string $deformers[] = `ls -type weightGeometryFilter $allDeformers`; if (size($deformers) > 1) buildDeformerList($deformers); } else if ($selSize == 2) { string $allSrcDeformers[] = findRelatedDeformer($currentSelection[0]); string $allDstDeformers[] = findRelatedDeformer($currentSelection[1]); string $srcDeformers[] = `ls -type weightGeometryFilter $allSrcDeformers`; string $dstDeformers[] = `ls -type weightGeometryFilter $allDstDeformers`; string $intersector = `stringArrayIntersector -intersect $srcDeformers`; stringArrayIntersector -e -intersect $dstDeformers $intersector; string $comDeformers[] = `stringArrayIntersector -q $intersector`; if (size($comDeformers) > 0) buildDeformerList($comDeformers); // If more than one object is involved in the mirroring, disable the // invert checkbox. checkBoxGrp -e -enable false mirrorInverseWidget; } } return $tabForm; } global proc mirrorDeformerWeightsOptions () { string $commandName = "mirrorDeformerWeights"; // Build the option box "methods" // 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; setOptionBoxCommandName("mirrorDeformerWeights"); setUITemplate -pushTemplate DefaultTemplate; waitCursor -state 1; tabLayout -scr true -tv false; // To get the scroll bars string $parent = `columnLayout -adjustableColumn 1`; mirrorDeformerWeightsWidgets $parent; waitCursor -state 0; setUITemplate -popTemplate; // 'Apply' button. // string $applyBtn = getOptionBoxApplyBtn(); button -edit -label (uiRes("m_performMirrorDeformerWeights.kDfrmMirror")) -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; // Set the option box title. // setOptionBoxTitle (uiRes("m_performMirrorDeformerWeights.kMirrorDeformerWeightsOptions")); // Customize the 'Help' menu item text. // setOptionBoxHelpTag( "MirrorDeformerWeights" ); // Set the current values of the option box. // eval (($setup + " " + $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 $cmd; setOptionVars(false); // Setup the arguments for our mirror command // string $args = " -mirrorMode " + `optionVar -query mirrorDeformerAxis`; if( !`optionVar -query mirrorInverse`) $args = $args + " -mirrorInverse"; int $surfaceAssociationMode = `optionVar -query mirrorDeformerWeightsSurfaceAssociationOption`; string $surfaceAssociationModes[] = {"closestPoint", "rayCast", "closestComponent"}; $args = $args + " -surfaceAssociation " + $surfaceAssociationModes[$surfaceAssociationMode - 1]; int $create = (`optionVar -query mirrorDeformerWeightsCreate`); string $defToUse = mirrorDeformerWeightsSelectedDeformer(); // Now pass them over // $cmd = "doMirrorDeformerWeightsArgList( 2, { \"" + $args + "\", \"" + $defToUse + "\", \"" + $create+ "\"} );"; return $cmd; } // // Procedure Name: // performMirrorDeformerWeights // // Description: // Peform a mirroring operation of deformer weights to a selected object. // This procedure will also show the option box window if necessary as well // as construct the command string that will perform the mirroring operation // 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 performMirrorDeformerWeights (int $action) { string $cmd = ""; switch ($action) { // Execute the command. // case 0: // Retrieve the option settings // setOptionVars(false); // Get the command. // $cmd = `assembleCmd`; // Execute the command with the option settings. // evalEcho($cmd); break; // Show the option box. // case 1: mirrorDeformerWeightsOptions; break; case 2: // Get the command. // $cmd = `assembleCmd`; } return $cmd; }