4The script will generate MaterialX definitions for all color spaces found in the
5ACES Cg Config` and `ACES Studio Config` configurations.
7For source code generation
8- The definitions will be generated for the following MaterialX targets:
10- The resulting output is:
11 - A color4 implementation file containing the source code generated by OCIO.
12 - A color3 node graph implementation which uses the color4 implementation (nodegraph)
13 - A file with both color3 and color4 MaterialX definitions (nodedef).
14 - A MaterialX file containing implementation declarations for color3 and color4 variants.
16For functional node graph generation:
17- The definition will generate a `nodegraph` and `nodedef`pair based on the
18transforms returned from the OCIO processor.
19- Currently only a `color3 variant is generated.
21Additonaly, the script will generate a markdown file with information about the built-in configurations.
26import PyOpenColorIO
as OCIO
30 parser = argparse.ArgumentParser(description=
"Create Materialx definitions using OCIO.")
31 parser.add_argument(
'--graph', dest=
'graph', help=
'Generate a node graph implementations instead of source code.', action=
'store_true')
32 parser.add_argument(
'--outputPath', dest=
'outputPath', help=
'File path to output material files to.')
34 opts = parser.parse_args()
35 outputPath = mx.FilePath(
"./data/")
37 outputPath = mx.FilePath(opts.outputPath)
40 ver = OCIO.GetVersion()
41 ocioVersion = ver.split(
'.')
42 if len(ocioVersion) < 2:
43 print(
'OCIO version is not in the expected format.')
45 if int(ocioVersion[0]) < 2
or int(ocioVersion[1]) < 2:
46 print(
'OCIO version 2.2 or greater is required.')
49 print(
'OCIO version:', ver)
50 print(
'MaterialX version:', mx.getVersionString())
54 generator = mxocio.OCIOMaterialaxGenerator()
55 configs, aconfig = generator.getBuiltinConfigs()
56 md = generator.printConfigs(configs)
58 if not os.path.exists(outputPath.asString()):
59 os.makedirs(outputPath.asString())
60 configInfoFile = outputPath / mx.FilePath(
'OCIO_configurations.md')
61 print(
'Write out OCIO configurations to: ' + configInfoFile.asString())
62 f = open(configInfoFile.asString(),
'w')
65 sourceColorSpace =
"acescg"
66 targetColorSpace =
'lin_rec709'
70 IN_PIXEL_STRING =
'in'
75 config = configs[c][0]
76 for colorSpace
in config.getColorSpaces():
77 aliases = colorSpace.getAliases()
84 trySource = colorSpace.getName()
86 sourceColorSpace = trySource
89 if sourceColorSpace == targetColorSpace:
92 print(
'--- Generate transform for source color space:', trySource,
'---')
96 definitionDoc = mx.createDocument()
97 implDoc = mx.createDocument()
99 definition, transformName, code, extension, target = generator.generateOCIO(aconfig, definitionDoc, implDoc, sourceColorSpace, targetColorSpace,
'color4')
104 filename = outputPath / mx.FilePath(definition.getName() +
'.' +
'mtlx')
105 print(
'Write MaterialX definition file:', filename.asString())
106 mx.writeToXmlFile(definitionDoc, filename)
109 implFileName = outputPath / mx.FilePath(
'IM_' + transformName +
'.' +
'mtlx')
110 print(
'Write MaterialX implementation file:', implFileName.asString())
111 result = mx.writeToXmlFile(implDoc, implFileName)
113 generator.writeShaderCode(outputPath, code, transformName, extension, target)
116 outputType =
'color3'
117 graphDoc = generator.generateOCIOGraph(aconfig, sourceColorSpace, targetColorSpace, outputType)
119 transformName = generator.createTransformName(sourceColorSpace, targetColorSpace, outputType,
'mxgraph_')
120 filename = outputPath / mx.FilePath(transformName +
'.' +
'mtlx')
121 print(
'Write MaterialX node graph definition file:', filename.asString())
122 mx.writeToXmlFile(graphDoc, filename)
125 print(
'Could not find suitable color space name to use: ', colorSpace.getName())
128if __name__ ==
'__main__':