autodesk-forks / MaterialX

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

Runtime token support #1157

Closed bernardkwok closed 3 years ago

bernardkwok commented 3 years ago

Update #1159

Add in support for <token> as a runtime "input" which is marked as a token.

Example nodegraph with token called mytoken which is marked as non-visible.

<?xml version="1.0"?>
<materialx version="1.38">
  <nodegraph name="Tokenized_graph" xpos="1044.25" ypos="852.077" >
    <token name="mytoken" type="color3" value="1, 1, 1" uivisible="false" uiname="My Token"/>
    <input name="value" type="color3" value="0, 0, 0" uivisible="false"/>
    <constant name="constant" type="color3" xpos="-136.498" ypos="-120.44">
      <input name="value" type="color3" interfacename="value" value="0, 0, 0" uivisible="true" />
    </constant>
    <output name="out" type="color3" nodename="constant" />
  </nodegraph>
  <collection name="defaultCollection" includecollection="" includegeom="/*" xpos="315" ypos="229" />
</materialx>

Would look like this graphically: image

With the contents looking like this (token in "neon pink"). image

Based on the current specification <token> elements are not connectable.

Unit test will produce this file:

<?xml version="1.0"?>
<materialx version="1.38">
  <nodegraph name="nodegraph1">
    <input name="in" type="float" value="0" />
    <token name="token1" type="float" uniform="true" value="0" />
    <add name="add" type="float">
      <input name="in1" type="float" interfacename="in" value="0" />
    </add>
    <add name="add1" type="float">
      <input name="in1" type="float" nodename="add" />
    </add>
    <add name="add2" type="float" />
    <output name="out" type="float" nodename="add1" />
  </nodegraph>
  <add name="add" type="float">
    <input name="in1" type="float" nodegraph="nodegraph1" />
  </add>
</materialx>