MCPcopy Create free account
hub / github.com/AcademySoftwareFoundation/MaterialX / main

Function main

python/Scripts/baketextures.py:15–70  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

13 from MaterialX import PyMaterialXRenderMsl as mx_render_msl
14
15def main():
16 parser = argparse.ArgumentParser(description="Generate a baked version of each material in the input document.")
17 parser.add_argument("--width", dest="width", type=int, default=1024, help="Specify the width of baked textures.")
18 parser.add_argument("--height", dest="height", type=int, default=1024, help="Specify the height of baked textures.")
19 parser.add_argument("--hdr", dest="hdr", action="store_true", help="Save images to hdr format.")
20 parser.add_argument("--average", dest="average", action="store_true", help="Average baked images to generate constant values.")
21 parser.add_argument("--path", dest="paths", action='append', nargs='+', help="An additional absolute search path location (e.g. '/projects/MaterialX')")
22 parser.add_argument("--library", dest="libraries", action='append', nargs='+', help="An additional relative path to a custom data library folder (e.g. 'libraries/custom')")
23 parser.add_argument('--writeDocumentPerMaterial', dest='writeDocumentPerMaterial', type=mx.stringToBoolean, default=True, help='Specify whether to write baked materials to separate MaterialX documents. Default is True')
24 if platform == "darwin":
25 parser.add_argument("--glsl", dest="useGlslBackend", default=False, type=bool, help="Set to True to use GLSL backend (default = Metal).")
26 parser.add_argument(dest="inputFilename", help="Filename of the input document.")
27 parser.add_argument(dest="outputFilename", help="Filename of the output document.")
28 opts = parser.parse_args()
29
30 # Load standard and custom data libraries.
31 stdlib = mx.createDocument()
32 searchPath = mx.getDefaultDataSearchPath()
33 searchPath.append(os.path.dirname(opts.inputFilename))
34 libraryFolders = []
35 if opts.paths:
36 for pathList in opts.paths:
37 for path in pathList:
38 searchPath.append(path)
39 if opts.libraries:
40 for libraryList in opts.libraries:
41 for library in libraryList:
42 libraryFolders.append(library)
43 libraryFolders.extend(mx.getDefaultDataLibraryFolders())
44 mx.loadLibraries(libraryFolders, searchPath, stdlib)
45
46 # Read and validate the source document.
47 doc = mx.createDocument()
48 try:
49 mx.readFromXmlFile(doc, opts.inputFilename)
50 doc.setDataLibrary(stdlib)
51 except mx.ExceptionFileMissing as err:
52 print(err)
53 sys.exit(0)
54 valid, msg = doc.validate()
55 if not valid:
56 print("Validation warnings for input document:")
57 print(msg)
58
59 # Construct the texture baker.
60 baseType = mx_render.BaseType.FLOAT if opts.hdr else mx_render.BaseType.UINT8
61 if platform == "darwin" and not opts.useGlslBackend:
62 baker = mx_render_msl.TextureBaker.create(opts.width, opts.height, baseType)
63 else:
64 baker = mx_render_glsl.TextureBaker.create(opts.width, opts.height, baseType)
65
66 # Bake materials to textures.
67 if opts.average:
68 baker.setAverageImages(True)
69 baker.writeDocumentPerMaterial(opts.writeDocumentPerMaterial)
70 baker.bakeAllMaterials(doc, searchPath, opts.outputFilename)
71
72if __name__ == '__main__':

Callers 1

baketextures.pyFile · 0.70

Calls 6

printFunction · 0.85
setAverageImagesMethod · 0.80
appendMethod · 0.45
validateMethod · 0.45
createMethod · 0.45

Tested by

no test coverage detected