Skip to content

Commit

Permalink
Update token support for filename resolve and code generation
Browse files Browse the repository at this point in the history
  • Loading branch information
bernardkwok committed May 31, 2021
1 parent a734eaf commit aa39fe0
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 0 deletions.
22 changes: 22 additions & 0 deletions resources/Materials/TestSuite/stdlib/texture/tokenGraph.mtlx
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?xml version="1.0"?>
<materialx version="1.38">
<nodegraph name="Tokenized_Image_2k_png" >
<token name="Image_Resolution" type="string" value="2k" uiname="Image Resolution" />
<token name="Image_Extension" type="string" value="png" uiname="Image Extension" />
<input name="Image_Filename" type="filename" uniform="true" value="resources/images/cloth.[Image_Extension]" />
<tiledimage name="tiledimage" type="color3" nodedef="ND_tiledimage_color3" >
<input name="file" type="filename" uniform="true" interfacename="Image_Filename" value="resources/images/cloth.[Image_Extension]"/>
</tiledimage>
<output name="out_2k_png" type="color3" nodename="tiledimage" />
</nodegraph>

<nodegraph name="Tokenized_Image_4k_jpg" >
<tiledimage name="tiledimage" type="color3" nodedef="ND_tiledimage_color3" >
<token name="Image_Resolution" type="string" value="4k" uiname="Image Resolution" />
<token name="Image_Extension" type="string" value="jpg" uiname="Image Extension" />
<input name="file" type="filename" uniform="true" value="resources/images/cloth.[Image_Extension]"/>
</tiledimage>
<output name="out_4k_jpg" type="color3" nodename="tiledimage" />
</nodegraph>

</materialx>
13 changes: 13 additions & 0 deletions source/MaterialXCore/Element.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -434,6 +434,9 @@ StringResolverPtr Element::createStringResolver(const string& geom) const
// Add element tokens
addTokens(resolver);

// Add element tokens
addTokens(resolver);

return resolver;
}

Expand All @@ -447,6 +450,16 @@ void Element::addTokens(StringResolverPtr& resolver) const
}
}

void Element::addTokens(StringResolverPtr& resolver) const
{
// Check for any sibling token Elements
ConstElementPtr parent = getParent();
if (parent)
{
parent->addTokens(resolver);
}
}

string Element::asString() const
{
string res = "<" + getCategory();
Expand Down

0 comments on commit aa39fe0

Please sign in to comment.