MaterialXMaterials 1.39.5
Utilities for retrieving materials from remote servers
Loading...
Searching...
No Matches
materialxMaterials.ambientCGLoaderCmd Namespace Reference

Command to download ambientCG MaterialX materials. More...

Functions

 ambientCgLoaderCmd ()
 Utility to download ambientCG MaterialX materials.

Detailed Description

Command to download ambientCG MaterialX materials.

Function Documentation

◆ ambientCgLoaderCmd()

materialxMaterials.ambientCGLoaderCmd.ambientCgLoaderCmd ( )

Utility to download ambientCG MaterialX materials.

Definition at line 9 of file ambientCGLoaderCmd.py.

9def ambientCgLoaderCmd():
10 '''
11 Utility to download ambientCG MaterialX materials
12 '''
13 logger = logging.getLogger('ACG_CMD')
14 logging.basicConfig(level=logging.INFO)
15
16 parser = argparse.ArgumentParser(description='Get materials information and material package from ambientCG.'
17 ' By default the materials will be downloaded and a named and index material'
18 ' package will be extracted.')
19
20 parser.add_argument('--loadMaterials', type=str, default='',
21 help='Load JSON file containing list of materials that can be downloaded.')
22 parser.add_argument('--downloadMaterials', type=bool, default=None,
23 help='Download JSON file containing list of materials that can be downloaded.'
24 ' Has no effect if --loadMaterials is set')
25
26 # Material names query
27 parser.add_argument('--materialNames', type=bool, default=None,
28 help='Return material names. Default is False')
29
30 # Save download information for all materials or a specific one
31 # based on asset identifier
32 parser.add_argument('--saveMaterials', type=bool, default=None,
33 help='Save material lists. Default is None.'
34 ' Has no effect if --loadMaterials is set')
35 parser.add_argument('--saveMaterial', type=str, default='',
36 help='Save material download information in JSON format')
37
38 # Asset download options
39 parser.add_argument('--downloadMaterial', type=str, default='',
40 help='Download zip package for a materials which match a given string. Default is a sample material')
41 parser.add_argument('--downloadmageFormat', type=str, default='PNG',
42 help='Download image format. Valid values include PNG and JPEG. Default is PNG')
43 parser.add_argument('--downloadResolution', type=str, default='1',
44 help='Download image resulution. Valid values include 1,2,4,8 to indicate 1K to 8K.')
45
46 # Download full database iformation for material assets
47 parser.add_argument('--downloadDatabase', type=bool, default=None,
48 help='Download information database')
49 parser.add_argument('--saveDatabase', type=str, default='ambientCG_database.json',
50 help='Save information database')
51
52 # Output options
53 parser.add_argument('--output', type=str, default='',
54 help='Output folder for data files. Default location is the current execution folder.')
55 opts = parser.parse_args()
56
57 loader = acg.AmbientCGLoader(mx, None)
58
59 # Set output folder. Default is current folder
60 outputFolder = '.'
61 if opts.output:
62 outputFolder = opts.output
63 if not os.path.exists(outputFolder):
64 logger.error(f'Output directory does not exist: {outputFolder}')
65 sys.exit(1)
66
67 # Get materials list which contains download information
68 loadMaterials = opts.loadMaterials
69 downloadMaterials = opts.downloadMaterials or opts.saveMaterials
70 if loadMaterials or downloadMaterials:
71 materialsList = None
72 if len(loadMaterials) > 0:
73 materialsList = loader.loadMaterialsList(loadMaterials)
74 elif downloadMaterials:
75 materialsList = loader.downloadMaterialsList()
76 # Save materials list if specified. Only do so for download case
77 if opts.saveMaterials:
78 loader.writeMaterialList(materialsList, os.path.join(outputFolder,'ambientCG_materialsList.json'))
79
80 # Check if the list of materials is asked to be returned
81 if opts.materialNames:
82 materialNames = loader.getMaterialNames()
83 print(f'{materialNames}')
84
85 # Check if a material asset is specified to downloaded
86 materialName = opts.downloadMaterial
87 if len(materialName) > 0:
88 result = loader.findMaterial(materialName)
89 if result:
90 fileName = loader.downloadMaterialAsset(materialName) #, opts.downloadmageFormat, opts.downloadResolution)
91 if len(fileName) > 0:
92 loader.writeDownloadedMaterialToFile(outputFolder)
93 else:
94 print(f'Material not found: {materialName}')
95
96 # Check if material database is specified for download
97 databaseFileName = opts.saveDatabase
98 haveDatabaseFileName = len(databaseFileName) > 0
99 downloadDatabase = opts.downloadDatabase and haveDatabaseFileName
100 if downloadDatabase:
101 print('download database')
102 loader.downloadAssetDatabase()
103 if haveDatabaseFileName:
104 path = os.path.join(outputFolder, databaseFileName)
105 loader.writeDatabaseToFile(path)
106