// =========================================================================== // 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: 5 June, 1997 // // Description: // This script is a template script for option box dialogs. // // Input Arguments: // None. // // Return Value: // None. // proc setOptionVars (int $forceFactorySettings) { if( $forceFactorySettings || !`optionVar -exists blinnRed` ) { optionVar -floatValue blinnRed 0.5; } if( $forceFactorySettings || !`optionVar -exists blinnGreen` ) { optionVar -floatValue blinnGreen 0.5; } if( $forceFactorySettings || !`optionVar -exists blinnBlue` ) { optionVar -floatValue blinnBlue 0.5; } if( $forceFactorySettings || !`optionVar -exists blinnTransRed` ) { optionVar -floatValue blinnTransRed 0.0; } if( $forceFactorySettings || !`optionVar -exists blinnTransGreen` ) { optionVar -floatValue blinnTransGreen 0.0; } if( $forceFactorySettings || !`optionVar -exists blinnTransBlue` ) { optionVar -floatValue blinnTransBlue 0.0; } if( $forceFactorySettings || !`optionVar -exists blinnAmbientRed` ) { optionVar -floatValue blinnAmbientRed 0.0; } if( $forceFactorySettings || !`optionVar -exists blinnAmbientGreen` ) { optionVar -floatValue blinnAmbientGreen 0.0; } if( $forceFactorySettings || !`optionVar -exists blinnAmbientBlue` ) { optionVar -floatValue blinnAmbientBlue 0.0; } if( $forceFactorySettings || !`optionVar -exists blinnIncandRed` ) { optionVar -floatValue blinnIncandRed 0.0; } if( $forceFactorySettings || !`optionVar -exists blinnIncandGreen` ) { optionVar -floatValue blinnIncandGreen 0.0; } if( $forceFactorySettings || !`optionVar -exists blinnIncandBlue` ) { optionVar -floatValue blinnIncandBlue 0.0; } if( $forceFactorySettings || !`optionVar -exists blinnSpecularRed` ) { optionVar -floatValue blinnSpecularRed 0.0; } if( $forceFactorySettings || !`optionVar -exists blinnSpecularGreen` ) { optionVar -floatValue blinnSpecularGreen 0.0; } if( $forceFactorySettings || !`optionVar -exists blinnSpecularBlue` ) { optionVar -floatValue blinnSpecularBlue 0.0; } if( $forceFactorySettings || !`optionVar -exists blinnEccentricity` ) { optionVar -floatValue blinnEccentricity 0.3; } if( $forceFactorySettings || !`optionVar -exists blinnSpecularRollOff` ) { optionVar -floatValue blinnSpecularRollOff 0.7; } if( $forceFactorySettings || !`optionVar -exists blinnReflectivity` ) { optionVar -floatValue blinnReflectivity 0.5; } } global proc createBlinnSetup (string $parent, int $forceFactorySettings) { // Retrieve the option settings // setOptionVars( $forceFactorySettings ); setParent $parent; // Query the optionVar's and set the values into the controls // float $red = `optionVar -query blinnRed`; float $green = `optionVar -query blinnGreen`; float $blue = `optionVar -query blinnBlue`; colorSliderGrp -e -rgb $red $green $blue blinnRGB; $red = `optionVar -query blinnTransRed`; $green = `optionVar -query blinnTransGreen`; $blue = `optionVar -query blinnTransBlue`; colorSliderGrp -e -rgb $red $green $blue blinnTransRGB; $red = `optionVar -query blinnAmbientRed`; $green = `optionVar -query blinnAmbientGreen`; $blue = `optionVar -query blinnAmbientBlue`; colorSliderGrp -e -rgb $red $green $blue blinnAmbientRGB; $red = `optionVar -query blinnIncandRed`; $green = `optionVar -query blinnIncandGreen`; $blue = `optionVar -query blinnIncandBlue`; colorSliderGrp -e -rgb $red $green $blue blinnIncandRGB; $red = `optionVar -query blinnSpecularRed`; $green = `optionVar -query blinnSpecularGreen`; $blue = `optionVar -query blinnSpecularBlue`; colorSliderGrp -e -rgb $red $green $blue blinnSpecularRGB; floatSliderGrp -e -v `optionVar -q blinnEccentricity` blinnEccentricity; floatSliderGrp -e -v `optionVar -q blinnSpecularRollOff` blinnSpecularRollOff; floatSliderGrp -e -v `optionVar -q blinnReflectivity` blinnReflectivity; } global proc createBlinnCallback (string $parent, int $doIt) // // Description: // Set the optionVar's from the control values, and then perform // the command, or simply save the values and close the window // { setParent $parent; float $rgb[] = `colorSliderGrp -q -rgb blinnRGB`; optionVar -floatValue blinnRed $rgb[0]; optionVar -floatValue blinnGreen $rgb[1]; optionVar -floatValue blinnBlue $rgb[2]; $rgb = `colorSliderGrp -q -rgb blinnTransRGB`; optionVar -floatValue blinnTransRed $rgb[0]; optionVar -floatValue blinnTransGreen $rgb[1]; optionVar -floatValue blinnTransBlue $rgb[2]; $rgb = `colorSliderGrp -q -rgb blinnAmbientRGB`; optionVar -floatValue blinnAmbientRed $rgb[0]; optionVar -floatValue blinnAmbientGreen $rgb[1]; optionVar -floatValue blinnAmbientBlue $rgb[2]; $rgb = `colorSliderGrp -q -rgb blinnSpecularRGB`; optionVar -floatValue blinnSpecularRed $rgb[0]; optionVar -floatValue blinnSpecularGreen $rgb[1]; optionVar -floatValue blinnSpecularBlue $rgb[2]; $rgb = `colorSliderGrp -q -rgb blinnIncandRGB`; optionVar -floatValue blinnIncandRed $rgb[0]; optionVar -floatValue blinnIncandGreen $rgb[1]; optionVar -floatValue blinnIncandBlue $rgb[2]; optionVar -floatValue blinnEccentricity `floatSliderGrp -q -v blinnEccentricity`; optionVar -floatValue blinnSpecularRollOff `floatSliderGrp -q -v blinnSpecularRollOff`; optionVar -floatValue blinnReflectivity `floatSliderGrp -q -v blinnReflectivity`; if( $doIt ) { performCreateBlinn 0; } } global proc createBlinnOptions () { // Name of the command for this option box // string $commandName = "createBlinn"; // Build the option box "methods" // 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 -scr true -tv false; string $parent = `columnLayout -adjustableColumn 1`; // Create the widgets for this option box // separator -style "none" -h 5; colorSliderGrp -h 25 -label (uiRes("m_performCreateBlinn.kColor")) -rgb 0.5 0.5 0.5 blinnRGB; colorSliderGrp -h 25 -label (uiRes("m_performCreateBlinn.kTransparency")) -rgb 0 0 0 blinnTransRGB; colorSliderGrp -h 25 -label (uiRes("m_performCreateBlinn.kAmbientColor")) -rgb 0 0 0 blinnAmbientRGB; colorSliderGrp -h 25 -label (uiRes("m_performCreateBlinn.kIncandescence")) -rgb 0 0 0 blinnIncandRGB; separator -h 5; floatSliderGrp -h 25 -label (uiRes("m_performCreateBlinn.kEccentricity")) -field true -value 0.3 -min 0.0 -max 1.0 -pre 4 blinnEccentricity; floatSliderGrp -h 25 -label (uiRes("m_performCreateBlinn.kSpecularRollOff")) -field true -value 0.7 -min 0.0 -max 1.0 -pre 4 blinnSpecularRollOff; colorSliderGrp -h 25 -label (uiRes("m_performCreateBlinn.kSpecularColor")) -rgb 0 0 0 blinnSpecularRGB; floatSliderGrp -h 25 -label (uiRes("m_performCreateBlinn.kReflectivity")) -field true -value 0.5 -min 0.0 -max 1.0 -pre 4 blinnReflectivity; // 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 -label (uiRes("m_performCreateBlinn.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_performCreateBlinn.kOptions"))); // Step 8: Customize the 'Help' menu item text. // ============================================ // setOptionBoxHelpTag( "" ); // Step 9: Set the current values of the option box. // ================================================= // eval (($setup + " " + $parent + " " + 0)); // Step 10: Show the option box. // ============================= // showOptionBox(); } proc string getCmd() { string $cmd; setOptionVars( false ); float $red = `optionVar -query blinnRed`; float $green = `optionVar -query blinnGreen`; float $blue = `optionVar -query blinnBlue`; float $transR = `optionVar -query blinnTransRed`; float $transG = `optionVar -query blinnTransGreen`; float $transB = `optionVar -query blinnTransBlue`; float $ambR = `optionVar -query blinnAmbientRed`; float $ambG = `optionVar -query blinnAmbientGreen`; float $ambB = `optionVar -query blinnAmbientBlue`; float $incandR = `optionVar -query blinnIncandRed`; float $incandG = `optionVar -query blinnIncandGreen`; float $incandB = `optionVar -query blinnIncandBlue`; float $specR = `optionVar -query blinnSpecularRed`; float $specG = `optionVar -query blinnSpecularGreen`; float $specB = `optionVar -query blinnSpecularBlue`; float $eccentricity = `optionVar -query blinnEccentricity`; float $specRollOff = `optionVar -query blinnSpecularRollOff`; float $reflectivity = `optionVar -query blinnReflectivity`; $cmd = "{string $result;"; $cmd = $cmd + ( "$result = `shadingNode -asShader blinn`;" ); $cmd = $cmd + "string $SEName = `sets -renderable true -name ($result+\"Grp\") -empty`;"; $cmd = $cmd + "connectAttr -f ( $result + \".outColor\") ( $SEName + \".surfaceShader\" );"; // Set the attributes the from the optionVars set // in the optionBox // $cmd = $cmd + "setAttr ( $result + \".colorR\" ) " + $red + ";"; $cmd = $cmd + "setAttr ( $result+\".colorG\" ) " + $green + ";"; $cmd = $cmd + "setAttr ( $result+\".colorB\" ) " + $blue + ";"; $cmd = $cmd + "setAttr ( $result+\".transparencyR\" ) " + $transR + ";"; $cmd = $cmd + "setAttr ( $result+\".transparencyG\" ) " + $transG + ";"; $cmd = $cmd + "setAttr ( $result+\".transparencyB\" ) " + $transB + ";"; $cmd = $cmd + "setAttr ( $result+\".ambientColorR\" ) " + $ambR + ";"; $cmd = $cmd + "setAttr ( $result+\".ambientColorG\" ) " + $ambG + ";"; $cmd = $cmd + "setAttr ( $result+\".ambientColorB\" ) " + $ambB + ";"; $cmd = $cmd + "setAttr ( $result+\".incandescenceR\" ) " + $incandR + ";"; $cmd = $cmd + "setAttr ( $result+\".incandescenceG\" ) " + $incandG + ";"; $cmd = $cmd + "setAttr ( $result+\".incandescenceB\" ) " + $incandB + ";"; $cmd = $cmd + "setAttr ( $result+\".specularColorR\" ) " + $specR + ";"; $cmd = $cmd + "setAttr ( $result+\".specularColorG\" ) " + $specG + ";"; $cmd = $cmd + "setAttr ( $result+\".specularColorB\" ) " + $specB + ";"; $cmd = $cmd + "setAttr ( $result+\".eccentricity\" ) " + $eccentricity + ";"; $cmd = $cmd + "setAttr ( $result+\".specularRollOff\" ) " + $specRollOff + ";"; $cmd = $cmd + "setAttr ( $result+\".reflectivity\" ) " + $reflectivity + ";"; $cmd = $cmd + "}"; return $cmd; } global proc string performCreateBlinn (int $showOptionBox) { string $cmd; if ($showOptionBox == 0) { $cmd = getCmd(); eval($cmd); } else if( $showOptionBox == 1) { createBlinnOptions; } else if ($showOptionBox == 2) { $cmd = getCmd(); } return $cmd; }