// =========================================================================== // 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: November 25, 1996 // // Description: // This script provides an option box dialog for the lattice command. // // // 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 latticeDivX`) { optionVar -intValue latticeDivX 2; } if ($forceFactorySettings || !`optionVar -exists latticeDivY`) { optionVar -intValue latticeDivY 5; } if ($forceFactorySettings || !`optionVar -exists latticeDivZ`) { optionVar -intValue latticeDivZ 2; } if ($forceFactorySettings || !`optionVar -exists latticeLocalDivX`) { optionVar -intValue latticeLocalDivX 2; } if ($forceFactorySettings || !`optionVar -exists latticeLocalDivY`) { optionVar -intValue latticeLocalDivY 2; } if ($forceFactorySettings || !`optionVar -exists latticeLocalDivZ`) { optionVar -intValue latticeLocalDivZ 2; } if ($forceFactorySettings || !`optionVar -exists latticeLocal`) { optionVar -intValue latticeLocal 1; } if ($forceFactorySettings || !`optionVar -exists latticeFreezeMapping`) { optionVar -intValue latticeFreezeMapping 0; } if ($forceFactorySettings || !`optionVar -exists latticeObjectCentered`) { optionVar -intValue latticeObjectCentered 1; } if ($forceFactorySettings || !`optionVar -exists latticeCommonParent`) { optionVar -intValue latticeCommonParent 0; } if ($forceFactorySettings || !`optionVar -exists latticeAutoParent`) { optionVar -intValue latticeAutoParent 0; } if ($forceFactorySettings || !`optionVar -exists latticePositioning`) { optionVar -stringValue latticePositioning "default"; } if ($forceFactorySettings || !`optionVar -exists latticeExclusive`) { // 0 == no exclusive // 1 == exclusive with new name // 2 == exclusive using an existing partition // optionVar -intValue latticeExclusive 0; } if ($forceFactorySettings || !`optionVar -exists latticeExclName`) { optionVar -stringValue latticeExclName "deformPartition"; } if ($forceFactorySettings || !`optionVar -exists latticeOutsideTransform`) { optionVar -stringValue latticeOutsideTransform "inside"; } if ($forceFactorySettings || !`optionVar -exists latticeOutsideFalloffDistance`) { optionVar -floatValue latticeOutsideFalloffDistance 1.0; } } // // Procedure Name: // latticeSetup // // 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. // tabIndex - 0 = both tabs, 1 = basic, 2 = advanced // // Return Value: // None. // global proc latticeSetup(string $parent, int $forceFactorySettings, int $tabIndex) { // Retrieve the option settings // setOptionVars ($forceFactorySettings); setParent $parent; // Query the optionVar's and set the values into the controls if ($tabIndex != 2) { // Divisions in X, Y, Z int $divX = `optionVar -query latticeDivX`; intFieldGrp -edit -value1 $divX latticeDivisionsWidget; int $divY = `optionVar -query latticeDivY`; intFieldGrp -edit -value2 $divY latticeDivisionsWidget; int $divZ = `optionVar -query latticeDivZ`; intFieldGrp -edit -value3 $divZ latticeDivisionsWidget; // Local mode int $localMode = `optionVar -query latticeLocal`; checkBoxGrp -edit -value1 $localMode latticeLocalWidget; // Local Divisions in X, Y, Z int $localX = `optionVar -query latticeLocalDivX`; intFieldGrp -edit -value1 $localX localDivisionsWidget; int $localY = `optionVar -query latticeLocalDivY`; intFieldGrp -edit -value2 $localY localDivisionsWidget; int $localZ = `optionVar -query latticeLocalDivZ`; intFieldGrp -edit -value3 $localZ localDivisionsWidget; intFieldGrp -e -enable $localMode localDivisionsWidget; // Freeze mapping mode int $freeze = `optionVar -query latticeFreezeMapping`; checkBoxGrp -edit -value1 $freeze freezeWidget; // Object centered int $objectCentered = `optionVar -query latticeObjectCentered`; checkBoxGrp -edit -value1 $objectCentered latticeObjectCenteredWidget; // common parent int $commonParent = `optionVar -query latticeCommonParent`; checkBoxGrp -edit -value1 $commonParent latticeCommonParentWidget; // auto parent int $autoParent = `optionVar -query latticeAutoParent`; checkBoxGrp -edit -value1 $autoParent latticeAutoParentWidget; // Transform points which are outside the base lattice string $outsideTransform = `optionVar -query latticeOutsideTransform`; int $outsideFalloff = 0; if (`optionMenuGrp -exists latticeOutsideTransformWidget`) { if ($outsideTransform == "inside") { optionMenuGrp -edit -select 1 latticeOutsideTransformWidget; } else if ($outsideTransform == "all") { optionMenuGrp -edit -select 2 latticeOutsideTransformWidget; } else if ($outsideTransform == "falloff") { optionMenuGrp -edit -select 3 latticeOutsideTransformWidget; $outsideFalloff = 1; } else { optionMenuGrp -edit -select 1 latticeOutsideTransformWidget; } } // Falloff distance for points outside the base lattice float $outsideFalloffDistance = `optionVar -query latticeOutsideFalloffDistance`; floatFieldGrp -edit -value1 $outsideFalloffDistance -en $outsideFalloff latticeOutsideFalloffDistanceWidget; } if ($tabIndex != 1) { // Positioning of the lattice deformer in the DG string $positioning = `optionVar -query latticePositioning`; if (`optionMenuGrp -exists latticePositioningWidget`) { if ($positioning == "default") { optionMenuGrp -edit -select 1 latticePositioningWidget; } else if ($positioning == "before") { optionMenuGrp -edit -select 2 latticePositioningWidget; } else if ($positioning == "after") { optionMenuGrp -edit -select 3 latticePositioningWidget; } else if ($positioning == "split") { optionMenuGrp -edit -select 4 latticePositioningWidget; } else if ($positioning == "parallel") { optionMenuGrp -edit -select 5 latticePositioningWidget; } else { optionMenuGrp -edit -select 1 latticePositioningWidget; } } int $exc=`optionVar -query latticeExclusive`; if (`checkBoxGrp -exists exclWidget`) { checkBoxGrp -e -v1 $exc exclWidget; } string $exn=`optionVar -query latticeExclName`; if (`textFieldGrp -exists partitionNameWidget`) { textFieldGrp -e -tx $exn -enable $exc partitionNameWidget; } if (`optionMenuGrp -exists partitionListWidget`) { optionMenuGrp -e -enable $exc partitionListWidget; } } } // // Procedure Name: // latticeCallback // // 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 latticeCallback(string $parent, int $doIt) { setParent $parent; // Set the optionVar's from the control values, and then perform the // command // Divisions in X, Y, Z int $divX = `intFieldGrp -query -value1 latticeDivisionsWidget`; optionVar -intValue latticeDivX $divX; int $divY = `intFieldGrp -query -value2 latticeDivisionsWidget`; optionVar -intValue latticeDivY $divY; int $divZ = `intFieldGrp -query -value3 latticeDivisionsWidget`; optionVar -intValue latticeDivZ $divZ; // Object centered int $objectCentered = `checkBoxGrp -query -value1 latticeObjectCenteredWidget`; optionVar -intValue latticeObjectCentered $objectCentered; // common parent int $commonParent = `checkBoxGrp -query -value1 latticeCommonParentWidget`; optionVar -intValue latticeCommonParent $commonParent; // auto parent int $autoParent = `checkBoxGrp -query -value1 latticeAutoParentWidget`; optionVar -intValue latticeAutoParent $autoParent; // Local mode int $localMode = `checkBoxGrp -query -value1 latticeLocalWidget`; optionVar -intValue latticeLocal $localMode; // Local Divisions in X, Y, Z int $localX = `intFieldGrp -query -value1 localDivisionsWidget`; optionVar -intValue latticeLocalDivX $localX; int $localY = `intFieldGrp -query -value2 localDivisionsWidget`; optionVar -intValue latticeLocalDivY $localY; int $localZ = `intFieldGrp -query -value3 localDivisionsWidget`; optionVar -intValue latticeLocalDivZ $localZ; // Freeze mapping mode int $freeze = `checkBoxGrp -query -value1 freezeWidget`; optionVar -intValue latticeFreezeMapping $freeze; // Positioning of the lattice deformer in the DG string $positioning = "default"; if (`optionMenuGrp -exists latticePositioningWidget`) { if (`optionMenuGrp -query -select latticePositioningWidget` == 1) { $positioning = "default"; } else if (`optionMenuGrp -query -select latticePositioningWidget` == 2){ $positioning = "before"; } else if (`optionMenuGrp -query -select latticePositioningWidget` == 3){ $positioning = "after"; } else if (`optionMenuGrp -query -select latticePositioningWidget` == 4){ $positioning = "split"; } else if (`optionMenuGrp -query -select latticePositioningWidget` == 5){ $positioning = "parallel"; } } optionVar -stringValue latticePositioning $positioning; string $outsideTransform = "inside"; if (`optionMenuGrp -exists latticeOutsideTransformWidget`) { int $ot = `optionMenuGrp -query -select latticeOutsideTransformWidget`; if ( 1 == $ot ) { $outsideTransform = "inside"; } else if ( 2 == $ot ) { $outsideTransform = "all"; } else if ( 3 == $ot ) { $outsideTransform = "falloff"; } } optionVar -stringValue latticeOutsideTransform $outsideTransform; float $outsideFalloffDistance = `floatFieldGrp -query -value1 latticeOutsideFalloffDistanceWidget`; optionVar -floatValue latticeOutsideFalloffDistance $outsideFalloffDistance; if (`checkBoxGrp -exists exclWidget`) { int $exclusive = `checkBoxGrp -q -v1 exclWidget`; optionVar -intValue latticeExclusive $exclusive; if ($exclusive) { if (`textFieldGrp -exists partitionNameWidget`) { string $partitionNameVal = `optionMenuGrp -q -v partitionListWidget`; if ($partitionNameVal == uiRes("m_performLattice.kCreateNewPartition")) { if (`textFieldGrp -exists partitionNameWidget`) { $partitionNameVal = `textFieldGrp -q -tx partitionNameWidget`; } } else { // a value of 2 indicates that we use an existing partition // optionVar -intValue latticeExclusive 2; } optionVar -stringValue latticeExclName $partitionNameVal; } } } if ($doIt) { performLattice 0; addToRecentCommandQueue "performLattice 0" "Lattice"; } } // // Procedure Name: // latticeOutsideTransformChanged // // Description: // This procedure is called when the currently selected item in // the $outsideTransform menu is changed. It is used to alter // ghosting of affilited meny items. // // Input Arguments: // None. // // Return Value: // None. // global proc latticeOutsideTransformChanged() { int $outsideTransform = `optionMenuGrp -query -select latticeOutsideTransformWidget`; if ( 3 == $outsideTransform ) { floatFieldGrp -edit -en true latticeOutsideFalloffDistanceWidget; } else { floatFieldGrp -edit -en false latticeOutsideFalloffDistanceWidget; } } // // Procedure Name: // latticeTabUI // // Description: // This is an example of how to delay the creation of the tab UI. // The contents of each tab is created only when it is required, // ie. if the tab is initially visible or if the tab is selected // by the user. // // Input Arguments: // The name of the tab layout. // // Return Value: // None. // global proc latticeTabUI(string $tabLayout) { string $tab[] = `tabLayout -query -childArray $tabLayout`; int $currentTabIndex = `tabLayout -query -selectTabIndex $tabLayout`; // Determine if the UI for this tab has been created yet. // This is accomplished by querying the number of children // in the current tab. If the tab has no children then the UI // must be created. // if (0 == `columnLayout -query -numberOfChildren $tab[$currentTabIndex-1]`) { setParent $tab[$currentTabIndex-1]; string $label; int $index; // 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; // Turn on the wait cursor. // waitCursor -state 1; // The current tab has no children. Determine which tab is // active and create its UI. // if (1 == $currentTabIndex) { // Create UI for the first tab. // columnLayout -adjustableColumn true; // Lattice divisions in X, Y, Z intFieldGrp -label (uiRes("m_performLattice.kDivisions")) -numberOfFields 3 latticeDivisionsWidget; // Local mode checkBoxGrp -label (uiRes("m_performLattice.kLocalMode")) -label1 (uiRes("m_performLattice.kUseLocalMode")) -numberOfCheckBoxes 1 -onCommand "intFieldGrp -e -enable 1 localDivisionsWidget" -offCommand "intFieldGrp -e -enable 0 localDivisionsWidget" latticeLocalWidget; // Local divisions in X, Y, Z intFieldGrp -label (uiRes("m_performLattice.kLocalDivisions")) -numberOfFields 3 localDivisionsWidget; // Object centered checkBoxGrp -label (uiRes("m_performLattice.kPositioning")) -label1 (uiRes("m_performLattice.kCenterAroundSelection")) -numberOfCheckBoxes 1 latticeObjectCenteredWidget; // Common Parent checkBoxGrp -label (uiRes("m_performLattice.kGrouping")) -label1 (uiRes("m_performLattice.kGroupBase")) -numberOfCheckBoxes 1 latticeCommonParentWidget; // Object centered checkBoxGrp -label (uiRes("m_performLattice.kParenting")) -label1 (uiRes("m_performLattice.kAutoparent")) -numberOfCheckBoxes 1 latticeAutoParentWidget; // freeze mapping mode checkBoxGrp -label (uiRes("m_performLattice.kFreezeMode")) -label1 (uiRes("m_performLattice.kFreezeGeometryMapping")) -numberOfCheckBoxes 1 freezeWidget; separator; // Transform points which are outside the base lattice optionMenuGrp -label (uiRes("m_performLattice.kOutsideLattice")) -cc latticeOutsideTransformChanged latticeOutsideTransformWidget; menuItem -label (uiRes("m_performLattice.kTransformLattice")) latticeOutsideTransform1; menuItem -label (uiRes("m_performLattice.kTransformPoints")) latticeOutsideTransform2; menuItem -label (uiRes("m_performLattice.kTransformFalloff")) latticeOutsideTransform3; // Falloff distance for points outside the base lattice floatFieldGrp -label (uiRes("m_performLattice.kFalloffDistance")) latticeOutsideFalloffDistanceWidget; } else if (2 == $currentTabIndex) { // Create UI for the second tab. // columnLayout -adjustableColumn true; // Positioning of the lattice deformer in the DG optionMenuGrp -label (uiRes("m_performLattice.kDeformationOrder")) latticePositioningWidget; menuItem -label (uiRes("m_performLattice.kDefault")) latticePosItem1; menuItem -label (uiRes("m_performLattice.kBefore")) latticePosItem2; menuItem -label (uiRes("m_performLattice.kAfter")) latticePosItem3; menuItem -label (uiRes("m_performLattice.kSplit")) latticePosItem4; menuItem -label (uiRes("m_performLattice.kParallel")) latticePosItem5; separator; checkBoxGrp -numberOfCheckBoxes 1 -label "" -label1 (uiRes("m_performLattice.kExclusive")) -v1 0 -on1 "optionMenuGrp -e -enable 1 partitionListWidget; updatePartitionNameWidget;" -offCommand "optionMenuGrp -e -enable 0 partitionListWidget; updatePartitionNameWidget;" exclWidget; // Create an option menu listing the partitions // optionMenuGrp -label (uiRes("m_performLattice.kPartitiontoUse")) -enable `checkBoxGrp -q -v1 exclWidget` -cc "updatePartitionNameWidget" partitionListWidget; string $currentNameOption = ""; if (`optionVar -exists latticeExclName`) { $currentNameOption = `optionVar -q latticeExclName`; } // add all the partitions to the menu // int $pp; string $partitionArray[]; $partitionArray = `ls -type partition`; int $partitionCount = size($partitionArray); menuItem -label (uiRes("m_performLattice.kCreateNewPartition")) ; for ($pp = 0; $pp < $partitionCount; $pp++) { // Do not list the render partition as adding items to // it is only going to cause confusion. // if ($partitionArray[$pp] != "renderPartition" && $partitionArray[$pp] != "characterPartition") { menuItem -label $partitionArray[$pp]; } if ($currentNameOption == $partitionArray[$pp]) { optionVar -stringValue latticeExclName "deformPartition"; } } textFieldGrp -label (uiRes("m_performLattice.kNewPartitionName")) -enable `checkBoxGrp -q -v1 exclWidget` -tx "deformPartition" partitionNameWidget; updatePartitionNameWidget; } // Update the control values to match the options. // eval (("latticeSetup " + $tabLayout + " "+0+" "+$currentTabIndex)); // Turn off the wait cursor. // waitCursor -state 0; // Deactivate the default UI template. // setUITemplate -popTemplate; } } // // Procedure Name: // latticeOptions // // Description: // Construct the option box UI. Involves accessing the standard option // box and customizing the UI accordingly. // // Input Arguments: // None. // // Return Value: // None. // proc latticeOptions() { // Name of the command for this option box. // string $commandName = "lattice"; // 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($commandName); // 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. // // Note: this option box example delays the creation of the UI // until it is required. Therefore this step is moved to the // procedure where the UI is actually created. // //setUITemplate -pushTemplate DefaultTemplate; // STEP 4: Create option box contents. // =================================== // // This, of course, will vary from option box to option box. // Demonstrate the delaying of UI creation via tab layouts. // Instead of creating all of the option box UI initially, only // create that which is initially visible. Wait, until the // other tabs are selected to create the remaining UI. // string $tabLayout = `tabLayout -scrollable 1`; // Attach an action that will be invoked before a tab is selected. // tabLayout -edit -preSelectCommand ("latticeTabUI " + $tabLayout) $tabLayout; // Create just the immediate children of the tab layout so that // the tabs appear. // columnLayout; setParent ..; columnLayout; setParent ..; // Set the tab labels. // tabLayout -edit -tabLabelIndex 1 (uiRes("m_performLattice.kBasic")) -tabLabelIndex 2 (uiRes("m_performLattice.kAdvanced")) $tabLayout; // Create the UI for the tab that is initially visible. // latticeTabUI($tabLayout); // Step 5: Deactivate the default UI template. // =========================================== // // Note: this option box example delays the creation of the UI // until it is required. Therefore this step is moved to the // procedure where the UI is actually created. // // See also Step 2. // //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_performLattice.kCreate")) -command ($callback + " " + $tabLayout + " " + 1) $applyBtn; // 'Save' button. // string $saveBtn = getOptionBoxSaveBtn(); button -edit -command ($callback + " " + $tabLayout + " " + 0 + "; hideOptionBox") $saveBtn; // 'Reset' button. // string $resetBtn = getOptionBoxResetBtn(); button -edit -command ($setup + " " + $tabLayout + " " + 1+" "+0) $resetBtn; // Step 7: Set the option box title. // ================================= // setOptionBoxTitle (uiRes("m_performLattice.kLatticeOptions")); // Step 8: Customize the 'Help' menu item text. // ============================================ // setOptionBoxHelpTag( "CreateLattice" ); // Step 9: Set the current values of the option box. // ================================================= // // NOTE: Cannot do this here since we do not know what UI is // currently visible. This is moved to where the UI is created. // //eval (($setup + " " + $tabLayout + " " + 0)); // Step 10: Show the option box. // ============================= // showOptionBox(); } // // Procedure Name: // latticeHelp // // Description: // Return a short description about this command. // // Input Arguments: // None. // // Return Value: // string. // proc string latticeHelp() { // ******** Example // " Command: Extrude - create a surface using extrusion.\n" + // "Selection: curves and isoparms." return " Command: lattice"; } // // 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); $cmd = "lattice "; int $divX = `optionVar -query latticeDivX`; int $divY = `optionVar -query latticeDivY`; int $divZ = `optionVar -query latticeDivZ`; string $positioning = `optionVar -query latticePositioning`; // Convert the object centered boolean into a more meaningful string // Build a positioning flag if needed string $positioningFlag = ""; if ($positioning != "default") { $positioningFlag = ("-" + $positioning); } $cmd = ("lattice " + $positioningFlag + " -divisions " + $divX + " " + $divY + " " + $divZ); if ( `optionVar -query latticeCommonParent` ) { $cmd += " -cp "; } if ( `optionVar -query latticeFreezeMapping` ) { $cmd += " -fm true "; } if (`optionVar -query latticeObjectCentered`) { $cmd += " -objectCentered true "; } if (`optionVar -query latticeLocal`) { $divX = `optionVar -query latticeLocalDivX`; $divY = `optionVar -query latticeLocalDivY`; $divZ = `optionVar -query latticeLocalDivZ`; $cmd += " -ldv " + $divX + " " + $divY + " " + $divZ ; } string $outsideTransform = `optionVar -query latticeOutsideTransform`; if ( "all" == $outsideTransform ) { $cmd += " -ol 1"; } else if ( "falloff" == $outsideTransform ) { float $outsideFalloffDistance = `optionVar -query latticeOutsideFalloffDistance`; $cmd += " -ol 2 -ofd " + $outsideFalloffDistance; } int $exc=`optionVar -query latticeExclusive`; if ($exc) { string $exn=`optionVar -query latticeExclName`; if ($exn!="") { // make sure that we do not clash names with an existing // partition when the user requested a new partition, even // if the user may have entered a non-unique name // if ($exc == 1) $exn += "#"; $cmd += (" -exclusive \"" + $exn+"\""); } } if (`optionVar -query latticeAutoParent`) { $cmd = "latticeAutoparent \""+$cmd+"\""; } return $cmd; } // // Procedure Name: // performLattice // // Description: // Perform the lattice 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 lattice 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 performLattice(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: latticeOptions; break; // Return the command string. // case 2: // Retrieve the option settings. // setOptionVars (false); // Get the command. // $cmd = `assembleCmd`; break; } return $cmd; }