// =========================================================================== // 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: 12 March, 1999 // // Description: // Option box for subdivision surface create // Create a subdivision surface from a polygon or a nurbs surface. // // // Procedure Name: // setOptionVars // // Description: // Initialize the option values. // // Input Arguments: // Whether to set the options to default values. // // Return Value: // None. // // Note: // global proc subdivCreateVisibility( string $parent, int $mode, int $keep ) { setParent $parent; if( ($mode < 0) && ($keep < 0) ) { $mode = `radioButtonGrp -q -sl subdivCreateOrigObject`; $keep = `checkBoxGrp -q -v1 subdivCreateKeepOrigObject`; } switch( $mode ) { case 1: checkBoxGrp -e -en true subdivCreateKeepOrigObject; break; case 2: checkBoxGrp -e -en false subdivCreateKeepOrigObject; break; default: break; } if( $keep >= 0 ) { if( $keep ) { radioButtonGrp -e -en true subdivCreateOrigObject; } else { radioButtonGrp -e -en false subdivCreateOrigObject; } } } proc setOptionVars(int $forceFactorySettings) { // // Original Object // if ($forceFactorySettings || !`optionVar -exists subdivCreateOrigObject`) { optionVar -intValue subdivCreateOrigObject 1; } // Maximum Number Polygons that input mesh can have // if ($forceFactorySettings || !`optionVar -exists subdivCreateMaxPolygons`) { optionVar -intValue subdivCreateMaxPolygons 1000; } // Maximum Edges Per Vertex (valence) // if ($forceFactorySettings || !`optionVar -exists subdivCreateMaxEdgesPerVert`) { optionVar -intValue subdivCreateMaxEdgesPerVert 32; } } // // Procedure Name: // subdivCreateSetup // // 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 subdivCreateSetup(string $parent, int $forceFactorySettings) { int $method; // Retrieve the option settings // setOptionVars($forceFactorySettings); setParent $parent; // Query the optionVar's and set the values into the controls. // Original Object // int $origObject = `optionVar -query subdivCreateOrigObject`; switch( $origObject ) { case 0: radioButtonGrp -e -select 2 subdivCreateOrigObject; checkBoxGrp -e -v1 0 subdivCreateKeepOrigObject; break; case 1: default: radioButtonGrp -e -select 1 subdivCreateOrigObject; checkBoxGrp -e -v1 0 subdivCreateKeepOrigObject; break; case 2: radioButtonGrp -e -select 2 subdivCreateOrigObject; checkBoxGrp -e -v1 1 subdivCreateKeepOrigObject; break; case 3: radioButtonGrp -e -select 1 subdivCreateOrigObject; checkBoxGrp -e -v1 1 subdivCreateKeepOrigObject; break; } // Maximum Number Polygons that input mesh can have // intSliderGrp -e -value `optionVar -query subdivCreateMaxPolygons` subdivCreateMaxPolygons; // Maximum Edges Per Vertex (valence) // intSliderGrp -e -value `optionVar -query subdivCreateMaxEdgesPerVert` subdivCreateMaxEdgesPerVert; subdivCreateVisibility( $parent, -1, -1 ); } // // Procedure Name: // subdivCreateCallback // // 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 subdivCreateCallback(string $parent, int $doIt) { setParent $parent; // Set the optionVar's from the control values, and then // perform the command. // Original Object // int $origObject = 1; int $radioOrig = `radioButtonGrp -query -select subdivCreateOrigObject`; if( 1 == $radioOrig ) { if( `checkBoxGrp -q -v1 subdivCreateKeepOrigObject` ) { $origObject = 3; } else { $origObject = 1; } } else { if( `checkBoxGrp -q -v1 subdivCreateKeepOrigObject` ) { $origObject = 2; } else { $origObject = 0; } } optionVar -intValue subdivCreateOrigObject $origObject; // Maximum Number Polygons that input mesh can have // optionVar -intValue subdivCreateMaxPolygons `intSliderGrp -query -value subdivCreateMaxPolygons`; // Maximum Edges Per Vertex (valence) // optionVar -intValue subdivCreateMaxEdgesPerVert `intSliderGrp -query -value subdivCreateMaxEdgesPerVert`; if ($doIt) { performSubdivCreate 0; addToRecentCommandQueue "performSubdivCreate 0" "Create Subdiv"; } } // // Procedure Name: // subdivCreateOptions // // Description: // Construct the option box UI. Involves accessing the standard option // box and customizing the UI accordingly. // // Input Arguments: // None. // // Return Value: // None. // proc subdivCreateOptions() { // Name of the command for this option box. // string $commandName = "subdivCreate"; // Build the option box actions. // string $callback = ($commandName + "Callback"); string $setup = ($commandName + "Setup"); // STEP 1: Get the option box. // ============================ // string $layout = getOptionBox(); setParent $layout; // STEP 2: Pass the command name to the option box. // ================================================= // setOptionBoxCommandName($commandName); // STEP 3: Activate the default UI template. // ========================================== // setUITemplate -pushTemplate DefaultTemplate; // STEP 4: Create option box contents. // =================================== // // Turn on the wait cursor. // waitCursor -state 1; tabLayout -tabsVisible 0 -scrollable 1; string $parent = `columnLayout -adjustableColumn 1`; // Maximum Number Polygons that input mesh can have // intSliderGrp -label (uiRes("m_performSubdivCreate.kMaximumBase")) -min 1 -max 10000 -fmx 100000 subdivCreateMaxPolygons; // Maximum Edges Per Vertex (valence) // intSliderGrp -label (uiRes("m_performSubdivCreate.kMaximumEdges")) -min 2 -max 50 -fmx 255 subdivCreateMaxEdgesPerVert; // Original Object // radioButtonGrp -numberOfRadioButtons 2 -label (uiRes("m_performSubdivCreate.kSubdivisionSurface")) -label1 (uiRes("m_performSubdivCreate.kStandard")) -label2 (uiRes("m_performSubdivCreate.kProxyObjec")) -on1( "subdivCreateVisibility " + $parent + " 1 -1") -on2( "subdivCreateVisibility " + $parent + " 2 -1") subdivCreateOrigObject; checkBoxGrp -ncb 1 -label "" -label1 (uiRes("m_performSubdivCreate.kKeepOriginal")) -of1( "subdivCreateVisibility " + $parent + " -1 0") -on1( "subdivCreateVisibility " + $parent + " -1 1") subdivCreateKeepOrigObject; // Turn off the wait cursor. // waitCursor -state 0; // Step 5: Deactivate the default UI template. // =========================================== // setUITemplate -popTemplate; // Step 6: Customize the buttons. // ============================== // // 'Apply' button. // string $applyBtn = getOptionBoxApplyBtn(); button -e -label (uiRes("m_performSubdivCreate.kCreate")) -command ($callback + " " + $parent + " " + 1) $applyBtn; // 'Save' button. // string $saveBtn = getOptionBoxSaveBtn(); button -e -command ($callback + " " + $parent + " " + 0 + "; hideOptionBox") $saveBtn; // 'Reset' button. // string $resetBtn = getOptionBoxResetBtn(); button -e -command ($setup + " " + $parent + " " + 1) $resetBtn; // Step 7: Set the option box title. // ================================= // setOptionBoxTitle (uiRes("m_performSubdivCreate.kConvertNURBS")); // Step 8: Customize the 'Help' menu item text. // ============================================ // setOptionBoxHelpTag( "ConvertToSubdiv" ); // Step 9: Set the current values of the option box. // ================================================= // eval (($setup + " " + $parent + " " + 0)); // Step 10: Show the option box. // ============================= // showOptionBox(); } // // Procedure Name: // subdivCreateHelp // // Description: // Return a short description about this command. // // Input Arguments: // None. // // Return Value: // string. // proc string subdivCreateHelp() { return " Command: subdivCreate - create a subdivision surface from a poly or nurbs surface.\n" + "Selection: Polygon or nurbs surfaces."; } // // Procedure Name: // assembleCmd // // Description: // Construct the command that will apply the option box values. // // Input Arguments: // None. // proc string assembleCmd() { setOptionVars(false); int $origObject = `optionVar -query subdivCreateOrigObject`; int $doHistory = `constructionHistory -q -tgl`; int $maxPolys = `optionVar -query subdivCreateMaxPolygons`; int $maxEdgesPerVert = `optionVar -query subdivCreateMaxEdgesPerVert`; string $version = "\"2\""; string $cmd = "doSubdivCreate"; $cmd = $cmd + "( "; $cmd = $cmd + $version; $cmd = $cmd + ", { \"" ; $cmd = $cmd + $origObject; $cmd = $cmd + "\",\""; $cmd = $cmd + $doHistory; $cmd = $cmd + "\",\""; $cmd = $cmd + $maxPolys; $cmd = $cmd + "\",\""; $cmd = $cmd + $maxEdgesPerVert; $cmd = $cmd + "\"} )"; return $cmd; } // // Procedure Name: // performSubdivCreate // // Description: // Perform the performSubdivCreate 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 performSubdivCreate 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 performSubdivCreate(int $action) { string $cmd = ""; switch ($action) { case 0: $cmd = assembleCmd (); eval($cmd); break; case 1: subdivCreateOptions (); break; case 2: $cmd = assembleCmd (); break; } return $cmd; }