// =========================================================================== // 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: 18 December 2016 // // Description: // Distribute selected UVs evenly along either the U or V axis // // // Procedure Name: // setOptionVars // // Description: // Initialize the option values. // // Input Arguments: // forceFactorySettings - Whether to set the options to default values. // // Return Value: // None. // proc setOptionVars(int $forceFactorySettings) { if($forceFactorySettings || !`optionVar -ex distributeUVDistanceOption`) optionVar -iv distributeUVDistanceOption 1; if($forceFactorySettings || !`optionVar -ex distributeUVDistance`) optionVar -fv distributeUVDistance 0.5; if($forceFactorySettings || !`optionVar -ex distributeUVDirection`) optionVar -iv distributeUVDirection 1; } proc polyDistributeUVsOptions() { // Global template variables for form spacing global int $gOptionBoxTemplateFrameSpacing; // Name of the command for this option box. // string $commandName; $commandName = "DistributeUVs"; // 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(); // 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: Create option box contents. // ==================================== // setParent $layout; setUITemplate -pushTemplate OptionBoxTemplate; waitCursor -state 1; // Form layout string $parent = `formLayout polyDistributeUVsOptions`; // Settings frame string $settingsFrame = `frameLayout -label (uiRes("m_performPolyDistributeUVs.kSettingsFrame"))`; columnLayout -adjustableColumn true; // Distance radioButtonGrp -numberOfRadioButtons 2 -vertical -label (uiRes("m_performPolyDistributeUVs.kDistributionDistance")) -label1 (uiRes("m_performPolyDistributeUVs.kAutomatic")) -label2 (uiRes("m_performPolyDistributeUVs.kCustom")) -cc DistributeUVsDistancePresets polyDistributeUVsDistanceRadio; floatSliderGrp -minValue 0.0 -maxValue 10.0 -fieldMaxValue 10000.0 polyDistributeUVsDistanceField; // Direction radioButtonGrp -numberOfRadioButtons 2 -vertical -label (uiRes("m_performPolyDistributeUVs.kDistributeAlong")) -label1 (uiRes("m_performPolyDistributeUVs.kU")) -label2 (uiRes("m_performPolyDistributeUVs.kV")) polyDistributeUVsDirectionRadio; setParent..; // columnLayout; setParent $parent; // frameLayout setParent ..; // formLayout // Attach Settings frame to form layout formLayout -e -af $settingsFrame "top" $gOptionBoxTemplateFrameSpacing -af $settingsFrame "left" $gOptionBoxTemplateFrameSpacing -af $settingsFrame "right" $gOptionBoxTemplateFrameSpacing -an $settingsFrame "bottom" $parent; waitCursor -state 0; setUITemplate -popTemplate; // STEP 4: Customize the buttons. // =============================== // // Provide more descriptive labels for the buttons. // Disable those buttons that are not applicable to the option box. // Attach actions to those buttons that are applicable to the option box. string $applyAndCloseBtn = getOptionBoxApplyAndCloseBtn(); button -e -command ($callback + " " + $parent + " 1; hideOptionBox;") $applyAndCloseBtn; string $applyBtn = getOptionBoxApplyBtn(); button -e -command ($callback + " " + $parent + " 1;") $applyBtn; string $resetBtn = getOptionBoxResetBtn(); button -e -command($setup + " " + $parent + " 1") $resetBtn; string $saveBtn = getOptionBoxSaveBtn(); button -e -command($callback + " " + $parent + " 0; hideOptionBox;") $saveBtn; // STEP 5: Set the option box title. // ================================== // setOptionBoxTitle((uiRes("m_performPolyDistributeUVs.kDistributeUVsOptions"))); // STEP 6: Customize the 'Help' menu item text. // ============================================= // setOptionBoxHelpTag($commandName); // Set the current values of the option box. // ========================================= // eval ($setup + " " + $parent + " 0"); // Show the option box. // ==================== // showOptionBox(); } // // Procedure Name: // DistributeUVsCallback // // Description: // Update the option values and execute command // // 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 DistributeUVsCallback(string $parent, int $doIt) { setOptionVars(false); setParent $parent; if(`radioButtonGrp -q -ex polyDistributeUVsDistanceRadio`) optionVar -iv distributeUVDistanceOption `radioButtonGrp -q -select polyDistributeUVsDistanceRadio`; if(`floatSliderGrp -q -ex polyDistributeUVsDistanceField`) optionVar -fv distributeUVDistance (`floatSliderGrp -q -value polyDistributeUVsDistanceField`); if(`radioButtonGrp -q -ex polyDistributeUVsDirectionRadio`) optionVar -iv distributeUVDirection (`radioButtonGrp -q -select polyDistributeUVsDirectionRadio`); if($doIt) performPolyDistributeUVs 0; } // // Procedure Name: // DistributeUVsSetup // // 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 DistributeUVsSetup(string $parent, int $forceFactorySettings) { // Retrieve the option settings // setOptionVars($forceFactorySettings); setParent $parent; int $distanceOption = 1; if(`radioButtonGrp -q -ex polyDistributeUVsDistanceRadio`) { $distanceOption = `optionVar -q distributeUVDistanceOption`; radioButtonGrp -e -select $distanceOption polyDistributeUVsDistanceRadio; } if(`floatSliderGrp -q -ex polyDistributeUVsDistanceField`) { float $distance = `optionVar -q distributeUVDistance`; floatSliderGrp -e -en ($distanceOption == 2) -value $distance polyDistributeUVsDistanceField; } if(`radioButtonGrp -q -ex polyDistributeUVsDirectionRadio`) { int $direction = `optionVar -q distributeUVDirection`; radioButtonGrp -e -select $direction polyDistributeUVsDirectionRadio; } } global proc DistributeUVsDistancePresets() { int $distanceOption = `radioButtonGrp -q -select polyDistributeUVsDistanceRadio`; if(`floatSliderGrp -q -ex polyDistributeUVsDistanceField`) floatSliderGrp -e -en ($distanceOption == 2) polyDistributeUVsDistanceField; } proc string assembleCmd() { setOptionVars(false); string $cmd = "texDistributeUVs "; int $dir = `optionVar -q distributeUVDirection`; if($dir == 1) $cmd += "\"U\" "; else if($dir == 2) $cmd += "\"V\" "; float $distance = -1.0; if(`optionVar -q distributeUVDistanceOption` == 2) $distance = `optionVar -q distributeUVDistance`; $cmd += $distance; return $cmd; } // // Procedure Name: // performPolyDistributeUVs // // Description: // Prepare parameters and run texDistributeUVs // // Input Arguments: // 0 - Execute the command. // 1 - Show the option box dialog. // 2 - Return the command. // global proc string performPolyDistributeUVs(int $action) { string $cmd = ""; switch ($action) { // Execute the command. // case 0: $cmd = assembleCmd(); // Execute the command with the option settings. // evalEcho($cmd); break; // Show the option box. // case 1: polyDistributeUVsOptions(); break; // Return the command string. // case 2: // Get the command. // $cmd = assembleCmd(); break; } return $cmd; }