// =========================================================================== // 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: Date // // Description: // // description // source clipMenuCommands.mel; source containerOperations.mel; source colorProfileProcedures.mel; //--------------------------------------------------------------------------- // The procedure which builds the menu // global proc buildHypergraphNodePopupMenuItems( string $hypershade, string $node) { // // Description: // This procedure is called when the user RMB clicks on a node in a scene // or graph tab hypershade editor. // This procedure builds the menu items which will appear in the popup // menu. // The popup menu this procedure generates can vary depending on the // type of the node under the cursor. // string $nodeType = `nodeType $node`; string $menuDisplayString; // Node name, displayed without the path. // string $nodeName = match("[^|]*$", $node) + "..."; menuItem -label $nodeName -command ("hyperGraph -e -attributeEditor single -useFeedbackList " + $hypershade); menuItem -divider true; menuItem -divider true; menuItem -divider true; if ( $nodeType == "place3dTexture") { menuItem -label (uiRes("m_buildHypergraphNodePopupMenuItems.kFitToGroupBoundingBox")) -command ("source AEplace3dTextureTemplate.mel; " + "PSfitPlacementToGroup " + $node); string $selection[] = `ls -sl`; if (size($selection) > 0) { string $leadSelectionItem = $selection[0]; $menuDisplayString = (uiRes("m_buildHypergraphNodePopupMenuItems.kParentPlacement")); menuItem -label `format -s $leadSelectionItem $menuDisplayString` -command ("parent " + $node + " " + $leadSelectionItem); } else { menuItem -label (uiRes("m_buildHypergraphNodePopupMenuItems.kParentPlacementToSelection")) -enable false; } menuItem -divider true; } else if (isClassified($node, "shader")) { string $shadingGroupArray[] = stringArrayRemoveDuplicates(`listConnections -source false -destination true -type "shadingEngine" $node`); int $isOceanShader = $nodeType == "oceanShader"; int $groupSize = size($shadingGroupArray); // The "Assign Material Override" option is not supported by Render Setup, only by Legacy Render Layers. if(!mayaHasRenderSetup()) { string $layer = currentRenderLayerLabel(); if ($layer != "" && $layer != "masterLayer") { $menuDisplayString = (uiRes("m_buildHypergraphNodePopupMenuItems.kAssignMaterialOverride")); menuItem -radialPosition "W" -label `format -s $layer $menuDisplayString` -command ("hookShaderOverride(\""+$layer+"\",\"\",\""+$node+"\")"); } } menuItem -label (uiRes("m_buildHypergraphNodePopupMenuItems.kGenSwatch")) -command ("updateFileNodeSwatch(\"" + $node + "\")") -radialPosition "SW" -annotation (uiRes("m_buildHypergraphNodePopupMenuItems.kGenSwatchAnnot")) ; if ( $groupSize <= 1) { string $assignMaterial = (uiRes("m_buildHypergraphNodePopupMenuItems.kAssignMaterialToSelection")); if( $isOceanShader ) { menuItem -radialPosition "N" -label $assignMaterial -command ("assignOceanShader " + $node); } else { menuItem -radialPosition "N" -label $assignMaterial -command ("hyperShade -assign " + $node); menuItem -radialPosition "NE" -label (uiRes("m_buildHypergraphNodePopupMenuItems.kPaintAssignShader")) -command ("shaderPaintTool " + $node); } menuItem -radialPosition "E" -label (uiRes("m_buildHypergraphNodePopupMenuItems.kSelectObjectsWithMaterial")) -command ("hyperShade -objects " + $node); menuItem -label (uiRes("m_buildHypergraphNodePopupMenuItems.kFrameObjectsWithMaterial")) -command ("hyperShade -objects " + $node + ";fitAllPanels -selected"); // The "Remove Material Override" option is not supported by Render Setup, only by Legacy Render Layers. if(!mayaHasRenderSetup()) { menuItem -divider true; string $removeOverrideMenuItem = `menuItem -label (uiRes("m_buildHypergraphNodePopupMenuItems.kRemoveMaterialOverride")) -subMenu true`; menuItem -edit -postMenuCommand ("buildMaterialRemoveOverrideMenu -shader "+$node+" "+$removeOverrideMenuItem) $removeOverrideMenuItem; } setParent -m ..; menuItem -divider true; } else { int $i; $menuDisplayString = (uiRes("m_buildHypergraphNodePopupMenuItems.kAssignToSelection")); // Can only have one element at any radialPosition - choose // last one for backwards compatibility, and add other ones to // overflow menu. // int $radialItem = size($shadingGroupArray)-1; for ($i = 0; $i < size($shadingGroupArray); $i++) { if( $i == $radialItem ){ menuItem -radialPosition "N" -label `format -s $shadingGroupArray[$radialItem] $menuDisplayString` -command ("hyperShade -assign " + $shadingGroupArray[$radialItem]); } else { menuItem -label `format -s $shadingGroupArray[$i] $menuDisplayString` -command ("hyperShade -assign " + $shadingGroupArray[$i]); } } string $menuStr1 = (uiRes("m_buildHypergraphNodePopupMenuItems.kSelectObjects")); string $menuStr2 = (uiRes("m_buildHypergraphNodePopupMenuItems.kFrameObjects")); for ($i = 0; $i < size($shadingGroupArray); $i++) { if( $i == $radialItem ){ menuItem -label `format -s $shadingGroupArray[$i] $menuStr1` -radialPosition "E" -command ("hyperShade -objects " + $shadingGroupArray[$i]); } else { menuItem -label `format -s $shadingGroupArray[$i] $menuStr1` -command ("hyperShade -objects " + $shadingGroupArray[$i]); } menuItem -label `format -s $shadingGroupArray[$i] $menuStr2` -command ("hyperShade -objects " + $shadingGroupArray[$i] + ";fitAllPanels -selected"); } menuItem -divider true; } } else if (isClassified($node, "texture")) { menuItem -label (uiRes("m_buildHypergraphNodePopupMenuItems.kAssignTextureMaterialToSelection")) -radialPosition "N" -command ("hypergraphAssignTextureToSelection " + $node); menuItem -label (uiRes("m_buildHypergraphNodePopupMenuItems.kTestTexture")) -command ("select -replace " + `hyperGraph -query -feedbackNode $hypershade` + ";TestTexture;") -radialPosition "W" -annotation (getRunTimeCommandAnnotation ("TestTexture")) ; if( $nodeType == "psdFileTex" ) { menuItem -label (uiRes("m_buildHypergraphNodePopupMenuItems.kConvertToLayeredTexture")) -command ("hypergraphConvertPsdToLTNetwork " + $node) -radialPosition "SW" -annotation (uiRes("m_buildHypergraphNodePopupMenuItems.kConvertToLayeredTextureAnnot")) ; menuItem -label (uiRes("m_buildHypergraphNodePopupMenuItems.kConvertToFileTexture")) -command ("hypergraphConvertPsdToFile " + $node) -radialPosition "NW" -annotation (uiRes("m_buildHypergraphNodePopupMenuItems.kConvertToFileTextureAnnot")) ; } menuItem -label (uiRes("m_buildHypergraphNodePopupMenuItems.kRenderTextureRange")) -command ("select -replace " + `hyperGraph -query -feedbackNode $hypershade` + ";RenderTextureRange;") -radialPosition "E" -annotation (getRunTimeCommandAnnotation ("RenderTextureRange")) ; if( ( $nodeType == "psdFileTex" ) || ( $nodeType == "file" )) { menuItem -label (uiRes("m_buildHypergraphNodePopupMenuItems.kEditTexture")) -command ("hyperShadeEditTexture " + $node) -radialPosition "SE" -annotation (getRunTimeCommandAnnotation ("EditTexture")) ; } menuItem -label `uiRes( "m_buildHypergraphNodePopupMenuItems.kGenSwatch" )` -command ("updateFileNodeSwatch(\"" + $node + "\")") -radialPosition "SW" -annotation `uiRes( "m_buildHypergraphNodePopupMenuItems.kGenSwatchAnnot" )` ; if ($nodeType == "file") { menuItem -label (uiRes("m_buildHypergraphNodePopupMenuItems.kReloadImageFile")) -command ("string $name=`getAttr " + $node + ".fileTextureName`;" + "setAttr " + $node + ".fileTextureName " + "-type \"string\" $name;"); menuItem -divider true; } } else if (isClassified($node, "utility")) { // test to make sure the utility node has an output connection // if it does not, convertSolidTx will fail // // a utility node will always be connected to defaultRenderUtilityList // so we want to make sure it has more than 1 connection string $connections[] = `listConnections -s 0 -d 1 $node`; if (`size ($connections)` > 1){ menuItem -label (uiRes("m_buildHypergraphNodePopupMenuItems.kUtilityAssignTextureMaterialToSelection")) -radialPosition "N" -command ("hypergraphAssignTextureToSelection " + $node); menuItem -label (uiRes("m_buildHypergraphNodePopupMenuItems.kUtilityTestTexture")) -command ("select -replace " + `hyperGraph -query -feedbackNode $hypershade` + ";TestTexture;") -radialPosition "W" -annotation (getRunTimeCommandAnnotation ("TestTexture")) ; menuItem -label (uiRes("m_buildHypergraphNodePopupMenuItems.kUtilityRenderTextureRange")) -command ("select -replace " + `hyperGraph -query -feedbackNode $hypershade` + ";RenderTextureRange;") -radialPosition "E" -annotation (getRunTimeCommandAnnotation ("RenderTextureRange")) ; } } else if (isClassified($node, "light")) { menuItem -label (uiRes("m_buildHypergraphNodePopupMenuItems.kMakeLinksWithSelectedObjects")) -command ("lightlink -make -light "+$node+" -useActiveObjects"); menuItem -label (uiRes("m_buildHypergraphNodePopupMenuItems.kBreakLinksWithSelectedObjects")) -command ("lightlink -break -light "+$node+" -useActiveObjects"); menuItem -divider true; menuItem -label (uiRes("m_buildHypergraphNodePopupMenuItems.kSelectObjectsIlluminatedByLight")) -radialPosition "E" -command ("selectObjectsIlluminatedBy "+$node); menuItem -label (uiRes("m_buildHypergraphNodePopupMenuItems.kFrameObjectsIlluminatedByLight")) -command ("selectObjectsIlluminatedBy "+$node+"; fitAllPanels -selected"); menuItem -divider true; } else if ($nodeType == "textureBakeSet" || $nodeType == "vertexBakeSet" ) { menuItem -label (uiRes("m_buildHypergraphNodePopupMenuItems.kAssignSelectionToBakeSet")) -radialPosition "N" -command ("sets -forceElement " + $node + " `ls -dag -objectsOnly -geometry -selection`" ); menuItem -label (uiRes("m_buildHypergraphNodePopupMenuItems.kSelectObjectsInBakeSet")) -radialPosition "E" -command ("select " + $node); menuItem -label (uiRes("m_buildHypergraphNodePopupMenuItems.kFrameObjectsInBakeSet")) -command ("select " + $node + " ;fitAllPanels -selected"); menuItem -divider true; } else if ($nodeType == "animClip") { menuItem -label (uiRes("m_buildHypergraphNodePopupMenuItems.kCopy")) -annotation (uiRes("m_buildHypergraphNodePopupMenuItems.kCopyAnnot")) -command ("clipCopyMenuCommand " + $node) ClipCopyItem; menuItem -label (uiRes("m_buildHypergraphNodePopupMenuItems.kInstance")) -annotation (uiRes("m_buildHypergraphNodePopupMenuItems.kInstanceAnnot")) -command ("clipInstanceMenuCommand " + $node) ClipInstanceItem; menuItem -label (uiRes("m_buildHypergraphNodePopupMenuItems.kDuplicate")) -annotation (uiRes("m_buildHypergraphNodePopupMenuItems.kDuplicateClip")) -command ("clipDuplicateMenuCommand " + $node) ClipDuplicateItem; menuItem -label (uiRes("m_buildHypergraphNodePopupMenuItems.kExport")) -annotation (uiRes("m_buildHypergraphNodePopupMenuItems.kExportClip")) -command ("doExportClipArgList 2 { \"\", \"" + $node + "\"}") ClipExportItem; menuItem -divider true; menuItem -label (uiRes("m_buildHypergraphNodePopupMenuItems.kApplyPose")) -annotation (uiRes("m_buildHypergraphNodePopupMenuItems.kApplyPoseAnnot")) -command ("clipApplyPoseMenuCommand " + $node) ClipApplyPoseItem; menuItem -divider true; } if ($nodeType == "colorProfile") { menuItem -label (uiRes("m_buildHypergraphNodePopupMenuItems.kApplyColorProfileToSelected")) -annotation (uiRes("m_buildHypergraphNodePopupMenuItems.kApplyColorProfileToSelectedAnnotaton")) -command ("applyColorProfileToSelection " + $node) ColorProfileApplyToSelection; menuItem -divider true; } menuItem -label (uiRes("m_buildHypergraphNodePopupMenuItems.kSelectInputNodes")) -command ("select -noExpand `listHistory " + $node + "`") -annotation (uiRes("m_buildHypergraphNodePopupMenuItems.kSelectInputNodesAnnot")); menuItem -label (uiRes("m_buildHypergraphNodePopupMenuItems.kSelectOutputNodes")) -command ("select -noExpand `listHistory -future true " + $node + "`") -annotation (uiRes("m_buildHypergraphNodePopupMenuItems.kSelectOutputNodesAnnot")); menuItem -divider true; menuItem -label (uiRes("m_buildHypergraphNodePopupMenuItems.kRename")) -command ("hyperGraph -e -rename -useFeedbackList " + $hypershade); menuItem -divider true; menuItem -label (uiRes("m_buildHypergraphNodePopupMenuItems.kCreateNewAsset")) -command ("createContainerWithNodes(`ls -sl`)") -annotation (uiRes("m_buildHypergraphNodePopupMenuItems.kCreateNewAssetAnnot")); if( `container -q -isContainer $node` ) { menuItem -label (uiRes("m_buildHypergraphNodePopupMenuItems.kSelectAssetContent")) -command ("select -r `container -q -nl " + $node + "`") -annotation (uiRes("m_buildHypergraphNodePopupMenuItems.kSelectAssetContentAnnot")); menuItem -enable (`container -q -current` != $node) -label (uiRes("m_buildHypergraphNodePopupMenuItems.kSetAssetCurrent")) -command ("container -e -c 1 " + $node ) -annotation (uiRes("m_buildHypergraphNodePopupMenuItems.kSetContainerCurrentAnnot")); menuItem -label (uiRes("m_buildHypergraphNodePopupMenuItems.kLayoutAsset")) -annotation (uiRes("m_buildHypergraphNodePopupMenuItems.kLayoutAssetAnnot")) -enable ( `getAttr ($node + ".isCollapsed")` == 0 ) -subMenu true; menuItem -label (uiRes("m_HyperGraphEdMenu.kHierarchicalLayout")) -command ("hyperGraph -e -layoutSelected hierarchicalLayout -useFeedbackList " + $hypershade); menuItem -label (uiRes("m_HyperGraphEdMenu.kSetBackgroundImage")) -command ("python(\"import maya.app.general.adjustBackgroundImageWin as modu; modu.adjustBackgroundImageWin('" + $hypershade +"')\")"); string $nodesToAdd = getNodesToAddToContainer($node); menuItem -label (uiRes("m_buildHypergraphNodePopupMenuItems.kAddToAsset")) -enable (size($nodesToAdd) > 0) -command ("container -e -f -an "+$nodesToAdd+" "+$node); } callbacks -executeCallbacks -hook "addItemsToHypergraphNodePopupMenu" $node; // If the mouse is RMB over a node that is not selected, // then only act on it, otherwise act on all selected nodes. // string $removeNodes = getNodesToRemoveFromContainer($node); menuItem -label (uiRes("m_buildHypergraphNodePopupMenuItems.kRemoveFromAsset")) -enable (size($removeNodes) > 0) -command ("removeNodesFromContainer("+$removeNodes+",\"\",0)"); }