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.' ) ;
2016-08-25 13:48:34 -04:00
console . log ( ' -c --compress Quantize positions, compress texture coordinates, and oct-encode normals.' ) ;
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' ) ;
2016-07-25 22:12:41 -04:00
console . log ( ' --cesium Optimize the glTF for Cesium by using the sun as a default light source.' ) ;
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-08-25 13:48:34 -04:00
var compress = defaultValue ( defaultValue ( argv . c , argv . compress ) , false ) ;
2016-07-12 18:14:56 -04:00
var ao = defaultValue ( argv . ao , false ) ;
2016-07-25 22:12:41 -04:00
var optimizeForCesium = defaultValue ( argv . cesium , 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-08-25 13:48:34 -04:00
compress : compress ,
2016-07-25 22:12:41 -04:00
ao : ao ,
optimizeForCesium : optimizeForCesium
2016-06-09 13:33:08 -04:00
} ;
2015-10-16 17:32:23 -04:00
2016-07-22 14:09:13 -04:00
convert ( objFile , outputPath , options )
. then ( function ( ) {
console . timeEnd ( 'Total' ) ;
2016-07-22 16:27:20 -04:00
} )
. catch ( function ( err ) {
console . log ( err ) ;
2016-07-22 14:09:13 -04:00
} ) ;