Last few tweaks

This commit is contained in:
Robert Taglang 2016-07-22 16:17:27 -04:00
parent 68582967ac
commit dc1a1976db
4 changed files with 195 additions and 193 deletions

View File

@ -15,9 +15,10 @@ var convert = obj2gltf.convert;
var options = {
embedImage : false // Don't embed image in the converted glTF
}
convert('model.obj', 'model.gltf', options, function() {
convert('model.obj', 'model.gltf', options)
.then(function() {
console.log('Converted model');
});
});
```
Using obj2gltf as a command-line tool:

View File

@ -37,7 +37,7 @@ function convert(objFile, outputPath, options) {
extension = binary ? '.glb' : '.gltf';
var gltfFile = path.join(outputPath, modelName + extension);
parseObj(objFile, inputPath)
return parseObj(objFile, inputPath)
.then(function(data) {
return createGltf(data, inputPath, modelName);
})

View File

@ -2,7 +2,6 @@
var Cesium = require('cesium');
var Promise = require('bluebird');
var async = require('async');
var byline = require('byline');
var fs = require('fs-extra');
var path = require('path');
@ -28,7 +27,8 @@ function parseObj(objFile, inputPath) {
});
}
function processObj(objFile, info, materials, images, done) {
function processObj(objFile, info, materials, images) {
return new Promise(function(resolve) {
// A vertex is specified by indexes into each of the attribute arrays,
// but these indexes may be different. This maps the separate indexes to a single index.
var vertexCache = {};
@ -175,7 +175,7 @@ function processObj(objFile, info, materials, images, done) {
var facePattern4 = /f( +(-?\d+)\/\/(-?\d+))( +(-?\d+)\/\/(-?\d+))( +(-?\d+)\/\/(-?\d+))( +(-?\d+)\/\/(-?\d+))?/;
var stream = byline(fs.createReadStream(objFile, {encoding: 'utf8'}));
stream.on('data', function(line) {
stream.on('data', function (line) {
line = line.trim();
var result;
if ((line.length === 0) || (line.charAt(0) === '#')) {
@ -231,17 +231,18 @@ function processObj(objFile, info, materials, images, done) {
}
});
stream.on('end', function() {
done({
vertexCount : vertexCount,
vertexArray : vertexArray,
positionMin : positionMin,
positionMax : positionMax,
hasUVs : hasUVs,
hasNormals : hasNormals,
materialGroups : materialGroups,
materials : materials,
images : images
stream.on('end', function () {
resolve({
vertexCount: vertexCount,
vertexArray: vertexArray,
positionMin: positionMin,
positionMax: positionMax,
hasUVs: hasUVs,
hasNormals: hasNormals,
materialGroups: materialGroups,
materials: materials,
images: images
});
});
});
}

View File

@ -10,7 +10,7 @@ var gltfFile = './specs/data/BoxTextured/BoxTextured.gltf';
describe('convert', function() {
it('converts an obj to gltf', function(done) {
var spy = spyOn(gltfPipeline, 'processJSONToDisk').and.callFake(function() {
var spy = spyOn(gltfPipeline, 'processJSONToDisk').and.callFake(function(gltf, outputPath, options, callback) {
return;
});
expect(convert(objFile, gltfFile, {})