obj2three.js 672 B

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