// =========================================================================== // 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: 9 July 2002 // // // Description: // This script defines the option box for the light points menu item. // // // 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) { // Number of Light Points if( $forceFactorySettings || !`optionVar -exists OFLP_NumberOfLightPoints`){ optionVar -intValue OFLP_NumberOfLightPoints 2; } // Distance between Light Points if ($forceFactorySettings || !`optionVar -exists OFLP_DistanceBetweenLPs`){ optionVar -floatValue OFLP_DistanceBetweenLPs 1.0; } // Directional Type if ($forceFactorySettings || !`optionVar -exists OFLP_LightType`){ optionVar -stringValue OFLP_LightType "Omnidirectional"; } // Light Points' Normal if ($forceFactorySettings || !`optionVar -exists OFLP_LightNormalsX`){ optionVar -floatValue OFLP_LightNormalsX 0.0; } if ($forceFactorySettings || !`optionVar -exists OFLP_LightNormalsY`){ optionVar -floatValue OFLP_LightNormalsY 0.0; } if ($forceFactorySettings || !`optionVar -exists OFLP_LightNormalsZ`){ optionVar -floatValue OFLP_LightNormalsZ 1.0; } // Color of Light Points if ($forceFactorySettings || !`optionVar -exists OFLP_LightColorR`){ optionVar -floatValue OFLP_LightColorR 1.0; } if ($forceFactorySettings || !`optionVar -exists OFLP_LightColorG`){ optionVar -floatValue OFLP_LightColorG 1.0; } if ($forceFactorySettings || !`optionVar -exists OFLP_LightColorB`){ optionVar -floatValue OFLP_LightColorB 1.0; } } proc string OFLP_LightType_melToUI (string $mel) { string $result = $mel; string $omnidirectional = (uiRes("m_performLightPoints.kOmnidirectional")); string $unidirectional = (uiRes("m_performLightPoints.kUnidirectional")); string $bidirectional = (uiRes("m_performLightPoints.kBidirectional")); if ($mel == "Omnidirectional"){ $result = $omnidirectional; } else if ($mel == "Unidirectional"){ $result = $unidirectional; } else if ($mel == "Bidirectional"){ $result = $bidirectional; } else{ uiToMelMsg( "OFLP_LightType_melToUI", $mel, 1 ); } return $result; } proc string OFLP_LightType_uiToMel (string $ui) { string $result = $ui; if ($ui == (uiRes("m_performLightPoints.kOmnidirectional")) ){ $result = "Omnidirectional"; } else if ($ui == (uiRes("m_performLightPoints.kUnidirectional")) ){ $result = "Unidirectional"; } else if ($ui == (uiRes("m_performLightPoints.kBidirectional")) ){ $result = "Bidirectional"; } else{ uiToMelMsg( "OFLP_LightType_uiToMel", $ui, 1 ); } return $result; } // // Procedure Name: // fltLightPointsSetup // // 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 fltLightPointsSetup(string $parent, int $forceFactorySettings) { // Retrieve the option settings // setOptionVars($forceFactorySettings); setParent $parent; // Query the optionVar's and set the values into the controls. int $useGlobalTol = false; // Number of Light Points intFieldGrp -e -v1 `optionVar -q OFLP_NumberOfLightPoints` OFLP_NumberOfLightPoints; // Distance Between Light Points floatFieldGrp -e -v1 `optionVar -q OFLP_DistanceBetweenLPs` OFLP_DistanceBetweenLPs; // Light Type string $selectedMenu = `optionVar -q OFLP_LightType`; optionMenuGrp -e -value `OFLP_LightType_melToUI $selectedMenu` OFLP_LightType; // Normal of Light Points floatFieldGrp -e -v1 `optionVar -q OFLP_LightNormalsX` -v2 `optionVar -q OFLP_LightNormalsY` -v3 `optionVar -q OFLP_LightNormalsZ` OFLP_LightNormals; // Color of Light Points colorSliderGrp -e -rgb `optionVar -q OFLP_LightColorR` `optionVar -q OFLP_LightColorG` `optionVar -q OFLP_LightColorB` OFLP_LightColor; // Update the enabled state of the light normals lightPointsUpdateType $parent; } // // Procedure Name: // fltLightPointsCallback // // 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 fltLightPointsCallback(string $parent, int $doIt) { setParent $parent; // Set the optionVar's from the control values, and then // perform the command. optionVar -intValue OFLP_NumberOfLightPoints `intFieldGrp -q -v1 OFLP_NumberOfLightPoints`; optionVar -floatValue OFLP_DistanceBetweenLPs `floatFieldGrp -q -v1 OFLP_DistanceBetweenLPs`; string $selectedMenu = `optionMenuGrp -q -value OFLP_LightType`; optionVar -stringValue OFLP_LightType `OFLP_LightType_uiToMel $selectedMenu`; optionVar -floatValue OFLP_LightNormalsX `floatFieldGrp -q -v1 OFLP_LightNormals`; optionVar -floatValue OFLP_LightNormalsY `floatFieldGrp -q -v2 OFLP_LightNormals`; optionVar -floatValue OFLP_LightNormalsZ `floatFieldGrp -q -v3 OFLP_LightNormals`; float $lightColor[3] = `colorSliderGrp -q -rgb OFLP_LightColor`; optionVar -floatValue OFLP_LightColorR $lightColor[0]; optionVar -floatValue OFLP_LightColorG $lightColor[1]; optionVar -floatValue OFLP_LightColorB $lightColor[2]; if ($doIt) { performLightPoints 0; addToRecentCommandQueue "performLightPoints 0" "Light Points"; } } global proc lightPointsUpdateType( string $node ) { string $lightTypeName = $node + "|OFLP_LightType"; string $normalsName = $node + "|OFLP_LightNormals"; string $dirType = `optionMenuGrp -q -value $lightTypeName`; $dirType = `OFLP_LightType_uiToMel $dirType`; int $lightIsDirectional = ($dirType != "Omnidirectional"); floatFieldGrp -e -enable $lightIsDirectional $normalsName; } // // Procedure Name: // lightPointsOptions // // Description: // Construct the option box UI. Involves accessing the standard option // box and customizing the UI accordingly. // // Input Arguments: // None. // // Return Value: // None. // proc lightPointsOptions() { // Name of the command for this option box. // string $commandName = "fltLightPoints"; // 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; // Turn on the wait cursor. // waitCursor -state 1; // STEP 4: Create option box contents. // =================================== // tabLayout -scr true -tv false; string $parent = `columnLayout -adjustableColumn 1`; intFieldGrp -label (uiRes("m_performLightPoints.kNumberOfLightPoints")) OFLP_NumberOfLightPoints; floatFieldGrp -label (uiRes("m_performLightPoints.kDistanceBetweenLightPoints")) OFLP_DistanceBetweenLPs; string $lightTypeCmd = "lightPointsUpdateType " + $parent; optionMenuGrp -label (uiRes("m_performLightPoints.kLightType")) -changeCommand $lightTypeCmd OFLP_LightType; menuItem -label `OFLP_LightType_melToUI "Omnidirectional"` ; menuItem -label `OFLP_LightType_melToUI "Unidirectional"`; menuItem -label `OFLP_LightType_melToUI "Bidirectional"` ; floatFieldGrp -label (uiRes("m_performLightPoints.kLightNormal")) -nf 3 OFLP_LightNormals; colorSliderGrp -label (uiRes("m_performLightPoints.kLightColor")) OFLP_LightColor; // Update the enabled state of the light normals eval $lightTypeCmd; // 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. // Disable those buttons that are not applicable to the option box. // Attach actions to those buttons that are applicable to the option box. // 'Apply' button. // string $applyBtn = getOptionBoxApplyBtn(); button -edit -label (uiRes("m_performLightPoints.kCreate")) -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; // Step 7: Set the option box title. // ================================= // setOptionBoxTitle (uiRes("m_performLightPoints.kLightPointsOptions")); // Step 8: Customize the 'Help' menu item text. // ============================================ // setOptionBoxHelpTag( "LightPoints" ); // Set the current values of the option box. // ========================================= // eval (($setup + " " + $parent + " " + 0)); // Show the option box. // ==================== // showOptionBox(); } // // Procedure Name: // lightPointsHelp // // Description: // Return a short description about this command. // // Input Arguments: // None. // // Return Value: // string. // proc string lightPointsHelp() { return " Command: fltLightPoints - create OpenFlight light points.\n"; } // // Procedure Name: // assembleCmd // // Description: // Construct the command that will apply the option box values. // // Input Arguments: // None. // proc string assembleCmd() { string $cmd = "fltLightPoints"; setOptionVars(false); $cmd = ($cmd + " -c " + `optionVar -q OFLP_NumberOfLightPoints` + " -d " + `optionVar -q OFLP_DistanceBetweenLPs` + " -clr " + `optionVar -q OFLP_LightColorR` + " " + `optionVar -q OFLP_LightColorG` + " " + `optionVar -q OFLP_LightColorB` + " -nml " + `optionVar -q OFLP_LightNormalsX` + " " + `optionVar -q OFLP_LightNormalsY` + " " + `optionVar -q OFLP_LightNormalsZ` + " -dt " + `optionVar -q OFLP_LightType` + ";objectMoveCommand"); return $cmd; } // // Procedure Name: // performLightPoints // // Description: // Perform the fltLightPoints 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 fltLightPoints 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 performLightPoints(int $action) { string $cmd = ""; switch ($action) { // Execute the command. // case 0: // Get the command. // $cmd = `assembleCmd`; // Execute the command with the option settings. // evalEcho($cmd); break; // Show the option box. // case 1: lightPointsOptions; break; // Return the command string. // case 2: // Get the command. // $cmd = `assembleCmd`; break; } return $cmd; }