Skip to content

Commit

Permalink
Merge pull request #3329 from Autodesk/bailp/EMSUSD-594/material-dup-…
Browse files Browse the repository at this point in the history
…ten-times

EMSUSD-594 material dup ten times
  • Loading branch information
seando-adsk authored Sep 20, 2023
2 parents 974b0a1 + 42450d0 commit 8223656
Show file tree
Hide file tree
Showing 5 changed files with 183 additions and 8 deletions.
1 change: 1 addition & 0 deletions lib/mayaUsd/ufe/UsdUndoDuplicateCommand.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ void UsdUndoDuplicateCommand::execute()

MayaUsdUtils::MergePrimsOptions options;
options.verbosity = MayaUsdUtils::MergeVerbosity::None;
options.mergeChildren = true;
bool isFirst = true;

for (const SdfPrimSpecHandle& layerAndPath : authLayerAndPaths) {
Expand Down
11 changes: 3 additions & 8 deletions lib/mayaUsd/ufe/UsdUndoDuplicateSelectionCommand.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -198,14 +198,9 @@ bool UsdUndoDuplicateSelectionCommand::updateSdfPathVector(
for (size_t i = 0; i < pathVec.size(); ++i) {
const PXR_NS::SdfPath& path = pathVec[i];
PXR_NS::SdfPath finalPath = path;
// Paths are lexicographically ordered, this means we can search quickly for bounds of
// candidate paths.
auto itPath = otherPairs.lower_bound(finalPath);
if (itPath != otherPairs.begin()) {
--itPath;
}
const auto endPath = otherPairs.upper_bound(finalPath);
bool isExternalPath = true;
auto itPath = otherPairs.begin();
const auto endPath = otherPairs.end();
bool isExternalPath = true;
for (; itPath != endPath; ++itPath) {
if (*itPath == duplicatePair) {
// That one was correctly processed by USD when duplicating.
Expand Down
51 changes: 51 additions & 0 deletions test/lib/ufe/testDuplicateCmd.py
Original file line number Diff line number Diff line change
Expand Up @@ -726,5 +726,56 @@ def testDuplicateUniqueName(self):
newObjItem = ufe.Hierarchy.createItem(ufe.PathString.path(newObj[0]))
self.assertEqual(newObjItem.nodeName(), 'Cone3')

def testConnectionWithChangingOrderOfTen(self):
'''
Test duplicating a prim that has mateiral connections
when the new prim name suffix will increase to a new power of ten
(ex: 9 > 10), as opposed to having the same suffix length (ex: 4 -> 5).
The connections should not be lost.
'''

cmds.file(new=True, force=True)

usdFile = testUtils.getTestScene("dup_material", "dup_material.usda")
stageDagPath, usdStage = mayaUtils.createProxyFromFile(usdFile)
dupSourceUfePathString = ','.join([stageDagPath, "/rock2"])

cmds.duplicate(dupSourceUfePathString)

# Verify that the duplicated item still has connections.
destPrim = usdStage.GetPrimAtPath('/rock10')
self.assertIsNotNone(destPrim)

destPrim = usdStage.GetPrimAtPath('/rock10')
self.assertIsNotNone(destPrim)
self.assertTrue(destPrim)

prim_paths_and_attr_names = [
('/rock10/mtl/rock_moss_set_01_rock01SG', 'outputs:surface'),
('/rock10/mtl/rock_moss_set_01_rock01SG/standardSurface2', 'inputs:diffuseColor'),
('/rock10/mtl/rock_moss_set_01_rock01SG/standardSurface2', 'inputs:roughness'),
('/rock10/mtl/rock_moss_set_01_rock01SG/standardSurface2', 'inputs:specularColor'),
('/rock10/mtl/rock_moss_set_01_rock01SG/normalmap_texture', 'inputs:st'),
('/rock10/mtl/rock_moss_set_01_rock01SG/place2dTexture3', 'inputs:varname'),
('/rock10/mtl/rock_moss_set_01_rock01SG/base_color_texture', 'inputs:st'),
('/rock10/mtl/rock_moss_set_01_rock01SG/place2dTexture1', 'inputs:varname'),
('/rock10/mtl/rock_moss_set_01_rock01SG/roughness_texture', 'inputs:st'),
('/rock10/mtl/rock_moss_set_01_rock01SG/place2dTexture2', 'inputs:varname'),
]

for primPath, attrName in prim_paths_and_attr_names:
prim = usdStage.GetPrimAtPath(primPath)
self.assertIsNotNone(prim)
self.assertTrue(prim)

prop = prim.GetProperty(attrName)
self.assertIsNotNone(prop)
self.assertTrue(prop)
propConnections = prop.GetConnections()
self.assertIsNotNone(propConnections)
self.assertEqual(len(propConnections), 1)
self.assertTrue(str(propConnections[0]).startswith('/rock10/mtl'))

if __name__ == '__main__':
unittest.main(verbosity=2)
128 changes: 128 additions & 0 deletions test/testSamples/dup_material/dup_material.usda

Large diffs are not rendered by default.

Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 8223656

Please sign in to comment.