-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathcompress.js
executable file
·39 lines (33 loc) · 1.13 KB
/
compress.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
34
35
36
37
38
39
#!/usr/bin/env node
const fs = require('fs')
const { readdir } = require('fs').promises;
const path = require('path')
const yargs = require('yargs')
const { hideBin } = require('yargs/helpers')
const argv = yargs(hideBin(process.argv)).argv
const { dracoCompressB3dm } = require('./bin/3d-tiles-tools')
async function getFiles(dir) {
const dirents = await readdir(dir, { withFileTypes: true });
const files = await Promise.all(dirents.map((dirent) => {
const res = path.resolve(dir, dirent.name);
return dirent.isDirectory() ? getFiles(res) : res;
}));
return files.flat().filter(e => e.match(/.*\.(b3dm)$/ig))
}
async function main() {
if (argv.input) {
const inputDir = path.resolve('', argv.input)
const files = await getFiles(inputDir)
if (files.length === 0) {
console.log(`no .b3dm files anywhere inside ${inputDir} ... BYE`)
process.exit(1)
}
for(let i=0; i<files.length; i++) {
const file = files[i]
await dracoCompressB3dm(file, argv.quality ? Number(argv.quality) : 100, argv.quality !== undefined)
}
} else {
console.log('gimme an input directory yo')
}
}
main()