obj2three.js 705 B

123456789101112131415161718192021222324252627282930
  1. var fs = require( 'fs' );
  2. var path = require( 'path' );
  3. if ( process.argv.length <= 2 ) {
  4. console.log( "Usage: " + path.basename( __filename ) + " model.obj" );
  5. process.exit( - 1 );
  6. }
  7. //
  8. var PRECISION = 6;
  9. function parseNumber( key, value ) {
  10. return typeof value === 'number' ? parseFloat( value.toFixed( PRECISION ) ) : value;
  11. }
  12. THREE = require( '../../build/three.js' );
  13. require( '../../examples/js/loaders/OBJLoader.js' );
  14. var file = process.argv[ 2 ];
  15. var loader = new THREE.OBJLoader();
  16. var text = fs.readFileSync( file, 'utf8' );
  17. var content = JSON.stringify( loader.parse( text ).toJSON(), parseNumber );
  18. fs.writeFileSync( path.basename( file, '.obj' ) + '.json', content, 'utf8' );