// =========================================================================== // 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: 20 August 1996 // // Procedure Name: // createRenderNode // // Description: // Procedure to popup the render creation window. // // Input Arguments: // A flag specifying which types of render nodes to create. // Currently "-all", "-allWithTexturesUp", "-allWithShadersUp", // "-allWithLightsUp", "-textures", "-shadersSG", "-shaders", // "-lights", "-utilities" are supported. // // The command to run after the a node has been created. The name // of the created node will substituted "%node" in the command // string. If an empty string is passed for the command nothing // will be done. Currently the command is only attached to the // buttons in the texture tab. // // If a command is specified the createRenderNode window will be // closed. // // Return Value: // None. // ////////////////////////////////////////////////////////////////////// // // Procedure Name: // createRenderNodeCB // // Description: // Procedure to create the node classified as specified by the inputs // // Input Arguments: // $as - // A flag specifying which how to classify the node created. // Choices: // -as2DTexture : 2d textures // -as3DTexture : 3d textures // -asEnvTexture : Environment textures // -asShader : as a shader // -asLight : as a light // -asUtility : as a rendering utility node // // $flag - // A secondary flag used to make decisions in combination with $as. // Choices: // -asBump : defines a created texture as a bump // -asNoShadingGroup : for materials; create without a shading group // -asDisplacement : for anything; map the created node // to a displacement material. // -asUtility : for anything; do whatever the $as flag says, // but also classify as a utility // -asPostProcess : for any postprocess node // // $type - // The type of node to be created. // // $command - // A command entered by the user when invoking createRenderNode. // The command will substitute the string %node with the name of the // node it creates. createRenderWindow will be closed if a command // is not the null string (""). // // Return Value: // None. // global proc string createRenderNodeCB ( string $as, string $flag, string $type, string $postCommand ) { int $projection = (`optionVar -query create2dTextureType` == "projection"); int $stencil = (`optionVar -query create2dTextureType` == "stencil"); int $placement = `optionVar -query createTexturesWithPlacement`; int $shadingGroup = `optionVar -query createMaterialsWithShadingGroup`; int $createAndDrop = 0; string $editor = ""; return renderCreateNode( $as, $flag, $type, $postCommand, $projection, $stencil, $placement, $shadingGroup, $createAndDrop, $editor); } proc selectRenderNodeCategories(string $category, string $subCategory) // // Description: // This is a helper function to create a node path string to be // used to select that specific path in the Create Render Node // treeLister. // { global string $gCreateRenderNodeWindowTreeLister; string $nodePath = ($category + $subCategory); treeLister -e -selectPath $nodePath $gCreateRenderNodeWindowTreeLister; } global int $gCreateRenderNodePluginCallbacksRegistered = false; global proc createRenderNode( string $nodeTypesFlag, string $command, string $flag ) // // Description: // This procedure creates the Create Render Node window, // which gives the user the ability to choose from // different texture types. // // Arguments: // $nodeTypesFlag - Specifies what is shown and selected in the window. // // $command - A command to be run after a node is created. // // $flag - A flag to help determine how the node is created. // { // Add a line to close the Create Render Node Window to the command, // since we want the window to close after a node is selected from it. // $command = strip($command); if(size($command) > 0) { $command = $command + "; window -e -vis false createRenderNodeWindow;"; } // If we only want to show nodes of a specific type, create a string // with the appropriate classifications for the treeLister to filter. // string $filterString; string $first4 = substring($nodeTypesFlag,1,4); if ($nodeTypesFlag == "-textures") { $filterString = "texture"; } else if ($nodeTypesFlag == "-shaders" || $nodeTypesFlag == "-shadersSG") { $filterString = "shader"; if($nodeTypesFlag == "-shaders") { menuItem -e -checkBox false shadingGroupCheckBox; } else if($nodeTypesFlag == "-shadersSG") { menuItem -e -checkBox true shadingGroupCheckBox; } } else if ($nodeTypesFlag == "-lights") { $filterString = "light"; } else if ($nodeTypesFlag == "-utilities") { $filterString = "utility imageplane postprocess/opticalFX"; } else if($first4 != "-all") { error (uiRes("m_createRenderNode.kNodeError")); } int $crnWindowWidth = 380; global string $gCreateRenderNodeWindowTreeLister; if (!`window -exists createRenderNodeWindow`) { string $createRenderNode = (uiRes("m_createRenderNode.kCreateRenderNode")); window -rtf false -title $createRenderNode -iconName $createRenderNode -menuBar true -maximizeButton false -ret -wh $crnWindowWidth 730 createRenderNodeWindow; // // Setup up the menu bar // menu -label (uiRes("m_createRenderNode.kOptions")) optionsMenu; $includeShadingGroupItem = `menuItem -label (uiRes("m_createRenderNode.kIncludeShadingGroupwithMaterials")) -checkBox true -annotation (uiRes("m_createRenderNode.kIncludeShadingGroupwithMaterialsAnnot")) shadingGroupCheckBox`; menuItem -edit -checkBox `optionVar -query createMaterialsWithShadingGroup` -command ("optionVar -intValue createMaterialsWithShadingGroup " + "`menuItem -query -checkBox " + $includeShadingGroupItem + "`; refreshCreateNodeUI();") $includeShadingGroupItem; $createIncludePlacementItem = `menuItem -label (uiRes("m_createRenderNode.kIncludePlacementWithTextures")) -checkBox true -annotation (uiRes("m_createRenderNode.kIncludePlacementWithTexturesAnnot")) placementCheckBox`; menuItem -edit -checkBox `optionVar -query createTexturesWithPlacement` -command ("optionVar -intValue createTexturesWithPlacement " + "`menuItem -query -checkBox " + $createIncludePlacementItem + "`; refreshCreateNodeUI();") $createIncludePlacementItem; setParent -m ..; // from optionsMenu menu -label (uiRes("m_createRenderNode.kHelp")) -helpMenu true; menuItem -label (uiRes("m_createRenderNode.kHelpOnCreateRenderNode")) -enableCommandRepeat false -command "showHelp CreateRenderNode"; setParent -m ..; // // Setup up the treeLister // formLayout creationWindowForm; global string $gCreateRenderNodeWindowTreeLister; $gCreateRenderNodeWindowTreeLister = createRenderNodeTreeLister($command, $filterString); button -label (uiRes("m_createRenderNode.kClose")) -h 26 -c "window -e -vis false createRenderNodeWindow" closeButton; setParent ..; formLayout -e -af $gCreateRenderNodeWindowTreeLister "left" 1 -af $gCreateRenderNodeWindowTreeLister "right" 1 -af $gCreateRenderNodeWindowTreeLister "top" 1 -ac $gCreateRenderNodeWindowTreeLister "bottom" 5 closeButton -af closeButton "left" 5 -af closeButton "right" 5 -af closeButton "bottom" 5 -an closeButton "top" creationWindowForm; } else { refreshRenderNodeTreeLister($gCreateRenderNodeWindowTreeLister, $command, $filterString); } setParent createRenderNodeWindow; // Select the node categories in the treeLister that match the node // type that we want explictly highlighted. // if ($first4 == "-all") { if($nodeTypesFlag != "-all") { string $mayaCategory = "Maya/"; if($nodeTypesFlag == "-allWithShadersUp") { string $subCategory = localizedNodeClassificationLabel( "Surface" ); selectRenderNodeCategories($mayaCategory, $subCategory); $subCategory = localizedNodeClassificationLabel( "Volumetric" ); selectRenderNodeCategories($mayaCategory, $subCategory); $subCategory = localizedNodeClassificationLabel( "Displacement" ); selectRenderNodeCategories($mayaCategory, $subCategory); } else if($nodeTypesFlag == "-allWithTexturesUp") { string $subCategory = localizedNodeClassificationLabel( "2D Textures" ); selectRenderNodeCategories($mayaCategory, $subCategory); $subCategory = localizedNodeClassificationLabel( "3D Textures" ); selectRenderNodeCategories($mayaCategory, $subCategory); $subCategory = localizedNodeClassificationLabel( "Env Textures" ); selectRenderNodeCategories($mayaCategory, $subCategory); $subCategory = localizedNodeClassificationLabel( "Other Textures" ); selectRenderNodeCategories($mayaCategory, $subCategory); } else if($nodeTypesFlag == "-allWithLightsUp") { string $subCategory = localizedNodeClassificationLabel( "Lights" ); selectRenderNodeCategories($mayaCategory, $subCategory); } else { // run the custom UI callbacks here // strip the leading '-' from the types flag so it isn't interpreted by the callbacks command string $newNodeTypesFlag = substring($nodeTypesFlag, 2, size($nodeTypesFlag)); callbacks -executeCallbacks -hook "createRenderNodeSelectNodeCategories" $newNodeTypesFlag $gCreateRenderNodeWindowTreeLister; } } } showWindow createRenderNodeWindow; // Establish a callback which will be called when a plugin is loaded. // The callback will find out what plugin was loaded and will update the // create render node window if necessary. // global int $gCreateRenderNodePluginCallbacksRegistered; if (!$gCreateRenderNodePluginCallbacksRegistered) { loadPlugin -addCallback createRenderNodeLoadPluginCallback; unloadPlugin -addCallback createRenderNodeUnloadPluginCallback; $gCreateRenderNodePluginCallbacksRegistered = true; } } proc createRenderNodePluginChange( string $changeType, string $plugin) { // // Description: // This procedure is called from createRenderNodeLoadPluginCallback() or // from createRenderNodeUnloadPluginCallback(). If this method has been // called because a plugin has finished loading, $changeType should be // "loadPlugin". If it has been called because a plugin is about to be // unloaded, $changeType should be "unloadPlugin". // This procedure determines what node types, if any, are affected by the // plugin loading/unloading, and refreshes the createRenderNodeWindow if // any of those node types are displayed therein. // if (!`window -exists createRenderNodeWindow`) { return; } // Get a list of all node types loaded by the plugin // string $pluginNodeTypeArray[] = `pluginInfo -query -dependNode $plugin`; string $nodeType; int $needToRefreshTreeLister = 0; for ($nodeType in $pluginNodeTypeArray) { // Determine the classification(s) of each node type. Note that nodes // can have multiple classifications. // string $classificationArray[] = `getClassification $nodeType`; string $classification; for ($classification in $classificationArray) { // give UI callbacks a chance to request a tree lister refresh int $callbacksResults[] = `callbacks -executeCallbacks -hook "createRenderNodePluginChange" $classification`; string $currentResult; int $customUIRefresh = 0; for ($currentResult in $callbacksResults){ if ($currentResult){ $customUIRefresh = 1; break; } } string $tokenArray[]; int $numTokens = tokenize($classification, "/", $tokenArray); if ( ($tokenArray[0] == "texture") || ($tokenArray[0] == "shader") || ($tokenArray[0] == "light") || ($tokenArray[0] == "utility") || ($tokenArray[0] == "imageplane") || ($tokenArray[0] == "postprocess") || $customUIRefresh ) { $needToRefreshTreeLister = 1; break; } } if($needToRefreshTreeLister) { break; } } if($needToRefreshTreeLister) { // The node type is classified as something which appears // within the createRenderNodeWindow, so we need to refresh // that window. We do this by closing the window so that its // contents will be refreshed on reopen. // // Note that the above list needs to be kept in sync with the // types of nodes which appear in the createRenderNodeWindow. // if($changeType == "unloadPlugin") { // The plug-in is being unloaded, which might render some // treeLister items invalid. Close the window so the // treeLister can be refreshed. window -e -vis false createRenderNodeWindow; } } } global proc createRenderNodeUnloadPluginCallback(string $plugin) { // // Description: // This procedure is called immediately before a plugin is unloaded. // This procedure invokes createRenderNodePluginChange() to potentially // refresh the createRenderNodeWindow. // createRenderNodePluginChange("unloadPlugin", $plugin); } global proc createRenderNodeLoadPluginCallback(string $plugin) { // // Description: // This procedure is called immediately after a plugin is loaded. // This procedure invokes createRenderNodePluginChange() to potentially // refresh the createRenderNodeWindow. // createRenderNodePluginChange("loadPlugin", $plugin); } global proc refreshCreateRenderNodeWindow( string $classification ) { // // Description: // This procedure is called when a plugin is initialized. // This procedure closes the Create Render Node window, so // that it will refresh its contents on reopen. // if (!`window -exists createRenderNodeWindow`) { return; } window -e -vis false createRenderNodeWindow; }