// =========================================================================== // 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: September 12, 1997 // // Description: // This script is use to display and update the grid spacing options. // // Input Arguments: // int showOptionBox true - show the option box dialog // false - just execute the command // // Return Value: // None. // // // Procedure Name: // textureWindowPanelName // // Description: // return the texture window panel name. // // Input Arguments: // // // Return Value: // texture window panel name // proc string textureWindowPanelName() { string $texWinName[] = `getPanel -sty polyTexturePlacementPanel`; return $texWinName[0]; } // // 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) { // There don't seem to be any options // If you wanted these values to be saved between sessions you should // put in your optionVars here // Grid spacing. // if ($forceFactorySettings || !`optionVar -exists textureWindowGridSpacing`) { optionVar -floatValue textureWindowGridSpacing 0.1; } // Grid subdivisions. // if ($forceFactorySettings || !`optionVar -exists textureWindowGridDivisions`) { optionVar -floatValue textureWindowGridDivisions 2.0; } // Grid size. // if ($forceFactorySettings || !`optionVar -exists textureWindowGridSize`) { optionVar -floatValue textureWindowGridSize 10.0; } // Display grid axes. // if ($forceFactorySettings || !`optionVar -exists textureWindowDisplayGridAxes`) { optionVar -intValue textureWindowDisplayGridAxes true; } // Display grid lines. // if ($forceFactorySettings || !`optionVar -exists textureWindowDisplayGridLines`) { optionVar -intValue textureWindowDisplayGridLines true; } // Display division lines. // if ($forceFactorySettings || !`optionVar -exists textureWindowDisplayDivisionLines`) { optionVar -intValue textureWindowDisplayDivisionLines false; } // Display grid labels. // if ($forceFactorySettings || !`optionVar -exists textureWindowDisplayGridLabels`) { optionVar -intValue textureWindowDisplayGridLabels true; } // Display location of labels. // if ($forceFactorySettings || !`optionVar -exists textureWindowDisplayGridLabelPosition`) { optionVar -stringValue textureWindowDisplayGridLabelPosition "axis"; } // Display subregions. if ($forceFactorySettings || !`optionVar -exists textureWindowDrawSubregions`) { optionVar -stringValue textureWindowDrawSubregions true; } // Display tile labels. if ($forceFactorySettings || !`optionVar -exists textureWindowDisplayTileLabels`) { optionVar -intValue textureWindowDisplayTileLabels false; } // Axes color if ($forceFactorySettings || !`optionVar -exists textureWindowAxesColor`) { optionVar -floatValue textureWindowAxesColor 0.0; optionVar -floatValueAppend textureWindowAxesColor 0.0; optionVar -floatValueAppend textureWindowAxesColor 1.0; } // Grid lines color if ($forceFactorySettings || !`optionVar -exists textureWindowGridLinesColor`) { optionVar -floatValue textureWindowGridLinesColor 0.325; optionVar -floatValueAppend textureWindowGridLinesColor 0.325; optionVar -floatValueAppend textureWindowGridLinesColor 0.325; } // Grid lines and numbers color if ($forceFactorySettings || !`optionVar -exists textureWindowGridNumbersColor`) { optionVar -floatValue textureWindowGridNumbersColor 0.2; optionVar -floatValueAppend textureWindowGridNumbersColor 0.2; optionVar -floatValueAppend textureWindowGridNumbersColor 0.2; } // Subdivision lines color if ($forceFactorySettings || !`optionVar -exists textureWindowSubdivisionLinesColor`) { optionVar -floatValue textureWindowSubdivisionLinesColor 0.25; optionVar -floatValueAppend textureWindowSubdivisionLinesColor 0.25; optionVar -floatValueAppend textureWindowSubdivisionLinesColor 0.25; } // Tiles lines color if ($forceFactorySettings || !`optionVar -exists textureWindowTileLinesColor`) { optionVar -floatValue textureWindowTileLinesColor 0.0; optionVar -floatValueAppend textureWindowTileLinesColor 0.0; optionVar -floatValueAppend textureWindowTileLinesColor 0.0; } } // // Procedure Name: // tvGridSetup // // 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 tvGridSetup(string $parent, int $forceFactorySettings) { setParent $parent; setOptionVars($forceFactorySettings); // Get the grid dimension values. // float $spacing = `optionVar -query textureWindowGridSpacing`; float $size = `optionVar -query textureWindowGridSize`; int $divisions = `optionVar -query textureWindowGridDivisions`; // Get the grid display values. // int $displayAxes = `optionVar -query textureWindowDisplayGridAxes`; int $displayGridLines = `optionVar -query textureWindowDisplayGridLines`; int $displayDivisionLines = `optionVar -query textureWindowDisplayDivisionLines`; int $displayGridLabels = `optionVar -query textureWindowDisplayGridLabels`; int $drawSubregions = `optionVar -query textureWindowDrawSubregions`; int $displayTileLabels = `optionVar -query textureWindowDisplayTileLabels`; string $labelPosition = `optionVar -query textureWindowDisplayGridLabelPosition`; int $location; float $AxesColor[] = `optionVar -query textureWindowAxesColor`; float $GridLinesColor[] = `optionVar -query textureWindowGridLinesColor`; float $GridNumbersColor[] = `optionVar -query textureWindowGridNumbersColor`; float $SubdivisionLinesColor[] = `optionVar -query textureWindowSubdivisionLinesColor`; float $TileLinesColor[] = `optionVar -query textureWindowTileLinesColor`; // Update the grid controls. // floatFieldGrp -edit -value1 $size TextureWindowGridOptionsSize; floatFieldGrp -edit -value1 $spacing TextureWindowGridOptionsDistance; intSliderGrp -edit -value $divisions TextureWindowGridOptionsDivisions; // Update grid color controls. // colorSliderGrp -e -rgb $AxesColor[0] $AxesColor[1] $AxesColor[2] TextureWindowGridOptionAxesColor; updateTextureWindowGridColors("Axes"); colorSliderGrp -e -rgb $GridLinesColor[0] $GridLinesColor[1] $GridLinesColor[2] TextureWindowGridOptionGridLinesColor; updateTextureWindowGridColors("GridLines"); colorSliderGrp -e -rgb $GridNumbersColor[0] $GridNumbersColor[1] $GridNumbersColor[2] TextureWindowGridOptionGridNumbersColor; updateTextureWindowGridColors("GridNumbers"); colorSliderGrp -e -rgb $SubdivisionLinesColor[0] $SubdivisionLinesColor[1] $SubdivisionLinesColor[2] TextureWindowGridOptionSubdivisionLinesColor; updateTextureWindowGridColors("SubdivisionLines"); colorSliderGrp -e -rgb $TileLinesColor[0] $TileLinesColor[1] $TileLinesColor[2] TextureWindowGridOptionTileLinesColor; updateTextureWindowGridColors("TileLines"); // Update the state of the display controls. // checkBoxGrp -edit -value1 $displayAxes TextureWindowGridOptionsDisplayAxes; checkBoxGrp -edit -value1 $displayGridLines TextureWindowGridOptionsDisplayGridLines; checkBoxGrp -edit -value1 $displayDivisionLines TextureWindowGridOptionsDisplayDivisionLines; checkBoxGrp -edit -value1 $drawSubregions TextureWindowGridOptionsDrawSubregions; checkBoxGrp -edit -value1 $displayTileLabels TextureWindowGridOptionsTileLabels; if ($displayGridLabels) { if ("axis" == $labelPosition) { $location = 2; } else { $location = 3; } } else { $location = 1; } radioButtonGrp -edit -select $location TextureWindowGridOptionsLabelPosition; } // // Procedure Name: // updateTextureWindowGridColors // // Description: // Update UV Editor grid color and update optionVar by current UI settings // // Input Arguments: // colorType - grid color type // // Return Value: // None. // global proc updateTextureWindowGridColors(string $colorType) { string $winName = textureWindowPanelName(); if($colorType == "Axes") { float $AxesColor[] = `colorSliderGrp -q -rgb TextureWindowGridOptionAxesColor`; optionVar -floatValue textureWindowAxesColor $AxesColor[0]; optionVar -floatValueAppend textureWindowAxesColor $AxesColor[1]; optionVar -floatValueAppend textureWindowAxesColor $AxesColor[2]; $cmd = "textureWindow -edit -axesColor " + $AxesColor[0] + " " + $AxesColor[1] + " " + $AxesColor[2] + " " + $winName + ";"; eval($cmd); } else if($colorType == "GridLines") { float $GridLinesColor[] = `colorSliderGrp -q -rgb TextureWindowGridOptionGridLinesColor`; optionVar -floatValue textureWindowGridLinesColor $GridLinesColor[0]; optionVar -floatValueAppend textureWindowGridLinesColor $GridLinesColor[1]; optionVar -floatValueAppend textureWindowGridLinesColor $GridLinesColor[2]; $cmd = "textureWindow -edit -gridLinesColor " + $GridLinesColor[0] + " " + $GridLinesColor[1] + " " + $GridLinesColor[2] + " " + $winName + ";"; eval($cmd); } else if($colorType == "GridNumbers") { float $GridNumbersColor[] = `colorSliderGrp -q -rgb TextureWindowGridOptionGridNumbersColor`; optionVar -floatValue textureWindowGridNumbersColor $GridNumbersColor[0]; optionVar -floatValueAppend textureWindowGridNumbersColor $GridNumbersColor[1]; optionVar -floatValueAppend textureWindowGridNumbersColor $GridNumbersColor[2]; $cmd = "textureWindow -edit -gridNumbersColor " + $GridNumbersColor[0] + " " + $GridNumbersColor[1] + " " + $GridNumbersColor[2] + " " + $winName + ";"; eval($cmd); } else if($colorType == "SubdivisionLines") { float $SubdivisionLinesColor[] = `colorSliderGrp -q -rgb TextureWindowGridOptionSubdivisionLinesColor`; optionVar -floatValue textureWindowSubdivisionLinesColor $SubdivisionLinesColor[0]; optionVar -floatValueAppend textureWindowSubdivisionLinesColor $SubdivisionLinesColor[1]; optionVar -floatValueAppend textureWindowSubdivisionLinesColor $SubdivisionLinesColor[2]; $cmd = "textureWindow -edit -subdivisionLinesColor " + $SubdivisionLinesColor[0] + " " + $SubdivisionLinesColor[1] + " " + $SubdivisionLinesColor[2] + " " + $winName + ";"; eval($cmd); } else if($colorType == "TileLines") { float $TileLinesColor[] = `colorSliderGrp -q -rgb TextureWindowGridOptionTileLinesColor`; optionVar -floatValue textureWindowTileLinesColor $TileLinesColor[0]; optionVar -floatValueAppend textureWindowTileLinesColor $TileLinesColor[1]; optionVar -floatValueAppend textureWindowTileLinesColor $TileLinesColor[2]; $cmd = "textureWindow -edit -tileLinesColor " + $TileLinesColor[0] + " " + $TileLinesColor[1] + " " + $TileLinesColor[2] + " " + $winName + ";"; eval($cmd); } } // // Procedure Name: // tvGridCallback // // 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 tvGridCallback(string $parent, int $doIt) { // Get the grid values from the UI. // float $size = `floatFieldGrp -query -value1 TextureWindowGridOptionsSize`; float $spacing = `floatFieldGrp -query -value1 TextureWindowGridOptionsDistance`; int $divisions = `intSliderGrp -query -value TextureWindowGridOptionsDivisions`; // Get the grid display values. // int $displayAxes = `checkBoxGrp -query -value1 TextureWindowGridOptionsDisplayAxes`; int $displayGridLines = `checkBoxGrp -query -value1 TextureWindowGridOptionsDisplayGridLines`; int $displayDivisionLines = `checkBoxGrp -query -value1 TextureWindowGridOptionsDisplayDivisionLines`; int $drawSubregions = `checkBoxGrp -query -value1 TextureWindowGridOptionsDrawSubregions`; int $displayTileLabels = `checkBoxGrp -query -value1 TextureWindowGridOptionsTileLabels`; int $labelPosition = `radioButtonGrp -query -select TextureWindowGridOptionsLabelPosition`; // Verify the values. // if (1.0 > $size) { error (uiRes("m_performTextureViewGridOptions.kLowLengthAndWidthValue")); return; } if (0.0 >= $spacing) { error (uiRes("m_performTextureViewGridOptions.kGridLineSpacing")); return; } // Update the grid values. // optionVar -floatValue textureWindowGridSpacing $spacing; optionVar -floatValue textureWindowGridSize $size; optionVar -floatValue textureWindowGridDivisions $divisions; // Update the grid display values. // optionVar -intValue textureWindowDisplayGridAxes $displayAxes; optionVar -intValue textureWindowDisplayGridLines $displayGridLines; optionVar -intValue textureWindowDisplayDivisionLines $displayDivisionLines; optionVar -intValue textureWindowDrawSubregions $drawSubregions; optionVar -intValue textureWindowDisplayTileLabels $displayTileLabels; if (1 == $labelPosition) { optionVar -intValue textureWindowDisplayGridLabels false; } else if (2 == $labelPosition) { optionVar -stringValue textureWindowDisplayGridLabelPosition "axis"; optionVar -intValue textureWindowDisplayGridLabels true; } else { optionVar -stringValue textureWindowDisplayGridLabelPosition "edge"; optionVar -intValue textureWindowDisplayGridLabels true; } if ($doIt) { performTextureViewGridOptions 0; addToRecentCommandQueue "performTextureViewGridOptions 0" "TextureViewGrid"; } } // // Procedure Name: // tvGridOptions // // Description: // Construct the option box UI. Involves accessing the standard option // box and customizing the UI accordingly. // // Input Arguments: // None. // // Return Value: // None. // proc tvGridOptions() { // Name of the command for this option box. // string $commandName = "tvGrid"; // 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(); setParent $layout; // 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: Activate the default UI template. // ========================================== // // Activate the default UI template so that the layout of this // option box is consistent with the layout of the rest of the // application. // setUITemplate -pushTemplate DefaultTemplate; // STEP 4: Create option box contents. // =================================== // // This, of course, will vary from option box to option box. // Turn on the wait cursor. // waitCursor -state 1; tabLayout -tabsVisible 0 -scrollable 1; string $parent = `columnLayout -adjustableColumn 1 -rowSpacing 4`; // Grid size. // frameLayout -label (uiRes("m_performTextureViewGridOptions.kSize")) -collapsable false -collapse false; columnLayout; string $units = (uiRes("m_performTextureViewGridOptions.kUnits")); $gridSize = `floatFieldGrp -label (uiRes("m_performTextureViewGridOptions.kLengthAndWidth")) -extraLabel $units TextureWindowGridOptionsSize`; $gridDistance = `floatFieldGrp -label (uiRes("m_performTextureViewGridOptions.kGridLinesEvery")) -extraLabel $units TextureWindowGridOptionsDistance`; $divisions = `intSliderGrp -label (uiRes("m_performTextureViewGridOptions.kSubdivisions")) -field true -min 2 -max 256 -fieldMinValue 2 -fieldMaxValue 4096 -step 1 TextureWindowGridOptionsDivisions`; setParent ..; setParent ..; // Grid Color. // frameLayout -label (uiRes("m_performTextureViewGridOptions.kColor")) -collapsable false -collapse false; columnLayout; string $texWinName[] = `getPanel -sty polyTexturePlacementPanel`; colorSliderGrp -label (uiRes("m_performTextureViewGridOptions.kAxesColor")) -cc "updateTextureWindowGridColors \"Axes\"" TextureWindowGridOptionAxesColor; colorSliderGrp -label (uiRes("m_performTextureViewGridOptions.kGridLinesColor")) -cc "updateTextureWindowGridColors \"GridLines\"" TextureWindowGridOptionGridLinesColor; colorSliderGrp -label (uiRes("m_performTextureViewGridOptions.kGridNumbersColor")) -cc "updateTextureWindowGridColors \"GridNumbers\"" TextureWindowGridOptionGridNumbersColor; colorSliderGrp -label (uiRes("m_performTextureViewGridOptions.kSubdivisionLinesColor")) -cc "updateTextureWindowGridColors \"SubdivisionLines\"" TextureWindowGridOptionSubdivisionLinesColor; colorSliderGrp -label (uiRes("m_performTextureViewGridOptions.kTileLinesColor")) -cc "updateTextureWindowGridColors \"TileLines\"" TextureWindowGridOptionTileLinesColor; setParent ..; setParent ..; // Grid Display. // frameLayout -label (uiRes("m_performTextureViewGridOptions.kDisplay")) -collapsable false -collapse false; columnLayout; checkBoxGrp -numberOfCheckBoxes 1 -label "" -label1 (uiRes("m_performTextureViewGridOptions.kAxes")) TextureWindowGridOptionsDisplayAxes; checkBoxGrp -numberOfCheckBoxes 1 -label "" -label1 (uiRes("m_performTextureViewGridOptions.kGridLines")) TextureWindowGridOptionsDisplayGridLines; checkBoxGrp -numberOfCheckBoxes 1 -label "" -label1 (uiRes("m_performTextureViewGridOptions.kSubdivisionLines")) TextureWindowGridOptionsDisplayDivisionLines; checkBoxGrp -numberOfCheckBoxes 1 -label "" -label1 (uiRes("m_performTextureViewGridOptions.kTiles")) TextureWindowGridOptionsDrawSubregions; checkBoxGrp -numberOfCheckBoxes 1 -label "" -label1 (uiRes("m_performTextureViewGridOptions.kTileLabels")) TextureWindowGridOptionsTileLabels; string $hide = (uiRes("m_performTextureViewGridOptions.kHide")); string $onAxes = (uiRes("m_performTextureViewGridOptions.kOnAxes")); string $alongEdge = (uiRes("m_performTextureViewGridOptions.kAlongEdge")); radioButtonGrp -numberOfRadioButtons 3 -label (uiRes("m_performTextureViewGridOptions.kGridNumbers")) -labelArray3 $hide $onAxes $alongEdge TextureWindowGridOptionsLabelPosition; setParent ..; setParent ..; // Turn off the wait cursor. // waitCursor -state 0; // Step 5: Deactivate the default UI template. // =========================================== // setUITemplate -popTemplate; // Step 6: Customize the buttons. // ============================== // // Provide more descriptive labels for the buttons. This is not // necessary, but in some cases, for example, a button labelled // 'Create' may be more meaningful to the user than one labelled // 'Apply'. // // Disable those buttons that are not applicable to the option box. // // Attach actions to those buttons that are applicable to the option // box. Note that the 'Close' button has a default action attached // to it that will hide the window. If a a custom action is // attached to the 'Close' button then be sure to call the 'hide the // option box' procedure within the custom action so that the option // box is hidden properly. // 'Apply' button. // string $applyBtn = getOptionBoxApplyBtn(); button -edit -command ($callback + " " + $parent + " " + 1) $applyBtn; // 'Save' button. // string $saveBtn = getOptionBoxSaveBtn(); button -edit -command ($callback + " " + $parent + " " + 1 + "; hideOptionBox") $saveBtn; // 'Reset' button. // string $resetBtn = getOptionBoxResetBtn(); button -edit -command ($setup + " " + $parent + " " + 1) $resetBtn; // Step 7: Set the option box title. // ================================= // setOptionBoxTitle (uiRes("m_performTextureViewGridOptions.kUVTextureEditorGridOptions")); // Step 8: Customize the 'Help' menu item text. // ============================================ // setOptionBoxHelpTag( "UVEditorGrid" ); // Step 9: Set the current values of the option box. // ================================================= // eval (($setup + " " + $parent + " " + 0)); // Step 10: Show the option box. // ============================= // showOptionBox(); if(!`optionVar -ex uvEditorGridOptBoxInit`) { optionVar -iv uvEditorGridOptBoxInit 1; global string $gOptionBox; window -e -widthHeight 546 400 $gOptionBox; } } // // Procedure Name: // assembleCmd // // Description: // Construct the command that will apply the option box values. // // Input Arguments: // None. // proc string assembleCmd() { string $cmd; setOptionVars(false); string $winName = textureWindowPanelName(); float $spacing = `optionVar -query textureWindowGridSpacing`; int $divisions = `optionVar -query textureWindowGridDivisions`; float $size = `optionVar -query textureWindowGridSize`; int $displayAxes = `optionVar -query textureWindowDisplayGridAxes`; int $displayGridLines = `optionVar -query textureWindowDisplayGridLines`; int $displayDivisionLines = `optionVar -query textureWindowDisplayDivisionLines`; int $displayGridLabels = `optionVar -query textureWindowDisplayGridLabels`; string $labelPosition = `optionVar -query textureWindowDisplayGridLabelPosition`; int $drawSubregions = `optionVar -query textureWindowDrawSubregions`; int $displayTileLabels = `optionVar -query textureWindowDisplayTileLabels`; $cmd = "textureWindow -edit -spacing " + $spacing + " -divisions " + $divisions + " -size " + $size + " -displayAxes " + $displayAxes + " -displayGridLines " + $displayGridLines + " -displayDivisionLines " + $displayDivisionLines + " -displayLabels " + $displayGridLabels + " -labelPosition " + $labelPosition + " -drawSubregions " + $drawSubregions + " -tileLabels " + $displayTileLabels + " " + $winName + ";" ; return $cmd; } // // Procedure Name: // performTextureViewGridOptions // // Description: // Perform the grid 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 grid command with the current // option box values. // // Input Arguments: // 0 - Execute the command. // 1 - Show the option box dialog. // 2 - Return the command. // global proc string performTextureViewGridOptions(int $action) { string $cmd = ""; switch ($action) { // Execute the command. // case 0: // Get the command. // $cmd = `assembleCmd`; // Execute the command with the option settings. // eval($cmd); break; // Show the option box. // case 1: tvGridOptions; break; // Return the command string. // case 2: // Get the command. // $cmd = `assembleCmd`; break; } return $cmd; }