Skip to content

Commit

Permalink
Add resolveNameReference for datalibrary
Browse files Browse the repository at this point in the history
  • Loading branch information
ashwinbhat committed Oct 10, 2024
1 parent 7fab194 commit 5f53365
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
13 changes: 13 additions & 0 deletions source/MaterialXCore/Element.h
Original file line number Diff line number Diff line change
Expand Up @@ -849,6 +849,19 @@ class MX_CORE_API Element : public std::enable_shared_from_this<Element>
return child ? child : scope->getChildOfType<T>(name);
}

// Resolve a reference to a named element at the scope of the given datalibrary and parent
// taking the namespace at the scope of this element into account. If no datalibrary or parent
// is provided, then the root scope of the document is used.
template <class T> shared_ptr<T> resolveNameReference(ConstElementPtr datalibrary, const string& name, ConstElementPtr parent = nullptr) const
{
shared_ptr<T> child = datalibrary ? datalibrary->getChildOfType<T>(getQualifiedName(name)) : nullptr;

if (child)
return child;

return resolveNameReference<T>(name, parent);
}

// Enforce a requirement within a validate method, updating the validation
// state and optional output text if the requirement is not met.
void validateRequire(bool expression, bool& res, string* message, const string& errorDesc) const;
Expand Down
13 changes: 13 additions & 0 deletions source/MaterialXCore/Node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,19 @@ string Node::getConnectedNodeName(const string& inputName) const

NodeDefPtr Node::getNodeDef(const string& target, bool allowRoughMatch) const
{
if (hasNodeDefString())
{
NodeDefPtr resolvedNode = resolveNameReference<NodeDef>(getNodeDefString());
if (!resolvedNode && getDocument()->hasDataLibrary())
{
return resolveNameReference<NodeDef>(getDocument()->getRegisteredDataLibrary(), getNodeDefString());
}
else
{
return resolvedNode;
}
}

// Collect document nodes
vector<NodeDefPtr> nodeDefs = getDocument()->getMatchingNodeDefs(getQualifiedName(getCategory()));
vector<NodeDefPtr> secondary = getDocument()->getMatchingNodeDefs(getCategory());
Expand Down

0 comments on commit 5f53365

Please sign in to comment.