Skip to content

Commit

Permalink
Merge pull request #2977 from dj-mcg/pr/Restrict_Namespace_Edits_to_C…
Browse files Browse the repository at this point in the history
…urrent_Stage

Restrict namespace edits to current stage
  • Loading branch information
seando-adsk authored Mar 30, 2023
2 parents 50833d3 + d9196f2 commit 42fb722
Showing 1 changed file with 32 additions and 4 deletions.
36 changes: 32 additions & 4 deletions lib/mayaUsd/utils/layers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -116,16 +116,44 @@ void enforceMutedLayer(const PXR_NS::UsdPrim& prim, const char* command)
}
}

static SdfPrimSpecHandleVector _GetLocalPrimStack(const UsdPrim& prim)
{
SdfPrimSpecHandleVector primSpecs;

UsdStagePtr stage = prim.GetStage();
if (!stage)
return primSpecs;

// The goal is to avoid editing non-local layers. This issue is,
// for example, that a rename operation would fail when applied
// to a prim that references a show asset because the rename operation
// would be attempted on the reference and classes it inherits.
//
// Concrete example:
// - Create a test asset that inherits from one or more classes
// - Create a prim within a Maya Usd scene that references this asset
// - Attempt to rename the prim
// - Observe the failure due to Sdf policy

for (const SdfLayerHandle& layer : stage->GetLayerStack()) {
const SdfPrimSpecHandle primSpec = layer->GetPrimAtPath(prim.GetPath());
if (primSpec)
primSpecs.push_back(primSpec);
}

return primSpecs;
}

void applyToAllPrimSpecs(const UsdPrim& prim, const PrimSpecFunc& func)
{
const SdfPrimSpecHandleVector primStack = prim.GetPrimStack();
const SdfPrimSpecHandleVector primStack = _GetLocalPrimStack(prim);
for (const SdfPrimSpecHandle& spec : primStack)
func(prim, spec);
}

void applyToAllLayersWithOpinions(const UsdPrim& prim, PrimLayerFunc& func)
{
const SdfPrimSpecHandleVector primStack = prim.GetPrimStack();
const SdfPrimSpecHandleVector primStack = _GetLocalPrimStack(prim);
for (const SdfPrimSpecHandle& spec : primStack) {
const auto layer = spec->GetLayer();
func(prim, layer);
Expand All @@ -137,7 +165,7 @@ void applyToSomeLayersWithOpinions(
const std::set<SdfLayerRefPtr>& layers,
PrimLayerFunc& func)
{
const SdfPrimSpecHandleVector primStack = prim.GetPrimStack();
const SdfPrimSpecHandleVector primStack = _GetLocalPrimStack(prim);
for (const SdfPrimSpecHandle& spec : primStack) {
const auto layer = spec->GetLayer();
if (layers.count(layer) == 0)
Expand Down Expand Up @@ -215,4 +243,4 @@ SdfLayerHandle getStrongerLayer(
return getStrongerLayer(stage->GetRootLayer(), layer1, layer2);
}

} // namespace MAYAUSD_NS_DEF
} // namespace MAYAUSD_NS_DEF

0 comments on commit 42fb722

Please sign in to comment.