Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

EMSUSD-676 use the outliner menu in the viewport #3375

Merged
merged 2 commits into from
Oct 16, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
211 changes: 1 addition & 210 deletions plugin/adsk/scripts/USDMenuProc.mel
Original file line number Diff line number Diff line change
Expand Up @@ -24,166 +24,6 @@ proc string expandToSelection(string $obj)
}
}

proc int canEditAsMaya(string $obj)
{
if (!hasPrimUpdater())
return 0;

if (size($obj) != 0) {
return `python("from mayaUsd.lib import PrimUpdaterManager; PrimUpdaterManager.canEditAsMaya('" + $obj + "')")`;
}
return 0;
}

proc int canDupAsMaya(string $obj)
{
string $typ = `nodeType $obj`;
return $typ != "MayaReference";
}

global proc mayaUsdMenu_editAsMaya(string $obj)
{
if (!hasPrimUpdater())
return;

if (size($obj) != 0) {
mayaUsdEditAsMaya $obj;
}
}

global proc mayaUsdMenu_duplicate(string $ufePath)
{
if (!hasPrimUpdater())
return;

if (size($ufePath)) {
mayaUsdDuplicate $ufePath "|world";
}
}

global proc mayaUsdMenu_assignNewMaterial(string $ufePath, string $material)
{
if (!hasPrimUpdater())
return;

if (size($ufePath) != 0 && size($material) != 0) {
string $temp = `python("import ufe;\
ufePath = ufe.PathString.path('" + $ufePath + "');\
item = ufe.Hierarchy.createItem(ufePath);\
contextOps = ufe.ContextOps.contextOps(item);\
cmd = contextOps.doOpCmd(['Assign New Material', '', '" + $material + "']);\
ufe.UndoableCommandMgr.instance().executeCmd(cmd);")`;
}
}

global proc mayaUsdMenu_assignExistingMaterial(string $ufePath, string $material)
{
if (!hasPrimUpdater())
return;

if (size($ufePath) != 0 && size($material) != 0) {
string $temp = `python("import ufe;\
ufePath = ufe.PathString.path('" + $ufePath + "');\
item = ufe.Hierarchy.createItem(ufePath);\
contextOps = ufe.ContextOps.contextOps(item);\
cmd = contextOps.doOpCmd(['Assign Existing Material', '', '" + $material + "']);\
ufe.UndoableCommandMgr.instance().executeCmd(cmd);")`;
}
}

global proc mayaUsdMenu_addNewMaterials(string $ufePath)
{
string $materials[] = `mayaUsdGetMaterialsFromRenderers`;
string $previousRendererString;
string $menuItem;
for ($material in $materials)
{
// We want our materials grouped into submenus according to their path in the hierarchy.
string $rendererAndMaterial[];
$numTokens = `tokenize $material "/" $rendererAndMaterial`;

// Expects tokenized string in the form "RendererName/Material Name|MaterialIdentifer"
if ($numTokens != 2)
continue;

string $materialName = $rendererAndMaterial[$numTokens - 1];

// Get a string containing the path to the material without the name of the material itself.
string $renderer[] = $rendererAndMaterial;
stringArrayRemoveAtIndex($numTokens - 1, $renderer);
string $rendererString = stringArrayToString($renderer, "/");

// Create a new submenu for each path.
if ($previousRendererString != $rendererString)
{
if ($menuItem != "")
{
setParent -menu ..;
}

$previousRendererString = $rendererString;
$menuItem = `menuItem -subMenu true -tearOff false -label $rendererString`;
}

string $labelAndIdentifier[];
$numTokens = `tokenize $materialName "|" $labelAndIdentifier`;

// Expects tokenized string in the form "Material Name|MaterialIdentifer"
if ($numTokens != 2)
continue;

menuItem -label $labelAndIdentifier[0] -command ("mayaUsdMenu_assignNewMaterial \"" + $ufePath + "\" \"" + $labelAndIdentifier[1] + "\"");
}
setParent -menu ..;
}

global proc mayaUsdMenu_addExistingMaterials(string $ufePath)
{
string $materials[] = `mayaUsdGetMaterialsInStage $ufePath`;
string $previousPathString;
string $menuItem;
for ($material in $materials)
{
// We want our materials grouped into submenus according to their path in the hierarchy.
string $pathAndMaterial[];
$numTokens = `tokenize $material "/" $pathAndMaterial`;

string $materialName = $pathAndMaterial[$numTokens - 1];

// Get a string containing the path to the material without the name of the material itself.
string $path[] = $pathAndMaterial;
stringArrayRemoveAtIndex($numTokens - 1, $path);
string $pathString = "/" + stringArrayToString($path, "/");

// Create a new submenu for each path.
if ($previousPathString != $pathString)
{
if ($menuItem != "")
{
setParent -menu ..;
}

$previousPathString = $pathString;
$menuItem = `menuItem -subMenu true -tearOff false -label $pathString`;
}

menuItem -label $materialName -parent $menuItem -command ("mayaUsdMenu_assignExistingMaterial \"" + $ufePath + "\" \"" + $material + "\"");
}
setParent -menu ..;
}

global proc mayaUsdMenu_unassignMaterial(string $ufePath)
{
if (size($ufePath) != 0) {
string $temp = `python("import ufe;\
ufePath = ufe.PathString.path('" + $ufePath + "');\
item = ufe.Hierarchy.createItem(ufePath);\
contextOps = ufe.ContextOps.contextOps(item);\
cmd = contextOps.doOpCmd(['Unassign Material']);\
ufe.UndoableCommandMgr.instance().executeCmd(cmd);")`;
}
}

global proc mayaUsdMenu_EditAsMayaDataOptionsCallback(string $optionsString)
seando-adsk marked this conversation as resolved.
Show resolved Hide resolved
{
optionVar -stringValue usdMaya_EditAsMayaDataOptions $optionsString;
Expand Down Expand Up @@ -264,58 +104,9 @@ global proc mayaUsdMenu_EditAsMayaDataOptions(string $obj)
// following procedure.
global proc USDMenuProc(string $parent, string $obj)
{
if (!hasPrimUpdater())
return;

$obj = expandToSelection($obj);
if (size($obj) != 0)
{
popupMenu -e -dai $parent;
setParent -menu $parent;

setParent -menu ..;
if (canEditAsMaya($obj)) {
menuItem -label `getMayaUsdString("kEditAsMayaData")` -image "edit_as_Maya.png" -command ("{waitCursor -state 1; mayaUsdMenu_editAsMaya \"" + $obj + "\"; waitCursor -state 0;}");
menuItem -command ("{mayaUsdMenu_EditAsMayaDataOptions \"" + $obj + "\";}") -optionBox true;
}
if (canDupAsMaya($obj)) {
menuItem -label "Duplicate As Maya Data" -command ("{waitCursor -state 1; mayaUsdMenu_duplicate \"" + $obj + "\"; waitCursor -state 0;}");
}

menuItem -divider true;

// Material-related options should only be shown if the right-clicked object is of a type known to support material bindings.
int $allowMaterialFunctions = `mayaUsdMaterialBindings $obj -canAssignMaterialToNodeType true`;
if ($allowMaterialFunctions)
{
// "Assign New Material" from a list of materials provided by the renderers.
menuItem -subMenu true -tearOff false -label "Assign New Material";
{
mayaUsdMenu_addNewMaterials($obj);
}
setParent -menu ..;

// Only show if we have materials in the stage.
string $materials[] = `mayaUsdGetMaterialsInStage $obj`;
if (size($materials) > 0)
{
// "Assign Existing Material" from a list of materials in the selected item's stage.
menuItem -subMenu true -tearOff false -label "Assign Existing Material";
{
mayaUsdMenu_addExistingMaterials($obj);
}
setParent -menu ..;
}

// Only show the following entry if the object actually has a material assigned.
int $hasMaterialBindingAPI = `mayaUsdMaterialBindings $obj -hasMaterialBinding true`;
if ($hasMaterialBindingAPI)
{
// Unassign (aka "unbind") the material from the selected object.
menuItem -label "Unassign Material" -command ("{waitCursor -state 1; mayaUsdMenu_unassignMaterial \"" + $obj + "\"; waitCursor -state 0;}");
}
}
}
python("import maya.app.ufe.outlinerSupport; maya.app.ufe.outlinerSupport.buildNonMayaContextMenu('''" + $obj + "''')");

// Allow the user to define a proc with additional menu items
if (`exists USDUserMenuProc`)
Expand Down