// =========================================================================== // 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: June 9, 1999 // Major update: February, 2012 // // // Procedure Name: // // performPolyReduce (UI interface to polyReduce) // // Input Arguments: // Returns: // Reduce command // // Description: // // Perform a a poly reduction // // ////////////////////////////////////////////////////////////////////// proc setOptionVars (int $forceFactorySettings) // // Description: // Set user definable options // Arguments: // forceFactorySettings : use defaults // Returns: // // { if( !`exists pr_setOptionVars` ){ eval("source \"polyReduceUtils.mel\""); } pr_setOptionVars( $forceFactorySettings, "PolyReduce" ); // Percentage of vertices to remove if ($forceFactorySettings || !`optionVar -exists polyReducePercent`) optionVar -floatValue polyReducePercent 50.0; // Number of vertices to keep if ($forceFactorySettings || !`optionVar -exists polyReduceVertexCount`) optionVar -intValue polyReduceVertexCount 0; // Number of triangles to keep if ($forceFactorySettings || !`optionVar -exists polyReduceTriangleCount`) optionVar -intValue polyReduceTriangleCount 0; // Keep Original setting if ($forceFactorySettings || !`optionVar -exists polyKeepOriginal`) optionVar -intValue polyKeepOriginal 0; } global proc updatePolyReduceTerminationCallback (string $parent) // // Description: // When the termination condition option changes, update the // enable/disable status of the termination conditions. // { setParent $parent; int $termType = (`optionMenuGrp -q -sl polyReduceTermination`-1); floatSliderGrp -e -vis ($termType == 0) polyReducePercent; intFieldGrp -e -vis ($termType == 1) polyReduceVertexCount; intFieldGrp -e -vis ($termType == 2) polyReduceTriangleCount; } global proc performPolyReduceSetup( string $parent, int $forceFactorySettings ) // // Description: // Do the setup of widget states // Arguments: // parent : parent widget; if NULL, only set the option vars. // forceFactorySettings : set to defaults // Returns: // none // { setOptionVars($forceFactorySettings); if( $parent == "" ){ return; } pr_performSetup( $parent, $forceFactorySettings, "PolyReduce" ); setParent terminationConditions; $fVal = `optionVar -query polyReducePercent`; floatSliderGrp -edit -value $fVal polyReducePercent; $iVal = `optionVar -query polyReduceVertexCount`; intFieldGrp -e -v1 $iVal polyReduceVertexCount; $iVal = `optionVar -query polyReduceTriangleCount`; intFieldGrp -e -v1 $iVal polyReduceTriangleCount; setParent ..; setParent constructionOptions; $iVal = `optionVar -query polyKeepOriginal`; checkBoxGrp -edit -value1 $iVal polyKeepOriginal; setParent ..; // Disable termination options depending on termination type. updatePolyReduceTerminationCallback $parent; } global proc performPolyReduceCallback (string $parent, int $doIt ) // // Description: // Save option variables before application or save. // Arguments: // parent : parent widget // doIt : perform action // Returns: // none // { string $oldParent = `setParent -q`; setParent $parent; pr_performCallback( "PolyReduce" ); setParent constructionOptions; optionVar -intValue polyKeepOriginal `checkBoxGrp -query -value1 polyKeepOriginal`; setParent ..; setParent terminationConditions; optionVar -floatValue polyReducePercent `floatSliderGrp -query -value polyReducePercent`; optionVar -intValue polyReduceVertexCount `intFieldGrp -query -v1 polyReduceVertexCount`; optionVar -intValue polyReduceTriangleCount `intFieldGrp -query -v1 polyReduceTriangleCount`; setParent ..; setParent $oldParent; if ($doIt) { performPolyReduce 0; addToRecentCommandQueue "performPolyReduce 0" "PolyReduce"; } } global proc buildPolyReduceSettingsSection() // // Description: // This is called by pr_performOptions to build the Settings Section. // { // Build the frame layout for the Settings Method // frameLayout -l (uiRes("m_performPolyReduce.kConstructionOptions")) -collapsable 1 -collapse 0 constructionOptions; checkBoxGrp -label1 (uiRes("m_performPolyReduce.kKeepOriginal")) -ann (uiRes("m_performPolyReduce.kKeepOiginalTooltip")) polyKeepOriginal; setParent ..; } global proc buildPolyReduceReductionSection( string $parent ) { frameLayout -l (uiRes("m_performPolyReduce.kTerminationConditions")) -ann (uiRes("m_performPolyReduce.kTerminationTooltip")) -collapsable 1 -collapse 0 terminationConditions; optionMenuGrp -label (uiRes("m_performPolyReduce.kTermination")) -cc ("updatePolyReduceTerminationCallback " + $parent) polyReduceTermination; menuItem -label (uiRes("m_performPolyReduce.kPercentage")); menuItem -label (uiRes("m_performPolyReduce.kVertexCount")); menuItem -label (uiRes("m_performPolyReduce.kTriangleCount")); floatSliderGrp -label (uiRes("m_performPolyReduce.kReduceBy")) -minValue 0.0 -maxValue 100.0 -fieldMinValue 0.0 -fieldMaxValue 100.0 polyReducePercent; // Target vertex and triangle counts don't have sliders since // we have no good way of putting a max on them in the option // box. intFieldGrp -l (uiRes("m_performPolyReduce.kTargetVertexCount")) polyReduceVertexCount; intFieldGrp -l (uiRes("m_performPolyReduce.kTargetTriangleCount")) polyReduceTriangleCount; setParent ..; } global proc buildPolyReduceButtonTitleHelp( string $applyBtn ) { button -edit -label (uiRes("m_performPolyReduce.kReduceButton")) $applyBtn; setOptionBoxTitle( (uiRes("m_performPolyReduce.kReduceOptions")) ); setOptionBoxHelpTag( "Reduce" ); } proc performPolyReduceOptions() // // Description: // Options for poly Reduce // Arguments: // none // Returns: // none // { if( !`exists pr_performOptions` ){ eval("source \"polyReduceUtils.mel\""); } pr_performOptions( "PolyReduce" ); } proc string assembleCmd() // // Description: // Build a command based on the current option variables. // Arguments: // None. // Returns: // string command // { if( !`exists pr_assembleCmd` ){ eval("source \"polyReduceUtils.mel\""); } string $commonOptions = pr_assembleCmd("PolyReduce"); string $cmd = "doPerformPolyReduceArgList 3 {" + $commonOptions + ",\"" + `optionVar -query polyReducePercent` + "\"" + ",\"" + `optionVar -query polyReduceVertexCount` + "\"" + ",\"" + `optionVar -query polyReduceTriangleCount` + "\"" + ",\"" + !((int)(`optionVar -query polyKeepOriginal`)) + "\"" + // -preserveLocation is off // ",\"0\"" + // Specify level 0 for a standard polyReduce operation // ",\"0\"" + // CopySkinWeights needs to be off // ",\"0\"" + // maxThreshold is not used for polyReduce // ",\"0\"};"; return $cmd; } global proc string performPolyReduce(int $option) // // Description: // Polygon Reduce (UI wrapper) // // Arguments: // option: 0=execute, 1=option box, 2=drag to shelf // // Returns: // command // { string $cmd = ""; switch ($option) { case 0: // Retrieve the option settings // setOptionVars( false ); // Get the command. // $cmd = `assembleCmd`; // Execute the command with the option settings. // evalEcho($cmd); break; case 1: // Just show the option box performPolyReduceOptions(); break; case 2: // Retrieve the option settings. // setOptionVars( false ); // Get the command. // $cmd = `assembleCmd`; break; } return $cmd; }