Command line interface to convert from a glTF file to a MaterialX file.
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('-fn', '--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('-ca', '--createAssignments', dest='createAssignments', type=mx.stringToBoolean, default=True, help='Create material assignments. Default is True')
46 parser.add_argument('-ai','--addAllInputs', dest='addAllInputs', type=mx.stringToBoolean, default=False, help='Add all definition inputs to MaterialX shader nodes. Default is False')
47 parser.add_argument('-ax', '--assignXform', dest='assignXform', type=mx.stringToBoolean, default=False, help='Assign to transforms vs shapes. Default is False' )
48
49 opts = parser.parse_args()
50
51
52 gltfFileName = opts.gltfFileName
53 if not os.path.exists(gltfFileName):
54 print('Cannot find input file: ', gltfFileName)
55 exit(-1)
56
57
58 mtlxFilePath = gltfFileName + '_converted.mtlx'
59 if opts.mtlxFileName:
60 mtlxFilePath = opts.mtlxFileName
61
62
63 options = GLTF2MtlxOptions()
64 options['createAssignments'] = opts.createAssignments
65 options['addAllInputs'] = opts.addAllInputs
66 options['assignXform'] = opts.assignXform
67 converted, err = gltf2Mtlx(gltfFileName, mtlxFilePath, options)
68 print('Converted glTF file %s to MaterialX file: %s. Status: %s.' % (gltfFileName, mtlxFilePath, converted))
69 if not converted:
70 print('- Error: ', err)
71