-
Notifications
You must be signed in to change notification settings - Fork 58
/
Copy pathremote-svf-to-gltf.js
33 lines (29 loc) · 1.49 KB
/
remote-svf-to-gltf.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
/*
* Example: converting an SVF from Model Derivative service.
* Usage:
* export APS_CLIENT_ID=<your client id>
* export APS_CLIENT_SECRET=<your client secret>
* node remote-svf-to-gltf.js <your model urn> <path to output folder>
*/
const path = require('path');
const { getSvfDerivatives } = require('./shared.js');
const { SvfReader, GltfWriter, TwoLeggedAuthenticationProvider } = require('..');
const { APS_CLIENT_ID, APS_CLIENT_SECRET, APS_REGION } = process.env;
async function run(urn, outputDir) {
try {
const derivatives = await getSvfDerivatives(urn, APS_CLIENT_ID, APS_CLIENT_SECRET, APS_REGION);
const writer0 = new GltfWriter({ deduplicate: false, skipUnusedUvs: false, center: true, log: console.log });
const writer1 = new GltfWriter({ deduplicate: true, skipUnusedUvs: true, center: true, log: console.log });
const authenticationProvider = new TwoLeggedAuthenticationProvider(APS_CLIENT_ID, APS_CLIENT_SECRET);
for (const derivative of derivatives) {
const reader = await SvfReader.FromDerivativeService(urn, derivative.guid, authenticationProvider);
const scene = await reader.read({ log: console.log });
await writer0.write(scene, path.join(outputDir, derivative.guid, 'gltf-raw'));
await writer1.write(scene, path.join(outputDir, derivative.guid, 'gltf-dedup'));
}
} catch(err) {
console.error(err);
process.exit(1);
}
}
run(process.argv[2], process.argv[3]);