From f0fd134dfdc88d63bed0a5a98e031791201268d4 Mon Sep 17 00:00:00 2001 From: Jonathan Feldstein Date: Fri, 18 Oct 2024 13:56:18 -0400 Subject: [PATCH] Add defaultgeomprop support for nodegraph inputs. --- .../defaultgeomprop/defaultgeomprop.mtlx | 41 +++++++++++++++++++ source/MaterialXCore/Interface.cpp | 2 +- source/MaterialXGenShader/ShaderGraph.cpp | 18 ++++++++ 3 files changed, 60 insertions(+), 1 deletion(-) create mode 100644 resources/Materials/TestSuite/stdlib/defaultgeomprop/defaultgeomprop.mtlx diff --git a/resources/Materials/TestSuite/stdlib/defaultgeomprop/defaultgeomprop.mtlx b/resources/Materials/TestSuite/stdlib/defaultgeomprop/defaultgeomprop.mtlx new file mode 100644 index 0000000000..86bddc9650 --- /dev/null +++ b/resources/Materials/TestSuite/stdlib/defaultgeomprop/defaultgeomprop.mtlx @@ -0,0 +1,41 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/source/MaterialXCore/Interface.cpp b/source/MaterialXCore/Interface.cpp index 24d3ccfe0d..1c12e38ded 100644 --- a/source/MaterialXCore/Interface.cpp +++ b/source/MaterialXCore/Interface.cpp @@ -295,7 +295,7 @@ bool Input::validate(string* message) const if (hasDefaultGeomPropString()) { - validateRequire(parent->isA(), res, message, "Invalid defaultgeomprop on non-definition input"); + validateRequire(parent->isA() || parent->isA(), res, message, "Invalid defaultgeomprop on non-definition and non-nodegraph input"); validateRequire(getDefaultGeomProp() != nullptr, res, message, "Invalid defaultgeomprop string"); } if (parent->isA()) diff --git a/source/MaterialXGenShader/ShaderGraph.cpp b/source/MaterialXGenShader/ShaderGraph.cpp index 0f39b46c32..2857138e11 100644 --- a/source/MaterialXGenShader/ShaderGraph.cpp +++ b/source/MaterialXGenShader/ShaderGraph.cpp @@ -95,6 +95,24 @@ void ShaderGraph::createConnectedNodes(const ElementPtr& downstreamElement, newNode = createNode(upstreamNode, context); } + // + // Handle defaultgeomprops + // + + const vector activeInputs = upstreamNode->getActiveInputs(); + for (const InputPtr& activeInput : activeInputs) + { + if (!activeInput->hasInterfaceName() || activeInput->getConnectedNode()) { + continue; + } + const auto graphInput = activeInput->getInterfaceInput(); + // We have an input connected to an interface. See if it has defaultgeomprop + if (graphInput && graphInput->hasDefaultGeomPropString()) { + ShaderInput* shaderInput = getNode(upstreamNode->getName())->getInput(activeInput->getName()); + addDefaultGeomNode(shaderInput, *graphInput->getDefaultGeomProp(), context); + } + } + // // Make connections //