Skip to content

Commit

Permalink
Add support for multioutput connection edits (AcademySoftwareFoundati…
Browse files Browse the repository at this point in the history
…on#1506)

Incorrect connections were being stored on the MaterialX document when making / breaking connections with upstream nodes which have more than one output (mulitoutput nodes).

## Fixes

- Make sure to remove any reference on an input to an upstream output attribute when breaking links.
- Make sure to add the connection to an upstream output if the upstream node is multioutput. Otherwise use the current logic to connect to the node. 
- If we always add an output reference on the downstream input, then there is a validation warning if the upstream node is not multioutput but you specify an output on the downstream input. This might be worthwhile to remove as it's not really an error.
  • Loading branch information
kwokcb authored Aug 31, 2023
1 parent 34a27d0 commit 2f3c5a7
Showing 1 changed file with 30 additions and 1 deletion.
31 changes: 30 additions & 1 deletion source/MaterialXGraphEditor/Graph.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2606,7 +2606,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())
{
Expand Down Expand Up @@ -2716,6 +2742,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)
Expand Down

0 comments on commit 2f3c5a7

Please sign in to comment.