-
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
Handle locale for MaterialX inputs #1178
Conversation
fixup! fix build break
Also add githash on generated files e.g. given a node def e.g. ND_standard_surface_surfaceshader will generate a standard_surface.json and standard_surface.hpp The hpp/json can be used for simple reflection instead of parsing mtlx libraries
Move utility python script into contrib
8032b13
to
95a0994
Compare
@bernardkwok I'm unsure why the build tests fail. I'm unable to repro this locally |
|
||
def main(): | ||
parser = argparse.ArgumentParser( | ||
description="MaterialX nodedef to json/hpp convert.") |
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.
Nitpick. "converter" instead of "convert" ?
return None | ||
for elem in elemlist: | ||
if elem.isA(mx.NodeDef) and elem.getName() == nodedefname: | ||
#print (elem) |
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.
Remove commented out code.
parser.add_argument(dest="inputFilename", | ||
help="Filename of the input document.") | ||
parser.add_argument("--node", dest="nodedef", type=str, | ||
default="ND_standard_surface_surfaceshader", |
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.
Maybe leave the default to be empty string instead ?
if elem.isA(mx.NodeDef): | ||
jsonfilename = elem.getNodeString()+'.json' | ||
hppfilename = elem.getNodeString()+'.hpp' | ||
export_json(elem, jsonfilename) |
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.
Should we catch exceptions here in case the files cannot be written.
\n{nodename}\nSHA1:{filehash}\nVersion:{version}\n*/\n"\ | ||
.format(nodename=elem, filehash=INPUTFILEHASH, version=mx.getVersionString()) | ||
variable_defs = "" | ||
for inp in elem.getActiveInputs(): |
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.
As mentioned in chat, would you want to export outputs as well ?
In which case would it be better to get "value elements" instead of just inputs. ?
For MaterialX let's assume we have a xml with `<input name="diffColor" type="vector3" value="1,1.5,2.0"/>` mx:Vector3(1,1.5,2.0) should be interpreted as float[3] = [1.0f, 1.5f, 2.0f]. But based on the locale settings, 1,1.5 will be parsed as a value. By setting the locale on std::stringstream we ensure that input values are correctly read Some background reference around this https://stdcxx.apache.org/doc/stdlibug/24-3.html https://docs.microsoft.com/en-us/globalization/locale/number-formatting Partially addresses Issue #1183 Other changes: Basic utility to generate a json and hpp export from MaterialX nodedef e.g. given a node def e.g. ND_standard_surface_surfaceshader will generate a standard_surface.json and standard_surface.hpp The hpp/json can be used for simple reflection instead of parsing mtlx libraries
Some background reference around this https://stdcxx.apache.org/doc/stdlibug/24-3.html
https://docs.microsoft.com/en-us/globalization/locale/number-formatting
For MaterialX let's assume we have a xml with
<input name="diffColor" type="vector3" value="1,1.5,2.0"/>
mx:Vector3(1,1.5,2.0) should be interpreted as float[3] = [1.0f, 1.5f, 2.0f]
But based on the locale settings,
1,1.5
will be parsed as a value.#1183