autodesk-forks / MaterialX

MaterialX C++ and Python libraries
http://www.materialx.org/
Apache License 2.0
107 stars 23 forks source link

Explicit Inputs for NodeGraph instances #849

Open bernardkwok opened 4 years ago

bernardkwok commented 4 years ago

Proposal

Allow for inputs to be explicitly listed "published" for nodegraphs.

Upgrade Path:

Examples

<nodegraph name="graph1">
   <input name="input1" type="float" />
   <input name="input2" type="float/>
   <output name="out1" type="float" nodename="addnode" />
   <add name="addnode" type="float">
      <input name="in1" type="float" value="1.0" interfacename="input1/>
      <input name="in2" type="float" value="0.0" interfacename="input2" />
    </add>
</nodegraph>

Here 2 inputs are defined input1 and input2 which route data to the add node.

Example 2:

<constant name="foo1" type="float" value="2.3">

<nodegraph name="graph1">
   <input name="input1" type="float" nodename="foo1"/>
   <input name="input2" type="float/>
   <output name="out1" type="float" nodename="addnode" />
   <add name="addnode" type="float">
      <input name="in1" type="float" value="1.0" interfacename="input1/>
      <input name="in2" type="float" value="0.0" interfacename="input2" />
    </add>
</nodegraph>

Here is the same example but connected to a non-nodegrah node foo1 via input `input1.

bernardkwok commented 3 years ago

Note that a graph like this will be handled after looking at #1062 which would encapsulate the nodegraph properly to avoid conflicts.

<?xml version="1.0"?>
<materialx version="1.37">
   <!-- Check for inputs with same nodenames at different levels -->
   <constant name="foo1" type="color3">
      <parameter name="value" type="color3" value="1, 0, 0"/>
   </constant>
   <nodegraph name="nodename_check" >
      <input name="in1" type="color3" nodename="foo1" />
      <input name="in2" type="color3" value="0, 1, 0" />
      <constant name="foo1" type="float">
         <parameter name="value" type="float" value="0.5"/>
      </constant>
      <mix name="mix1" type="color3">
         <input name="bg" type="color3" interfacename="in1" />
         <input name="fg" type="color3" interfacename="in1" />
         <input name="mix" type="float" nodename="foo1" />
      </mix>
      <output name="out_nodename_check" type="color3" nodename="mix1" />
   </nodegraph>
</materialx>