// =========================================================================== // 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: 11/28/2016 // // Description: // Performs normal-based UV projection // // // Procedure Name: // normalBasedProjectionOptions // // Description: // Construct the option box UI. Involves accessing the standard option // box and customizing the UI accordingly. // // Input Arguments: // None. // // Return Value: // None. // global proc normalBasedProjectionOptions() { // Name of the command for this option box. // string $commandName; $commandName = "NormalBasedProjection"; // 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. // TODO: Check with Doc team setOptionBoxCommandName($commandName); // STEP 3: Create option box contents. // ==================================== // setParent $layout; $parent = normalBasedProjectionOptionsUI(); setParent ..; // 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_performNormalBasedProjection.kNormalBasedProjectionOptions"))); // STEP 6: Customize the 'Help' menu item text. // TODO: Check with doc team // ============================================= // setOptionBoxHelpTag($commandName); // Set the current values of the option box. // ========================================= // eval ($setup + " " + $parent + " 0"); // Show the option box. // ==================== // showOptionBox(); } // // Procedure Name: // normalBasedProjectionOptionsUI // // Description: // Build normal-based projection options UI // // Input Arguments: // parent - Top level parent layout of the option box UI. Required so // that UI object names can be successfully resolved. // // Return Value: // Layout. // global proc string normalBasedProjectionOptionsUI() { $layout = `columnLayout -adjustableColumn true`; //Description frameLayout -lv false; $desForm = `formLayout`; $des = `text -align center -l (uiRes("m_performNormalBasedProjection.kNormalBasedProjectionDescription"))`; setParent ..; formLayout -e -af $des top 10 -af $des left 0 -af $des right 0 -af $des bottom 10 $desForm; setParent ..; //Settings frameLayout -l (uiRes("m_performNormalBasedProjection.kSettings")); checkBoxGrp -vr -ncb 2 -label "" -label1 (uiRes("m_performNormalBasedProjection.kKeepRatio")) -label2 (uiRes("m_performNormalBasedProjection.kInsertProjectionBeforeDeformers")) texNorProjSettingsCheckBox; setParent ..; //UV Set frameLayout -l (uiRes("m_performNormalBasedProjection.kUVSet")); checkBoxGrp -label "" -label1 (uiRes("m_performNormalBasedProjection.kCreateNewUVSet")) -cc "normalBasedProjectionUpdateUVSetField" texNorProjUVSetCheckBox; textFieldGrp -label (uiRes("m_performNormalBasedProjection.kUVSetName")) texNorProjUVSetField; setParent ..; setParent..; return $layout; } // // Procedure Name: // normalBasedProjectionUpdateUVSetField // // Description: // Update text field based on checkbox // // Input Arguments: // None. // // Return Value: // None. // global proc normalBasedProjectionUpdateUVSetField() { if(!`checkBoxGrp -q -ex texNorProjUVSetCheckBox` || !`textFieldGrp -q -ex texNorProjUVSetField`) return; textFieldGrp -e -en (`checkBoxGrp -q -value1 texNorProjUVSetCheckBox`) texNorProjUVSetField; } // // Procedure Name: // NormalBasedProjectionCallback // // 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 NormalBasedProjectionCallback(string $parent, int $doIt) { normalBasedProjectionSetOptionVars (false); setParent $parent; if(`checkBoxGrp -q -ex texNorProjSettingsCheckBox`) { optionVar -iv texNorProjKeepRatio (`checkBoxGrp -q -value1 texNorProjSettingsCheckBox`); optionVar -iv texNorProjBeforeDeformers (`checkBoxGrp -q -value2 texNorProjSettingsCheckBox`); } if(`checkBoxGrp -q -ex texNorProjUVSetCheckBox`) optionVar -iv texNorProjCreateUVSet (`checkBoxGrp -q -value1 texNorProjUVSetCheckBox`); if(`textFieldGrp -q -ex texNorProjUVSetField`) optionVar -sv texNorProjUVSetName (`textFieldGrp -q -tx texNorProjUVSetField`); if($doIt) performNormalBasedProjection 0; } // // Procedure Name: // NormalBasedProjectionSetup // // 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 NormalBasedProjectionSetup(string $parent, int $forceFactorySettings) { // Retrieve the option settings // normalBasedProjectionSetOptionVars ($forceFactorySettings); setParent $parent; if(`checkBoxGrp -q -ex texNorProjSettingsCheckBox`) { checkBoxGrp -e -value1 (`optionVar -q texNorProjKeepRatio`) texNorProjSettingsCheckBox; checkBoxGrp -e -value2 (`optionVar -q texNorProjBeforeDeformers`) texNorProjSettingsCheckBox; } if(`checkBoxGrp -q -ex texNorProjUVSetCheckBox`) checkBoxGrp -e -value1 (`optionVar -q texNorProjCreateUVSet`) texNorProjUVSetCheckBox; if(`textFieldGrp -q -ex texNorProjUVSetField`) { $text = `optionVar -q texNorProjUVSetName`; textFieldGrp -e -en (`optionVar -q texNorProjCreateUVSet`) -tx $text texNorProjUVSetField; } } // // Procedure Name: // normalBasedProjectionSetOptionVars // // Description: // Initialize the option values. // // Input Arguments: // forceFactorySettings - Whether to set the options to default values. // // Return Value: // None. // global proc normalBasedProjectionSetOptionVars(int $forceFactorySettings) { if ($forceFactorySettings || !`optionVar -exists texNorProjKeepRatio`) { optionVar -iv texNorProjKeepRatio 1; } if ($forceFactorySettings || !`optionVar -exists texNorProjBeforeDeformers`) { optionVar -iv texNorProjBeforeDeformers 1; } if ($forceFactorySettings || !`optionVar -exists texNorProjCreateUVSet`) { optionVar -iv texNorProjCreateUVSet 0; } if ($forceFactorySettings || !`optionVar -exists texNorProjUVSetName`) { optionVar -sv texNorProjUVSetName "uvSet"; } } proc string assembleCmd() { normalBasedProjectionSetOptionVars(false); string $cmd = "texNormalProjection "; if(`optionVar -q texNorProjKeepRatio`) $cmd += "1 "; else $cmd += "0 "; if(`optionVar -q texNorProjBeforeDeformers`) $cmd += "1 "; else $cmd += "0 "; if(`optionVar -q texNorProjCreateUVSet`) $cmd += "\"" + `optionVar -q texNorProjUVSetName` + "\""; else $cmd += "\"\" "; return $cmd; } // // Procedure Name: // performNormalBasedProjection // // Description: // Prepare parameters and run texNormalProjection // // Input Arguments: // 0 - Execute the command. // 1 - Show the option box dialog. // 2 - Return the command. // global proc string performNormalBasedProjection(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: normalBasedProjectionOptions(); break; // Return the command string. // case 2: // Get the command. // $cmd = assembleCmd(); break; } return $cmd; }