Use different read-line library

This commit is contained in:
Sean Lilley 2016-06-23 22:35:07 -04:00
parent 139f473785
commit 388f9928c3
2 changed files with 8 additions and 15 deletions

View File

@ -1,8 +1,8 @@
"use strict"; "use strict";
var async = require('async'); var async = require('async');
var byline = require('byline');
var fs = require('fs-extra'); var fs = require('fs-extra');
var path = require('path'); var path = require('path');
var readline = require('readline');
var loadImage = require('./image'); var loadImage = require('./image');
var Material = require('./mtl'); var Material = require('./mtl');
var Cesium = require('cesium'); var Cesium = require('cesium');
@ -163,12 +163,8 @@ function processObj(objFile, info, materials, images, done) {
// f vertex//normal vertex//normal vertex//normal ... // f vertex//normal vertex//normal vertex//normal ...
var facePattern4 = /f( +(-?\d+)\/\/(-?\d+))( +(-?\d+)\/\/(-?\d+))( +(-?\d+)\/\/(-?\d+))( +(-?\d+)\/\/(-?\d+))?/; var facePattern4 = /f( +(-?\d+)\/\/(-?\d+))( +(-?\d+)\/\/(-?\d+))( +(-?\d+)\/\/(-?\d+))( +(-?\d+)\/\/(-?\d+))?/;
var stream = fs.createReadStream(objFile, 'utf8'); var stream = byline(fs.createReadStream(objFile, {encoding: 'utf8'}));
var reader = readline.createInterface({ stream.on('data', function(line) {
input : stream
});
reader.on('line', function(line) {
line = line.trim(); line = line.trim();
var result; var result;
if ((line.length === 0) || (line.charAt(0) === '#')) { if ((line.length === 0) || (line.charAt(0) === '#')) {
@ -224,7 +220,7 @@ function processObj(objFile, info, materials, images, done) {
} }
}); });
reader.on('close', function() { stream.on('end', function() {
done({ done({
vertexCount : vertexCount, vertexCount : vertexCount,
vertexArray : vertexArray, vertexArray : vertexArray,
@ -301,12 +297,8 @@ function getObjInfo(objFile, inputPath, done) {
var hasNormals = false; var hasNormals = false;
var hasUVs = false; var hasUVs = false;
var stream = fs.createReadStream(objFile, 'utf8'); var stream = byline(fs.createReadStream(objFile, {encoding: 'utf8'}));
var reader = readline.createInterface({ stream.on('data', function(line) {
input : stream
});
reader.on('line', function(line) {
if (!defined(mtlPath)) { if (!defined(mtlPath)) {
var mtllibMatches = line.match(/^mtllib.*/gm); var mtllibMatches = line.match(/^mtllib.*/gm);
if (mtllibMatches !== null) { if (mtllibMatches !== null) {
@ -331,7 +323,7 @@ function getObjInfo(objFile, inputPath, done) {
} }
}); });
reader.on('close', function() { stream.on('end', function() {
if (!hasPositions) { if (!hasPositions) {
throw new Error('Could not process OBJ file, no positions.'); throw new Error('Could not process OBJ file, no positions.');
} }

View File

@ -25,6 +25,7 @@
}, },
"dependencies": { "dependencies": {
"async": "^1.4.2", "async": "^1.4.2",
"byline": "^4.2.1",
"cesium": "^1.22.0", "cesium": "^1.22.0",
"fs-extra": "^0.30.0", "fs-extra": "^0.30.0",
"gltf-pipeline": "git://github.com/AnalyticalGraphicsInc/gltf-pipeline.git", "gltf-pipeline": "git://github.com/AnalyticalGraphicsInc/gltf-pipeline.git",