Skip to content

Commit

Permalink
Merge pull request #1219 from autodesk-forks/t_rusel/adjust_node_def_…
Browse files Browse the repository at this point in the history
…naming

t-rusel/LOOKDEVX-421/adjust-node-def-naming
  • Loading branch information
lyuborusev authored Jul 1, 2021
2 parents f21a4db + 7b2786a commit 33a7005
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 11 deletions.
4 changes: 3 additions & 1 deletion source/MaterialXRuntime/RtFileIo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -700,13 +700,15 @@ namespace
// for implementation associations.
RtNodeDef nodedef(prim->hnd());
RtString nodeDefName = prim->getName();
RtString defNamespace = nodedef.getNamespace();
RtString qualifiedName = !defNamespace.empty() ? RtString(defNamespace.str() + NAME_PREFIX_SEPARATOR + nodeDefName.str()) : nodeDefName;
RtSchemaPredicate<RtNodeGraph> filter;
for (RtPrim child : stage->getRootPrim()->getChildren(filter))
{
// The association between a nodedef and a nodegraph is by name. No
// version check is required as nodegraphs are not versioned.
RtNodeGraph nodeGraph(child);
if (nodeGraph.getDefinition() == nodeDefName)
if (nodeGraph.getDefinition() == qualifiedName)
{
PvtPrim* graphPrim = PvtObject::cast<PvtPrim>(child);
writeNodeGraph(graphPrim, document, options);
Expand Down
13 changes: 7 additions & 6 deletions source/MaterialXRuntime/RtStage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -151,20 +151,16 @@ RtPrim RtStage::createNodeDef(RtPrim nodegraphPrim,
throw ExceptionRuntimeError("Cannot create nodedef '" + nodeDefName.str() + "', with node name: '" + nodeName.str() + "'");
}

// Always used qualified namespace
const bool isNameSpaced = !namespaceString.empty();
const RtString qualifiedNodeDefName = isNameSpaced ? RtString(namespaceString.str() + MaterialX::NAME_PREFIX_SEPARATOR + nodeDefName.str()) : nodeDefName;

PvtStage* stage = PvtStage::cast(this);

// Make sure the nodedef name is unique among all prims in the stage.
PvtPath path(nodeDefName);
if (stage->getPrimAtPath(path))
{
throw ExceptionRuntimeError("The nodedef name '" + qualifiedNodeDefName.str() + "' is not unique");
throw ExceptionRuntimeError("The nodedef name '" + nodeDefName.str() + "' is not unique");
}

PvtPrim* nodedefPrim = stage->createPrim(stage->getPath(), qualifiedNodeDefName, RtNodeDef::typeName());
PvtPrim* nodedefPrim = stage->createPrim(stage->getPath(), nodeDefName, RtNodeDef::typeName());
RtNodeDef nodedef(nodedefPrim->hnd());

// Set node, version and optional node group
Expand Down Expand Up @@ -212,6 +208,10 @@ RtPrim RtStage::createNodeDef(RtPrim nodegraphPrim,
RtValue::copy(output.getType(), output.getValue(), nodedefOutput.getValue());
}

// Always used qualified namespace
const bool isNameSpaced = !namespaceString.empty();
const RtString qualifiedNodeDefName = isNameSpaced ? RtString(namespaceString.str() + MaterialX::NAME_PREFIX_SEPARATOR + nodeDefName.str()) : nodeDefName;

// Set namespace for the nodegraph and nodedef
if (isNameSpaced)
{
Expand All @@ -221,6 +221,7 @@ RtPrim RtStage::createNodeDef(RtPrim nodegraphPrim,

// Set the definition on the nodegraph
// turning this into a functional graph
// Note that the nodeDefName is a Qualified node def name.
nodegraph.setDefinition(qualifiedNodeDefName);

// Create the relationship between nodedef and it's implementation.
Expand Down
9 changes: 5 additions & 4 deletions source/MaterialXTest/MaterialXRuntime/Runtime.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -923,13 +923,14 @@ TEST_CASE("Runtime: NodeGraphs", "[runtime]")

// Test creating a nodedef from a nodegraph
const mx::RtString NG_ADDGRAPH("NG_addgraph");
const mx::RtString ND_ADDGRAPH("ND_addgraph");
const mx::RtString ADDGRAPH("addgraph");
const mx::RtString ND_ADDGRAPH("ND_namespace1_addgraph_float_v3_4");
const mx::RtString ADDGRAPH("addgraph_float");
const mx::RtString MATH_GROUP("math");
const mx::RtString ADDGRAPH_VERSION("3.4");
const mx::RtString ADDGRAPH_TARGET("mytarget");
const mx::RtString NAMESPACE("namespace1");
const mx::RtString QUALIFIED_DEFINITION("namespace1:ND_addgraph");
const mx::RtString QUALIFIED_DEFINITION("ND_namespace1_addgraph_float_v3_4");
const mx::RtString NAMESPACED_QUALIFIED_DEFINITION(NAMESPACE.str() + mx::NAME_PREFIX_SEPARATOR + QUALIFIED_DEFINITION.str());
const std::string DOC("Sample documentation string");
bool isDefaultVersion = false;
stage->renamePrim(graph1.getPath(), NG_ADDGRAPH);
Expand All @@ -942,7 +943,7 @@ TEST_CASE("Runtime: NodeGraphs", "[runtime]")
REQUIRE(api->hasImplementation<mx::RtNodeGraph>(NG_ADDGRAPH));

mx::RtNodeDef addgraphDef(addgraphPrim);
REQUIRE(graph1.getDefinition() == QUALIFIED_DEFINITION);
REQUIRE(graph1.getDefinition() == NAMESPACED_QUALIFIED_DEFINITION);
REQUIRE(graph1.getVersion().empty());
REQUIRE(graph1.getNamespace() == NAMESPACE);
REQUIRE(addgraphDef.numInputs() == 2);
Expand Down

0 comments on commit 33a7005

Please sign in to comment.