-
Notifications
You must be signed in to change notification settings - Fork 23
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
1.38 Explicit nodegraph inputs and nodegraph input connections #1053
Changes from 11 commits
6ff89e0
3983d41
4fe36e5
e2260d5
a92ad8a
2e25652
92546db
a68aac2
134fb2d
c5fd321
0189c3c
7ca7460
3f95de6
459c16c
2cc92db
68e97c0
6b68b55
dcc2826
340d957
9c5dc54
bfa2a8c
16693d6
f5eccbc
da83fa9
1b381a4
9258b8d
97da53f
2e8e67a
6a887a4
9026165
8087988
ad320a3
8ad4e98
cf45883
710c654
b7a1ff2
46600e8
acde996
da21e8f
91d6b54
d4e5dcd
a160b32
12c481f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
<?xml version="1.0"?> | ||
<materialx version="1.37"> | ||
<nodegraph name="upstream3" xpos="10" ypos="153" > | ||
<input name="file" type="filename" uniform="true" value="resources/Images/cloth.png" /> | ||
<input name="file1" type="filename" uniform="true" value="resources/Images/grid.png" /> | ||
<image name="upstream_image" type="color3" xpos="10" ypos="8.86024"> | ||
<input name="file" type="filename" uniform="true" interfacename="file" value="resources/Images/cloth.png" /> | ||
<input name="frameoffset" type="integer" uniform="true" value="0" /> | ||
</image> | ||
<image name="upstream_image1" type="color3" xpos="19.1695" ypos="421"> | ||
<input name="file" type="filename" uniform="true" interfacename="file1" value="resources/Images/grid.png" /> | ||
<input name="frameoffset" type="integer" uniform="true" value="0" /> | ||
</image> | ||
<output name="out" type="color3" nodename="upstream_image" /> | ||
<output name="out1" type="color3" nodename="upstream_image1" /> | ||
</nodegraph> | ||
|
||
|
||
<nodegraph name="upstream2" xpos="315" ypos="82" > | ||
<input name="upstream2_in1" type="color3" nodegraph="upstream3" output="out" value="0, 1, 0" /> | ||
<input name="upstream2_in2" type="color3" nodegraph="upstream3" output="out1" value="0, 1, 0" /> | ||
<multiply name="multiply_by_image" type="color3" xpos="333.028" ypos="-27.8587"> | ||
<input name="in1" type="color3" interfacename="upstream2_in1" value="0, 1, 0" /> | ||
<input name="in2" type="color3" nodename="image" /> | ||
</multiply> | ||
<multiply name="make_red" type="color3" xpos="361.069" ypos="248.883"> | ||
<input name="in1" type="color3" interfacename="upstream2_in2" value="0, 1, 0" /> | ||
<input name="in2" type="color3" value="1, 0.1, 0.1" /> | ||
</multiply> | ||
<image name="image" type="color3" xpos="-30.4805" ypos="-249.603"> | ||
<input name="file" type="filename" uniform="true" value="resources/Images/grid.png" /> | ||
</image> | ||
<output name="upstream2_out1" type="color3" nodename="multiply_by_image" /> | ||
<output name="upstream2_out2" type="color3" nodename="make_red" /> | ||
</nodegraph> | ||
|
||
<nodegraph name="upstream1" xpos="620" ypos="10" > | ||
<input name="upstream1_in1" type="color3" nodegraph="upstream2" output="upstream2_out1" value="0, 1, 0" /> | ||
<input name="upstream1_in2" type="color3" nodegraph="upstream2" output="upstream2_out2" value="0, 1, 0" /> | ||
<multiply name="make_yellow" type="color3" xpos="-77.0636" ypos="-139.845"> | ||
<input name="in1" type="color3" interfacename="upstream1_in1" value="0, 1, 0" /> | ||
<input name="in2" type="color3" value="1, 1, 0" /> | ||
</multiply> | ||
<multiply name="remove_red" type="color3" xpos="-75.6416" ypos="242.103"> | ||
<input name="in1" type="color3" interfacename="upstream1_in2" value="0, 1, 0" /> | ||
<input name="in2" type="color3" value="0, 1, 1" /> | ||
</multiply> | ||
<output name="upstream1_out1" type="color3" nodename="make_yellow" /> | ||
<output name="upstream1_out2" type="color3" nodename="remove_red" /> | ||
</nodegraph> | ||
|
||
<output name="top_upstream1_out1" type="color3" nodename="upstream1" output="upstream1_out1"/> | ||
<output name="top_upstream1_out2" type="color3" nodename="upstream1" output="upstream1_out2"/> | ||
|
||
<standard_surface name="standard_surface" type="surfaceshader" version="1.0.1" xpos="949.876" ypos="-189.576"> | ||
<input name="base_color" type="color3" nodegraph="upstream1" output="upstream1_out1" /> | ||
</standard_surface> | ||
<standard_surface name="standard_surface1" type="surfaceshader" version="1.0.1" xpos="940.476" ypos="307.63"> | ||
<input name="base_color" type="color3" nodegraph="upstream1" output="upstream1_out2" /> | ||
</standard_surface> | ||
<surfacematerial name="surfacematerial" type="material" xpos="1303.4" ypos="-234.282"> | ||
<input name="surfaceshader" type="surfaceshader" nodename="standard_surface" /> | ||
<input name="displacementshader" type="displacementshader" value="" /> | ||
</surfacematerial> | ||
<surfacematerial name="surfacematerial1" type="material" xpos="1325.2" ypos="245.001"> | ||
<input name="surfaceshader" type="surfaceshader" nodename="standard_surface1" /> | ||
<input name="displacementshader" type="displacementshader" value="" /> | ||
</surfacematerial> | ||
</materialx> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,133 @@ | ||
<?xml version="1.0"?> | ||
<materialx version="1.37"> | ||
<!-- Nodegraph to nodegraph connections --> | ||
<nodegraph name="upstream_graph" > | ||
<input name="file" type="filename" value="resources/Images/grid.png" /> | ||
<input name="file2" type="filename" value="resources/Images/cloth.png" /> | ||
<image name="image" type="color3"> | ||
<input name="file" type="filename" interfacename="file" value="resources/Images/grid.png" /> | ||
</image> | ||
<image name="image2" type="color3"> | ||
<input name="file" type="filename" interfacename="file2" value="resources/Images/cloth.png" /> | ||
</image> | ||
<output name="graph_out_image" type="color3" nodename="image" /> | ||
<output name="graph_out_image2" type="color3" nodename="image2" /> | ||
</nodegraph> | ||
<nodegraph name="graph_graph" > | ||
<input name="input" type="color3" nodegraph="upstream_graph" output="graph_out_image" value="1, 0, 0" /> | ||
<input name="input2" type="color3" nodegraph="upstream_graph" output="graph_out_image2" value="1, 0, 0" /> | ||
<multiply name="multiply" type="color3"> | ||
<input name="in1" type="color3" interfacename="input" value="1, 0, 0" /> | ||
<input name="in2" type="color3" value="0.4, 0.4, 0.4" /> | ||
</multiply> | ||
<multiply name="multiply2" type="color3"> | ||
<input name="in1" type="color3" interfacename="input2" value="1, 0, 0" /> | ||
<input name="in2" type="color3" value="0.4, 0.4, 0.4" /> | ||
</multiply> | ||
<output name="graph_graph_out" type="color3" nodename="multiply" /> | ||
<output name="graph_graph_out2" type="color3" nodename="multiply2" /> | ||
</nodegraph> | ||
<nodegraph name="surf_graph_graph" > | ||
<input name="input" type="color3" nodegraph="graph_graph" output="graph_graph_out" value="1, 1, 1" /> | ||
<input name="input2" type="color3" nodegraph="graph_graph" output="graph_graph_out2" value="1, 1, 1" /> | ||
<standard_surface name="default_shader" type="surfaceshader"> | ||
<input name="base_color" type="color3" interfacename="input" value="1, 1, 1" /> | ||
</standard_surface> | ||
<standard_surface name="default_shader2" type="surfaceshader"> | ||
<input name="base_color" type="color3" interfacename="input2" value="1, 1, 1" /> | ||
</standard_surface> | ||
<output name="surf_graph_graph_out" type="surfaceshader" nodename="default_shader" /> | ||
<output name="surf_graph_graph_out2" type="surfaceshader" nodename="default_shader2" /> | ||
</nodegraph> | ||
|
||
<!-- Connect node instance with multiple outputs to nodegraph --> | ||
<nodedef name="ND_upstream_graph" node="upstream_graph_def" version="1.0" isdefaultversion="true" nodegroup="procedural2d"> | ||
<input name="nd_file" type="filename" uniform="true" value="resources/Images/grid.png" /> | ||
<input name="nd_file2" type="filename" uniform="true" value="resources/Images/cloth.png" /> | ||
<output name="nd_graph_out_image" type="color3" value="0, 0, 0" /> | ||
<output name="nd_graph_out_image2" type="color3" value="0, 0, 0" /> | ||
</nodedef> | ||
<nodegraph name="NG_upstream_graph" nodedef="ND_upstream_graph" > | ||
<input name="nd_file" type="filename" uniform="true" value="resources/Images/grid.png" /> | ||
<input name="nd_file2" type="filename" uniform="true" value="resources/Images/cloth.png" /> | ||
<image name="image" type="color3" xpos="-79" ypos="-448.596"> | ||
<input name="file" type="filename" uniform="true" interfacename="nd_file" value="resources/Images/grid.png" /> | ||
</image> | ||
<image name="image2" type="color3"> | ||
<input name="file" type="filename" uniform="true" interfacename="nd_file2" value="resources/Images/cloth.png" /> | ||
</image> | ||
<output name="nd_graph_out_image" type="color3" nodename="image" /> | ||
<output name="nd_graph_out_image2" type="color3" nodename="image2" /> | ||
</nodegraph> | ||
<upstream_graph_def name="upstream_graph_instance" type="multioutput"> | ||
<output name="nd_graph_out_image" type="color3" /> | ||
<output name="nd_graph_out_image2" type="color3" /> | ||
</upstream_graph_def> | ||
<nodegraph name="nd_graph_graph" > | ||
<input name="nd_input" type="color3" nodename="upstream_graph_instance" output="nd_graph_out_image" value="1, 0, 0" /> | ||
<input name="nd_input2" type="color3" nodename="upstream_graph_instance" output="nd_graph_out_image2" value="1, 0, 0" /> | ||
<multiply name="multiply" type="color3"> | ||
<input name="in1" type="color3" interfacename="nd_input" value="1, 0, 0" /> | ||
<input name="in2" type="color3" value="0.4, 0.4, 0.4" /> | ||
</multiply> | ||
<multiply name="multiply2" type="color3"> | ||
<input name="in1" type="color3" interfacename="nd_input2" value="1, 0, 0" /> | ||
<input name="in2" type="color3" value="0.4, 0.4, 0.4" /> | ||
</multiply> | ||
<output name="nd_graph_graph_out" type="color3" nodename="multiply" /> | ||
<output name="nd_graph_graph_out2" type="color3" nodename="multiply2" /> | ||
</nodegraph> | ||
<nodegraph name="ng_surf_graph_graph" > | ||
<input name="nd_input" type="color3" nodename="upstream_graph_instance" output="nd_graph_out_image" value="1, 1, 1" /> | ||
<input name="nd_input2" type="color3" nodename="upstream_graph_instance" output="nd_graph_out_image2" value="1, 1, 1" /> | ||
<standard_surface name="default_shader" type="surfaceshader"> | ||
<input name="base_color" type="color3" interfacename="nd_input" value="1, 1, 1" /> | ||
</standard_surface> | ||
<standard_surface name="default_shader2" type="surfaceshader"> | ||
<input name="base_color" type="color3" interfacename="nd_input2" value="1, 1, 1" /> | ||
</standard_surface> | ||
<output name="nd_surf_graph_graph_out" type="surfaceshader" nodename="default_shader" /> | ||
<output name="nd_surf_graph_graph_out2" type="surfaceshader" nodename="default_shader2" /> | ||
</nodegraph> | ||
<!-- | ||
<output name="blah1" type="color3" nodename="upstream_graph_instance" output="nd_graph_out_image"/> | ||
<output name="blah2" type="color3" nodename="upstream_graph_instance" output="nd_graph_out_image2"/> | ||
<standard_surface name="default_shader" type="surfaceshader"> | ||
<input name="base_color" type="color3" nodename="upstream_graph_instance" output="nd_graph_out_image" /> | ||
<input name="specular_color" type="color3" nodename="upstream_graph_instance" output="nd_graph_out_image2" /> | ||
</standard_surface> | ||
<output name="surf_graph_node_out" type="surfaceshader" nodename="default_shader" /> | ||
--> | ||
|
||
<!-- Nodegraph to nodegraph to top level shader and utility node --> | ||
<standard_surface name="default_shader_top" type="surfaceshader"> | ||
<input name="base_color" type="color3" nodegraph="graph_graph" output="graph_graph_out" /> | ||
</standard_surface> | ||
<output name="surf_graph_graph_out_top" type="surfaceshader" nodename="default_shader_top" /> | ||
<multiply name="multiply_top" type="color3"> | ||
<input name="in1" type="color3" nodegraph="graph_graph" output="graph_graph_out" /> | ||
<input name="in2" type="color3" value="0.4, 0.4, 0.4" /> | ||
</multiply> | ||
<output name="graph_graph_out_top" type="color3" nodename="multiply_top" /> | ||
|
||
<!-- Nodegraph to node connection --> | ||
<image name="upstream_image" type="color3"> | ||
<input name="file" type="filename" interfacename="file" value="resources/Images/cloth.png" /> | ||
</image> | ||
<nodegraph name="graph_to_node" > | ||
<input name="input" type="color3" nodename="upstream_image" value="0, 1, 0" /> | ||
<multiply name="multiply" type="color3"> | ||
<input name="in1" type="color3" interfacename="input" value="0, 1, 0" /> | ||
<input name="in2" type="color3" value="0.4, 0.4, 0.4" /> | ||
</multiply> | ||
<output name="node_graph_out" type="color3" nodename="multiply" /> | ||
</nodegraph> | ||
<nodegraph name="surf_graph_node" > | ||
<input name="input" type="color3" nodegraph="graph_to_node" value="1, 1, 1" /> | ||
<standard_surface name="default_shader" type="surfaceshader"> | ||
<input name="base_color" type="color3" interfacename="input" value="1, 1, 1" /> | ||
</standard_surface> | ||
<output name="surf_graph_node_out" type="surfaceshader" nodename="default_shader" /> | ||
</nodegraph> | ||
|
||
</materialx> |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -329,8 +329,15 @@ OutputPtr Input::getConnectedOutput() const | |
// Look for output on a node | ||
else if (hasNodeName()) | ||
{ | ||
const string& nodeName = getNodeName(); | ||
ConstGraphElementPtr graph = getAncestorOfType<GraphElement>(); | ||
NodePtr node = graph ? graph->getNode(getNodeName()) : nullptr; | ||
NodePtr node = graph ? graph->getNode(nodeName) : nullptr; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For a given nodegraph input check at the parent nodegraph level for a connection. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think there is a risk of ambiguity here, if a node outside the graph has the same name as a node inside the graph. It's a possible setup since they have two different naming scopes. So if a nodegraph input connects to a node "foo1" outside the graph (nodename="foo1"), but there is also a node inside the graph named "foo1", the node inside the graph will be used, since both scopes are checked and inside nodes takes precedence. This would naturally be invalid since a node inside the graph is not connectable to a nodegraph input. I think we have to handle graph inputs and node inputs separately in this traversal, since graph inputs can only connect to elements outside the graph scope, and node inputs can only connected to elements in the same scope as the node. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I was trying to make this as reusable as possible. I'll need to take a closer look but getAncestorOfType<>() on an input in a graph is what being handled here which requires traversing twice as the first returned value is the graph itself and not it's parent. Basically, the rule for node vs nodegraph does not differ -- look for the referenced item on the parent. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm mainly thinking of name collisions with nodes inside vs outside the graph scope. As in this example:
If the internal scope is always searched first, in this case the internal node "foo1" would be returned as being connected to the input "in1", when in fact it is the external node "foo1" that is connected. A test case like this could be added to make sure this is handled correctly. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @bernardkwok @niklasharrysson As discussed in a separate thread, I think it would be valuable to merge the latest work from the v1.38 branch of MaterialX before proceeding too far with these new improvements, as there's a good deal of code that's been removed from Interface.cpp. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I've done the merge so this logic still needs to be resolved :). This basically means to always look up 2 levels from the input (if they exist). We don't have the concept of a input which is not a child of a node or nodegraph (i.e. at the Document level) so this does not need to be considered. |
||
if (!node && graph) | ||
{ | ||
ConstElementPtr parent = graph->getParent(); | ||
graph = parent->getAncestorOfType<GraphElement>(); | ||
node = graph ? graph->getNode(nodeName) : nullptr; | ||
} | ||
if (node) | ||
{ | ||
std::vector<OutputPtr> outputs = node->getOutputs(); | ||
|
@@ -355,8 +362,29 @@ OutputPtr Input::getConnectedOutput() const | |
return result; | ||
} | ||
|
||
InputPtr Input::getInterface() const | ||
bernardkwok marked this conversation as resolved.
Show resolved
Hide resolved
|
||
{ | ||
const string& interfaceName = getInterfaceName(); | ||
if (!interfaceName.empty()) | ||
{ | ||
ConstNodeGraphPtr graph = getAncestorOfType<NodeGraph>(); | ||
if (graph && !graph->hasNodeDefString()) | ||
{ | ||
return graph->getInput(interfaceName); | ||
} | ||
} | ||
return nullptr; | ||
} | ||
|
||
NodePtr Input::getConnectedNode() const | ||
{ | ||
// Traverse through interface names to nodegraph input | ||
InputPtr graphInput = getInterface(); | ||
if (graphInput && (graphInput->hasNodeName() || graphInput->hasNodeGraphString())) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If this input has an interfacename, then traverse through to that input to find any upstream connection. |
||
{ | ||
return graphInput->getConnectedNode(); | ||
} | ||
|
||
OutputPtr output = getConnectedOutput(); | ||
if (output) | ||
{ | ||
|
@@ -366,8 +394,16 @@ NodePtr Input::getConnectedNode() const | |
} | ||
if (hasNodeName()) | ||
{ | ||
// Check on current parent, and graph parent if any | ||
const string& nodeName = getNodeName(); | ||
ConstGraphElementPtr graph = getAncestorOfType<GraphElement>(); | ||
NodePtr node = graph ? graph->getNode(getNodeName()) : nullptr; | ||
NodePtr node = graph ? graph->getNode(nodeName) : nullptr; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For a given nodegraph input check at the parent nodegraph level for a connection. |
||
if (!node && graph) | ||
{ | ||
ConstElementPtr parent = graph->getParent(); | ||
graph = parent->getAncestorOfType<GraphElement>(); | ||
node = graph ? graph->getNode(nodeName) : nullptr; | ||
} | ||
if (node) | ||
{ | ||
return node; | ||
|
@@ -432,6 +468,11 @@ bool Input::validate(string* message) const | |
{ | ||
validateRequire(getDefaultGeomProp() != nullptr, res, message, "Invalid defaultgeomprop string"); | ||
} | ||
InputPtr interfaceInput = getInterface(); | ||
if (interfaceInput) | ||
{ | ||
return interfaceInput->validate() && res; | ||
} | ||
return PortElement::validate(message) && res; | ||
} | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This invalid case of an interfacename w/o a proper input is now caught.