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-1949 better support for grouping prims with references #4048

Merged
merged 1 commit into from
Dec 17, 2024
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
7 changes: 7 additions & 0 deletions cmake/modules/FindUSD.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,13 @@ if (USD_INCLUDE_DIR AND EXISTS "${USD_INCLUDE_DIR}/pxr/imaging/hd/changeTracker.
endif()
endif()

# See if USD changetracker has instance count.
set(USD_HAS_NAMESPACE_EDIT FALSE CACHE INTERNAL "USD.NamespaceEdit")
if (USD_INCLUDE_DIR AND EXISTS "${USD_INCLUDE_DIR}/pxr/usd/sdf/namespaceEdit.h")
set(USD_HAS_NAMESPACE_EDIT TRUE CACHE INTERNAL "USD.NamespaceEdit")
message(STATUS "USD has namespace edit")
endif()

# See if MaterialX shaders with color4 inputs exist natively in Sdr:
# Not yet in a tagged USD version: https://github.com/PixarAnimationStudios/USD/pull/1894
set(USD_HAS_COLOR4_SDR_SUPPORT FALSE CACHE INTERNAL "USD.Sdr.PropertyTypes.Color4")
Expand Down
8 changes: 8 additions & 0 deletions lib/usdUfe/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,14 @@ if (USD_HAS_COLOR4_SDR_SUPPORT)
)
endif()

message(STATUS "USD_HAS_NAMESPACE_EDIT is ${USD_HAS_NAMESPACE_EDIT}")
if (USD_HAS_NAMESPACE_EDIT)
target_compile_definitions(${PROJECT_NAME}
PRIVATE
USD_HAS_NAMESPACE_EDIT=1
)
endif()

message(STATUS "MAYA_HAS_DISPLAY_LAYER_API is ${MAYA_HAS_DISPLAY_LAYER_API}")
if (MAYA_HAS_DISPLAY_LAYER_API)
target_compile_definitions(${PROJECT_NAME}
Expand Down
20 changes: 20 additions & 0 deletions lib/usdUfe/ufe/UsdUndoInsertChildCommand.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@

#include <pxr/base/tf/token.h>
#include <pxr/usd/sdf/copyUtils.h>
#ifdef USD_HAS_NAMESPACE_EDIT
#include <pxr/usd/sdf/namespaceEdit.h>
#endif
#include <pxr/usd/usd/editContext.h>
#include <pxr/usd/usd/stage.h>
#include <pxr/usd/usdGeom/gprim.h>
Expand Down Expand Up @@ -215,6 +218,23 @@ static void doInsertion(
throw std::runtime_error(error);
}

#ifdef USD_HAS_NAMESPACE_EDIT
// Try to use a single-layer renaming namespace edit.
// This only works correctly if there is a single layer and the destination layer
// is the same as the source layer. If it fails we will fall through to the other
// algorithm below.
if (1 == authLayerAndPaths.size()) {
SdfBatchNamespaceEdit edits;

const auto parentPath = dstUsdPath.GetParentPath();
edits.Add(SdfNamespaceEdit::Reparent(srcUsdPath, parentPath, SdfNamespaceEdit::Same));

if (dstLayer->Apply(edits)) {
return;
}
}
#endif

UsdUfe::MergePrimsOptions options;
options.verbosity = UsdUfe::MergeVerbosity::None;
options.mergeChildren = true;
Expand Down
26 changes: 26 additions & 0 deletions test/lib/ufe/testGroupCmd.py
Original file line number Diff line number Diff line change
Expand Up @@ -1137,6 +1137,32 @@ def testGroupNested(self):
self.assertNotIn(groupName, groupNames)
groupNames.add(groupName)

@unittest.skipUnless(Usd.GetVersion() >= (0, 24, 3), 'Requires USD 24.03 or greater for namespace edits')
def testGroupPrimWithRef(self):
"""
Tests that grouping a prim with a reference does not flatten
the reference when done in a single layer.
"""
cmds.file(new=True, force=True)
import mayaUsd_createStageWithNewLayer

proxyShapePathStr = mayaUsd_createStageWithNewLayer.createStageWithNewLayer()
stage = mayaUsd.lib.GetPrim(proxyShapePathStr).GetStage()
self.assertTrue(stage)

# create a over containing a reference
primWithRef = stage.OverridePrim("/primWithRef")
self.assertTrue(primWithRef)
cubeRefFile = testUtils.getTestScene("cubeRef", "cube.usda")
primWithRef.GetReferences().AddReference(cubeRefFile)

cmds.group('%s,/primWithRef' % proxyShapePathStr)

self.assertFalse(stage.GetPrimAtPath('/primWithRef'))
primWithRef = stage.GetPrimAtPath('/group1/primWithRef')
self.assertTrue(primWithRef)
self.assertTrue(primWithRef.HasAuthoredReferences())


if __name__ == '__main__':
unittest.main(verbosity=2)