// =========================================================================== // 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: 24 April 1997 // // Description: // This script provides an option box dialog for the tangentConstraint command. // // Input Arguments: // boolean showOptionBox true - show the option box dialog // false - just execute the 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) { // weight // if ($forceFactorySettings || !`optionVar -exists tangentConstraintWeight`) { optionVar -floatValue tangentConstraintWeight 1.0; } // aimVector. // if ($forceFactorySettings || !`optionVar -exists tangentConstraintAimVector`) { optionVar -floatValue tangentConstraintAimVector 1.0 -floatValueAppend tangentConstraintAimVector 0.0 -floatValueAppend tangentConstraintAimVector 0.0; } // upVector. // if ($forceFactorySettings || !`optionVar -exists tangentConstraintUpVector`) { optionVar -floatValue tangentConstraintUpVector 0.0 -floatValueAppend tangentConstraintUpVector 1.0 -floatValueAppend tangentConstraintUpVector 0.0; } // World up if ($forceFactorySettings || !`optionVar -exists tangentConstraintWorldUpType`) { optionVar -stringValue tangentConstraintWorldUpType "vector"; } if ($forceFactorySettings || !`optionVar -exists tangentConstraintWorldUpVector`) { optionVar -floatValue tangentConstraintWorldUpVector 0.0 -floatValueAppend tangentConstraintWorldUpVector 1.0 -floatValueAppend tangentConstraintWorldUpVector 0.0; } if ($forceFactorySettings || !`optionVar -exists tangentConstraintWorldUpObject`) { optionVar -stringValue tangentConstraintWorldUpObject ""; } } // // Procedure Name: // tangentConstraintSetup // // 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 tangentConstraintSetup(string $parent, int $forceFactorySettings) { // Retrieve the option settings // setOptionVars($forceFactorySettings); setParent $parent; // Query the optionVar's and set the values into the controls. // weight // floatSliderGrp -edit -value `optionVar -query tangentConstraintWeight` tangentConstraintWeight; // aimVector. // float $aimVector[] = `optionVar -query tangentConstraintAimVector`; floatFieldGrp -edit -value1 $aimVector[0] -value2 $aimVector[1] -value3 $aimVector[2] tangentConstraintAimVector; // upVector. // float $upVector[] = `optionVar -query tangentConstraintUpVector`; floatFieldGrp -edit -value1 $upVector[0] -value2 $upVector[1] -value3 $upVector[2] tangentConstraintUpVector; // World up string $worldUpType = `optionVar -query tangentConstraintWorldUpType`; switch ( $worldUpType ) { case "scene": optionMenuGrp -edit -select 1 tangentConstraintWorldUpType; break; case "object": optionMenuGrp -edit -select 2 tangentConstraintWorldUpType; break; case "objectrotation": optionMenuGrp -edit -select 3 tangentConstraintWorldUpType; break; case "vector": optionMenuGrp -edit -select 4 tangentConstraintWorldUpType; break; case "none": optionMenuGrp -edit -select 5 tangentConstraintWorldUpType; break; } float $worldUpVector[] = `optionVar -query tangentConstraintWorldUpVector`; floatFieldGrp -edit -value1 $worldUpVector[0] -value2 $worldUpVector[1] -value3 $worldUpVector[2] tangentConstraintWorldUpVector; textFieldGrp -edit -text `optionVar -query tangentConstraintWorldUpObject` tangentConstraintWorldUpObject; tangentConstraintEnabling $parent; } // // Procedure Name: // tangentConstraintCallback // // 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 tangentConstraintCallback(string $parent, int $doIt) { setParent $parent; // Set the optionVar's from the control values, and then // perform the command. // weight // optionVar -floatValue tangentConstraintWeight `floatSliderGrp -query -value tangentConstraintWeight`; // aimVector. // optionVar -floatValue tangentConstraintAimVector `floatFieldGrp -query -value1 tangentConstraintAimVector` -floatValueAppend tangentConstraintAimVector `floatFieldGrp -query -value2 tangentConstraintAimVector` -floatValueAppend tangentConstraintAimVector `floatFieldGrp -query -value3 tangentConstraintAimVector`; // upVector. // optionVar -floatValue tangentConstraintUpVector `floatFieldGrp -query -value1 tangentConstraintUpVector` -floatValueAppend tangentConstraintUpVector `floatFieldGrp -query -value2 tangentConstraintUpVector` -floatValueAppend tangentConstraintUpVector `floatFieldGrp -query -value3 tangentConstraintUpVector`; // World up int $state = `optionMenuGrp -query -select tangentConstraintWorldUpType`; switch ( $state ) { case 1: optionVar -stringValue tangentConstraintWorldUpType "scene"; break; case 2: optionVar -stringValue tangentConstraintWorldUpType "object"; break; case 3: optionVar -stringValue tangentConstraintWorldUpType "objectrotation"; break; case 4: optionVar -stringValue tangentConstraintWorldUpType "vector"; break; case 5: optionVar -stringValue tangentConstraintWorldUpType "none"; break; } optionVar -floatValue tangentConstraintWorldUpVector `floatFieldGrp -query -value1 tangentConstraintWorldUpVector` -floatValueAppend tangentConstraintWorldUpVector `floatFieldGrp -query -value2 tangentConstraintWorldUpVector` -floatValueAppend tangentConstraintWorldUpVector `floatFieldGrp -query -value3 tangentConstraintWorldUpVector`; optionVar -stringValue tangentConstraintWorldUpObject `textFieldGrp -query -text tangentConstraintWorldUpObject`; if ($doIt) { performTangentConstraint 0; addToRecentCommandQueue "performTangentConstraint 0" "Tangent Constraint"; } } // Callbacks to dim/undim different widget // global proc tangentConstraintEnabling(string $parent) { setParent $parent; int $state = `optionMenuGrp -query -select tangentConstraintWorldUpType`; switch ( $state ) { case 1: // Scene Up case 5: // None floatFieldGrp -edit -enable false tangentConstraintWorldUpVector; textFieldGrp -edit -enable false tangentConstraintWorldUpObject; break; case 2: // Object Up floatFieldGrp -edit -enable false tangentConstraintWorldUpVector; textFieldGrp -edit -enable true tangentConstraintWorldUpObject; break; case 3: // Object Rotation Up floatFieldGrp -edit -enable true tangentConstraintWorldUpVector; textFieldGrp -edit -enable true tangentConstraintWorldUpObject; break; case 4: // Vector floatFieldGrp -edit -enable true tangentConstraintWorldUpVector; textFieldGrp -edit -enable false tangentConstraintWorldUpObject; break; } } // // Procedure Name: // tangentConstraintOptions // // Description: // Construct the option box UI. Involves accessing the standard option // box and customizing the UI accordingly. // // Input Arguments: // None. // // Return Value: // None. // proc tangentConstraintOptions() { // Name of the command for this option box. // string $commandName = "tangentConstraint"; // 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 default UI template. // setUITemplate -pushTemplate DefaultTemplate; // Turn on the wait cursor. // waitCursor -state 1; string $parent = `columnLayout -adjustableColumn 1`; floatSliderGrp -label (uiRes("m_performTangentConstraint.kWeight")) -field true -min 0.0 -max 1.0 tangentConstraintWeight; floatFieldGrp -label (uiRes("m_performTangentConstraint.kAimVector")) -numberOfFields 3 tangentConstraintAimVector; floatFieldGrp -label (uiRes("m_performTangentConstraint.kUpVector")) -numberOfFields 3 tangentConstraintUpVector; optionMenuGrp -label (uiRes("m_performTangentConstraint.kWorldUpType")) -cc ("tangentConstraintEnabling " + $parent) tangentConstraintWorldUpType; menuItem -label (uiRes("m_performTangentConstraint.kSceneUp")) tangentConstraintUpDirMI1; menuItem -label (uiRes("m_performTangentConstraint.kObjectUp")) tangentConstraintUpDirMI2; menuItem -label (uiRes("m_performTangentConstraint.kObjectRotationUp")) tangentConstraintUpDirMI3; menuItem -label (uiRes("m_performTangentConstraint.kVector")) tangentConstraintUpDirMI4; menuItem -label (uiRes("m_performTangentConstraint.kNone")) tangentConstraintUpDirMI5; floatFieldGrp -label (uiRes("m_performTangentConstraint.kWorldUpVector")) -nf 3 tangentConstraintWorldUpVector; textFieldGrp -label (uiRes("m_performTangentConstraint.kWorldUpObject")) tangentConstraintWorldUpObject; // 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_performTangentConstraint.kAddButton")) -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_performTangentConstraint.kTangentConstraintOptions")); // Customize the 'Help' menu item text. // setOptionBoxHelpTag( "Tangent" ); // Set the current values of the option box. // eval (($setup + " " + $parent + " " + 0)); // Show the option box. // showOptionBox(); } // // Procedure Name: // tangentConstraintHelp // // Description: // Return a short description about this command. // // Input Arguments: // None. // // Return Value: // string. // proc string tangentConstraintHelp() { // ******** Example // " Command: Extrude - create a surface using extrusion.\n" + // "Selection: curves and isoparms." return " Command: tangentConstraint - Creates a tangent constraint.n" + "Selection: "; } // // Procedure Name: // assembleCmd // // Description: // Construct the command that will apply the option box values. // // Input Arguments: // None. // // Return Value: // None. // proc string assembleCmd() { string $cmd = "tangentConstraint"; setOptionVars(false); float $aimVector[] = `optionVar -query tangentConstraintAimVector`; float $upVector[] = `optionVar -query tangentConstraintUpVector`; $cmd = ($cmd + " -weight " + `optionVar -query tangentConstraintWeight` + " -aimVector " + $aimVector[0] + " " + $aimVector[1] + " " + $aimVector[2] + " -upVector " + $upVector[0] + " " + $upVector[1] + " " + $upVector[2] ); // world up related options string $worldUpType = `optionVar -query tangentConstraintWorldUpType`; $cmd = ($cmd + " -worldUpType " + "\"" + $worldUpType + "\"" ); float $worldUpVector[]; string $worldUpObject; switch ( $worldUpType ) { case "scene": case "none": break; case "object": $worldUpObject = `optionVar -query tangentConstraintWorldUpObject`; $cmd = ($cmd + " -worldUpObject " + $worldUpObject); break; case "objectrotation": $worldUpVector = `optionVar -query tangentConstraintWorldUpVector`; $cmd = ($cmd + " -worldUpVector " + $worldUpVector[0] + " " + $worldUpVector[1] + " " + $worldUpVector[2]); $worldUpObject = `optionVar -query tangentConstraintWorldUpObject`; $cmd = ($cmd + " -worldUpObject " + $worldUpObject); break; case "vector": $worldUpVector = `optionVar -query tangentConstraintWorldUpVector`; $cmd = ($cmd + " -worldUpVector " + $worldUpVector[0] + " " + $worldUpVector[1] + " " + $worldUpVector[2]); break; } return $cmd; } // // Procedure Name: // performTangentConstraint // // Description: // Perform the tangentConstraint 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 tangentConstraint 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: // None. // global proc string performTangentConstraint(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: tangentConstraintOptions; break; // Return the command string. // case 2: // Retrieve the option settings. // setOptionVars (false); // Get the command. // $cmd = `assembleCmd`; break; } return $cmd; }