Skip to content

Commit

Permalink
Merge pull request #652 from Autodesk/sabrih/usd_utility_functions
Browse files Browse the repository at this point in the history
Convenience function for printing the list of queried composition arcs in order
  • Loading branch information
Krystian Ligenza authored Jul 14, 2020
2 parents 954c767 + de4ed7c commit 461668a
Show file tree
Hide file tree
Showing 2 changed files with 73 additions and 0 deletions.
69 changes: 69 additions & 0 deletions lib/usd/utils/util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

#include "util.h"

#include <pxr/usd/pcp/layerStack.h>
#include <pxr/usd/sdf/layer.h>
#include <pxr/usd/usd/prim.h>
#include <pxr/usd/usd/primCompositionQuery.h>
Expand All @@ -25,6 +26,53 @@

PXR_NAMESPACE_USING_DIRECTIVE

namespace
{
std::map<std::string,std::string>
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
Expand Down Expand Up @@ -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
4 changes: 4 additions & 0 deletions lib/usd/utils/util.h
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 461668a

Please sign in to comment.