diff --git a/lib/usd/utils/util.cpp b/lib/usd/utils/util.cpp index a4f0c9d842..7c30d8fbe3 100644 --- a/lib/usd/utils/util.cpp +++ b/lib/usd/utils/util.cpp @@ -16,6 +16,7 @@ #include "util.h" +#include #include #include #include @@ -25,6 +26,53 @@ PXR_NAMESPACE_USING_DIRECTIVE +namespace +{ + std::map + getDict(const UsdPrimCompositionQueryArc& arc) { + std::string arcType; + switch (arc.GetArcType()) { + case PcpArcTypeRoot: + arcType = "PcpArcTypeRoot"; + break; + case PcpArcTypeReference: + arcType = "PcpArcTypeReference"; + break; + case PcpArcTypePayload: + arcType = "PcpArcTypePayload"; + break; + case PcpArcTypeInherit: + arcType = "PcpArcTypeInherit"; + break; + case PcpArcTypeSpecialize: + arcType = "PcpArcTypeSpecialize"; + break; + case PcpArcTypeVariant: + arcType = "PcpArcTypeVariant"; + break; + default: + break; + } + + auto introducingLayer = arc.GetIntroducingLayer(); + auto introducingNode = arc.GetIntroducingNode(); + + return { + {"arcType" , arcType}, + {"hasSpecs", arc.HasSpecs() ? "True" : "False"}, + {"introLayer", introducingLayer ? introducingLayer->GetRealPath() : ""}, + {"introLayerStack", introducingNode ? introducingNode.GetLayerStack()->GetIdentifier().rootLayer->GetRealPath() : ""}, + {"introPath", arc.GetIntroducingPrimPath().GetString()}, + {"isAncestral", arc.IsAncestral() ? "True" : "False"}, + {"isImplicit", arc.IsImplicit() ? "True" : "False"}, + {"isIntroRootLayer", arc.IsIntroducedInRootLayerStack() ? "True" : "False"}, + {"isIntroRootLayerPrim", arc.IsIntroducedInRootLayerPrimSpec() ? "True" : "False" }, + {"nodeLayerStack", introducingNode ? introducingNode.GetLayerStack()->GetIdentifier().rootLayer->GetRealPath() : ""}, + {"nodePath", arc.GetTargetNode().GetPath().GetString()}, + }; + } +} + namespace MayaUsdUtils { SdfLayerHandle @@ -137,4 +185,25 @@ hasSpecs(const UsdPrim& prim) return found; } +void +printCompositionQuery(const UsdPrim& prim, std::ostream& os) +{ + UsdPrimCompositionQuery query(prim); + + os << "[\n"; + + // the composition arcs are always returned in order from strongest + // to weakest regardless of the filter. + for (const auto& arc : query.GetCompositionArcs()) { + const auto& arcDic = getDict(arc); + os << "{\n"; + std::for_each(arcDic.begin(),arcDic.end(), [&](const auto& it) { + os << it.first << ": " << it.second << '\n'; + }); + os << "}\n"; + } + + os << "]\n\n"; +} + } // MayaUsdUtils diff --git a/lib/usd/utils/util.h b/lib/usd/utils/util.h index 4c16a28810..780120a6cc 100644 --- a/lib/usd/utils/util.h +++ b/lib/usd/utils/util.h @@ -53,6 +53,10 @@ namespace MayaUsdUtils { MAYA_USD_UTILS_PUBLIC bool hasSpecs(const UsdPrim&); + //! Convenience function for printing the list of queried composition arcs in order. + MAYA_USD_UTILS_PUBLIC + void printCompositionQuery(const UsdPrim&, std::ostream&); + } // namespace MayaUsdUtils #endif // MAYAUSDUTILS_UTIL_H \ No newline at end of file