Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgrade project for gltf-pipeline #7

Merged
merged 9 commits into from
Jun 23, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
**/node_modules
node_modules
npm-debug.log
.idea/workspace.xml
.idea/tasks.xml
.DS_Store
Thumbs.db
9 changes: 9 additions & 0 deletions .idea/OBJ2GLTF.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/encodings.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions .idea/jsLibraryMappings.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 14 additions & 0 deletions .idea/libraries/OBJ2GLTF_node_modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 13 additions & 0 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions .idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

59 changes: 59 additions & 0 deletions .jshintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
{
"bitwise": false,
"camelcase": false,
"curly": true,
"eqeqeq": true,
"forin": true,
"freeze": true,
"immed": true,
"latedef": "nofunc",
"noarg": true,
"nonbsp": true,
"nonew": true,
"plusplus": false,
"quotmark": false,
"undef": true,
"unused": "strict",
"strict": true,
"asi": false,
"boss": false,
"debug": false,
"eqnull": false,
"moz": false,
"evil": false,
"expr": false,
"funcscope": false,
"globalstrict": false,
"iterator": false,
"lastsemic": false,
"laxbreak": false,
"laxcomma": false,
"loopfunc": false,
"multistr": true,
"noyield": false,
"notypeof": false,
"proto": false,
"scripturl": false,
"shadow": false,
"sub": false,
"supernew": false,
"validthis": false,
"browser": false,
"browserify": false,
"couch": false,
"devel": true,
"dojo": false,
"jasmine": false,
"jquery": false,
"mocha": true,
"mootools": false,
"node": true,
"nonstandard": false,
"prototypejs": false,
"qunit": false,
"rhino": false,
"shelljs": false,
"worker": false,
"wsh": false,
"yui": false
}
8 changes: 8 additions & 0 deletions .npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
node_modules
npm-debug.log
.idea
.DS_Store
Thumbs.db
.npmignore
gulpfile.js
.jshintrc
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ Run `node bin/obj2gltf.js` and pass it the path to an OBJ file.
|`-i`|Path to the input OBJ file.| :white_check_mark: Yes|
|`-o`|Directory or filename for the exported glTF file.|No|
|`-e`|Embed glTF resources, including images, into the exported glTF file.|No, default `false`|
|`-t`|Shading technique. Possible values are `lambert`, `phong`, `blinn`, and `constant`. The shading technique is typically determined by the MTL file, but this allows more explicit control.|No|
|`-h`|Display help|No|

###Examples:
Expand Down
62 changes: 16 additions & 46 deletions bin/obj2gltf.js
Original file line number Diff line number Diff line change
@@ -1,67 +1,37 @@
#!/usr/bin/env node
"use strict";
var fs = require('fs');
var path = require('path');
var argv = require('minimist')(process.argv.slice(2));
var parseObj = require('../lib/obj');
var createGltf = require('../lib/gltf');
var util = require('../lib/util');
var defined = util.defined;
var defaultValue = util.defaultValue;
var argv = require('yargs').argv;
var Cesium = require('Cesium');
var defined = Cesium.defined;
var defaultValue = Cesium.defaultValue;
var convert = require('../lib/convert');

// TODO : support zlib
// TODO : support binary export
if (process.argv.length < 3 || defined(argv.h) || defined(argv.help)) {
console.log('Usage: ./bin/obj2gltf.js [INPUT] [OPTIONS]\n');
console.log('Usage: ./bin/obj2gltf.js [INPUT] [OPTIONS]');
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');
console.log(' -e, --embed Embed glTF resources into a single file');
console.log(' -t, --technique Shading technique. Possible values are lambert, phong, blinn, constant');
console.log(' -h, --help Display this help');
process.exit(0);
}

var objFile = defaultValue(argv._[0], defaultValue(argv.i, argv.input));
var outputPath = defaultValue(argv._[1], defaultValue(argv.o, argv.output));
var binary = defaultValue(defaultValue(argv.b, argv.binary), false);
var embed = defaultValue(defaultValue(argv.e, argv.embed), false);
var technique = defaultValue(argv.t, argv.technique);
var binary = defaultValue(argv.b, argv.binary);
var embed = defaultValue(argv.e, argv.embed);

if (!defined(objFile)) {
console.error('-i or --input argument is required. See --help for details.');
process.exit(1);
throw new Error('-i or --input argument is required. See --help for details.');
}

if (!defined(outputPath)) {
outputPath = path.dirname(objFile);
}

if (defined(technique)) {
technique = technique.toUpperCase();
if ((technique !== 'LAMBERT') && (technique !== 'PHONG') && (technique !== 'BLINN') && (technique !== 'CONSTANT')) {
console.log('Unrecognized technique \'' + technique + '\'. Using default instead.');
}
}
console.time('Total');

var inputPath = path.dirname(objFile);
var modelName = path.basename(objFile, '.obj');

var outputIsGltf = /.gltf$/.test(outputPath);
if (outputIsGltf) {
modelName = path.basename(outputPath, '.gltf');
outputPath = path.dirname(outputPath);
}
var options = {
binary : binary,
embed : embed
};

fs.mkdir(outputPath, function(){
console.time('Total');
console.time('Parse Obj');
parseObj(objFile, inputPath, function(data) {
console.timeEnd('Parse Obj');
console.time('Create glTF');
createGltf(data, modelName, inputPath, outputPath, binary, embed, technique, function() {
console.timeEnd('Create glTF');
console.timeEnd('Total');
});
});
convert(objFile, outputPath, options, function() {
console.timeEnd('Total');
});
25 changes: 25 additions & 0 deletions gulpfile.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
'use strict';

var jshint = require('gulp-jshint');
var gulp = require('gulp');

var jsHintFiles = ['index.js', 'bin/*.js', 'lib/*.js'];

gulp.task('default', ['jsHint']);

gulp.task('jsHint', function() {
return gulp.src(jsHintFiles)
.pipe(jshint.extract('auto'))
.pipe(jshint())
.pipe(jshint.reporter('jshint-stylish'))
.pipe(jshint.reporter('fail'));
});

gulp.task('jsHint-watch', function() {
gulp.watch(jsHintFiles).on('change', function(event) {
gulp.src(event.path)
.pipe(jshint.extract('auto'))
.pipe(jshint())
.pipe(jshint.reporter('jshint-stylish'));
});
});
3 changes: 3 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports = {
convert : require('./lib/convert')
};
Loading