From 1081aa551e1f52b9c1eec2bd71fb455f925cb29f Mon Sep 17 00:00:00 2001 From: Bohdon Sayre Date: Tue, 29 Aug 2023 16:22:54 -0400 Subject: [PATCH] add rmbmenuhook overrides for Maya 2024 --- .../rmbmenuhook/rmbmenuhookOverrides2024.mel | 722 ++++++++++++++++++ 1 file changed, 722 insertions(+) create mode 100644 src/workflowtools/scripts/rmbmenuhook/rmbmenuhookOverrides2024.mel diff --git a/src/workflowtools/scripts/rmbmenuhook/rmbmenuhookOverrides2024.mel b/src/workflowtools/scripts/rmbmenuhook/rmbmenuhookOverrides2024.mel new file mode 100644 index 0000000..ddb29f6 --- /dev/null +++ b/src/workflowtools/scripts/rmbmenuhook/rmbmenuhookOverrides2024.mel @@ -0,0 +1,722 @@ +/* + Contains overridden global procedures for Maya 2023 + + These overridden functions have hooks added that make + calls to the rmb menu manager. + + The following procedures are overridden: + buildObjectMenuItemsNow + dagMenuProc + optionalDagMenuProc (referenced by dagMenuProc and not global) + setUpArtisanSkinContext (referenced by dagMenuProc and not global) +*/ + + +//Copied from from /scripts/others/buildObjectMenuItemsNow.mel +//=========================================================================== + + +//This procedure is called from ModelEdMenu as a postMenuCommand +global proc buildObjectMenuItemsNow( string $parentName) +{ + if (`exists DRUseModelingToolkitMM` && DRUseModelingToolkitMM($parentName)) { + return; + } + + global int $gIsMarkingMenuOn; + + if (`popupMenu -e -exists $parentName`) { + popupMenu -e -deleteAllItems $parentName; + if (`popupMenu -q -mm $parentName` != $gIsMarkingMenuOn) { + popupMenu -e -mm $gIsMarkingMenuOn $parentName; + } + + int $editMode = 0; + string $currentContext = `currentCtx`; + if (`contextInfo -exists $currentContext`) { + string $ctx = `contextInfo -c $currentContext`; + if ($ctx == "manipMove") { + $editMode = `manipMoveContext -q -editPivotMode Move`; + } else if ($ctx == "manipScale") { + $editMode = `manipScaleContext -q -editPivotMode Scale`; + } else if ($ctx == "manipRotate") { + $editMode = `manipRotateContext -q -editPivotMode Rotate`; + } else if ($ctx == "sculptMeshCache") { + setParent -menu $parentName; + sculptMeshCacheOptionsPopup(); + return; + } else if ($ctx == "polyCutUV") { + setParent -menu $parentName; + polyCutUVOptionsPopup(); + return; + } + else if(contextXGenToolsMM($parentName)) + { + return; + } + else if ($ctx == "bpDraw" && `pluginInfo -q -l bluePencil`) { + setParent -menu $parentName; + bpDrawOptionsPopup(); + return; + } + } + + if ($editMode) { + setParent -menu $parentName; + + menuItem + -label (uiRes("m_buildObjectMenuItemsNow.kPinComponentPivot")) + -checkBox `manipPivot -q -pin` + -radialPosition "N" + -command ("setTRSPinPivot #1"); + + menuItem + -label (uiRes("m_buildObjectMenuItemsNow.kResetPivot")) + -radialPosition "S" + -command ("manipPivotReset true true"); + + menuItem + -label (uiRes("m_buildObjectMenuItemsNow.kSnapPivotOrientation")) + -checkBox `manipPivot -q -snapOri` + -radialPosition "NW" + -command ("setTRSSnapPivotOri #1"); + + menuItem + -label (uiRes("m_buildObjectMenuItemsNow.kSnapPivotPosition")) + -checkBox `manipPivot -q -snapPos` + -radialPosition "NE" + -command ("setTRSSnapPivotPos #1"); + + menuItem + -label (uiRes("m_buildObjectMenuItemsNow.kResetPivotOrientation")) + -radialPosition "SW" + -command ("manipPivotReset false true"); + + menuItem + -label (uiRes("m_buildObjectMenuItemsNow.kResetPivotPosition")) + -radialPosition "SE" + -command ("manipPivotReset true false"); + + menuItem + -label (uiRes("m_buildObjectMenuItemsNow.kShowPivotOrientationHandle")) + -checkBox `optionVar -q manipShowPivotRotateHandle` + -radialPosition "W" + -command ("setTRSPivotOriHandle #1"); + + menuItem + -label (uiRes("m_buildObjectMenuItemsNow.kExitPivotMode")) + -radialPosition "E" + -command ("ctxEditMode"); + + // Lower non-gestural menu items + + menuItem + -label (uiRes("m_buildObjectMenuItemsNow.kBakePivotOri")) + -checkBox `manipPivot -q -bakeOri` + -command ("setTRSBakePivotOri #1"); + + setParent ..; + } else { + if (!`dagObjectHit -mn $parentName`) { + // Nothing was hit - check selection/hilight list. + // Include UFE objects, and ask for long names so we can properly check + // the type. + string $leadObject[] = `ls -sl -tail 1 -typ transform -typ shape`; + + if (size($leadObject) == 0) { + $leadObject = `ls -hl -tail 1 -typ transform -typ shape`; + } + if (size($leadObject) > 0) { + // MAYA-67156: Something is selected/hilighted so pass + // an empty object to dagMenuProc to indicate nothing was + // under the cursor and let it decide what object(s) to use + dagMenuProc($parentName, ""); + + // RMBHOOK CHANGES + } else if (rmbmenuhook_buildMenu($parentName)) { + return; + // RMBHOOK END CHANGES + + } else { + // No native Maya objects selected, but could be a UFE runtime object + $leadObject = `ls -sl -ufe -long -tail 1 -typ transform -typ shape`; + + string $ufeRuntime = "Maya-DG"; + if (size($leadObject) > 0) { + $ufeRuntime = `nodeType -ufeRuntimeName $leadObject[0]`; + } + + if ( "Maya-DG" != $ufeRuntime) { + // Empty string for the object name is an indication that the user did not + // click on an object, we looked at what was selected to decide what + // script to call. Also including the ufe runtime name which the proc + // uses to look up a runtime-specific proc. + ufeMenuProc($parentName, "", $ufeRuntime); + return; + } + + if (`modelingTookitActive` && (`nexCtx -rmbComplete -q`) ) { + ctxCompletion; + return; + } + + setParent -menu $parentName; + + menuItem + -version "2014" + -label (uiRes("m_buildObjectMenuItemsNow.kSelectAll")) + -radialPosition "S" + -command ("SelectAll"); + + menuItem + -label (uiRes("m_buildObjectMenuItemsNow.kCompleteTool")) + -radialPosition "N" + -command ("CompleteCurrentTool"); + + setParent ..; + } + } + } + } else { + warning (uiRes("m_buildObjectMenuItemsNow.kParentWarn")); + } +} + + + + + + +//Copied from /scripts/others/dagMenuProc.mel +//=========================================================================== + + +proc optionalDagMenuProc( string $parent, string $item ) +{ + // Look at the shape child of this object + // + string $object[] = `listRelatives -path -s $item`; + + string $shape = ""; + int $gotVisible = 0; + + if( size($object) < 1 ) return; + + for( $i=0; $i 0) { + $object = $leadObject[0]; + } + } + + if( hasTraversalMM() ){ + global int $gTraversal; + if( $gTraversal ){ + if (`popupMenu -e -exists $parent`) { + setParent -m $parent; + buildTraversalMM( $object ); + } + return; + } + } + if (`exists modelingTookitActive` && `modelingTookitActive` && (`nexCtx -q -rmbComplete`) ) { + ctxCompletion; + return; + } + global string $gArtSelectObject ; + string $mode = ""; + + if (`optionVar -exists currentMenuBarTab`) { + $mode = `optionVar -q currentMenuBarTab`; + } else { + optionVar -category "Interface" -sv currentMenuBarTab $mode; + } + + if (($object == "CubeCompass")) + { + createViewCubeMenuItems($parent); + return; + } + + if (`popupMenu -e -exists $parent`) { + setParent -m $parent; + + // RMBHOOK CHANGES + if (rmbmenuhook_buildMenuWithObject($parent, $object)) { + return; + } + // RMBHOOK END CHANGES + + string $currContext = `currentCtx`; + if ( $currContext == "artAttrSkinContext" ) + { + setUpArtisanSkinContext($parent, $object); + } + else + { + // label the object + string $shortName = `substitute ".*|" $object ""`; + menuItem -label ($shortName + "...") -c ("showEditor "+$object); + menuItem -divider true; + menuItem -divider true; + + // Create the list of selection masks + createSelectMenuItems($parent, $object, $defaultObject); + + menuItem -d true; + + menuItem -label (uiRes("m_dagMenuProc.kSelect")) -c ("select -r " + $object); + menuItem -version "2014" -label (uiRes("m_dagMenuProc.kSelectAll")) -c ("SelectAll"); + menuItem -version "2014" -label (uiRes("m_dagMenuProc.kDeselect")) -c ("SelectNone;"); + menuItem -label (uiRes("m_dagMenuProc.kSelectHierarchy")) -c ("select -hierarchy " + $object); + menuItem -version "2014" -label (uiRes("m_dagMenuProc.kInverseSelection")) -c ("InvertSelection"); + string $container = `container -q -fc $object`; + if( $container != "" ){ + string $containerLabel = ""; + if(`assembly -query -isa $container`){ + $containerLabel = (uiRes("m_dagMenuProc.kSelectAssembly")); + } + else + { + $containerLabel = (uiRes("m_dagMenuProc.kSelectContainer")); + } + menuItem -label $containerLabel -c ("select -r " + $container); + } + + menuItem -d true; + + if(`pluginInfo -q -loaded "modelingToolkit"`) { + menuItem -version "2014" -label (uiRes("m_dagMenuProc.kSelectSimilar")) -c ("SelectSimilar"); + menuItem -optionBox true -c ("SelectSimilarOptions"); + + menuItem -d true; + } + + menuItem -d true; + menuItem -version "2014" -c ("makeLive " + $object) -en (`canMakeLive $object`) -label (uiRes("m_dagMenuProc.kMakeLive")); + menuItem -d true; + + optionalDagMenuProc( $parent, $object ); + + // Create the dg traversal menu + // + string $menu = `menuItem -subMenu true -aob true -label (uiRes("m_dagMenuProc.kDGTraversal")) `; + menu -e + -pmc ( "createTraversalMenuItems \""+$menu+"\" "+$object ) $menu; + setParent -m $parent; + + // create the history menu + // + $menu = `menuItem -subMenu true -aob true -label (uiRes("m_dagMenuProc.kInputs")) `; + menu -e + -pmc ( "createHistoryMenuItems \""+$menu+"\" "+$object ) $menu; + setParent -m $parent; + + $menu = `menuItem -subMenu true -aob true -label (uiRes("m_dagMenuProc.kOutputs")) `; + menu -e -pmc ( "createFutureMenuItems \""+$menu+"\" "+$object ) $menu; + setParent -m $parent; + + // Look at the shape child of this object + // + string $shapes[] = `listRelatives -path -s $object`; + // get current selection of shapes + string $currentSel[] = `ls -sl -dagObjects -shapes` ; + + string $paintParent = "" ; + int $selIndex ; + + int $i; + for ($i = 0; $i < size($shapes); ++$i) + { + string $nodeType = `nodeType $shapes[$i]` ; + + if ( ( $nodeType == "nurbsSurface") || + ( $nodeType == "mesh") || + ( $nodeType == "subdiv")) + { + // save the object name if it is not already selected by the user + // We use this info to select the object if user chooses a paint option + // + // If user has selected multiple objects and is using context menu on one of them + // we do not change the selection list as user may want to paint some attribute + // on all of them. (It is the way it has been working all along...we don't want to + // break it ) + + int $found = 0 ; + for( $selIndex = 0 ; $selIndex < size( $currentSel ); ++$selIndex ) + { + if( $shapes[$i] == $currentSel[ $selIndex ] ) + { + $found = 1 ; + break ; + } + } + + if( $found ) + { + $gArtSelectObject = "" ; + } + else + { + // check if the object is in component selection mode + // and if it is, do not do any further selection. + // We are assuming that if the object is in hilite mode + // then the user is in component selection mode. + + $currentSel = `ls -hilite` ; + for( $selIndex = 0 ; $selIndex < size( $currentSel ); ++$selIndex ) + { + if( $object == $currentSel[ $selIndex ] ) + { + $found = 1 ; + break ; + } + } + + if( !$found ) + $gArtSelectObject = $object ; + else + $gArtSelectObject = "" ; + } + + $paintParent = `menuItem -subMenu true -aob true -label (uiRes("m_dagMenuProc.kPaintSubmenu")) `; + menu -e -pmc ( "createArtAttrMenuItems \""+ $paintParent +"\" "+$object ) $paintParent ; + setParent -m $parent; + break ; + } + } + + // menuitem for metadata in right click menu list + $menu = `menuItem -version 2016 -label (uiRes("m_dagMenuProc.kMetadataMenu")) -subMenu true`; + menu -e -pmc ( "createMetadataMenuItems \""+$menu+"\" "+$object ) $menu; + setParent -m $parent; + + $menu = `menuItem -subMenu true -label (uiRes("m_dagMenuProc.kActions")) `; + menu -e -pmc ( "createActionsMenuItems \""+$menu+"\" "+$object ) $menu; + + setParent -m $parent; + + // If the object can handle uv sets then add the uvset menu + // + string $shape = objectHandlesUvSets( $object ); + if ($shape != "") + { + $menu = `menuItem -subMenu true -label (uiRes("m_dagMenuProc.kUVSets")) `; + menu -e + -pmc ( "createUVsetMenuItems \""+$menu+"\" " +$object + " "+ $shape ) + $menu; + setParent -m $parent; + } + + $shape = objectHandlesColorSets( $object ); + if ($shape != "") + { + $menu = `menuItem -subMenu true -label (uiRes("m_dagMenuProc.kColorSets")) `; + menu -e + -pmc ( "createColorSetMenuItems \""+$menu+"\" " +$object + " "+ $shape ) + $menu; + setParent -m $parent; + } + $menu = `menuItem -subMenu true -label (uiRes("m_dagMenuProc.kCTEMenu")) -version 2017`; + menu -e + -pmc ( "createTimeEditorMenuItems \""+$menu+"\" ") + $menu; + setParent -m $parent; + + if(size(`assembly -q -listTypes`) > 0){ + menuItem -d true; + $menu = `menuItem -subMenu true -label (uiRes("m_dagMenuProc.kSceneAssemblyMenuProc")) `; + menu -e -pmc ( "createSceneAssemblyMenuItems \""+$menu+"\"" ) $menu; + setParent -m $parent; + } + // Shader menu to be able to quickly assign existing shaders + // to the object under the pointer. + // + menuItem -d true; + + menuItem -label (uiRes("m_dagMenuProc.kMaterialAttributes")) -c ("showSG "+$object); + + menuItem -d true; + + buildShaderMenus($object); + // The "Remove Material Override" option is not supported by Render Setup, only by Legacy Render Layers. + if(!mayaHasRenderSetup()) + { + menuItem -d true; + + menuItem -divider true; + + string $removeOverrideMenuItem = `menuItem + -label (uiRes("m_dagMenuProc.kRemoveMaterialOverride")) + -subMenu true`; + menuItem -edit -postMenuCommand + ("buildMaterialRemoveOverrideMenu -surface "+$object+" "+$removeOverrideMenuItem) + $removeOverrideMenuItem; + } + setParent -m ..; + + // Giving the chance to third parties to add their baking menu items + // + callbacks -executeCallbacks -hook "addRMBBakingMenuItems" $object; + setParent -m $parent; + + if ($mode == "dynamicsMenuSet") { + menuItem -d true; + menuItem -label (uiRes("m_dagMenuProc.kConnectField")) -c ("connectDynamic -f " + $object); + menuItem -label (uiRes("m_dagMenuProc.kConnectEmitter")) -c ("connectDynamic -em " + $object); + menuItem -label (uiRes("m_dagMenuProc.kConnectCollision")) -c ("connectDynamic -c " + $object); + } + + // is there a reference associated with the object ? + // and if so, is it in a loaded or unloaded state? + string $refNode = `getRelatedReference $object`; + + if( size($refNode) > 0) + { + // Check if this reference node is associated with multiple representation. + string $refObjects[] = `listConnections -s 0 -d 1 -type representation ($refNode+".message")`; + if (size($refObjects) == 0) // The referende node is not associated with multiple representation, can show reference related menuItems. + { + menuItem -d true; + if( `file -rfn $refNode -q -dr` ) { + menuItem -label (uiRes("m_dagMenuProc.kLoadRelatedReference")) -c ("loadRelatedReference " + $object); + } else { + menuItem -label (uiRes("m_dagMenuProc.kReloadRelatedReference")) -c ("loadRelatedReference " + $object); + menuItem -label (uiRes("m_dagMenuProc.kUnloadRelatedReference")) -c ("unloadRelatedReference " + $object); + } + // Is this reference a proxy? If so, add proxy switch submenu + // + string $proxyNodes[] = `getRelatedProxies $refNode`; + if(size($proxyNodes) > 0) { + $menu = `menuItem -subMenu true -label (uiRes("m_dagMenuProc.kReloadProxy")) `; + menu -e + -pmc ( "createSwitchProxyMenuItems \""+$menu+"\" "+$object + " " + $refNode ) + $menu; + setParent -m $parent; + } + } + } + + $container = `container -q -findContainer { $object }`; + + if (size($container) > 0) + { + string $menuProc = `getAttr ($container+".rmbCommand")`; + if (size($menuProc) > 0) + { + if (`exists $menuProc`) + { + string $menuItems[] = `eval $menuProc`; + int $mm; + int $menuCount = size($menuItems); + if ($menuCount % 2 != 0) + { + // the user provided an invalid # of items, skip + // the last + // + $menuCount--; + } + if ($menuCount > 0) { + string $containerType = `getAttr ($container + ".containerType")`; + if ($containerType == "") + { + menuItem -d true; + menuItem - subMenu true -label (uiRes("m_dagMenuProc.kCustom")); + } + else + { + menuItem -d true; + menuItem -subMenu true -label ($containerType); + } + for ($mm = 0; $mm < $menuCount; $mm+=2) + { + menuItem -label $menuItems[$mm] -c ($menuItems[$mm+1]+" "+$object); + } + } + } + else { + string $warnStr = (uiRes("m_dagMenuProc.kSkippedRmb")); + warning(`format -s $menuProc $warnStr`); + } + } + } + + setParent -m $parent; + + } + } else { + string $warn = (uiRes("m_dagMenuProc.kMenuWarn")); + warning(`format -s $parent $warn`); + } +}