121 async
downloadMaterialAsset(assetId, imageFormat =
'PNG', imageResolution =
'1', downloadAttributeKey =
'downloadAttribute', downloadLinkKey =
'downloadLink') {
136 let downloadAttribute =
'';
138 items.forEach(item => {
139 downloadAttribute = item[downloadAttributeKey];
140 if (downloadAttribute === target) {
141 url = item[downloadLinkKey];
142 this.logger.info(`Found Asset: ${assetId}. Download Attribute: ${downloadAttribute} -> ${url}`);
147 this.logger.error(`No download link found
for asset: ${assetId}, attribute: ${target}`);
151 this.downloadMaterialFileName = url.split(
'file=')[1];
152 console.log(
'>>>> URL:', url,
'Filename:', this.downloadMaterialFileName);
155 const response = await fetch(url);
157 throw new Error(`HTTP error! Status: ${response.status}`);
161 const arrayBuffer = await response.arrayBuffer();
164 this.downloadMaterial = Buffer.from(arrayBuffer);
165 this.logger.info(`Material file downloaded: ${this.downloadMaterialFileName}`);
168 this.downloadMaterialFileName =
'';
169 this.logger.error(`Error occurred
while downloading the file: ${error}`);
172 return this.downloadMaterialFileName;
205 const headers = { Accept:
'application/csv' };
207 method:
'PBRPhotogrammetry',
212 const url =
new URL(
'https://ambientCG.com/api/v2/downloads_csv');
213 url.searchParams.append(
'method',
'PBRPhotogrammetry');
214 url.searchParams.append(
'type',
'Material');
215 url.searchParams.append(
'sort',
'Alphabet');
217 this.logger.info(
'Downloading materials CSV list...');
219 const response = await fetch(url, { headers });
220 if (response.status === 200) {
221 const csvContent = await response.text();
222 this.csvMaterials = csvContent;
223 this.materials = parse(csvContent, { columns:
true });
224 this.logger.info(
'Downloaded CSV material list as JSON.');
226 this.materials =
null;
227 this.logger.warning(`Failed to fetch the CSV material content. HTTP status code: ${response.status}`);
230 this.materials =
null;
231 this.logger.error(`Error downloading materials list: ${error}`);
234 return this.materials;
261 const url =
'https://ambientcg.com/api/v2/full_json';
262 const headers = { Accept:
'application/json' };
264 method:
'PBRPhotogrammetry',
270 const response = await axios.get(url, { headers, params });
271 if (response.status === 200) {
272 this.database = response.data;
273 this.assets = this.database.foundAssets;
275 this.logger.error(`Status: ${response.status}, ${response.data}`);
278 this.logger.error(`Error downloading asset database: ${error}`);
281 return this.database;