diff --git a/python/Scripts/baketextures.py b/python/Scripts/baketextures.py index ce132036a6..7856dca749 100644 --- a/python/Scripts/baketextures.py +++ b/python/Scripts/baketextures.py @@ -27,13 +27,7 @@ def main(): parser.add_argument(dest="outputFilename", help="Filename of the output document.") opts = parser.parse_args() - doc = mx.createDocument() - try: - mx.readFromXmlFile(doc, opts.inputFilename) - except mx.ExceptionFileMissing as err: - print(err) - sys.exit(0) - + # Load standard and custom data libraries. stdlib = mx.createDocument() searchPath = mx.getDefaultDataSearchPath() searchPath.append(os.path.dirname(opts.inputFilename)) @@ -48,21 +42,28 @@ def main(): libraryFolders.append(library) libraryFolders.extend(mx.getDefaultDataLibraryFolders()) mx.loadLibraries(libraryFolders, searchPath, stdlib) - doc.importLibrary(stdlib) + # Read and validate the source document. + doc = mx.createDocument() + try: + mx.readFromXmlFile(doc, opts.inputFilename) + doc.setDataLibrary(stdlib) + except mx.ExceptionFileMissing as err: + print(err) + sys.exit(0) valid, msg = doc.validate() if not valid: print("Validation warnings for input document:") print(msg) + # Construct the texture baker. baseType = mx_render.BaseType.FLOAT if opts.hdr else mx_render.BaseType.UINT8 - - if platform == "darwin" and not opts.useGlslBackend: baker = mx_render_msl.TextureBaker.create(opts.width, opts.height, baseType) else: baker = mx_render_glsl.TextureBaker.create(opts.width, opts.height, baseType) + # Bake materials to textures. if opts.average: baker.setAverageImages(True) baker.writeDocumentPerMaterial(opts.writeDocumentPerMaterial)