3import os, argparse, sys, logging
4import ambientCGLoader
as acg
7def ambientCgLoaderCmd():
9 Utility to download and write ambientCG materials
11 logger = logging.getLogger(
'ACG_CMD')
12 logging.basicConfig(level=logging.INFO)
14 parser = argparse.ArgumentParser(description=
'Get materials information and material package from ambientCG.'
15 ' By default the materials will be downloaded and a named and index material'
16 ' package will be extracted.')
18 parser.add_argument(
'--loadMaterials', type=str, default=
'',
19 help=
'Load JSON file containing list of materials that can be downloaded.')
20 parser.add_argument(
'--downloadMaterials', type=bool, default=
None,
21 help=
'Download JSON file containing list of materials that can be downloaded.'
22 ' Has no effect if --loadMaterials is set')
25 parser.add_argument(
'--materialNames', type=bool, default=
None,
26 help=
'Return material names. Default is False')
30 parser.add_argument(
'--saveMaterials', type=bool, default=
None,
31 help=
'Save material lists. Default is None.'
32 ' Has no effect if --loadMaterials is set')
33 parser.add_argument(
'--saveMaterial', type=str, default=
'',
34 help=
'Save material download information in JSON format')
37 parser.add_argument(
'--downloadMaterial', type=str, default=
'',
38 help=
'Download zip package for a materials which match a given string. Default is a sample material')
39 parser.add_argument(
'--downloadmageFormat', type=str, default=
'PNG',
40 help=
'Download image format. Valid values include PNG and JPEG. Default is PNG')
41 parser.add_argument(
'--downloadResolution', type=str, default=
'1',
42 help=
'Download image resulution. Valid values include 1,2,4,8 to indicate 1K to 8K.')
45 parser.add_argument(
'--downloadDatabase', type=bool, default=
None,
46 help=
'Download information database')
47 parser.add_argument(
'--saveDatabase', type=str, default=
'ambientCG_database.json',
48 help=
'Save information database')
51 parser.add_argument(
'--output', type=str, default=
'',
52 help=
'Output folder for data files. Default location is the current execution folder.')
53 opts = parser.parse_args()
55 loader = acg.AmbientCGLoader(mx,
None)
60 outputFolder = opts.output
61 if not os.path.exists(outputFolder):
62 logger.error(f
'Output directory does not exist: {outputFolder}')
66 loadMaterials = opts.loadMaterials
67 downloadMaterials = opts.downloadMaterials
or opts.saveMaterials
68 if loadMaterials
or downloadMaterials:
70 if len(loadMaterials) > 0:
71 materialsList = loader.loadMaterialsList(loadMaterials)
72 elif downloadMaterials:
73 materialsList = loader.downloadMaterialsList()
75 if opts.saveMaterials:
76 loader.writeMaterialList(materialsList, os.path.join(outputFolder,
'ambientCG_materialsList.json'))
79 if opts.materialNames:
80 materialNames = loader.getMaterialNames()
81 print(f
'{materialNames}')
84 materialName = opts.downloadMaterial
85 if len(materialName) > 0:
86 result = loader.findMaterial(materialName)
88 fileName = loader.downloadMaterialAsset(materialName)
90 loader.writeDownloadedMaterialToFile(outputFolder)
92 print(f
'Material not found: {materialName}')
95 databaseFileName = opts.saveDatabase
96 haveDatabaseFileName = len(databaseFileName) > 0
97 downloadDatabase = opts.downloadDatabase
and haveDatabaseFileName
99 print(
'download database')
100 loader.downloadAssetDatabase()
101 if haveDatabaseFileName:
102 path = os.path.join(outputFolder, databaseFileName)
103 loader.writeDatabaseToFile(path)
105if __name__ ==
'__main__':