5This module contains the utilities for MaterialX glTF Procedural Texture graph conversion.
14 @param filename: The file to load.
15 @return: The JSON string
18 with open(filename,
'r')
as file:
19 file = json.load(file)
20 json_string = json.dumps(file, indent=2)
24 '''Load standard MaierialX libraries.
25 @return: The standard library and the list of library files.
27 stdlib = mx.createDocument()
28 libFiles = mx.loadLibraries(mx.getDefaultDataLibraryFolders(), mx.getDefaultDataSearchPath(), stdlib)
29 return stdlib, libFiles
32 '''Create a working document and import any libraries
33 @param libraries: The list of definition libraries to import.
34 @return: The new working document
36 doc = mx.createDocument()
38 doc.importLibrary(lib)
43 '''Import libraries into a document.
44 @param doc: The document to import into.
45 @param libraries: The list of libraries to import.
47 doc.importLibrary(libraries)
51 Read a MaterialX document from a file.
52 @param materialx_doc: The MaterialX document to read into.
53 @param input_file: The file to read from.
55 mx.readFromXmlFile(materialx_doc, input_file)
58 '''Convert a MaterialX document to a string.
59 @param materialx_doc: The document to convert.
60 @return: The document as a string.
62 return mx.writeToXmlString(materialx_doc)
65 '''Validate a MaterialX document.
66 @param doc: The document to validate.
67 @return: The validation result as a tuple of [valid, error string].
69 valid, error_string = doc.validate()
70 return valid, error_string
73 '''Get all files with a given extension in a directory.
74 @param rootPath: The root directory to search.
75 @param extension: The file extension to search for.
76 @return: The list of files with the given extension.
80 for subdir, dirs, files
in os.walk(rootPath):
82 if file.lower().endswith(exts):
83 filelist.append(os.path.join(subdir, file))
88 Check if the current vesion matches a given version
89 @parm major: The major version number
90 @parm minor: The minor version number
91 @parm patch: The patch version number
92 @return: True if the current version is greater or equal to the given version
94 imajor, iminor, ipatch = mx.getVersionIntegers()
108 Remove all comments from a MaterialX document.
109 @param doc: The document to remove comments from.
111 comments = doc.getChildren()
112 for comment
in comments:
113 if comment.getCategory() ==
'comment':
114 doc.removeChild(comment.getName())
materialX_doc_to_string(materialx_doc)
Convert a MaterialX document to a string.
get_files(rootPath, extension)
Get all files with a given extension in a directory.
create_working_document(libraries)
Create a working document and import any libraries.
load_json_file(filename)
Load a JSON file.
have_version(major, minor, patch)
Check if the current vesion matches a given version @parm major: The major version number @parm minor...
load_standard_libraries()
Load standard MaierialX libraries.
remove_comments(doc)
Remove all comments from a MaterialX document.
import_libraries(doc, libraries)
Import libraries into a document.
validate_document(doc)
Validate a MaterialX document.
read_materialX_document(materialx_doc, input_file)
Read a MaterialX document from a file.