// =========================================================================== // 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 sculpt 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 sculptMode`) { optionVar -stringValue sculptMode "stretch"; } if ($forceFactorySettings || !`optionVar -exists sculptInsideMode`) { optionVar -stringValue sculptInsideMode "even"; } if ($forceFactorySettings || !`optionVar -exists sculptMaxDisp`) { optionVar -floatValue sculptMaxDisp 0.1; } if ($forceFactorySettings || !`optionVar -exists sculptDropoffType`) { optionVar -stringValue sculptDropoffType "linear"; } if ($forceFactorySettings || !`optionVar -exists sculptDropoffDist`) { optionVar -floatValue sculptDropoffDist 1.0; } if ($forceFactorySettings || !`optionVar -exists sculptObjectCentered`) { optionVar -intValue sculptObjectCentered 1; } if ($forceFactorySettings || !`optionVar -exists sculptGroupWithLocator`) { optionVar -intValue sculptGroupWithLocator 0; } if ($forceFactorySettings || !`optionVar -exists sculptTool`) { optionVar -intValue sculptTool 0; } if ($forceFactorySettings || !`optionVar -exists sculptPositioning`) { optionVar -stringValue sculptPositioning "default"; } if ($forceFactorySettings || !`optionVar -exists sculptExclusive`) { // 0 == no exclusive // 1 == exclusive with new name // 2 == exclusive using an existing partition // optionVar -intValue sculptExclusive 0; } if ($forceFactorySettings || !`optionVar -exists sculptExclName`) { optionVar -stringValue sculptExclName "deformPartition"; } } // // Procedure Name: // sculptSetup // // 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 sculptSetup(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 // Mode if ($tabIndex != 2) { string $mode = `optionVar -query sculptMode`; string $insideMode = `optionVar -query sculptInsideMode`; if ($mode == "project") { radioButtonGrp -edit -select 2 sculptModeWidget; checkBoxGrp -e -en false sculptGroupWithLocWidget; } else if ($mode == "stretch") { radioButtonGrp -edit -select 3 sculptModeWidget; checkBoxGrp -e -en true sculptGroupWithLocWidget; } else { radioButtonGrp -edit -select 1 sculptModeWidget; int $modeIsEven = ($insideMode == "even"); checkBoxGrp -e -en $modeIsEven sculptGroupWithLocWidget; } // Inside mode if ($insideMode == "even") { radioButtonGrp -edit -select 2 sculptInsideModeWidget; } else { radioButtonGrp -edit -select 1 sculptInsideModeWidget; } // Maximum displacement float $maxDisp = `optionVar -query sculptMaxDisp`; floatSliderGrp -edit -value $maxDisp sculptMaxDispWidget; // Dropoff type string $dropoffType = `optionVar -query sculptDropoffType`; if ($dropoffType == "none") { radioButtonGrp -edit -select 1 sculptDropoffTypeWidget; } else if ($dropoffType == "linear") { radioButtonGrp -edit -select 2 sculptDropoffTypeWidget; } else { radioButtonGrp -edit -select 1 sculptDropoffTypeWidget; } // Dropoff distance float $dropoffDist = `optionVar -query sculptDropoffDist`; floatSliderGrp -edit -value $dropoffDist sculptDropoffDistWidget; // Object centered int $objectCentered = `optionVar -query sculptObjectCentered`; checkBoxGrp -edit -value1 $objectCentered sculptObjectCenteredWidget; // Group with locator int $groupWithLocator = `optionVar -query sculptGroupWithLocator`; checkBoxGrp -edit -value1 $groupWithLocator sculptGroupWithLocWidget; // Sculpt Tool int $sculptTool = `optionVar -query sculptTool`; checkBoxGrp -edit -value1 $sculptTool sculptToolWidget; } if ($tabIndex != 1) { // Positioning of the sculpt deformer in the DG string $positioning = `optionVar -query sculptPositioning`; if (`optionMenuGrp -exists sculptPositioningWidget`) { if ($positioning == "default") { optionMenuGrp -edit -select 1 sculptPositioningWidget; } else if ($positioning == "before") { optionMenuGrp -edit -select 2 sculptPositioningWidget; } else if ($positioning == "after") { optionMenuGrp -edit -select 3 sculptPositioningWidget; } else if ($positioning == "split") { optionMenuGrp -edit -select 4 sculptPositioningWidget; } else if ($positioning == "parallel") { optionMenuGrp -edit -select 5 sculptPositioningWidget; } else { optionMenuGrp -edit -select 1 sculptPositioningWidget; } } int $exc = `optionVar -query sculptExclusive`; if (`checkBoxGrp -exists exclWidget`) { checkBoxGrp -e -v1 $exc exclWidget; } string $exn = `optionVar -query sculptExclName`; if (`textFieldGrp -exists partitionNameWidget`) { textFieldGrp -e -tx $exn -enable $exc partitionNameWidget; } if (`optionMenuGrp -exists partitionListWidget`) { optionMenuGrp -e -enable $exc partitionListWidget; } } } // // Procedure Name: // sculptCallback // // 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 sculptCallback(string $parent, int $doIt) { setParent $parent; // Set the optionVar's from the control values, and then perform the command // Mode string $mode; if (`radioButtonGrp -query -select sculptModeWidget` == 1) { $mode = "flip"; } else if (`radioButtonGrp -query -select sculptModeWidget` == 2) { $mode = "project"; } else if (`radioButtonGrp -query -select sculptModeWidget` == 3) { $mode = "stretch"; } else { $mode = "flip"; } optionVar -stringValue sculptMode $mode; // Inside mode string $insideMode; if (`radioButtonGrp -query -select sculptInsideModeWidget` == 1) { $insideMode = "ring"; } else if (`radioButtonGrp -query -select sculptInsideModeWidget` == 2) { $insideMode = "even"; } else { $insideMode = "ring"; } optionVar -stringValue sculptInsideMode $insideMode; // Maximum displacement optionVar -floatValue sculptMaxDisp `floatSliderGrp -query -value sculptMaxDispWidget`; // Dropoff type string $dropoffType; if (`radioButtonGrp -query -select sculptDropoffTypeWidget` == 1) { $dropoffType = "none"; } else if (`radioButtonGrp -query -select sculptDropoffTypeWidget` == 2) { $dropoffType = "linear"; } else { $dropoffType = "none"; } optionVar -stringValue sculptDropoffType $dropoffType; // Dropoff distance optionVar -floatValue sculptDropoffDist `floatSliderGrp -query -value sculptDropoffDistWidget`; // Object centered int $objectCentered = `checkBoxGrp -query -value1 sculptObjectCenteredWidget`; optionVar -intValue sculptObjectCentered $objectCentered; // Group with locator int $groupWithLocator = `checkBoxGrp -query -value1 sculptGroupWithLocWidget`; optionVar -intValue sculptGroupWithLocator $groupWithLocator; // Sculpt Tool int $sculptTool = `checkBoxGrp -query -value1 sculptToolWidget`; optionVar -intValue sculptTool $sculptTool; // Positioning of the sculpt deformer in the DG string $positioning = "default"; if (`optionMenuGrp -exists sculptPositioningWidget`) { if (`optionMenuGrp -query -select sculptPositioningWidget` == 1) { $positioning = "default"; } else if (`optionMenuGrp -query -select sculptPositioningWidget` == 2) { $positioning = "before"; } else if (`optionMenuGrp -query -select sculptPositioningWidget` == 3) { $positioning = "after"; } else if (`optionMenuGrp -query -select sculptPositioningWidget` == 4) { $positioning = "split"; } else if (`optionMenuGrp -query -select sculptPositioningWidget` == 5) { $positioning = "parallel"; } } optionVar -stringValue sculptPositioning $positioning; if (`checkBoxGrp -exists exclWidget`) { optionVar -intValue sculptExclusive `checkBoxGrp -q -v1 exclWidget`; } if (`optionMenuGrp -exists partitionListWidget`) { string $partitionNameVal = `optionMenuGrp -q -v partitionListWidget`; if ($partitionNameVal == (uiRes("m_performSculpt.kCreateNewPartition"))) { if (`textFieldGrp -exists partitionNameWidget`) { $partitionNameVal = `textFieldGrp -q -tx partitionNameWidget`; } } else { // a value of 2 indicates that we use an existing partition // optionVar -intValue sculptExclusive 2; } optionVar -stringValue sculptExclName $partitionNameVal; } if ($doIt) { performSculpt 0; addToRecentCommandQueue "performSculpt 0" "Sculpt"; } } global proc setFlipModeGroupWithLocator() { if (`radioButtonGrp -query -select sculptModeWidget` == 1) { int $inMode = `radioButtonGrp -query -select sculptInsideModeWidget`; int $modeIsEven = ($inMode == 2); checkBoxGrp -e -en $modeIsEven sculptGroupWithLocWidget; } } // // Procedure Name: // sculptTabUI // // 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 sculptTabUI(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. // // Mode radioButtonGrp -label (uiRes("m_performSculpt.kMode")) -numberOfRadioButtons 3 -label1 (uiRes("m_performSculpt.kFlip")) -label2 (uiRes("m_performSculpt.kProject")) -label3 (uiRes("m_performSculpt.kStretch")) -cc1 "setFlipModeGroupWithLocator" -cc2 "checkBoxGrp -e -en false sculptGroupWithLocWidget;" -cc3 "checkBoxGrp -e -en true sculptGroupWithLocWidget;" sculptModeWidget; // Inside mode radioButtonGrp -label (uiRes("m_performSculpt.kInsideMode")) -numberOfRadioButtons 2 -label1 (uiRes("m_performSculpt.kRing")) -label2 (uiRes("m_performSculpt.kEven")) -cc1 "setFlipModeGroupWithLocator" -cc2 "setFlipModeGroupWithLocator" sculptInsideModeWidget; // Maximum displacement floatSliderGrp -label (uiRes("m_performSculpt.kMaxDisplacement")) -field true -min -10.0 -max 10.0 -fmn -100000.0 -fmx 100000.0 -pre 3 sculptMaxDispWidget; // Dropoff type radioButtonGrp -label (uiRes("m_performSculpt.kDropoffType")) -numberOfRadioButtons 2 -label1 (uiRes("m_performSculpt.kNone")) -label2 (uiRes("m_performSculpt.kLinear")) sculptDropoffTypeWidget; // Dropoff distance floatSliderGrp -label (uiRes("m_performSculpt.kDropoffDistance")) -field true -min 0.0 -max 10.0 -fmn 0 -fmx 100000.0 -pre 3 sculptDropoffDistWidget; // Object centered checkBoxGrp -label (uiRes("m_performSculpt.kPositioning")) -label1 (uiRes("m_performSculpt.kCenterWithinSelection")) -numberOfCheckBoxes 1 sculptObjectCenteredWidget; // Group sculpt sphere with the locator checkBoxGrp -label (uiRes("m_performSculpt.kGrouping")) -label1 (uiRes("m_performSculpt.kGroupSculptorWithLocator")) -numberOfCheckBoxes 1 sculptGroupWithLocWidget; // Use secondary object as fieldShape checkBoxGrp -label (uiRes("m_performSculpt.kSculptTool")) -label1 (uiRes("m_performSculpt.kUseSecondaryNURBSObject")) -annotation (uiRes("m_performSculpt.kUsesecondaryAnnot")) -numberOfCheckBoxes 1 sculptToolWidget; } else if (2 == $currentTabIndex) { // Create UI for the second tab. // // Positioning of the sculpt deformer in the DG optionMenuGrp -label (uiRes("m_performSculpt.kDeformationOrder")) sculptPositioningWidget; menuItem -label (uiRes("m_performSculpt.kDefault")) sculptPosItem1; menuItem -label (uiRes("m_performSculpt.kBefore")) sculptPosItem2; menuItem -label (uiRes("m_performSculpt.kAfter")) sculptPosItem3; menuItem -label (uiRes("m_performSculpt.kSplit")) sculptPosItem4; menuItem -label (uiRes("m_performSculpt.kParallel")) sculptPosItem5; separator; checkBoxGrp -numberOfCheckBoxes 1 -label "" -label1 (uiRes("m_performSculpt.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_performSculpt.kPartitiontoUse")) -enable `checkBoxGrp -q -v1 exclWidget` -cc "updatePartitionNameWidget" partitionListWidget; string $currentNameOption = ""; if (`optionVar -exists sculptExclName`) { $currentNameOption = `optionVar -q sculptExclName`; } // add all the partitions to the menu // int $pp; string $partitionArray[]; $partitionArray = `ls -type partition`; int $partitionCount = size($partitionArray); menuItem -label (uiRes("m_performSculpt.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 sculptExclName "deformPartition"; } } textFieldGrp -label (uiRes("m_performSculpt.kNewPartitionName")) -enable `checkBoxGrp -q -v1 exclWidget` -tx "deformPartition" partitionNameWidget; updatePartitionNameWidget; } // Update the control values to match the options. // eval (("sculptSetup " + $tabLayout + " "+0+" "+$currentTabIndex)); // Turn off the wait cursor. // waitCursor -state 0; // Deactivate the default UI template. // setUITemplate -popTemplate; } } // // Procedure Name: // sculptOptions // // Description: // Construct the option box UI. Involves accessing the standard option // box and customizing the UI accordingly. // // Input Arguments: // None. // // Return Value: // None. // proc sculptOptions() { // Name of the command for this option box. // string $commandName = "sculpt"; // 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 ("sculptTabUI " + $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_performSculpt.kBasic")) -tabLabelIndex 2 (uiRes("m_performSculpt.kAdvanced")) $tabLayout; // Create the UI for the tab that is initially visible. // sculptTabUI($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_performSculpt.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_performSculpt.kSculptOptions")); // Step 8: Customize the 'Help' menu item text. // ============================================ // setOptionBoxHelpTag( "CreateSculptDeformer" ); // 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: // sculptHelp // // Description: // Return a short description about this command. // // Input Arguments: // None. // // Return Value: // string. // proc string sculptHelp() { return " Command: sculpt"; } // // Procedure Name: // assembleCmd // // Description: // Construct the command that will apply the option box values. // // Input Arguments: // None. // // Return Value: // string cmd : Assembled "sculpt ..." command // string "" : An error occured (and was reported to the user) // proc string assembleCmd() { string $cmd; setOptionVars(false); $cmd = "sculpt "; string $mode = `optionVar -query sculptMode`; string $insideMode = `optionVar -query sculptInsideMode`; float $maxDisp = `optionVar -query sculptMaxDisp`; string $dropoffType = `optionVar -query sculptDropoffType`; float $dropoffDist = `optionVar -query sculptDropoffDist`; float $objectCentered = `optionVar -query sculptObjectCentered`; float $groupWithLocator = `optionVar -query sculptGroupWithLocator`; float $sculptTool = `optionVar -query sculptTool`; string $positioning = `optionVar -query sculptPositioning`; // Build a positioning flag if needed string $positioningFlag = ""; if ($positioning != "default") { $positioningFlag = ("-" + $positioning); } // If the user set the "Sculpt Tool" option, we expect exactly // two objects to be selected. The first is the object to be // deformed and the second the sculpt tool. // string $sculptToolFlag = ""; string $selection[] = `ls -sl`; if ( $sculptTool ) { if ( size( $selection ) != 2 ) { error((uiRes("m_performSculpt.kSculptToolOption"))); return ""; } $sculptToolFlag = ("-sculptTool "+$selection[1]); select -d $selection[1]; $selection = `ls -sl`; // refresh selection after deselection secondaty object } // Finally do the command as appropriate $cmd = ("sculpt " + $positioningFlag + $sculptToolFlag + " -mode " + $mode + " -insideMode " + $insideMode + " -maxDisplacement " + $maxDisp + " -dropoffType " + $dropoffType + " -dropoffDistance " + $dropoffDist + " -groupWithLocator " + $groupWithLocator + " -objectCentered " + $objectCentered); int $exc = `optionVar -query sculptExclusive`; if ($exc) { string $exn=`optionVar -query sculptExclName`; 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+"\""); } } // object(s) to be sculpted is provided last for ($selObj in $selection) { $cmd += (" "+$selObj); } return $cmd; } // // Procedure Name: // performSculpt // // Description: // Perform the sculpt 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 sculpt 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 performSculpt(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. // if ( $cmd != "" ) { evalEcho($cmd); } break; // Show the option box. // case 1: sculptOptions; break; // Return the command string. // case 2: // Retrieve the option settings. // setOptionVars (false); // Get the command. // $cmd = `assembleCmd`; break; } return $cmd; }