mirror of
https://github.com/CesiumGS/obj2gltf.git
synced 2025-02-17 08:03:55 -05:00
Changed callback code to promises
This commit is contained in:
parent
68003e43b7
commit
68582967ac
@ -40,6 +40,7 @@ var options = {
|
|||||||
ao : ao
|
ao : ao
|
||||||
};
|
};
|
||||||
|
|
||||||
convert(objFile, outputPath, options, function() {
|
convert(objFile, outputPath, options)
|
||||||
console.timeEnd('Total');
|
.then(function() {
|
||||||
});
|
console.timeEnd('Total');
|
||||||
|
});
|
||||||
|
@ -9,7 +9,7 @@ var defaultValue = Cesium.defaultValue;
|
|||||||
|
|
||||||
module.exports = convert;
|
module.exports = convert;
|
||||||
|
|
||||||
function convert(objFile, outputPath, options, done) {
|
function convert(objFile, outputPath, options) {
|
||||||
options = defaultValue(options, {});
|
options = defaultValue(options, {});
|
||||||
var binary = defaultValue(options.binary, false);
|
var binary = defaultValue(options.binary, false);
|
||||||
var embed = defaultValue(options.embed, true);
|
var embed = defaultValue(options.embed, true);
|
||||||
@ -37,24 +37,21 @@ function convert(objFile, outputPath, options, done) {
|
|||||||
extension = binary ? '.glb' : '.gltf';
|
extension = binary ? '.glb' : '.gltf';
|
||||||
var gltfFile = path.join(outputPath, modelName + extension);
|
var gltfFile = path.join(outputPath, modelName + extension);
|
||||||
|
|
||||||
parseObj(objFile, inputPath, function(data) {
|
parseObj(objFile, inputPath)
|
||||||
createGltf(data, inputPath, modelName, function(gltf) {
|
.then(function(data) {
|
||||||
|
return createGltf(data, inputPath, modelName);
|
||||||
|
})
|
||||||
|
.then(function(gltf) {
|
||||||
var aoOptions = ao ? {} : undefined;
|
var aoOptions = ao ? {} : undefined;
|
||||||
var options = {
|
var options = {
|
||||||
binary : binary,
|
binary: binary,
|
||||||
embed : embed,
|
embed: embed,
|
||||||
embedImage : embedImage,
|
embedImage: embedImage,
|
||||||
quantize : quantize,
|
quantize: quantize,
|
||||||
aoOptions : aoOptions,
|
aoOptions: aoOptions,
|
||||||
createDirectory : false,
|
createDirectory: false,
|
||||||
basePath : inputPath
|
basePath: inputPath
|
||||||
};
|
};
|
||||||
gltfPipeline.processJSONToDisk(gltf, gltfFile, options, function(error) {
|
return gltfPipeline.processJSONToDisk(gltf, gltfFile, options);
|
||||||
if (error) {
|
|
||||||
throw error;
|
|
||||||
}
|
|
||||||
done();
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
18
lib/gltf.js
18
lib/gltf.js
@ -1,14 +1,18 @@
|
|||||||
"use strict";
|
"use strict";
|
||||||
|
var Cesium = require('cesium');
|
||||||
|
var Promise = require('bluebird');
|
||||||
var fs = require('fs-extra');
|
var fs = require('fs-extra');
|
||||||
var path = require('path');
|
var path = require('path');
|
||||||
var Cesium = require('cesium');
|
|
||||||
var defined = Cesium.defined;
|
var defined = Cesium.defined;
|
||||||
var defaultValue = Cesium.defaultValue;
|
var defaultValue = Cesium.defaultValue;
|
||||||
var WebGLConstants = Cesium.WebGLConstants;
|
var WebGLConstants = Cesium.WebGLConstants;
|
||||||
|
|
||||||
|
var fsWriteFile = Promise.promisify(fs.writeFile);
|
||||||
|
|
||||||
module.exports = createGltf;
|
module.exports = createGltf;
|
||||||
|
|
||||||
function createGltf(data, inputPath, modelName, done) {
|
function createGltf(data, inputPath, modelName) {
|
||||||
var vertexCount = data.vertexCount;
|
var vertexCount = data.vertexCount;
|
||||||
var vertexArray = data.vertexArray;
|
var vertexArray = data.vertexArray;
|
||||||
var positionMin = data.positionMin;
|
var positionMin = data.positionMin;
|
||||||
@ -328,13 +332,7 @@ function createGltf(data, inputPath, modelName, done) {
|
|||||||
|
|
||||||
if (bufferSeparate) {
|
if (bufferSeparate) {
|
||||||
var bufferPath = path.join(inputPath, modelName + '.bin');
|
var bufferPath = path.join(inputPath, modelName + '.bin');
|
||||||
fs.writeFile(bufferPath, buffer, function(err) {
|
return fsWriteFile(bufferPath, buffer);
|
||||||
if (err) {
|
|
||||||
throw err;
|
|
||||||
}
|
|
||||||
done(gltf);
|
|
||||||
});
|
|
||||||
} else {
|
|
||||||
done(gltf);
|
|
||||||
}
|
}
|
||||||
|
return gltf;
|
||||||
}
|
}
|
||||||
|
47
lib/image.js
47
lib/image.js
@ -1,7 +1,10 @@
|
|||||||
"use strict";
|
"use strict";
|
||||||
|
var Promise = require('bluebird');
|
||||||
var fs = require('fs-extra');
|
var fs = require('fs-extra');
|
||||||
var path = require('path');
|
var path = require('path');
|
||||||
|
|
||||||
|
var fsReadFile = Promise.promisify(fs.readFile);
|
||||||
|
|
||||||
module.exports = loadImage;
|
module.exports = loadImage;
|
||||||
|
|
||||||
function getChannels(colorType) {
|
function getChannels(colorType) {
|
||||||
@ -34,31 +37,27 @@ function getUriType(extension) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function loadImage(imagePath, done) {
|
function loadImage(imagePath) {
|
||||||
fs.readFile(imagePath, function(error, data) {
|
return fsReadFile(imagePath)
|
||||||
if (error) {
|
.then(function(data) {
|
||||||
throw(error);
|
var extension = path.extname(imagePath).slice(1);
|
||||||
}
|
var uriType = getUriType(extension);
|
||||||
|
var uri = uriType + ';base64,' + data.toString('base64');
|
||||||
|
|
||||||
var extension = path.extname(imagePath).slice(1);
|
var info = {
|
||||||
var uriType = getUriType(extension);
|
transparent: false,
|
||||||
var uri = uriType + ';base64,' + data.toString('base64');
|
channels: 3,
|
||||||
|
data: data,
|
||||||
|
uri: uri
|
||||||
|
};
|
||||||
|
|
||||||
var info = {
|
if (path.extname(imagePath) === 'png') {
|
||||||
transparent: false,
|
// Color type is encoded in the 25th bit of the png
|
||||||
channels: 3,
|
var colorType = data[25];
|
||||||
data: data,
|
var channels = getChannels(colorType);
|
||||||
uri: uri
|
info.channels = channels;
|
||||||
};
|
info.transparent = (channels === 4);
|
||||||
|
}
|
||||||
if (path.extname(imagePath) === 'png') {
|
return info;
|
||||||
// Color type is encoded in the 25th bit of the png
|
|
||||||
var colorType = data[25];
|
|
||||||
var channels = getChannels(colorType);
|
|
||||||
info.channels = channels;
|
|
||||||
info.transparent = (channels === 4);
|
|
||||||
}
|
|
||||||
|
|
||||||
done(info);
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
166
lib/mtl.js
166
lib/mtl.js
@ -1,7 +1,10 @@
|
|||||||
"use strict";
|
"use strict";
|
||||||
|
var Promise = require('bluebird');
|
||||||
var fs = require('fs-extra');
|
var fs = require('fs-extra');
|
||||||
var defined = require('cesium').defined;
|
var defined = require('cesium').defined;
|
||||||
|
|
||||||
|
var fsReadFile = Promise.promisify(fs.readFile);
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
getDefault : getDefault,
|
getDefault : getDefault,
|
||||||
parse : parse
|
parse : parse
|
||||||
@ -31,89 +34,84 @@ function getDefault() {
|
|||||||
return material;
|
return material;
|
||||||
}
|
}
|
||||||
|
|
||||||
function parse(mtlPath, done) {
|
function parse(mtlPath) {
|
||||||
fs.readFile(mtlPath, 'utf8', function (error, contents) {
|
return fsReadFile(mtlPath, 'utf8')
|
||||||
if (error) {
|
.then(function (contents) {
|
||||||
console.log('Could not read material file at ' + mtlPath + '. Using default material instead.');
|
var materials = {};
|
||||||
done({});
|
var material;
|
||||||
return;
|
var values;
|
||||||
}
|
var value;
|
||||||
|
var lines = contents.split('\n');
|
||||||
var materials = {};
|
var length = lines.length;
|
||||||
var material;
|
for (var i = 0; i < length; ++i) {
|
||||||
|
var line = lines[i].trim();
|
||||||
var values;
|
if (/^newmtl /i.test(line)) {
|
||||||
var value;
|
var name = line.substring(7).trim();
|
||||||
var lines = contents.split('\n');
|
material = createMaterial();
|
||||||
var length = lines.length;
|
materials[name] = material;
|
||||||
for (var i = 0; i < length; ++i) {
|
} else if (/^Ka /i.test(line)) {
|
||||||
var line = lines[i].trim();
|
values = line.substring(3).trim().split(' ');
|
||||||
if (/^newmtl /i.test(line)) {
|
material.ambientColor = [
|
||||||
var name = line.substring(7).trim();
|
parseFloat(values[0]),
|
||||||
material = createMaterial();
|
parseFloat(values[1]),
|
||||||
materials[name] = material;
|
parseFloat(values[2]),
|
||||||
} else if (/^Ka /i.test(line)) {
|
1.0
|
||||||
values = line.substring(3).trim().split(' ');
|
];
|
||||||
material.ambientColor = [
|
} else if (/^Ke /i.test(line)) {
|
||||||
parseFloat(values[0]),
|
values = line.substring(3).trim().split(' ');
|
||||||
parseFloat(values[1]),
|
material.emissionColor = [
|
||||||
parseFloat(values[2]),
|
parseFloat(values[0]),
|
||||||
1.0
|
parseFloat(values[1]),
|
||||||
];
|
parseFloat(values[2]),
|
||||||
} else if (/^Ke /i.test(line)) {
|
1.0
|
||||||
values = line.substring(3).trim().split(' ');
|
];
|
||||||
material.emissionColor = [
|
} else if (/^Kd /i.test(line)) {
|
||||||
parseFloat(values[0]),
|
values = line.substring(3).trim().split(' ');
|
||||||
parseFloat(values[1]),
|
material.diffuseColor = [
|
||||||
parseFloat(values[2]),
|
parseFloat(values[0]),
|
||||||
1.0
|
parseFloat(values[1]),
|
||||||
];
|
parseFloat(values[2]),
|
||||||
} else if (/^Kd /i.test(line)) {
|
1.0
|
||||||
values = line.substring(3).trim().split(' ');
|
];
|
||||||
material.diffuseColor = [
|
} else if (/^Ks /i.test(line)) {
|
||||||
parseFloat(values[0]),
|
values = line.substring(3).trim().split(' ');
|
||||||
parseFloat(values[1]),
|
material.specularColor = [
|
||||||
parseFloat(values[2]),
|
parseFloat(values[0]),
|
||||||
1.0
|
parseFloat(values[1]),
|
||||||
];
|
parseFloat(values[2]),
|
||||||
} else if (/^Ks /i.test(line)) {
|
1.0
|
||||||
values = line.substring(3).trim().split(' ');
|
];
|
||||||
material.specularColor = [
|
} else if (/^Ns /i.test(line)) {
|
||||||
parseFloat(values[0]),
|
value = line.substring(3).trim();
|
||||||
parseFloat(values[1]),
|
material.specularShininess = parseFloat(value);
|
||||||
parseFloat(values[2]),
|
} else if (/^d /i.test(line)) {
|
||||||
1.0
|
value = line.substring(2).trim();
|
||||||
];
|
material.alpha = parseFloat(value);
|
||||||
} else if (/^Ns /i.test(line)) {
|
} else if (/^Tr /i.test(line)) {
|
||||||
value = line.substring(3).trim();
|
value = line.substring(3).trim();
|
||||||
material.specularShininess = parseFloat(value);
|
material.alpha = parseFloat(value);
|
||||||
} else if (/^d /i.test(line)) {
|
} else if (/^map_Ka /i.test(line)) {
|
||||||
value = line.substring(2).trim();
|
material.ambientColorMap = line.substring(7).trim();
|
||||||
material.alpha = parseFloat(value);
|
} else if (/^map_Ke /i.test(line)) {
|
||||||
} else if (/^Tr /i.test(line)) {
|
material.emissionColorMap = line.substring(7).trim();
|
||||||
value = line.substring(3).trim();
|
} else if (/^map_Kd /i.test(line)) {
|
||||||
material.alpha = parseFloat(value);
|
material.diffuseColorMap = line.substring(7).trim();
|
||||||
} else if (/^map_Ka /i.test(line)) {
|
} else if (/^map_Ks /i.test(line)) {
|
||||||
material.ambientColorMap = line.substring(7).trim();
|
material.specularColorMap = line.substring(7).trim();
|
||||||
} else if (/^map_Ke /i.test(line)) {
|
} else if (/^map_Ns /i.test(line)) {
|
||||||
material.emissionColorMap = line.substring(7).trim();
|
material.specularShininessMap = line.substring(7).trim();
|
||||||
} else if (/^map_Kd /i.test(line)) {
|
} else if (/^map_Bump /i.test(line)) {
|
||||||
material.diffuseColorMap = line.substring(7).trim();
|
material.normalMap = line.substring(9).trim();
|
||||||
} else if (/^map_Ks /i.test(line)) {
|
} else if (/^map_d /i.test(line)) {
|
||||||
material.specularColorMap = line.substring(7).trim();
|
material.alphaMap = line.substring(6).trim();
|
||||||
} else if (/^map_Ns /i.test(line)) {
|
}
|
||||||
material.specularShininessMap = line.substring(7).trim();
|
|
||||||
} else if (/^map_Bump /i.test(line)) {
|
|
||||||
material.normalMap = line.substring(9).trim();
|
|
||||||
} else if (/^map_d /i.test(line)) {
|
|
||||||
material.alphaMap = line.substring(6).trim();
|
|
||||||
}
|
}
|
||||||
}
|
if (defined(material.alpha)) {
|
||||||
|
material.diffuseColor[3] = material.alpha;
|
||||||
if (defined(material.alpha)) {
|
}
|
||||||
material.diffuseColor[3] = material.alpha;
|
return materials;
|
||||||
}
|
})
|
||||||
|
.catch(function() {
|
||||||
done(materials);
|
console.log('Could not read material file at ' + mtlPath + '. Using default material instead.');
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
150
lib/obj.js
150
lib/obj.js
@ -1,11 +1,16 @@
|
|||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
|
var Cesium = require('cesium');
|
||||||
|
var Promise = require('bluebird');
|
||||||
var async = require('async');
|
var async = require('async');
|
||||||
var byline = require('byline');
|
var byline = require('byline');
|
||||||
var fs = require('fs-extra');
|
var fs = require('fs-extra');
|
||||||
var path = require('path');
|
var path = require('path');
|
||||||
|
|
||||||
var loadImage = require('./image');
|
var loadImage = require('./image');
|
||||||
var Material = require('./mtl');
|
var Material = require('./mtl');
|
||||||
var Cesium = require('cesium');
|
|
||||||
|
|
||||||
var Cartesian3 = Cesium.Cartesian3;
|
var Cartesian3 = Cesium.Cartesian3;
|
||||||
var defined = Cesium.defined;
|
var defined = Cesium.defined;
|
||||||
|
|
||||||
@ -13,10 +18,14 @@ module.exports = parseObj;
|
|||||||
|
|
||||||
// OBJ regex patterns are from ThreeJS (https://github.com/mrdoob/three.js/blob/master/examples/js/loaders/OBJLoader.js)
|
// OBJ regex patterns are from ThreeJS (https://github.com/mrdoob/three.js/blob/master/examples/js/loaders/OBJLoader.js)
|
||||||
|
|
||||||
function parseObj(objFile, inputPath, done) {
|
function parseObj(objFile, inputPath) {
|
||||||
getObjInfo(objFile, inputPath, function(info, materials, images) {
|
return getObjInfo(objFile, inputPath)
|
||||||
processObj(objFile, info, materials, images, done);
|
.then(function(result) {
|
||||||
});
|
var info = result.info;
|
||||||
|
var materials = result.materials;
|
||||||
|
var images = result.images;
|
||||||
|
return processObj(objFile, info, materials, images);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function processObj(objFile, info, materials, images, done) {
|
function processObj(objFile, info, materials, images, done) {
|
||||||
@ -237,7 +246,7 @@ function processObj(objFile, info, materials, images, done) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function getImages(inputPath, materials, done) {
|
function getImages(inputPath, materials) {
|
||||||
// Collect all the image files from the materials
|
// Collect all the image files from the materials
|
||||||
var images = [];
|
var images = [];
|
||||||
for (var name in materials) {
|
for (var name in materials) {
|
||||||
@ -259,84 +268,99 @@ function getImages(inputPath, materials, done) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Load the image files
|
// Load the image files
|
||||||
|
var promises = [];
|
||||||
var imagesInfo = {};
|
var imagesInfo = {};
|
||||||
async.each(images, function (image, callback) {
|
var imagesLength = images.length;
|
||||||
var imagePath = image;
|
for (var i = 0; i < imagesLength; i++) {
|
||||||
|
var imagePath = images[i];
|
||||||
if (!path.isAbsolute(imagePath)) {
|
if (!path.isAbsolute(imagePath)) {
|
||||||
imagePath = path.join(inputPath, image);
|
imagePath = path.join(inputPath, imagePath);
|
||||||
}
|
}
|
||||||
loadImage(imagePath, function(info) {
|
promises.push(loadImage(imagePath));
|
||||||
imagesInfo[image] = info;
|
}
|
||||||
callback();
|
Promise.all(promises).then(function(imageInfoArray) {
|
||||||
});
|
var imageInfoArrayLength = imageInfoArray.length;
|
||||||
}, function (error) {
|
for (var j = 0; j < imageInfoArrayLength; j++) {
|
||||||
if (error) {
|
var image = images[j];
|
||||||
throw error;
|
var imageInfo = imageInfoArray[j];
|
||||||
|
imagesInfo[image] = imageInfo;
|
||||||
}
|
}
|
||||||
done(imagesInfo);
|
return imagesInfo;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function getMaterials(mtlPath, hasMaterialGroups, done) {
|
function getMaterials(mtlPath, hasMaterialGroups) {
|
||||||
if (!hasMaterialGroups) {
|
if (!hasMaterialGroups) {
|
||||||
done({});
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (defined(mtlPath)) {
|
if (defined(mtlPath)) {
|
||||||
Material.parse(mtlPath, function(materials) {
|
return Material.parse(mtlPath);
|
||||||
done(materials);
|
|
||||||
});
|
|
||||||
} else {
|
|
||||||
done({});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function getObjInfo(objFile, inputPath, done) {
|
function getObjInfo(objFile, inputPath) {
|
||||||
var mtlPath;
|
var mtlPath;
|
||||||
|
var materials;
|
||||||
|
var info;
|
||||||
var hasMaterialGroups = false;
|
var hasMaterialGroups = false;
|
||||||
var hasPositions = false;
|
var hasPositions = false;
|
||||||
var hasNormals = false;
|
var hasNormals = false;
|
||||||
var hasUVs = false;
|
var hasUVs = false;
|
||||||
|
return new Promise(function(resolve, reject) {
|
||||||
var stream = byline(fs.createReadStream(objFile, {encoding: 'utf8'}));
|
var stream = byline(fs.createReadStream(objFile, {encoding: 'utf8'}));
|
||||||
stream.on('data', function(line) {
|
stream.on('data', 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) {
|
||||||
var mtlFile = mtllibMatches[0].substring(7).trim();
|
var mtlFile = mtllibMatches[0].substring(7).trim();
|
||||||
mtlPath = mtlFile;
|
mtlPath = mtlFile;
|
||||||
if (!path.isAbsolute(mtlPath)) {
|
if (!path.isAbsolute(mtlPath)) {
|
||||||
mtlPath = path.join(inputPath, mtlFile);
|
mtlPath = path.join(inputPath, mtlFile);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
if (!hasMaterialGroups) {
|
||||||
if (!hasMaterialGroups) {
|
hasMaterialGroups = /^usemtl/gm.test(line);
|
||||||
hasMaterialGroups = /^usemtl/gm.test(line);
|
}
|
||||||
}
|
if (!hasPositions) {
|
||||||
if (!hasPositions) {
|
hasPositions = /^v\s/gm.test(line);
|
||||||
hasPositions = /^v\s/gm.test(line);
|
}
|
||||||
}
|
if (!hasNormals) {
|
||||||
if (!hasNormals) {
|
hasNormals = /^vn/gm.test(line);
|
||||||
hasNormals = /^vn/gm.test(line);
|
}
|
||||||
}
|
if (!hasUVs) {
|
||||||
if (!hasUVs) {
|
hasUVs = /^vt/gm.test(line);
|
||||||
hasUVs = /^vt/gm.test(line);
|
}
|
||||||
}
|
});
|
||||||
});
|
|
||||||
|
stream.on('error', function(err) {
|
||||||
stream.on('end', function() {
|
reject(err);
|
||||||
if (!hasPositions) {
|
});
|
||||||
throw new Error('Could not process OBJ file, no positions.');
|
|
||||||
}
|
stream.on('end', function () {
|
||||||
var info = {
|
if (!hasPositions) {
|
||||||
hasNormals : hasNormals,
|
reject(new Error('Could not process OBJ file, no positions.'));
|
||||||
hasUVs : hasUVs
|
}
|
||||||
};
|
info = {
|
||||||
getMaterials(mtlPath, hasMaterialGroups, function(materials) {
|
hasNormals: hasNormals,
|
||||||
getImages(inputPath, materials, function(images) {
|
hasUVs: hasUVs
|
||||||
done(info, materials, images);
|
};
|
||||||
});
|
resolve();
|
||||||
|
});
|
||||||
|
})
|
||||||
|
.then(function() {
|
||||||
|
return getMaterials(mtlPath, hasMaterialGroups);
|
||||||
|
})
|
||||||
|
.then(function(returnedMaterials) {
|
||||||
|
materials = returnedMaterials;
|
||||||
|
return getImages(inputPath, materials);
|
||||||
|
})
|
||||||
|
.then(function(images) {
|
||||||
|
return {
|
||||||
|
info : info,
|
||||||
|
materials : materials,
|
||||||
|
images : images
|
||||||
|
};
|
||||||
});
|
});
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
@ -27,6 +27,7 @@
|
|||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"async": "2.0.0-rc.6",
|
"async": "2.0.0-rc.6",
|
||||||
|
"bluebird": "^3.4.1",
|
||||||
"byline": "4.2.1",
|
"byline": "4.2.1",
|
||||||
"cesium": "1.23.0",
|
"cesium": "1.23.0",
|
||||||
"fs-extra": "0.30.0",
|
"fs-extra": "0.30.0",
|
||||||
|
@ -1,4 +1,6 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
var Promise = require('bluebird');
|
||||||
|
|
||||||
var gltfPipeline = require('gltf-pipeline').gltfPipeline;
|
var gltfPipeline = require('gltf-pipeline').gltfPipeline;
|
||||||
var path = require('path');
|
var path = require('path');
|
||||||
var convert = require('../../lib/convert');
|
var convert = require('../../lib/convert');
|
||||||
@ -8,14 +10,14 @@ var gltfFile = './specs/data/BoxTextured/BoxTextured.gltf';
|
|||||||
|
|
||||||
describe('convert', function() {
|
describe('convert', function() {
|
||||||
it('converts an obj to gltf', function(done) {
|
it('converts an obj to gltf', function(done) {
|
||||||
var spy = spyOn(gltfPipeline, 'processJSONToDisk').and.callFake(function(gltf, gltfFile, options, callback) {
|
var spy = spyOn(gltfPipeline, 'processJSONToDisk').and.callFake(function() {
|
||||||
callback();
|
return;
|
||||||
});
|
|
||||||
convert(objFile, gltfFile, {}, function() {
|
|
||||||
var args = spy.calls.first().args;
|
|
||||||
expect(args[0]).toBeDefined();
|
|
||||||
expect(path.normalize(args[1])).toEqual(path.normalize(gltfFile));
|
|
||||||
done();
|
|
||||||
});
|
});
|
||||||
|
expect(convert(objFile, gltfFile, {})
|
||||||
|
.then(function() {
|
||||||
|
var args = spy.calls.first().args;
|
||||||
|
expect(args[0]).toBeDefined();
|
||||||
|
expect(path.normalize(args[1])).toEqual(path.normalize(gltfFile));
|
||||||
|
}), done).toResolve();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
Loading…
x
Reference in New Issue
Block a user