forked from pmndrs/gltfjsx
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
30 lines (27 loc) · 1.31 KB
/
index.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
#!/usr/bin/env node
const version = require('./package.json').version
const gltfjsx = require('./gltfjsx')
const argv = require('yargs')
.boolean('animation')
.boolean('draco')
.option('draco', { alias: 'd', describe: 'Adds draco-Loader', type: 'boolean' })
.option('types', { alias: 't', describe: 'Adds Typescript definitions' })
.option('animation', { alias: 'a', describe: 'Extracts animation clips' })
.option('compress', { alias: 'c', default: true, describe: 'Removes names and empty groups' })
.option('precision', { alias: 'p', default: 2, describe: 'Number of fractional digits', type: 'number' })
.option('binary', { alias: 'b', describe: 'Draco path', default: '/draco-gltf/', type: 'string' })
.usage('npx gltfjsx model.gltf [Model.js] [options]')
.help().argv
if (argv._[0]) {
let file = argv._[0]
let nameExt = file.match(/[-_\w]+[.][\w]+$/i)[0]
let name = nameExt.split('.').slice(0, -1).join('.')
let output = argv._[1] || name.charAt(0).toUpperCase() + name.slice(1) + (argv.types ? '.tsx' : '.js')
console.log(`gltfjsx ${version}, converting ${file} to ${output}`)
console.log('')
gltfjsx(file, nameExt, output, argv)
.then(() => console.log('\ndone.'))
.catch((err) => console.log('\nfailed.\n\n', err))
} else {
console.log('missing the input filename. type: gltfjsx --help')
}