From 8db17b7e95126f9750f9e498ea6f4c6ba195cdf4 Mon Sep 17 00:00:00 2001 From: Bernard Kwok Date: Thu, 31 Aug 2023 15:15:05 -0400 Subject: [PATCH] Multioutput connection support for nodes. --- source/MaterialXGraphEditor/Graph.cpp | 31 ++++++++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) diff --git a/source/MaterialXGraphEditor/Graph.cpp b/source/MaterialXGraphEditor/Graph.cpp index 4ddf257706..30cc1c31eb 100644 --- a/source/MaterialXGraphEditor/Graph.cpp +++ b/source/MaterialXGraphEditor/Graph.cpp @@ -2603,7 +2603,33 @@ void Graph::AddLink(ed::PinId inputPinId, ed::PinId outputPinId) { if (uiUpNode->getNode()) { - pin->_input->setConnectedNode(uiUpNode->getNode()); + mx::NodePtr upstreamNode = _graphNodes[upNode]->getNode(); + mx::NodeDefPtr upstreamNodeDef = upstreamNode->getNodeDef(); + bool isMultiOutput = upstreamNodeDef ? upstreamNodeDef->getOutputs().size() > 1 : false; + + // This is purely to avoid adding a reference to an update node only 1 output, + // as currently validation consides adding this an error. Otherwise + // it will add an "output" attribute all the time. + if (!isMultiOutput) + { + pin->_input->setConnectedNode(uiUpNode->getNode()); + } + else + { + for (UiPinPtr outPin : _graphNodes[upNode]->outputPins) + { + // set pin connection to correct output + if (outPin->_pinId == inputPinId) + { + mx::OutputPtr outputs = uiUpNode->getNode()->getOutput(outPin->_name); + if (!outputs) + { + outputs = uiUpNode->getNode()->addOutput(outPin->_name, pin->_input->getType()); + } + pin->_input->setConnectedOutput(outputs); + } + } + } } else if (uiUpNode->getNodeGraph()) { @@ -2713,6 +2739,9 @@ void Graph::deleteLinkInfo(int startAttr, int endAttr) setDefaults(_graphNodes[upNode]->getInput()); } + // Remove any output reference + pin->_input->removeAttribute(mx::PortElement::OUTPUT_ATTRIBUTE); + pin->setConnected(false); // if a value exists update the input with it if (val)