// =========================================================================== // 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. // =========================================================================== // // // // // // adapted from cpam's polyGridUVWin.mel // // creates UI for polyGridUV.mel command // // Procedure Name: // setOptionVars // // Description: // Initialize the option values. // // Input Arguments: // Whether to set the options to default values. // // Return Value: // None. // proc setOptionVars(int $forceFactorySettings) { // U // if ($forceFactorySettings || !`optionVar -exists polyGridUVValueU`) { optionVar -intValue polyGridUVValueU 256; } // V // if ($forceFactorySettings || !`optionVar -exists polyGridUVValueV`) { optionVar -intValue polyGridUVValueV 256; } // Pixel // if ($forceFactorySettings || !`optionVar -exists polyGridUVValuePixel`) { optionVar -intValue polyGridUVValuePixel 1; } } // // Procedure Name: // polyGridUVSetup // // 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 polyGridUVSetup(string $parent, int $forceFactorySettings) { // Retrieve the option settings // setOptionVars($forceFactorySettings); setParent $parent; // Query the optionVar's and set the values into the controls. // U // intSliderGrp -edit -value `optionVar -query polyGridUVValueU` ugrid; // V // intSliderGrp -edit -value `optionVar -query polyGridUVValueV` vgrid; // Pixel // radioButtonGrp -edit -select `optionVar -query polyGridUVValuePixel` snap; } // // Procedure Name: // polyGridUVCallback // // 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 polyGridUVCallback(string $parent, int $doIt) { setParent $parent; // Set the optionVar's from the control values, and then // perform the command. // U // optionVar -intValue polyGridUVValueU `intSliderGrp -query -value ugrid`; // V // optionVar -intValue polyGridUVValueV `intSliderGrp -query -value vgrid`; // Pixel // optionVar -intValue polyGridUVValuePixel (`radioButtonGrp -query -select snap` - 1); if ($doIt) { performPolyGridUV 0; addToRecentCommandQueue "performPolyGridUV 0" "PolyGridUV"; } } // // Procedure Name: // changePreset // // Description: // Helper procedure which sets the slider values to match the // item selected from the mapSizePreset menu group. // // Input Arguments: // None. // // Return Value: // None. // global proc performPolyGridUV_changePreset(){ int $presets[] = {0, 0, 1024, 512, 256, 128, 64, 32, 16}; int $selectedItem = `optionMenuGrp -query -select mapSizePreset`; intSliderGrp -edit -value $presets[$selectedItem] ugrid; intSliderGrp -edit -value $presets[$selectedItem] vgrid; } // // Procedure Name: // polyGridUVOptions // // Description: // Construct the option box UI. Involves accessing the standard option // box and customizing the UI accordingly. // // Input Arguments: // None. // // Return Value: // None. // proc polyGridUVOptions() { // Global template variables for form spacing global int $gOptionBoxTemplateFrameSpacing; // Name of the command for this option box. // string $commandName = "polyGridUV"; // Build the option box actions. // string $callback = ($commandName + "Callback"); string $setup = ($commandName + "Setup"); // Get the option box. // string $layout = getOptionBox(); setParent $layout; // Pass the command name to the option box. // setOptionBoxCommandName($commandName); // Activate the option box UI template. // setUITemplate -pushTemplate OptionBoxTemplate; // Turn on the wait cursor. // waitCursor -state 1; // Form layout string $parent = `formLayout polyUnmirrorOptions`; // Settings frame string $settingsFrame = `frameLayout -label (uiRes("m_performPolyGridUV.kSettingsFrame"))`; columnLayout; optionMenuGrp -label (uiRes("m_performPolyGridUV.kMapSizePresets")) -changeCommand "performPolyGridUV_changePreset" mapSizePreset; menuItem -label (uiRes("m_performPolyGridUV.kCustom")); menuItem -label (uiRes("m_performPolyGridUV.kMap1024")); menuItem -label (uiRes("m_performPolyGridUV.kMap512")); menuItem -label (uiRes("m_performPolyGridUV.kMap256")); menuItem -label (uiRes("m_performPolyGridUV.kMap128")); menuItem -label (uiRes("m_performPolyGridUV.kMap64")); menuItem -label (uiRes("m_performPolyGridUV.kMap32")); menuItem -label (uiRes("m_performPolyGridUV.kMap16")); intSliderGrp -label (uiRes("m_performPolyGridUV.kGridU")) -minValue 1 -maxValue 1024 -field 1 -fieldMinValue 1 -fieldMaxValue 1024 -changeCommand "optionMenuGrp -edit -select 1 mapSizePreset;" ugrid; intSliderGrp -label (uiRes("m_performPolyGridUV.kGridV")) -minValue 1 -maxValue 1024 -field 1 -fieldMinValue 1 -fieldMaxValue 1024 -changeCommand "optionMenuGrp -edit -select 1 mapSizePreset;" vgrid; string $pixelBorder = (uiRes("m_performPolyGridUV.kPixelBorder")); string $pixelCenter = (uiRes("m_performPolyGridUV.kPixelCenter")); radioButtonGrp -numberOfRadioButtons 2 -vertical -label (uiRes("m_performPolyGridUV.kMoveUVs")) -labelArray2 $pixelBorder $pixelCenter snap; setParent $parent; // frameLayout setParent ..; // formLayout // Attach Settings frames to form layout formLayout -e -attachForm $settingsFrame "top" $gOptionBoxTemplateFrameSpacing -attachForm $settingsFrame "left" $gOptionBoxTemplateFrameSpacing -attachForm $settingsFrame "right" $gOptionBoxTemplateFrameSpacing -attachNone $settingsFrame "bottom" $parent; // Turn off the wait cursor. // waitCursor -state 0; // Deactivate the default UI template. // setUITemplate -popTemplate; // 'Apply' button. // string $applyBtn = getOptionBoxApplyBtn(); button -edit -label (uiRes("m_performPolyGridUV.kApplyAndClose")) -command ($callback + " " + $parent + " " + 1) $applyBtn; // 'Save' button. // string $saveBtn = getOptionBoxSaveBtn(); button -edit -command ($callback + " " + $parent + " " + 0 + "; hideOptionBox") $saveBtn; // 'Reset' button. // string $resetBtn = getOptionBoxResetBtn(); button -edit -command ($setup + " " + $parent + " " + 1) $resetBtn; // Set the option box title. // setOptionBoxTitle (uiRes("m_performPolyGridUV.kGridUVsOptions")); // Customize the 'Help' menu item text. // setOptionBoxHelpTag( "PolyGridUV" ); // Set the current values of the option box. // eval (($setup + " " + $parent + " " + 0)); // Show the option box. // showOptionBox(); } // // Procedure Name: // polyGridUVHelp // // Description: // Return a short description about this command. // // Input Arguments: // None. // // Return Value: // string. // proc string polyGridUVHelp() { return " Command: polyGridUV - snap selected UVs to user specified grid.\n" + "Selection: UVs."; } // // Procedure Name: // assembleCmd // // Description: // Construct the command that will apply the option box values. // // Input Arguments: // None. // // Return Value: // string. // proc string assembleCmd() { setOptionVars(false); string $cmd = "polyGridUV" + " " + `optionVar -query polyGridUVValueU` + " " + `optionVar -query polyGridUVValueV` + " " + `optionVar -query polyGridUVValuePixel`; return $cmd; } // // Procedure Name: // performPolyGridUV // // Description: // Perform the polyGridUV 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 polyGridUV command with the current // option box values. // // Input Arguments: // 0 - Execute the command. // 1 - Show the option box dialog. // 2 - Return the command. // // Return Value: // string. // global proc string performPolyGridUV(int $action) { string $cmd = ""; switch ($action) { // Execute the command. // case 0: // Retrieve the option settings // setOptionVars(false); // Get the command. // $cmd = `assembleCmd`; // Execute the command with the option settings. // evalEcho($cmd); break; // Show the option box. // case 1: polyGridUVOptions; break; // Return the command string. // case 2: // Retrieve the option settings. // setOptionVars (false); // Get the command. // $cmd = `assembleCmd`; break; } return $cmd; }