MaterialXglTF 1.39.0.1
Loading...
Searching...
No Matches
materialxgltf.gltf2Mtlx Namespace Reference

Utility and command line interface to convert from a glTF file to a MaterialX file. More...

Functions

 gltf2Mtlx (gltfFileName, mtlxFileName, options=GLTF2MtlxOptions())
 Utility to convert a glTF file to MaterialX file.
 
 main ()
 Command line interface to convert from a glTF file to a MaterialX file.
 

Detailed Description

Utility and command line interface to convert from a glTF file to a MaterialX file.

Function Documentation

◆ gltf2Mtlx()

materialxgltf.gltf2Mtlx.gltf2Mtlx ( gltfFileName,
mtlxFileName,
options = GLTF2MtlxOptions() )

Utility to convert a glTF file to MaterialX file.

Parameters
gltfFileNamePath to glTF file to convert
mtlxFileNamePath to MaterialX file to write
optionsOptions for conversion

Definition at line 12 of file gltf2Mtlx.py.

12def gltf2Mtlx(gltfFileName, mtlxFileName, options=GLTF2MtlxOptions()):
13 '''
14 @brief Utility to convert a glTF file to MaterialX file
15
16 @param gltfFileName Path to glTF file to convert
17 @param mtlxFileName Path to MaterialX file to write
18 @param options Options for conversion
19 '''
20 status = True
21 err = ''
22
23 gltf2MtlxReader = GLTF2MtlxReader()
24 gltf2MtlxReader.setOptions(options)
25 doc = gltf2MtlxReader.convert(gltfFileName)
26 if not doc:
27 status = False
28 err = 'Error converting glTF file to MaterialX file'
29 else:
30 status, err = doc.validate()
31 if not status:
32 print('Validation error: ', err)
33 #print(mx.writeToXmlString(doc))
34 Util.writeMaterialXDoc(doc, mtlxFileName)
35
36 return status, err
37

◆ main()

materialxgltf.gltf2Mtlx.main ( )

Command line interface to convert from a glTF file to a MaterialX file.

Definition at line 38 of file gltf2Mtlx.py.

38def main():
39 '''
40 @brief Command line interface to convert from a glTF file to a MaterialX file
41 '''
42 parser = argparse.ArgumentParser(description='Utility to convert a glTF file to MaterialX file')
43 parser.add_argument(dest='gltfFileName', help='Path containing glTF file to convert.')
44 parser.add_argument('--mtlxFileName', dest='mtlxFileName', default='', help='Name of MaterialX output file. If not specified the glTF name with "_converted.mtlx" suffix will be used')
45 parser.add_argument('--createAssignments', dest='createAssignments', type=mx.stringToBoolean, default=True, help='Create material assignments. Default is True')
46 parser.add_argument('--addAllInputs', dest='addAllInputs', type=mx.stringToBoolean, default=False, help='Add all definition inputs to MaterialX shader nodes. Default is False')
47
48 opts = parser.parse_args()
49
50 # Check input glTF file
51 gltfFileName = opts.gltfFileName
52 if not os.path.exists(gltfFileName):
53 print('Cannot find input file: ', gltfFileName)
54 exit(-1)
55
56 # Set up MTLX file name
57 mtlxFilePath = gltfFileName + '_converted.mtlx'
58 if opts.mtlxFileName:
59 mtlxFilePath = opts.mtlxFileName
60
61 # Perform conversion
62 options = GLTF2MtlxOptions()
63 options['createAssignments'] = opts.createAssignments
64 options['addAllInputs'] = opts.addAllInputs
65 converted, err = gltf2Mtlx(gltfFileName, mtlxFilePath, options)
66 print('Converted glTF file %s to MaterialX file: %s. Status: %s.' % (gltfFileName, mtlxFilePath, converted))
67 if not converted:
68 print('- Error: ', err)
69