Skip to content

Commit

Permalink
usd: Fixes for UsdInherits::GetAllDirectInherits
Browse files Browse the repository at this point in the history
This function relied on Pcp not culling certain inherit
nodes so that their associated site paths would be
included in the result, even if there were currently
no opinions at that path. However, this assumption
failed in (at least) cases that involved a mix of
specializes and inherit arcs. This was discovered by
running testUsdInherits with the PCP_CULLING env
setting set to 0.

We now use the expanded prim index to find the desired
inherit paths to ensure that all possible sources of
opinions are present.

This change also fixes a bug where paths in non-local
layer stacks would be included in the result.

(Internal change: 2307606)
  • Loading branch information
sunyab authored and pixar-oss committed Dec 7, 2023
1 parent a8ae74f commit 4f325c1
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 7 deletions.
16 changes: 10 additions & 6 deletions pxr/usd/usd/inherits.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,9 @@ UsdInherits::GetAllDirectInherits() const

auto addIfDirectInheritFn = [&](const PcpNodeRef &node) {
if (node.GetArcType() == PcpArcTypeInherit &&
!node.GetOriginRootNode().IsDueToAncestor() &&
seen.insert(node.GetPath()).second) {
node.GetLayerStack() == node.GetRootNode().GetLayerStack() &&
!node.GetOriginRootNode().IsDueToAncestor() &&
seen.insert(node.GetPath()).second) {
ret.push_back(node.GetPath());
}
};
Expand All @@ -106,14 +107,17 @@ UsdInherits::GetAllDirectInherits() const
// specializes. Thus, we have to search under both the root's inherits
// and its specializes to find all propagated inherit arcs.
//
// Note that this relies on the fact that propagated direct class base arcs
// are not culled from the prim index even if they do not produce specs.
// We search the expanded prim index to ensure that we pick up all possible
// sources of opinions even if they currently do not produce specs. These
// locations may be culled from the index returned by _prim.GetPrimIndex().
PcpPrimIndex fullPrimIndex = _prim.ComputeExpandedPrimIndex();

for (const PcpNodeRef &node:
_prim.GetPrimIndex().GetNodeRange(PcpRangeTypeInherit)) {
fullPrimIndex.GetNodeRange(PcpRangeTypeInherit)) {
addIfDirectInheritFn(node);
}
for (const PcpNodeRef &node:
_prim.GetPrimIndex().GetNodeRange(PcpRangeTypeSpecialize)) {
fullPrimIndex.GetNodeRange(PcpRangeTypeSpecialize)) {
addIfDirectInheritFn(node);
}
return ret;
Expand Down
3 changes: 2 additions & 1 deletion pxr/usd/usd/testenv/testUsdInherits.py
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,8 @@ def "Child" (
self.assertEqual(child.GetInherits().GetAllDirectInherits(),
[Sdf.Path(path) for path in [
'/CI', '/CRI', '/CRI_NOSPEC', '/PRCI', '/PRCI_NOSPEC',
'/Parent/Sibling']])
'/Parent/Sibling', '/PISI/Sibling', '/PSI/Sibling',
]])

def test_ListPosition(self):
for fmt in allFormats:
Expand Down

0 comments on commit 4f325c1

Please sign in to comment.