// =========================================================================== // 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: 18 April 1997 // // Description: // ambientLight default options box. The content for each tab // is not created until it is accessed for the first time. // ////////////////////////////////////////////////////////////////////// // // 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) { // Intensity. // if ($forceFactorySettings || !`optionVar -exists ambientLightIntensity`) { optionVar -floatValue ambientLightIntensity 1; } // Ambient Shade. // if ($forceFactorySettings || !`optionVar -exists ambientLightShade`) { optionVar -floatValue ambientLightShade 0.45; } // Color. // if ($forceFactorySettings || !`optionVar -exists ambientLightColor`) { optionVar -floatValue ambientLightColor 1 -floatValueAppend ambientLightColor 1 -floatValueAppend ambientLightColor 1; } // Exclusive. // // if ($forceFactorySettings || !`optionVar -exists ambientLightExclusive`) { // optionVar -intValue ambientLightExclusive false; // } // Shadows. // if ($forceFactorySettings || !`optionVar -exists ambientLightShadows`) { optionVar -intValue ambientLightShadows false; } // Shadow Color. // if ($forceFactorySettings || !`optionVar -exists ambientLightShadowColor`) { optionVar -floatValue ambientLightShadowColor 0 -floatValueAppend ambientLightShadowColor 0 -floatValueAppend ambientLightShadowColor 0; } // // Depth Map Filter Size. // // // if ($forceFactorySettings || !`optionVar -exists ambientLightDepthMapFilterSize`) { // optionVar -intValue ambientLightDepthMapFilterSize 1; // } // // Depth Map Resolution. // // // if ($forceFactorySettings || !`optionVar -exists ambientLightDepthMapResolution`) { // optionVar -intValue ambientLightDepthMapResolution 512; // } // // Depth Map Bias. // // // if ($forceFactorySettings || !`optionVar -exists ambientLightDepthMapBias`) { // optionVar -floatValue ambientLightDepthMapBias 0.001; // } // Shadow Samples. // if ($forceFactorySettings || !`optionVar -exists ambientLightShadowSamples`) { optionVar -intValue ambientLightShadowSamples 1; } } // // Procedure Name: // ambientLightSetup // // 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 ambientLightSetup(string $parent, int $forceFactorySettings) { // Retrieve the option settings // setOptionVars($forceFactorySettings); setParent $parent; float $rgb[3]; // Query the optionVar's and set the values into the controls. // Intensity. // if (`floatSliderGrp -exists ambientLightIntensity`) { floatSliderGrp -edit -value `optionVar -query ambientLightIntensity` ambientLightIntensity; } // Ambient Shade. // if (`floatSliderGrp -exists ambientLightShade`) { floatSliderGrp -edit -value `optionVar -query ambientLightShade` ambientLightShade; } // Color. // if (`colorSliderGrp -exists ambientLightColor`) { $rgb = `optionVar -query ambientLightColor`; colorSliderGrp -edit -rgb $rgb[0] $rgb[1] $rgb[2] ambientLightColor; } // // Exclusive. // // // if (`checkBoxGrp -exists ambientLightExclusive`) { // checkBoxGrp -edit // -value1 `optionVar -query ambientLightExclusive` // ambientLightExclusive; // } // Shadows. // if (`checkBoxGrp -exists ambientLightShadows`) { checkBoxGrp -edit -value1 `optionVar -query ambientLightShadows` ambientLightShadows; } // Shadow Color. // if (`colorSliderGrp -exists ambientLightShadowColor`) { $rgb = `optionVar -query ambientLightShadowColor`; colorSliderGrp -edit -rgb $rgb[0] $rgb[1] $rgb[2] ambientLightShadowColor; } // // Depth Map Filter Size. // // // if (`intSliderGrp -exists ambientLightDepthMapFilterSize`) { // intSliderGrp -edit // -value `optionVar -query ambientLightDepthMapFilterSize` // ambientLightDepthMapFilterSize; // } // // Depth Map Resolution. // // // if (`intSliderGrp -exists ambientLightDepthMapResolution`) { // intSliderGrp -edit // -value `optionVar -query ambientLightDepthMapResolution` // ambientLightDepthMapResolution; // } // // Depth Map Bias. // // // if (`intSliderGrp -exists ambientLightDepthMapBias`) { // intSliderGrp -edit // -value `optionVar -query ambientLightDepthMapBias` // ambientLightDepthMapBias; // } // Shadow Samples. // if (`intSliderGrp -exists ambientLightShadowSamples`) { intSliderGrp -edit -value `optionVar -query ambientLightShadowSamples` ambientLightShadowSamples; } } // // Procedure Name: // ambientLightCallback // // 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 ambientLightCallback(string $parent, int $doIt) { setParent $parent; float $rgb[3]; // Set the optionVar's from the control values, and then // perform the command. // Intensity. // if (`floatSliderGrp -exists ambientLightIntensity`) { optionVar -floatValue ambientLightIntensity `floatSliderGrp -query -value ambientLightIntensity`; } // Ambient Shade. // if (`floatSliderGrp -exists ambientLightShade`) { optionVar -floatValue ambientLightShade `floatSliderGrp -query -value ambientLightShade`; } // Color. // if (`colorSliderGrp -exists ambientLightColor`) { $rgb = `colorSliderGrp -query -rgb ambientLightColor`; optionVar -floatValue ambientLightColor $rgb[0]; optionVar -floatValueAppend ambientLightColor $rgb[1]; optionVar -floatValueAppend ambientLightColor $rgb[2]; } // // Exclusive. // // // if (`checkBoxGrp -exists ambientLightExclusive`) { // optionVar -intValue ambientLightExclusive // `checkBoxGrp -query -value1 ambientLightExclusive`; // } // Shadow. // if (`checkBoxGrp -exists ambientLightShadows`) { optionVar -intValue ambientLightShadows `checkBoxGrp -query -value1 ambientLightShadows`; } // Shadow Color. // if (`colorSliderGrp -exists ambientLightShadowColor`) { $rgb = `colorSliderGrp -query -rgb ambientLightShadowColor`; optionVar -floatValue ambientLightShadowColor $rgb[0]; optionVar -floatValueAppend ambientLightShadowColor $rgb[1]; optionVar -floatValueAppend ambientLightShadowColor $rgb[2]; } // // Depth Map Filter Size. // // // if (`intSliderGrp -exists ambientLightDepthMapFilterSize`) { // optionVar -intValue ambientLightDepthMapFilterSize // `intSliderGrp -query -value ambientLightDepthMapFilterSize`; // } // // Depth Map Resolution. // // // if (`intSliderGrp -exists ambientLightDepthMapResolution`) { // optionVar -intValue ambientLightDepthMapResolution // `intSliderGrp -query -value ambientLightDepthMapResolution`; // } // // Depth Map Bias. // // // if (`floatSliderGrp -exists ambientLightBias`) { // optionVar -floatValue ambientLightBias // `floatSliderGrp -query -value ambientLightBias`; // } // Shadow Samples. // if (`intSliderGrp -exists ambientLightShadowSamples`) { optionVar -intValue ambientLightShadowSamples `intSliderGrp -query -value ambientLightShadowSamples`; } if ($doIt) { performAmbientLight 0; addToRecentCommandQueue "performAmbientLight 0" "AmbientLight"; } } // // Procedure Name: // createAmbientLightTabUI // // Description: // Create the tab UI. The contents of each tab are created only // when it is required, ie. if the tab is initially visible or // if the tab is selected by the user. // // Input Arguments: // The name of the tab layout. // // Return Value: // None. // global proc createAmbientLightTabUI(string $tabLayout) { string $tab[] = `tabLayout -query -childArray $tabLayout`; int $currentTabIndex = `tabLayout -query -selectTabIndex $tabLayout`; // Determine if the UI for this tab has been created yet. // This is accomplished by querying the number of children // in the current tab. If the tab has no children then the UI // must be created. // if (0 == `columnLayout -query -numberOfChildren $tab[$currentTabIndex-1]`) { setParent $tab[$currentTabIndex-1]; string $label; int $index; // 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; // The current tab has no children. Determine which tab is // active and create its UI. // // RECOMMENDATION: Use the 'Grp' commands where possible because // they obey the formatting specified in the default template. // This will result in a more consistent look throughout the // application. // if (1 == $currentTabIndex) { // Create UI for the first tab. // floatSliderGrp -label (uiRes("m_performAmbientLight.kIntensity")) ambientLightIntensity; colorSliderGrp -label (uiRes("m_performAmbientLight.kColor")) ambientLightColor; floatSliderGrp -label (uiRes("m_performAmbientLight.kAmbientShade")) ambientLightShade; separator; // Create UI for the third tab. // checkBoxGrp -ncb 1 -label1 (uiRes("m_performAmbientLight.kCastShadows")) ambientLightShadows; colorSliderGrp -label (uiRes("m_performAmbientLight.kShadowColor")) ambientLightShadowColor; // the light allows higher max values, but the command does not. intSliderGrp -label (uiRes("m_performAmbientLight.kShadowRays")) -min 1 -max 6 ambientLightShadowSamples; setParent ..; } // Update the control values to match the options. // eval (("ambientLightSetup " + $tabLayout + " " + 0)); // Turn off the wait cursor. // waitCursor -state 0; // Deactivate the default UI template. // setUITemplate -popTemplate; } } // // Procedure Name: // ambientLightOptions // // Description: // Construct the option box UI. Involves accessing the standard option // box and customizing the UI accordingly. // // Input Arguments: // None. // // Return Value: // None. // proc ambientLightOptions() { // Name of the command for this option box. // string $commandName = "ambientLight"; // 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. // // Note: this option box example delays the creation of the UI // until it is required. Therefore this step is moved to the // procedure where the UI is actually created. // //setUITemplate -pushTemplate DefaultTemplate; // STEP 4: Create option box contents. // =================================== // // This, of course, will vary from option box to option box. // Demonstrate the delaying of UI creation via tab layouts. // Instead of creating all of the option box UI initially, only // create that which is initially visible. Wait, until the // other tabs are selected to create the remaining UI. // string $tabLayout = `tabLayout -scrollable 1`; // Attach an action that will be invoked before a tab is selected. // tabLayout -edit -tabsVisible false -preSelectCommand ("createAmbientLightTabUI " + $tabLayout) $tabLayout; // Create just the immediate children of the tab layout so that // the tabs appear. // columnLayout -adj true; setParent ..; // Set the tab labels. // tabLayout -edit $tabLayout; // Create the UI for the tab that is initially visible. // createAmbientLightTabUI($tabLayout); // Step 5: Deactivate the default UI template. // =========================================== // // Note: this option box example delays the creation of the UI // until it is required. Therefore this step is moved to the // procedure where the UI is actually created. // // See also Step 2. // //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 -label (uiRes("m_performAmbientLight.kCreate")) -command ($callback + " " + $tabLayout + " " + 1) $applyBtn; // 'Save' button. // string $saveBtn = getOptionBoxSaveBtn(); button -edit -command ($callback + " " + $tabLayout + " " + 0 + "; hideOptionBox") $saveBtn; // 'Reset' button. // string $resetBtn = getOptionBoxResetBtn(); button -edit -command ($setup + " " + $tabLayout + " " + 1) $resetBtn; // Step 7: Set the option box title. // ================================= // setOptionBoxTitle (uiRes("m_performAmbientLight.kCreateAmbientLightOptions")); // Step 8: Customize the 'Help' menu item text. // ============================================ // setOptionBoxHelpTag( "AmbientLight" ); // Step 9: Set the current values of the option box. // ================================================= // // NOTE: Cannot do this here since we do not know what UI is // currently visible. This is moved to where the UI is created. // //eval (($setup + " " + $tabLayout + " " + 0)); // Step 10: Show the option box. // ============================= // showOptionBox(); } // // Procedure Name: // optionBoxExample1Help // // Description: // Return a short description about this command. // // Input Arguments: // None. // // Return Value: // string. // proc string ambientLightHelp() { return " Command: ambientLight - creates a ambientLight\n" + "Selection: None."; } proc string getCmd() { string $cmd = "defaultAmbientLight("; $cmd = $cmd + `optionVar -query ambientLightIntensity`; $cmd = $cmd + ", " + `optionVar -query ambientLightShade`; float $rgb[3] = `optionVar -query ambientLightColor`; $cmd = $cmd + ", " + $rgb[0] + "," + $rgb[1] + "," + $rgb[2]; $cmd = $cmd + ", \"" + `optionVar -query ambientLightShadows` + "\""; $rgb = `optionVar -query ambientLightShadowColor`; $cmd = $cmd + ", " + $rgb[0] + "," + $rgb[1] + "," + $rgb[2]; $cmd = $cmd + ", \"" + `optionVar -query ambientLightShadowSamples` + "\""; $cmd = $cmd + ");"; return $cmd; } // // Procedure Name: // performAmbientLight // // Description: // Perform the ambientLight 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 ambientLight 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 performAmbientLight(int $action) { string $cmd = ""; switch ($action) { // Execute the command. // case 0: // Retrieve the option settings // setOptionVars(false); // Get the command. // $cmd = getCmd(); // Execute the command with the option settings. // // NOTE: This following evaluation will fail because // this entire file exists only to serve as an example // for using option boxes. There is no command called // 'ambientLight'. // evalEcho($cmd); break; // Show the option box. // case 1: ambientLightOptions; break; // Return the command string. // case 2: // Retrieve the option settings. // setOptionVars (false); // Get the command. // $cmd = getCmd(); break; } return $cmd; }