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

MAYA-122014 support duplicate to Maya to non root #2166

Merged
merged 2 commits into from
Mar 9, 2022
Merged
Show file tree
Hide file tree
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
11 changes: 11 additions & 0 deletions lib/mayaUsd/fileio/primUpdaterManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1108,6 +1108,17 @@ bool PrimUpdaterManager::duplicate(
// to configure the updater
ctxArgs[UsdMayaPrimUpdaterArgsTokens->copyOperation] = true;

// Set destination of duplicate. The Maya world MDagPath is not valid,
// so don't try to validate the path if it is the world root.
MDagPath pullParentPath;
if (!MayaUsd::ufe::isMayaWorldPath(dstPath)) {
pullParentPath = MayaUsd::ufe::ufeToDagPath(dstPath);
if (!pullParentPath.isValid()) {
return false;
}
}
ctxArgs[kPullParentPathKey] = VtValue(std::string(pullParentPath.fullPathName().asChar()));

UsdMayaPrimUpdaterContext context(
srcProxyShape->getTime(), srcProxyShape->getUsdStage(), ctxArgs);

Expand Down
5 changes: 5 additions & 0 deletions lib/mayaUsd/ufe/Utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -372,6 +372,11 @@ MDagPath ufeToDagPath(const Ufe::Path& ufePath)
);
}

bool isMayaWorldPath(const Ufe::Path& ufePath)
{
return (ufePath.runTimeId() == g_MayaRtid && ufePath.size() == 1);
}

PXR_NS::MayaUsdProxyShapeBase* getProxyShape(const Ufe::Path& path)
{
// Path should not be empty.
Expand Down
4 changes: 4 additions & 0 deletions lib/mayaUsd/ufe/Utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,10 @@ Ufe::PathSegment dagPathToPathSegment(const MDagPath& dagPath);
MAYAUSD_CORE_PUBLIC
MDagPath ufeToDagPath(const Ufe::Path& ufePath);

//! Verify if the UFE path is the Maya world (root) path.
MAYAUSD_CORE_PUBLIC
bool isMayaWorldPath(const Ufe::Path& ufePath);

//! Return the gateway node (i.e. proxy shape)
MAYAUSD_CORE_PUBLIC
PXR_NS::MayaUsdProxyShapeBase* getProxyShape(const Ufe::Path& path);
Expand Down
33 changes: 33 additions & 0 deletions test/lib/mayaUsd/fileio/testDuplicateAs.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,39 @@ def testDuplicateAsMaya(self):
self.assertEqual(cmds.getAttr(bMayaPathStr + '.translate')[0],
bXlation)

def testDuplicateAsNonRootMaya(self):
'''Duplicate a USD transform hierarchy to Maya.'''

(_, _, aXlation, aUsdUfePathStr, aUsdUfePath, _, _,
bXlation, bUsdUfePathStr, bUsdUfePath, _) = \
createSimpleXformScene()

xform = cmds.createNode('transform')
xformNames = cmds.ls(xform)
self.assertEqual(1, len(xformNames))
xformName = xformNames[0]

# Duplicate USD data as Maya data, placing it under the transform we created.
with mayaUsd.lib.OpUndoItemList():
self.assertTrue(mayaUsd.lib.PrimUpdaterManager.duplicate(
aUsdUfePathStr, '|world|'+ xformName))

# Should now have two transform nodes in the Maya scene: the path
# components in the second segment of the aUsdItem and bUsdItem will
# now be under the transform.
aMayaPathStr = '|' + xformName + str(aUsdUfePath.segments[1]).replace('/', '|')
bMayaPathStr = '|' + xformName + str(bUsdUfePath.segments[1]).replace('/', '|')
self.assertEqual(1, len(cmds.ls(aMayaPathStr, long=True)))
self.assertEqual(1, len(cmds.ls(bMayaPathStr, long=True)))
self.assertEqual(cmds.ls(aMayaPathStr, long=True)[0], aMayaPathStr)
self.assertEqual(cmds.ls(bMayaPathStr, long=True)[0], bMayaPathStr)

# Translation should have been copied over to the Maya data model.
self.assertEqual(cmds.getAttr(aMayaPathStr + '.translate')[0],
aXlation)
self.assertEqual(cmds.getAttr(bMayaPathStr + '.translate')[0],
bXlation)

def testDuplicateAsMayaUndoRedo(self):
'''Duplicate a USD transform hierarchy to Maya and then undo and redo the command.'''

Expand Down