// =========================================================================== // 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. // =========================================================================== // // Utility functions for performPolyReduce, and its cousin, // performLODGenerateMeshes, since both of them share a lot of functionality. // // The methods that are common to both use the same name as the original // function, but are prefixed with pr_ (e.g., the common part of setOptionVars // is extracted out to pr_setOptionVars, and called by setOptionVars in both // performPolyReduce and performLODGenerateMeshes. // // ////////////////////////////////////////////////////////////////////// global proc pr_setOptionVars (int $forceFactorySettings, string $prefix) // // Description: // Set user definable options // // Arguments: // forceFactorySettings : use defaults // { ////////////////////////////// Termination conditions // Termination type, see TdnPolyReduce.attr for values. // if ($forceFactorySettings || !`optionVar -exists ($prefix+"polyReduceTermination")`){ optionVar -intValue ($prefix+"polyReduceTermination") 0; } ////////////////////////////// Shape // How hard to try keeping quad lines. 1 means use global reduction, // which is the fastest and best option for a quad mesh. // if ($forceFactorySettings || !`optionVar -exists ($prefix+"polyKeepQuadsWeight")`){ optionVar -floatValue ($prefix+"polyKeepQuadsWeight") 1; } // Sharpness coefficient // if ($forceFactorySettings || !`optionVar -exists ($prefix+"polyReduceSharpness")`){ optionVar -floatValue ($prefix+"polyReduceSharpness") 0.0; } // What kind of symmetry do we use? // default = none, 2 = auto, 3 = plane if ($forceFactorySettings || !`optionVar -exists ($prefix+"polyReduceSymmetryType")`){ optionVar -intValue ($prefix+"polyReduceSymmetryType") 1; } // The tolerance for symmetry maintenance. // if ($forceFactorySettings || !`optionVar -exists ($prefix+"polyReduceSymmetryTolerance")`){ optionVar -floatValue ($prefix+"polyReduceSymmetryTolerance") 0.01; } // Symmetry plane. 1 = XZ, 2 = XY, 3 = YZ. // if ($forceFactorySettings || !`optionVar -exists ($prefix+"polyReduceSymmetryPlane")`){ optionVar -intValue ($prefix+"polyReduceSymmetryPlane") 1; } ////////////////////////////// Feature Preservation // Default value is 0.5 meaning make some effort; 1.0 means // pin the vertices. // // Maintain geometric borders and the border of the selection. // if ($forceFactorySettings || !`optionVar -exists ($prefix+"polyReduceKeepBorder")`){ optionVar -intValue ($prefix+"polyReduceKeepBorder") 1; } if ($forceFactorySettings || !`optionVar -exists ($prefix+"polyReduceKeepBorderWeight")`){ optionVar -floatValue ($prefix+"polyReduceKeepBorderWeight") 0.5; } // Maintain uv borders // if ($forceFactorySettings || !`optionVar -exists ($prefix+"polyReduceKeepMapBorder")`){ optionVar -intValue ($prefix+"polyReduceKeepMapBorder") 1; } if ($forceFactorySettings || !`optionVar -exists ($prefix+"polyReduceKeepMapBorderWeight")`){ optionVar -floatValue ($prefix+"polyReduceKeepMapBorderWeight") 0.5; } // Maintain color borders if ($forceFactorySettings || !`optionVar -exists ($prefix+"polyReduceKeepColorBorder")`){ optionVar -intValue ($prefix+"polyReduceKeepColorBorder") 1; } if ($forceFactorySettings || !`optionVar -exists ($prefix+"polyReduceKeepColorBorderWeight")`) optionVar -floatValue ($prefix+"polyReduceKeepColorBorderWeight") 0.5; // Maintain material borders // if ($forceFactorySettings || !`optionVar -exists ($prefix+"polyReduceKeepMaterialBorder")`){ optionVar -intValue ($prefix+"polyReduceKeepMaterialBorder") 1; } if ($forceFactorySettings || !`optionVar -exists ($prefix+"polyReduceKeepMaterialBorderWeight")`){ optionVar -floatValue ($prefix+"polyReduceKeepMaterialBorderWeight") 0.5; } // Maintain hard edges // if ($forceFactorySettings || !`optionVar -exists ($prefix+"polyReduceKeepHardEdge")`){ optionVar -intValue ($prefix+"polyReduceKeepHardEdge") 1; } if ($forceFactorySettings || !`optionVar -exists ($prefix+"polyReduceKeepHardEdgeWeight")`){ optionVar -floatValue ($prefix+"polyReduceKeepHardEdgeWeight") 0.5; } // Maintain crease edges // if ($forceFactorySettings || !`optionVar -exists ($prefix+"polyReduceKeepCreaseEdge")`){ optionVar -intValue ($prefix+"polyReduceKeepCreaseEdge") 1; } if ($forceFactorySettings || !`optionVar -exists ($prefix+"polyReduceKeepCreaseEdgeWeight")`){ optionVar -floatValue ($prefix+"polyReduceKeepCreaseEdgeWeight") 0.5; } ////////////////////////////// Advanced options // if ($forceFactorySettings || !`optionVar -exists ($prefix+"polyReduceVertexMapName")`){ optionVar -stringValue ($prefix+"polyReduceVertexMapName") ""; } ////////////////////////////// Command options (no effect on node) } global proc pr_OBCheckBoxSliderEnable(string $parentPath) // // Enable or disable parentPath|field and parentPath|slider. // See the equivalent in AEpolyReduceTemplate.mel // { string $oldParent = `setParent -q`; setParent $parentPath; int $enable = `checkBox -q -v box`; floatField -e -en $enable field; floatSlider -e -en $enable slider; setParent $oldParent; } global proc pr_OBCBSGrpSliderChanged(string $parentPath) { string $oldParent = `setParent -q`; setParent $parentPath; float $fVal = `floatSlider -q -v slider`; if($fVal != `floatField -q -v field`) { floatField -e -v $fVal field; } setParent $oldParent; } global proc pr_OBCBSGrpFieldChanged(string $parentPath) { string $oldParent = `setParent -q`; setParent $parentPath; float $fVal = `floatField -q -v field`; if($fVal != `floatSlider -q -v slider`) { floatSlider -e -v $fVal slider; } setParent $oldParent; } proc checkBoxSliderGrp( string $label, string $annotation, int $boolVal, float $floatVal, string $shortName ) // // This is a checkBox and slider. // See also AEpolyReduceTemplate.mel attrCheckBoxSliderGrp(). // { // Edits to the setup here must be reflected in // checkBoxSliderGrpEdit below. // The rowLayout column widths are carefully eyeballed to make the // control line up with an attrFieldSliderGrp $parent = `rowLayout -nc 4 -cw 2 15 -cw 3 53 -cat 4 right 4 -adj 4 $shortName`; string $enableCallback = ("pr_OBCheckBoxSliderEnable " + $parent); string $fieldCB = ("pr_OBCBSGrpFieldChanged " + $parent); string $sliderCB = ("pr_OBCBSGrpSliderChanged " + $parent); text -al right -l $label; checkBox -l "" -cc $enableCallback -v $boolVal box; floatField -ann $annotation -cc $fieldCB -min 0 -max 1 -en $boolVal -v $floatVal field; floatSlider -ann $annotation -cc $sliderCB -dc $sliderCB -min 0 -max 1 -en $boolVal -v $floatVal slider; setParent ..; } proc checkBoxSliderGrpEdit( int $boolVal, float $floatVal, string $shortName ) { setParent $shortName; checkBox -e -v $boolVal box; floatField -e -en $boolVal -v $floatVal field; floatSlider -e -en $boolVal -v $floatVal slider; setParent ..; } // // Test whether the symmetry type has a tolerance. // proc int pr_symmetryTypeHasTolerance(int $symType) { return $symType > 1; } // Test whether the symmetry type has a plane. // proc int pr_symmetryTypeHasPlane(int $symType) { return $symType == 3; } // // When the symmetry type changes, enable/disable related controls. // global proc pr_OBUpdateSymmetryType (string $parent) { string $oldParent = `setParent -q`; setParent $parent; int $quads = (`floatSliderGrp -query -value polyKeepQuadsWeight` == 1.0); int $type = `optionMenuGrp -q -sl symmetryType`; floatFieldGrp -e -en (!$quads && pr_symmetryTypeHasTolerance($type)) symmetryTolerance; optionMenuGrp -e -en (!$quads && pr_symmetryTypeHasPlane($type)) symmetryPlane; setParent $oldParent; } // // When the quad weight changes, enable/disable related controls. // global proc pr_OBUpdateQuadsWeight (string $parent) { string $oldParent = `setParent -q`; setParent $parent; int $quads = (`floatSliderGrp -query -value polyKeepQuadsWeight` == 1.0); optionMenuGrp -e -en (!$quads) symmetryType; setParent $oldParent; pr_OBUpdateSymmetryType $parent; } global proc pr_performSetup( string $parent, int $forceFactorySettings, string $prefix ) // // Description: // Do the setup of widget states // Arguments: // parent : parent widget // forceFactorySettings : set to defaults // prefix : One of "PolyReduce" or "LODGenerateMeshes"; prefix to prepend // to each optionVar // Returns: // none // { setParent $parent; int $iVal; float $fVal; string $sval; setParent terminationConditions; $iVal = `optionVar -q ($prefix+"polyReduceTermination")`; optionMenuGrp -e -sl ($iVal+1) polyReduceTermination; setParent ..; setParent shape; $fVal = `optionVar -query ($prefix + "polyKeepQuadsWeight")`; int $quads = ($fVal == 1.0); // Symmetry only works for quads < 1.0 floatSliderGrp -edit -value $fVal polyKeepQuadsWeight; $fVal = `optionVar -query ($prefix + "polyReduceSharpness")`; floatSliderGrp -edit -value $fVal polyReduceSharpness; int $symmetryType = `optionVar -q ($prefix + "polyReduceSymmetryType")`; optionMenuGrp -e -en (!$quads) -sl $symmetryType symmetryType; $fVal = `optionVar -query ($prefix + "polyReduceSymmetryTolerance")`; floatFieldGrp -e -en (!$quads && pr_symmetryTypeHasTolerance($symmetryType)) -v1 $fVal symmetryTolerance; $iVal = `optionVar -q ($prefix + "polyReduceSymmetryPlane")`; optionMenuGrp -e -en (!$quads && pr_symmetryTypeHasPlane($symmetryType)) -sl $iVal symmetryPlane; setParent ..; setParent features; $iVal = `optionVar -query ($prefix + "polyReduceKeepBorder")`; $fVal = `optionVar -query ($prefix + "polyReduceKeepBorderWeight")`; checkBoxSliderGrpEdit $iVal $fVal polyReduceKeepBorder; $iVal = `optionVar -query ($prefix + "polyReduceKeepMapBorder")`; $fVal = `optionVar -query ($prefix + "polyReduceKeepMapBorderWeight")`; checkBoxSliderGrpEdit $iVal $fVal polyReduceKeepMapBorder; $iVal = `optionVar -query ($prefix + "polyReduceKeepColorBorder")`; $fVal = `optionVar -query ($prefix + "polyReduceKeepColorBorderWeight")`; checkBoxSliderGrpEdit $iVal $fVal polyReduceKeepColorBorder; $iVal = `optionVar -query ($prefix + "polyReduceKeepMaterialBorder")`; $fVal = `optionVar -query ($prefix + "polyReduceKeepMaterialBorderWeight")`; checkBoxSliderGrpEdit $iVal $fVal polyReduceKeepMaterialBorder; $iVal = `optionVar -query ($prefix + "polyReduceKeepHardEdge")`; $fVal = `optionVar -query ($prefix + "polyReduceKeepHardEdgeWeight")`; checkBoxSliderGrpEdit $iVal $fVal polyReduceKeepHardEdge; $iVal = `optionVar -query ($prefix + "polyReduceKeepCreaseEdge")`; $fVal = `optionVar -query ($prefix + "polyReduceKeepCreaseEdgeWeight")`; checkBoxSliderGrpEdit $iVal $fVal polyReduceKeepCreaseEdge; setParent ..; setParent advancedOptions; $sval = `optionVar -q ($prefix + "polyReduceVertexMapName")`; textFieldGrp -e -text $sval polyReduceVertexMapName; setParent ..; } global proc pr_performCallback( string $prefix ) // // Description: // Save common option variables before application or save. // Note: The caller is responsible for setting the parent, and // performing any action. // // Arguments: // prefix : prefix to pre-pend to optionVars // // Returns: // none // { setParent terminationConditions; optionVar -intValue ($prefix + "polyReduceTermination") (`optionMenuGrp -q -sl polyReduceTermination` - 1); setParent ..; setParent shape; optionVar -floatValue ($prefix + "polyKeepQuadsWeight") `floatSliderGrp -query -value polyKeepQuadsWeight`; optionVar -floatValue ($prefix + "polyReduceSharpness") `floatSliderGrp -query -value polyReduceSharpness`; optionVar -intValue ($prefix + "polyReduceSymmetryType") `optionMenuGrp -q -sl symmetryType`; optionVar -floatValue ($prefix + "polyReduceSymmetryTolerance") `floatFieldGrp -q -v1 symmetryTolerance`; optionVar -intValue ($prefix + "polyReduceSymmetryPlane") `optionMenuGrp -q -sl symmetryPlane`; setParent ..; setParent features; setParent polyReduceKeepBorder; optionVar -intValue ($prefix + "polyReduceKeepBorder") `checkBox -q -v box`; optionVar -floatValue ($prefix + "polyReduceKeepBorderWeight") `floatSlider -q -v slider`; setParent ..; setParent polyReduceKeepMapBorder; optionVar -intValue ($prefix + "polyReduceKeepMapBorder") `checkBox -q -v box`; optionVar -floatValue ($prefix + "polyReduceKeepMapBorderWeight") `floatSlider -q -v slider`; setParent ..; setParent polyReduceKeepColorBorder; optionVar -intValue ($prefix + "polyReduceKeepColorBorder") `checkBox -q -v box`; optionVar -floatValue ($prefix + "polyReduceKeepColorBorderWeight") `floatSlider -q -v slider`; setParent ..; setParent polyReduceKeepMaterialBorder; optionVar -intValue ($prefix + "polyReduceKeepMaterialBorder") `checkBox -q -v box`; optionVar -floatValue ($prefix + "polyReduceKeepMaterialBorderWeight") `floatSlider -q -v slider`; setParent ..; setParent polyReduceKeepHardEdge; optionVar -intValue ($prefix + "polyReduceKeepHardEdge") `checkBox -q -v box`; optionVar -floatValue ($prefix + "polyReduceKeepHardEdgeWeight") `floatSlider -q -v slider`; setParent ..; setParent polyReduceKeepCreaseEdge; optionVar -intValue ($prefix + "polyReduceKeepCreaseEdge") `checkBox -q -v box`; optionVar -floatValue ($prefix + "polyReduceKeepCreaseEdgeWeight") `floatSlider -q -v slider`; setParent ..; setParent ..; setParent advancedOptions; optionVar -stringValue ($prefix + "polyReduceVertexMapName") `textFieldGrp -q -text polyReduceVertexMapName`; setParent ..; } global proc pr_performOptions( string $name ) // // Description: // Options for poly Reduce // Arguments: // name: One of "PolyReduce" or "LODGenerateMeshes"; allows us to setup // the correct callbacks, and build variant-specific parts of UI. // Returns: // none // { string $commandName = "perform" + $name; string $callback = ($commandName + "Callback"); string $setup = ($commandName + "Setup"); string $layout = getOptionBox(); setParent $layout; setUITemplate -pushTemplate OptionBoxTemplate; waitCursor -state 1; scrollLayout; string $parent = `columnLayout`; string $cmd = "build" + $name + "SettingsSection"; eval( $cmd ); $cmd = "build" + $name + "ReductionSection \"" + $parent + "\""; eval( $cmd ); frameLayout -l (uiRes("m_polyReduceUtils.kShape")) -collapsable 1 -collapse 0 shape; floatSliderGrp -l (uiRes("m_polyReduceUtils.kPolyKeepQuadsWeight")) -ann (uiRes("m_polyReduceUtils.kKeepQuadWeightTooltip")) -minValue 0.0 -maxValue 1.0 -fieldMinValue 0.0 -fieldMaxValue 1.0 -cc ("pr_OBUpdateQuadsWeight " + $parent) polyKeepQuadsWeight; floatSliderGrp -l (uiRes("m_polyReduceUtils.kSharpness")) -ann (uiRes("m_polyReduceUtils.kReduceSharpnessTooltip")) -minValue 0.0 -maxValue 1.0 -fieldMinValue 0.0 -fieldMaxValue 1.0 polyReduceSharpness; optionMenuGrp -l (uiRes("m_polyReduceUtils.kSymmetry")) -ann (uiRes("m_polyReduceUtils.kReduceSymmetryTooltip")) -cc ("pr_OBUpdateSymmetryType " + `setParent -q`) symmetryType; menuItem -l (uiRes("m_polyReduceUtils.kSymmetryTypeNone")); // 1 menuItem -l (uiRes("m_polyReduceUtils.kSymmetryTypeAuto")); // 2 menuItem -l (uiRes("m_polyReduceUtils.kSymmetryTypePlanar")); // 3 floatFieldGrp -l (uiRes("m_polyReduceUtils.kSymmetryTolerance")) -ann (uiRes("m_polyReduceUtils.kReduceSymmetryToleranceTooltip")) symmetryTolerance; optionMenuGrp -l (uiRes("m_polyReduceUtils.kSymmetryPlane")) -ann (uiRes("m_polyReduceUtils.kReduceSymmetryPlaneTooltip")) symmetryPlane; menuItem -l (uiRes("m_polyReduceUtils.kSymmetryPlaneXZ")); // 1 menuItem -l (uiRes("m_polyReduceUtils.kSymmetryPlaneXY")); // 2 menuItem -l (uiRes("m_polyReduceUtils.kSymmetryPlaneYZ")); // 3 rowLayout -nc 2 -adj 2 symmetryHint; text -l ""; text -al left -l (uiRes("m_polyReduceUtils.kSymmetryHint")); setParent ..; setParent ..; frameLayout -l (uiRes("m_polyReduceUtils.kFeaturePreservation")) -collapsable 1 -collapse 0 features; checkBoxSliderGrp (uiRes("m_polyReduceUtils.kKeepBorder")) (uiRes("m_polyReduceUtils.kReduceBorderTooltip")) false 0.0 polyReduceKeepBorder; checkBoxSliderGrp (uiRes("m_polyReduceUtils.kKeepMapBorder")) (uiRes("m_polyReduceUtils.kReduceBorderUVTooltip")) false 0.0 polyReduceKeepMapBorder; checkBoxSliderGrp (uiRes("m_polyReduceUtils.kKeepColorBorder")) (uiRes("m_polyReduceUtils.kReduceColorTooltip")) false 0.0 polyReduceKeepColorBorder; checkBoxSliderGrp (uiRes("m_polyReduceUtils.kKeepMaterialBorder")) (uiRes("m_polyReduceUtils.kReduceMaterialTooltip")) false 0.0 polyReduceKeepMaterialBorder; checkBoxSliderGrp (uiRes("m_polyReduceUtils.kKeepHardEdge")) (uiRes("m_polyReduceUtils.kReduceHardEdgeTooltip")) false 0.0 polyReduceKeepHardEdge; checkBoxSliderGrp (uiRes("m_polyReduceUtils.kKeepCreaseEdge")) (uiRes("m_polyReduceUtils.kReduceCreaseEdgeTooltip")) false 0.0 polyReduceKeepCreaseEdge; setParent ..; frameLayout -l (uiRes("m_polyReduceUtils.kAdvancedOptions")) -collapsable 1 -collapse 1 advancedOptions; textFieldGrp -l (uiRes("m_polyReduceUtils.kVertexMapName")) -ann (uiRes("m_polyReduceUtils.kReduceVertexMapTooltip")) polyReduceVertexMapName; setParent ..; setParent ..; setParent ..; // // Standard template stuff // waitCursor -state 0; setUITemplate -popTemplate; string $applyBtn = getOptionBoxApplyBtn(); button -edit -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; $cmd = "build" + $name + "ButtonTitleHelp \"" + $applyBtn + "\""; eval( $cmd ); eval (($setup + " " + $parent + " " + 0)); showOptionBox(); } global proc string pr_assembleCmd( string $prefix ) // // Description: // Build the common portion of polyReduce/LODGenerateMeshes command // Arguments: // prefix: One of "PolyReduce" or "LODGenerateMeshes"; prefix prepended to // each optionVar. // Returns: // string command // { int $plane = `optionVar -q ($prefix + "polyReduceSymmetryPlane")`; // Convert to a plane normal. // float $sx = 0.0; float $sy = 0.0; float $sz = 0.0; if($plane == 2) { $sz = 1.0; } else if( $plane == 3 ){ $sx = 1.0; } else { $sy = 1.0; } string $cmd = // Always use Softimage algorithm // "\"1\"" + ",\"" + `optionVar -query ($prefix + "polyReduceTermination")` + "\"" + ",\"" + `optionVar -query ($prefix + "polyReduceSharpness")` + "\"" + ",\"" + `optionVar -query ($prefix + "polyReduceKeepBorder")` + "\"" + ",\"" + `optionVar -query ($prefix + "polyReduceKeepMapBorder")` + "\"" + ",\"" + `optionVar -query ($prefix + "polyReduceKeepColorBorder")` + "\"" + ",\"" + `optionVar -query ($prefix + "polyReduceKeepMaterialBorder")` + "\"" + ",\"" + `optionVar -query ($prefix + "polyReduceKeepHardEdge")` + "\"" + ",\"" + `optionVar -query ($prefix + "polyReduceKeepCreaseEdge")` + "\"" + ",\"" + `optionVar -query ($prefix + "polyReduceKeepBorderWeight")` + "\"" + ",\"" + `optionVar -query ($prefix + "polyReduceKeepMapBorderWeight")` + "\"" + ",\"" + `optionVar -query ($prefix + "polyReduceKeepColorBorderWeight")` + "\"" + ",\"" + `optionVar -query ($prefix + "polyReduceKeepMaterialBorderWeight")` + "\"" + ",\"" + `optionVar -query ($prefix + "polyReduceKeepHardEdgeWeight")` + "\"" + ",\"" + `optionVar -query ($prefix + "polyReduceKeepCreaseEdgeWeight")` + "\"" + // Menus start at 1, internally we start at 0. // ",\"" + ((int)(`optionVar -query ($prefix + "polyReduceSymmetryType")`)-1) + "\"" + ",\"" + `optionVar -query ($prefix + "polyReduceSymmetryTolerance")` + "\"" + // Plane normal; calculated above // ",\"" + $sx + "\"" + ",\"" + $sy + "\"" + ",\"" + $sz + "\"" + ",\"0.0\"" + // preserveTopoloy 1 // ",\"1\"" + ",\"" + `optionVar -query ($prefix + "polyKeepQuadsWeight")` + "\"" + ",\"" + `optionVar -q ($prefix + "polyReduceVertexMapName")` + "\"" + // cachingReduce 1 // ",\"1\"" + // Check if construction history is on // ",\"" + `constructionHistory -q -toggle` + "\""; return $cmd; }