3import os, argparse, sys, logging
4import GPUOpenLoader
as gpuo
8 Utility to download and write GPUOpen materials
10 logger = logging.getLogger(
'GPUO_CMD')
11 logging.basicConfig(level=logging.INFO)
13 parser = argparse.ArgumentParser(description=
'Get materials information and material package from AMD GPUOpen.'
14 ' By default the materials will be downloaded and a named and index material'
15 ' package will be extracted.')
16 parser.add_argument(
'--materialNames', type=bool, default=
None,
17 help=
'Return material names. Default is False')
21 parser.add_argument(
'--saveMaterials', type=bool, default=
None,
22 help=
'Save material lists. Default is None.'
23 ' Has no effect if --loadMaterials is set')
24 parser.add_argument(
'--extractExpression', type=str, default=
'Oliana Blue Painted Wood',
25 help=
'Extract out a package for a materials which match a given expression. Default is a sample material'
26 ' Has no effect if --loadMaterials is set')
27 parser.add_argument(
'--extractIndices', type=str, default=
'0,1,0',
28 help=
'Extract out a package for a materials which match a given material list, material index, and package index.'
29 ' Default is 0,1,0 which is currently the "Emerald Peaks Wallpaper" material')
30 parser.add_argument(
'--output', type=str, default=
'',
31 help=
'Output folder for data files. Default location is GPUOpenMaterialX.'
32 ' Has no effect if --loadMaterials is set')
33 opts = parser.parse_args()
35 loader = gpuo.GPUOpenMaterialLoader()
42 outputFolder =
'GPUOpenMaterialX'
44 if not os.path.exists(opts.output):
45 logger.error(f
'Error: Output directory does not exist: {opts.output}')
48 outputFolder = opts.output
51 materials = loader.getMaterials()
52 materialNames = loader.getMaterialNames()
53 materialCount = len(materialNames)
54 logger.info(f
'Available number of materials: {materialCount}')
55 if opts.saveMaterials:
56 loader.writeMaterialFiles(outputFolder,
'GPUOpenMaterialX')
60 if opts.extractExpression:
61 searchExpr = opts.extractExpression
62 if len(searchExpr) == 0:
63 logger.info(f
'> No search expression given.')
65 dataItems = loader.downloadPackageByExpression(searchExpr, 0)
66 for dataItem
in dataItems:
69 loader.writePackageDataToFile(data, outputFolder, title)
71 extractIndices = opts.extractIndices
72 if len(extractIndices) > 0:
73 indices = extractIndices.split(
',')
75 logger.error(f
'Error: Invalid indices given: {extractIndices}')
78 materialList = int(indices[0])
79 materialIndex = int(indices[1])
80 materialPackage = int(indices[2])
81 [data, title] = loader.downloadPackage(materialList, materialIndex, materialPackage)
82 logger.info(f
'> Download material: {title} List: {materialList}. Index: {materialIndex}. Package: {materialPackage}')
84 loader.writePackageDataToFile(data, outputFolder, title)
86 if opts.materialNames:
87 materialNamesFile = os.path.join(outputFolder,
'GPUOpenMaterialX_Names.json')
88 logger.info(f
'> Save materials names to file: {materialNamesFile}')
90 loader.writeMaterialNamesToFile(materialNamesFile, sorted)
92if __name__ ==
'__main__':