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-115074 Ensure duplicate-as-USD creates unique prim names. #1989

Merged
merged 2 commits into from
Jan 17, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
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: 10 additions & 1 deletion lib/mayaUsd/fileio/primUpdaterManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1103,9 +1103,18 @@ bool PrimUpdaterManager::duplicate(
// Copy the temporary layer contents out to the proper destination.
const auto& srcLayer = std::get<SdfLayerRefPtr>(pushExportOutput);
const auto& editTarget = dstStage->GetEditTarget();
auto dstRootPath = editTarget.MapToSpecPath(srcRootPath);
const auto& dstLayer = editTarget.GetLayer();

// Make the destination root path unique.
SdfPath dstRootPath = editTarget.MapToSpecPath(srcRootPath);
SdfPath dstParentPath = dstRootPath.GetParentPath();
std::string dstChildName = dstRootPath.GetName();
UsdPrim dstParentPrim = dstStage->GetPrimAtPath(dstParentPath);
if (dstParentPrim.IsValid()) {
dstChildName = ufe::uniqueChildName(dstParentPrim, dstChildName);
dstRootPath = dstParentPath.AppendChild(TfToken(dstChildName));
}

if (!SdfCopySpec(srcLayer, srcRootPath, dstLayer, dstRootPath)) {
return false;
}
Expand Down
2 changes: 1 addition & 1 deletion plugin/adsk/scripts/USDMenuProc.mel
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,6 @@ global proc USDMenuProc(string $parent, string $obj)
menuItem -label "Edit As Maya Data" -image "edit_as_Maya.png" -command ("mayaUsdEditAsMaya \"" + $obj + "\"");
}
}
menuItem -label "Duplicate As Maya Data" -command ("mayaUsdDuplicateAsMaya \"" + $obj + "\"");
menuItem -label "Duplicate As Maya Data" -command ("mayaUsdDuplicate \"" + $obj + "\"" + "\"|world\"");
}
}
28 changes: 28 additions & 0 deletions test/lib/mayaUsd/fileio/testDuplicateAs.py
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,34 @@ def testDuplicateAsUsd(self):
self.assertEqual([1, 2, 3], usdGroup1T3d.translation().vector)
self.assertEqual([-4, -5, -6], usdGroup2T3d.translation().vector)

def testDuplicateAsUsdSameName(self):
'''Duplicate a Maya transform to USD when USD already has a prim with that name.'''

# Create a Maya transform named 'A'.
mayaA = cmds.createNode('transform', name='A')
cmds.setAttr(mayaA + '.translate', 1, 2, 3)

# Create a stage to receive the USD duplicate, with a prim of the same name.
psPathStr = mayaUsd_createStageWithNewLayer.createStageWithNewLayer()
stage = mayaUsd.lib.GetPrim(psPathStr).GetStage()
aPrim = stage.DefinePrim('/A', 'Xform')

# Duplicate Maya data as USD data. As of 17-Nov-2021 no single-segment
# path handler registered to UFE for Maya path strings, so use absolute
# path.
with mayaUsd.lib.OpUndoItemList():
self.assertTrue(mayaUsd.lib.PrimUpdaterManager.duplicate(
cmds.ls(mayaA, long=True)[0], psPathStr))

# Maya hierarchy should be duplicated in USD, but with a numeric suffix sue to the collision.
seando-adsk marked this conversation as resolved.
Show resolved Hide resolved
usdNewAPathStr = psPathStr + ',/' + mayaA + '1'
usdNewAPath = ufe.PathString.path(usdNewAPathStr)

# Translations have been preserved.
usdNewA = ufe.Hierarchy.createItem(usdNewAPath)
usdNewAT3d = ufe.Transform3d.transform3d(usdNewA)
self.assertEqual([1, 2, 3], usdNewAT3d.translation().vector)

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

Expand Down