// =========================================================================== // 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: 4 April 1997 // // Procedure Name: // performPolySubdivide // // Description: // subdivide the selected polygon facets or edges // // Input Arguments: // $option : Whether to set the options to default values. // Return Value: // command string iff $option==2 // proc setOptionVars (string $comp, int $forceFactorySettings) { if ($forceFactorySettings || !`optionVar -exists ("polySubdSubd" + $comp)`) optionVar -intValue ("polySubdSubd" + $comp) 1; // Facet // if ($comp =="f") { if ($forceFactorySettings || !`optionVar -exists ("polySubdivideMethod")`) optionVar -intValue ("polySubdivideMethod") 1; if ($forceFactorySettings || !`optionVar -exists ("polySubdFacetMode" + $comp)`) optionVar -intValue ("polySubdFacetMode" + $comp) 1; if ($forceFactorySettings || !`optionVar -exists ("polySubdSubdU" + $comp)`) optionVar -intValue ("polySubdSubdU" + $comp) 1; if ($forceFactorySettings || !`optionVar -exists ("polySubdSubdV" + $comp)`) optionVar -intValue ("polySubdSubdV" + $comp) 1; // Edge // } else { if ($forceFactorySettings || !`optionVar -exists ("polySubdLen" + $comp)`) optionVar -floatValue ("polySubdLen" + $comp) 0; if ($forceFactorySettings || !`optionVar -exists ("polySubdWS" + $comp)`) optionVar -intValue ("polySubdWS" + $comp) 0; } } global proc performPolySubdivideSetup (string $comp, string $parent, int $forceFactorySettings) { setOptionVars($comp, $forceFactorySettings); setParent $parent; // Facet // if ($comp == "f") { int $method = `optionVar -query ("polySubdivideMethod")`; radioButtonGrp -edit -select $method polySubdivideMethod; int $ival = `optionVar -query ("polySubdSubd" + $comp)`; intSliderGrp -edit -value $ival polySubdSubd; $ival = `optionVar -query ("polySubdFacetMode" + $comp)`; optionMenuGrp -edit -sl $ival polySubdFacetMode; int $ival1 = `optionVar -query ("polySubdSubdU" + $comp)`; int $ival2 = `optionVar -query ("polySubdSubdV" + $comp)`; intSliderGrp -edit -value $ival1 polySubdSubdU; intSliderGrp -edit -value $ival2 polySubdSubdV; // Edge // } else { float $val = `optionVar -query ("polySubdLen" + $comp)`; floatSliderGrp -edit -value $val polySubdLen; int $ival = `optionVar -query ("polySubdWS" + $comp)`; checkBoxGrp -edit -value1 $ival polySubdWS; $ival = `optionVar -query ("polySubdSubd" + $comp)`; intSliderGrp -edit -value $ival polySubdSubdL; $val = `optionVar -query ("polySubdLen" + $comp)`; floatSliderGrp -edit -value $val polySubdLen; $ival = `optionVar -query ("polySubdWS" + $comp)`; checkBoxGrp -edit -value1 $ival polySubdWS; } polySubdivideVisibility($comp); } global proc performPolySubdivideCallback (string $comp, string $parent, int $doIt) { setParent $parent; // Facet // if ($comp =="f") { int $method = `radioButtonGrp -q -select polySubdivideMethod`; optionVar -intValue ("polySubdivideMethod") $method; optionVar -intValue ("polySubdSubd" + $comp) `intSliderGrp -query -value polySubdSubd`; optionVar -intValue ("polySubdFacetMode" + $comp) `optionMenuGrp -query -sl polySubdFacetMode`; optionVar -intValue ("polySubdSubdU" + $comp) `intSliderGrp -query -value polySubdSubdU`; optionVar -intValue ("polySubdSubdV" + $comp) `intSliderGrp -query -value polySubdSubdV`; // Edge } else { optionVar -intValue ("polySubdSubd" + $comp) `intSliderGrp -query -value polySubdSubdL`; optionVar -floatValue ("polySubdLen" + $comp) `floatSliderGrp -query -value polySubdLen`; optionVar -intValue ("polySubdWS" + $comp) `checkBoxGrp -query -value1 polySubdWS`; } if ($doIt) { performPolySubdivide $comp 0; string $tmpCmd = "performPolySubdivide \"" + $comp + "\" 0"; string $tmpLabel = "PolySubdivideEdge"; if ($comp =="f") $tmpLabel = "PolySubdivideFacet"; addToRecentCommandQueue $tmpCmd $tmpLabel; } } global proc polySubdivideVisibility(string $comp) // Description: // Dim/show exponential/linear frames according to method // { if ($comp == "f"){ int $showLinear = `radioButtonGrp -query -select polySubdivideMethod` - 1; // radioButtonGrp is 1 based frameLayout -edit -enable (1 - $showLinear) polyAddDivisionsExponentialFrame; frameLayout -edit -enable $showLinear polyAddDivisionsLinearFrameFace; } else { frameLayout -edit -enable 1 polyAddEdgeDivisionsLinearFrame; } } proc polySubdivideFaceOptions (string $comp) { // Global template variables for form spacing global int $gOptionBoxTemplateFrameSpacing; string $commandName = "performPolySubdivide"; string $callback = ($commandName + "Callback " + $comp); string $setup = ($commandName + "Setup " + $comp); string $layout = getOptionBox(); setParent $layout; setUITemplate -pushTemplate OptionBoxTemplate; waitCursor -state 1; // Form layout string $parent = `formLayout polyAddFaceDivisionsOptions`; string $worldspace = (uiRes("m_performPolySubdivide.kWorldspaceFace")); string $divisionLevels = (uiRes("m_performPolySubdivide.kDivisionLevelsFace")); string $minimumLength = (uiRes("m_performPolySubdivide.kMinimumLengthFace")); // Settings frame string $settingsFrame = `frameLayout -label (uiRes("m_performPolySubdivide.kSettingsFrame"))`; columnLayout; radioButtonGrp -numberOfRadioButtons 2 -vertical -label (uiRes("m_performPolySubdivide.kAddDivisions")) -label1 (uiRes("m_performPolySubdivide.kExponentially")) -label2 (uiRes("m_performPolySubdivide.kLinearly")) -changeCommand ("polySubdivideVisibility(\"" + $comp + "\")") polySubdivideMethod; setParent $parent; // frameLayout // Exponential controls frame string $exponentialFrame = `frameLayout -label (uiRes("m_performPolySubdivide.kExponentialFrameFace")) polyAddDivisionsExponentialFrame`; columnLayout; intSliderGrp -label $divisionLevels -minValue 1 -maxValue 4 -fieldMaxValue 8 polySubdSubd; optionMenuGrp -label (uiRes("m_performPolySubdivide.kMode")) polySubdFacetMode; menuItem -label (uiRes("m_performPolySubdivide.kQuads")) SubdFacetQuadsMenuItem; menuItem -label (uiRes("m_performPolySubdivide.kTriangles")) SubdFacetTrgsMenuItem; setParent -menu ..; optionMenuGrp -edit -select 1 polySubdFacetMode; setParent $parent; // frameLayout // Linear controls frame string $linearFrame = `frameLayout -label (uiRes("m_performPolySubdivide.kLinearFrameFace")) polyAddDivisionsLinearFrameFace`; columnLayout; intSliderGrp -label (uiRes("m_performPolySubdivide.kDivisionsInU")) -minValue 1 -maxValue 8 -fieldMaxValue 250 polySubdSubdU; intSliderGrp -label (uiRes("m_performPolySubdivide.kDivisionsInV")) -minValue 1 -maxValue 8 -fieldMaxValue 250 polySubdSubdV; setParent $parent; // frameLayout setParent ..; // formLayout // Attach frame to form layout formLayout -edit -attachForm $settingsFrame "top" $gOptionBoxTemplateFrameSpacing -attachForm $settingsFrame "left" $gOptionBoxTemplateFrameSpacing -attachForm $settingsFrame "right" $gOptionBoxTemplateFrameSpacing -attachNone $settingsFrame "bottom" -attachControl $exponentialFrame "top" $gOptionBoxTemplateFrameSpacing $settingsFrame -attachForm $exponentialFrame "left" $gOptionBoxTemplateFrameSpacing -attachForm $exponentialFrame "right" $gOptionBoxTemplateFrameSpacing -attachNone $exponentialFrame "bottom" -attachControl $linearFrame "top" $gOptionBoxTemplateFrameSpacing $exponentialFrame -attachForm $linearFrame "left" $gOptionBoxTemplateFrameSpacing -attachForm $linearFrame "right" $gOptionBoxTemplateFrameSpacing -attachNone $linearFrame "bottom" $parent; waitCursor -state 0; setUITemplate -popTemplate; string $applyBtn = getOptionBoxApplyBtn(); button -edit -label (uiRes("m_performPolySubdivide.kAddDivisionsButtonFace")) -command ($callback + " " + $parent + " " + 1) $applyBtn; string $saveBtn = getOptionBoxSaveBtn(); button -edit -command ($callback + " " + $parent + " " + 0 + "; hideOptionBox") $saveBtn; string $resetBtn = getOptionBoxResetBtn(); button -edit -command ($setup + " " + $parent + " " + 1) $resetBtn; string $lbl = (uiRes("m_performPolySubdivide.kFaceLabel")); string $obj = "Facet"; string $title = (uiRes("m_performPolySubdivide.kAddDivisionsOptionsFace")); setOptionBoxTitle( `format -s $lbl $title` ); // Customize the 'Help' menu item text. // setOptionBoxHelpTag( "EditPolygonsSubdivide" ); eval (($setup + " " + $parent + " " + 0)); scriptJob -protected -parent $parent -event "SelectTypeChanged" "evalDeferred \"performPolySubdivide \\\"\\\" 1\""; showOptionBox(); } proc polySubdivideEdgeOptions (string $comp) { // Global template variables for form spacing global int $gOptionBoxTemplateFrameSpacing; string $commandName = "performPolySubdivide"; string $callback = ($commandName + "Callback " + $comp); string $setup = ($commandName + "Setup " + $comp); string $layout = getOptionBox(); setParent $layout; setUITemplate -pushTemplate OptionBoxTemplate; waitCursor -state 1; // Form layout string $parent = `formLayout polyAddEdge7DivisionsOptions`; string $worldspace = (uiRes("m_performPolySubdivide.kWorldspace")); string $divisionLevels = (uiRes("m_performPolySubdivide.kDivisionLevels")); string $minimumLength = (uiRes("m_performPolySubdivide.kMinimumLength")); // Linear controls frame string $linearFrame = `frameLayout -label (uiRes("m_performPolySubdivide.kLinearFrame")) polyAddEdgeDivisionsLinearFrame`; columnLayout; intSliderGrp -label $divisionLevels -minValue 1 -maxValue 4 -fieldMaxValue 1000 polySubdSubdL; floatSliderGrp -label $minimumLength -minValue 0 -maxValue 10 -fieldMinValue 0 -fieldMaxValue 1000 polySubdLen; checkBoxGrp -label1 $worldspace polySubdWS; setParent $parent; // frameLayout setParent ..; // formLayout // Attach frame to form layout formLayout -edit -attachForm $linearFrame "top" $gOptionBoxTemplateFrameSpacing -attachForm $linearFrame "left" $gOptionBoxTemplateFrameSpacing -attachForm $linearFrame "right" $gOptionBoxTemplateFrameSpacing -attachNone $linearFrame "bottom" $parent; waitCursor -state 0; setUITemplate -popTemplate; string $applyBtn = getOptionBoxApplyBtn(); button -edit -label (uiRes("m_performPolySubdivide.kAddDivisionsButton")) -command ($callback + " " + $parent + " " + 1) $applyBtn; string $saveBtn = getOptionBoxSaveBtn(); button -edit -command ($callback + " " + $parent + " " + 0 + "; hideOptionBox") $saveBtn; string $resetBtn = getOptionBoxResetBtn(); button -edit -command ($setup + " " + $parent + " " + 1) $resetBtn; string $lbl = (uiRes("m_performPolySubdivide.kEdgeLabel")); ; string $obj = "Edge"; string $title = (uiRes("m_performPolySubdivide.kAddDivisionsOptions")); setOptionBoxTitle( `format -s $lbl $title` ); // Customize the 'Help' menu item text. // setOptionBoxHelpTag( "EditPolygonsSubdivideEdges" ); eval (($setup + " " + $parent + " " + 0)); scriptJob -protected -parent $parent -event "SelectTypeChanged" "evalDeferred \"performPolySubdivide \\\"\\\" 1\""; showOptionBox(); } proc polySubdivideOptions (string $comp) { if ($comp == "f") polySubdivideFaceOptions($comp); else polySubdivideEdgeOptions($comp); } global proc string performPolySubdivide (string $comp, int $option) { string $cmd=""; string $obj=""; if ($comp == "") { // If no comp is specified, use the selection list to decide on E/F //restrict the selection to polygon meshes and components select `filterExpand -sm 12 -sm 31 -sm 32 -sm 34 -ex false`; if (size(`filterExpand -ex false -sm 34`) != 0) { $comp="f"; $obj="Facet"; } else if (size(`filterExpand -ex false -sm 32`) != 0) { $comp="e"; $obj="Edge"; } else { // If nothing is selected, check which is about to be selected!! if (`selectMode -q -object`) { // Object Selection Mode // Check for RMB component selection if (`selectType -q -ocm -facet`) { $comp="f"; $obj="Facet"; } else if (`selectType -q -ocm -edge`) { $comp="e"; $obj="Edge"; } } else { // Component Selection Mode if (`selectType -q -facet`) { $comp="f"; $obj="Facet"; } else if (`selectType -q -edge`) { $comp="e"; $obj="Edge"; } } if ($comp == "") { // If still unresolvable, take facet as the default! $comp="f"; $obj="Facet"; } } } else { if ($comp == "f") $obj="Facet"; else if ($comp == "e") $obj="Edge"; else { if ($option < 2) { warning (uiRes("m_performPolySubdivide.kOnlyPolyEdgesAndFaces")); return ""; } } } string $sel[]; string $res[]; switch ($option) { case 0: setOptionVars($comp, false); if ($comp == "f") { int $method = `optionVar -query ("polySubdivideMethod")`; if($method == 1) { int $ival1 = `optionVar -query polySubdSubdf`; int $iv2 = `optionVar -query polySubdFacetModef` -1; $cmd=("polySubdivideFacet -dv " + $ival1 + " -m " + $iv2); } else { int $ival1 = `optionVar -query polySubdSubdUf`; int $ival2 = `optionVar -query polySubdSubdVf`; $cmd=("polySubdivideFacet -duv " + $ival1 + " -dvv " + $ival2 + " -sbm " + ($method - 1)); } } else { int $ival = `optionVar -query polySubdSubde`; float $val =`optionVar -query polySubdLene`; int $ws = `optionVar -query polySubdWSe`; $cmd=("polySubdivideEdge -ws " + $ws + " -s " + $val + " -dv " + $ival); } polyPerformAction $cmd $comp 0; // make sure node is selected when there is history if ( 0 != size(`ls -sl`) || (0 != size(`ls -hl`)) ) { string $tmp[] = `listHistory`; string $totalSel[]; for ($opNode in $tmp) { if (`nodeType $opNode` == "polySubdFace" || `nodeType $opNode` == "polySubdEdge") { $totalSel[size($totalSel)] = $opNode; } } if (size($totalSel) > 0) select -add $totalSel[0]; } setToolTo ShowManips; break; case 1: polySubdivideOptions $comp; break; case 2: /* setOptionVars($comp, false); // note that by 'freezing' the parameters, we now have to stick // the shelf item to either 'subdivide edges' or 'subdivide facets' // hence the command losses a bit of functionality: instead of // smartly applying to either edges or facets, it will apply // to only one of those categories. if ($comp == "e") { int $ival = `optionVar -query polySubdSubde`; float $val =`optionVar -query polySubdLene`; int $ws = `optionVar -query polySubdWSe`; $cmd=("polySubdivideEdge -ws " + $ws + " -s " + $val + " -dv " + $ival); } else if ($comp == "f") { int $ival = `optionVar -query polySubdSubdf`; int $iv2 = `optionVar -query polySubdFacetModef` -1; $cmd=("polySubdivideFacet -dv " + $ival + " -m " + $iv2); } else $cmd="performPolySubdivide \"\" 0"; if ($comp != "") $cmd=("polyPerformAction \""+ $cmd + "\" " + $comp + " 0"); */ $cmd="performPolySubdivide \"\" 0"; } return $cmd; }