2015-10-16 17:32:23 -04:00
#!/usr/bin/env node
"use strict" ;
2016-06-09 13:33:08 -04:00
var argv = require ( 'yargs' ) . argv ;
2016-06-23 16:25:40 -04:00
var Cesium = require ( 'cesium' ) ;
2016-06-09 13:33:08 -04:00
var defined = Cesium . defined ;
var defaultValue = Cesium . defaultValue ;
var convert = require ( '../lib/convert' ) ;
2015-10-16 17:32:23 -04:00
if ( process . argv . length < 3 || defined ( argv . h ) || defined ( argv . help ) ) {
2016-06-09 13:33:08 -04:00
console . log ( 'Usage: ./bin/obj2gltf.js [INPUT] [OPTIONS]' ) ;
2015-10-16 17:32:23 -04:00
console . log ( ' -i, --input Path to obj file' ) ;
console . log ( ' -o, --output Directory or filename for the exported glTF file' ) ;
console . log ( ' -b, --binary Output binary glTF' ) ;
2016-07-20 14:23:27 -04:00
console . log ( ' -s --separate Writes out separate geometry/animation data files, shader files, and textures instead of embedding them in the glTF file.' ) ;
console . log ( ' -t --separateImage Write out separate textures only.' ) ;
2015-10-16 17:32:23 -04:00
console . log ( ' -h, --help Display this help' ) ;
2016-07-12 18:14:56 -04:00
console . log ( ' --ao Apply ambient occlusion to the converted model' ) ;
2015-10-16 17:32:23 -04:00
process . exit ( 0 ) ;
}
var objFile = defaultValue ( argv . _ [ 0 ] , defaultValue ( argv . i , argv . input ) ) ;
2015-10-19 13:35:28 -04:00
var outputPath = defaultValue ( argv . _ [ 1 ] , defaultValue ( argv . o , argv . output ) ) ;
2016-06-23 21:21:21 -04:00
var binary = defaultValue ( defaultValue ( argv . b , argv . binary ) , false ) ;
2016-07-20 14:23:27 -04:00
var separate = defaultValue ( defaultValue ( argv . s , argv . separate ) , false ) ;
var separateImage = defaultValue ( defaultValue ( argv . t , argv . separateImage ) , false ) ;
2016-06-24 14:04:12 -04:00
var quantize = defaultValue ( defaultValue ( argv . q , argv . quantize ) , false ) ; // Undocumented option
2016-07-12 18:14:56 -04:00
var ao = defaultValue ( argv . ao , false ) ;
2015-10-16 17:32:23 -04:00
if ( ! defined ( objFile ) ) {
2016-06-09 13:33:08 -04:00
throw new Error ( '-i or --input argument is required. See --help for details.' ) ;
2015-10-16 17:32:23 -04:00
}
2016-06-09 13:33:08 -04:00
console . time ( 'Total' ) ;
2015-10-19 13:35:28 -04:00
2016-06-09 13:33:08 -04:00
var options = {
binary : binary ,
2016-07-20 14:23:27 -04:00
embed : ! separate ,
embedImage : ! separateImage ,
2016-07-12 18:14:56 -04:00
quantize : quantize ,
ao : ao
2016-06-09 13:33:08 -04:00
} ;
2015-10-16 17:32:23 -04:00
2016-06-09 13:33:08 -04:00
convert ( objFile , outputPath , options , function ( ) {
console . timeEnd ( 'Total' ) ;
2015-10-16 17:32:23 -04:00
} ) ;