Skip to content
Draft
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
1 change: 1 addition & 0 deletions pxr/external/boost/python/src/object/class.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
#include "pxr/external/boost/python/str.hpp"
#include "pxr/external/boost/python/ssize_t.hpp"
#include <functional>
#include <algorithm>
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I needed this to compile in Windows-10 with python-3.13

#include <vector>
#include <cstddef>
#include <cstdint>
Expand Down
35 changes: 35 additions & 0 deletions pxr/usd/pcp/composeSite.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,41 @@ PcpComposeSiteRelocates(PcpLayerStackRefPtr const &layerStack,
}
}

void
PcpComposeSiteRelocates(const PcpLayerStackRefPtr &layerStack,
const SdfPath &path,
std::vector<SdfRelocatesMap> *result,
PcpArcInfoVector *info )
{
static const TfToken field = SdfFieldKeys->Relocates;

TF_REVERSE_FOR_ALL(layer, layerStack->GetLayers()) {
SdfRelocates relocates = (*layer)->GetRelocates();
// Search for the first relocation where .second (target path) matches the queried path
auto relocateIter = std::find_if(
relocates.begin(),
relocates.end(),
[&path](const SdfRelocate& relocate) {
return relocate.second == path;
}
);
if (relocateIter != relocates.end()) {
const SdfPath& source = relocateIter->first; // Source path
const SdfPath& target = relocateIter->second; // Target path

SdfRelocatesMap relocMapCopy;
relocMapCopy[source.MakeAbsolutePath(path)] = target.MakeAbsolutePath(path);

result->push_back(std::move(relocMapCopy));

PcpArcInfo arcInfo;
arcInfo.sourceLayer = *layer;
arcInfo.arcNum = static_cast<int>(result->size()) - 1;
info->push_back(std::move(arcInfo));
}
}
}

// Helper for PcpComposeSiteInherits/Specializes/ overloads
// that want to provide source arc info with the layer that adds each result.
template <typename ResultType>
Expand Down
7 changes: 7 additions & 0 deletions pxr/usd/pcp/composeSite.h
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,13 @@ PcpComposeSiteRelocates(PcpLayerStackRefPtr const &layerStack,
SdfPath const &path,
SdfRelocatesMap *result);

PCP_API
void
PcpComposeSiteRelocates(PcpLayerStackRefPtr const &layerStack,
SdfPath const &path,
std::vector<SdfRelocatesMap> *result,
PcpArcInfoVector *info);

inline void
PcpComposeSiteRelocates(PcpNodeRef const &node, SdfRelocatesMap *result)
{
Expand Down
18 changes: 14 additions & 4 deletions pxr/usd/usd/primCompositionQuery.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,10 @@ UsdPrimCompositionQueryArc::GetIntroducingLayer() const
foundInfo = _GetIntroducingComposeInfo<std::string>(
*this, &PcpComposeSiteVariantSets, &info, nullptr);
break;
case PcpArcTypeRelocate:
foundInfo = _GetIntroducingComposeInfo<SdfRelocatesMap>(
*this, &PcpComposeSiteRelocates, &info, nullptr);
break;
default:
break;
}
Expand Down Expand Up @@ -394,11 +398,11 @@ UsdPrimCompositionQuery::UsdPrimCompositionQuery(const UsdPrim & prim,
_prim.ComputeExpandedPrimIndex().Swap(*_expandedPrimIndex);

// Compute the unfiltered list of composition arcs from all non-inert nodes.
// We still skip inert nodes in the unfiltered query so we don't pick up
// things like the original copies of specialize nodes that have been
// moved for strength ordering purposes.
// We still skip inert nodes in the unfiltered query, with the exception
// of relocates, to avoid picking up things like the original copies of
// specialize nodes that have been moved for strength ordering purposes.
for(const PcpNodeRef &node: _expandedPrimIndex->GetNodeRange()) {
if (!node.IsInert()) {
if (!node.IsInert() || node.GetArcType() == PcpArcTypeRelocate) {
_unfilteredArcs.push_back(UsdPrimCompositionQueryArc(node));
}
}
Expand Down Expand Up @@ -470,6 +474,9 @@ _TestArcType(const UsdPrimCompositionQueryArc &compArc,
case ArcTypeFilter::Variant:
arcMask = 1 << PcpArcTypeVariant;
break;
case ArcTypeFilter::Relocate:
arcMask = 1 << PcpArcTypeRelocate;
break;
case ArcTypeFilter::ReferenceOrPayload:
arcMask = (1 << PcpArcTypeReference) | (1 << PcpArcTypePayload);
break;
Expand All @@ -485,6 +492,9 @@ _TestArcType(const UsdPrimCompositionQueryArc &compArc,
case ArcTypeFilter::NotVariant:
arcMask = ~(1 << PcpArcTypeVariant);
break;
case ArcTypeFilter::NotRelocate:
arcMask = ~(1 << PcpArcTypeRelocate);
break;
}

return arcMask & (1 << compArc.GetArcType());
Expand Down
4 changes: 3 additions & 1 deletion pxr/usd/usd/primCompositionQuery.h
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,7 @@ class UsdPrimCompositionQuery
Inherit,
Specialize,
Variant,
Relocate,

// Related arc types
ReferenceOrPayload,
Expand All @@ -279,7 +280,8 @@ class UsdPrimCompositionQuery
// Inverse of related arc types
NotReferenceOrPayload,
NotInheritOrSpecialize,
NotVariant
NotVariant,
NotRelocate
};

/// Choices for filtering composition arcs on dependency type. This can
Expand Down
49 changes: 48 additions & 1 deletion pxr/usd/usd/testenv/testUsdPrimCompositionQuery.py
Original file line number Diff line number Diff line change
Expand Up @@ -388,6 +388,12 @@ def _VerifyArcIntroducingInfo(arc):
self.assertEqual(arc.GetTargetNode(), arc.GetIntroducingNode())
self.assertFalse(arc.GetIntroducingLayer())
self.assertFalse(arc.GetIntroducingPrimPath())
elif arc.GetArcType() == Pcp.ArcTypeRelocate:
# Confirm that the introducing layer contains the entry for the relocates arc
intro_layer = arc.GetIntroducingLayer()
entry = (arc.GetTargetPrimPath(), arc.GetIntroducingPrimPath())
listEntries = intro_layer.relocates
self.assertIn(entry, listEntries)
else:
# The introducing prim spec is obtained from the introducing layer
# and prim path.
Expand Down Expand Up @@ -484,7 +490,6 @@ def CheckWithFilter(

filteredExpectedValues = [d for d in expectedValues
if d['arcType'] == Pcp.ArcTypeVariant]
print(filteredExpectedValues)
self.assertEqual(len(filteredExpectedValues), 5)
CheckWithFilter(
filteredExpectedValues,
Expand Down Expand Up @@ -677,6 +682,48 @@ def CheckWithFilter(
for arc in arcs:
_VerifyArcIntroducingInfo(arc)

# Test relocates on a child prim that came through a reference
query = Usd.PrimCompositionQuery(prim.GetPrimAtPath("Child_Moved"))
# Expect to find relocates arcs from an unfiltered query
arcs = query.GetCompositionArcs()
# 26 arcs total with only 1 being ArcTypeRelocate
self.assertEqual(len(arcs), 26)

relocateArcs = [arc for arc in arcs
if arc.GetArcType() == Pcp.ArcTypeRelocate]
self.assertEqual(len(relocateArcs), 1)

filteredExpectedValues = [
{'nodeLayerStack': Sdf.Find('test.usda'),
'nodePath': Sdf.Path('/Sarah/Child_Will_Be_Moved'),
'arcType': Pcp.ArcTypeRelocate,
'hasSpecs': False,
'introLayerStack': Sdf.Find('test.usda'),
'introLayer': Sdf.Find('test.usda'),
'introPath': Sdf.Path('/Sarah/Child_Moved'),
'introInListEdit': None,
'isImplicit': False,
'isAncestral': False,
'isIntroRootLayer': True,
'isIntroRootLayerPrim': True},
]

CheckWithFilter(
filteredExpectedValues,
arcTypeFilter=Usd.PrimCompositionQuery.ArcTypeFilter.Relocate)

notRelocateArcs = [arc for arc in arcs
if arc.GetArcType() != Pcp.ArcTypeRelocate]
self.assertEqual(len(notRelocateArcs), 25)

# Apply the NotRelocate filter and confirm we get the same result as the manual filtering above
qFilter = Usd.PrimCompositionQuery.Filter()
qFilter.arcTypeFilter = Usd.PrimCompositionQuery.ArcTypeFilter.NotRelocate
query.filter = qFilter
filteredNotRelocateArcs = query.GetCompositionArcs()
self.assertEqual(len(filteredNotRelocateArcs), 25)
self.assertFalse(any([arc for arc in filteredNotRelocateArcs if arc.GetArcType() == Pcp.ArcTypeRelocate]))

# test to make sure c++ objects are propertly destroyed when
# PrimCollectionQuery instance is garbage collection
stage = Usd.Stage.CreateInMemory("testCreationAndGarbageCollect.usda")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
#usda 1.0
(
relocates = {
</Sarah/Child_Will_Be_Moved>: </Sarah/Child_Moved>,
}
)

class "_class_Sarah"
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ def "Sarah_Ref" (
)
{
custom color3d color = (1, 1, 1)
def "Child_Will_Be_Moved"
{
}
}

class "_class_Sarah_Ref"
Expand Down
2 changes: 2 additions & 0 deletions pxr/usd/usd/wrapPrimCompositionQuery.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -114,11 +114,13 @@ void wrapUsdPrimCompositionQuery()
.value("Inherit", This::ArcTypeFilter::Inherit)
.value("Specialize", This::ArcTypeFilter::Specialize)
.value("Variant", This::ArcTypeFilter::Variant)
.value("Relocate", This::ArcTypeFilter::Relocate)
.value("ReferenceOrPayload", This::ArcTypeFilter::ReferenceOrPayload)
.value("InheritOrSpecialize", This::ArcTypeFilter::InheritOrSpecialize)
.value("NotReferenceOrPayload", This::ArcTypeFilter::NotReferenceOrPayload)
.value("NotInheritOrSpecialize", This::ArcTypeFilter::NotInheritOrSpecialize)
.value("NotVariant", This::ArcTypeFilter::NotVariant)
.value("NotRelocate", This::ArcTypeFilter::NotRelocate)
;
enum_<This::DependencyTypeFilter>("DependencyTypeFilter")
.value("All", This::DependencyTypeFilter::All)
Expand Down