Support absolute paths

This commit is contained in:
Sean Lilley 2015-10-19 18:13:29 -04:00
parent d38b3bc82f
commit 87c8d2efb2
3 changed files with 15 additions and 9 deletions

View File

@ -9,8 +9,6 @@ var util = require('../lib/util');
var defined = util.defined;
var defaultValue = util.defaultValue;
// TODO : assuming all paths in obj are relative, but should consider absolute paths
// TODO : add command line flag for y-up to z-up
// TODO : support zlib
// TODO : support binary export
if (process.argv.length < 3 || defined(argv.h) || defined(argv.help)) {

View File

@ -36,14 +36,18 @@ function getImages(inputPath, outputPath, combine, materials, done) {
var imagesInfo = {};
async.each(images, function (image, callback) {
var imagePath = path.join(inputPath, image);
var copyPath = path.join(outputPath, path.basename(image));
var imagePath = image;
if (!path.isAbsolute(imagePath)) {
imagePath = path.join(inputPath, image);
}
var baseName = path.basename(image);
var copyPath = path.join(outputPath, baseName);
imageInfo(imagePath, function(info) {
var uri;
if (combine) {
uri = 'data:application/octet-stream;base64,' + info.data.toString('base64');
} else {
uri = image;
uri = baseName;
}
imagesInfo[image] = {
@ -54,7 +58,7 @@ function getImages(inputPath, outputPath, combine, materials, done) {
if (combine) {
callback();
} else {
} else if (path.relative(imagePath, copyPath) !== '') {
fsExtra.copy(imagePath, copyPath, {clobber : true}, function (err) {
if (err) {
throw err;
@ -177,11 +181,11 @@ function createGltf(data, modelName, inputPath, outputPath, binary, combine, tec
if (!defined(image)) {
return undefined;
}
return 'texture_' + image.substr(0, image.lastIndexOf('.'));
return 'texture_' + path.basename(image).substr(0, image.lastIndexOf('.'));
}
function getImageId(image) {
return 'image_' + image.substr(0, image.lastIndexOf('.'));
return 'image_' + path.basename(image).substr(0, image.lastIndexOf('.'));
}
var gltf = {

View File

@ -23,7 +23,11 @@ function getMaterials(contents, inputPath, done) {
done({});
} else {
var mtlFile = mtllibMatches[0].substring(7).trim();
var mtlPath = path.join(inputPath, mtlFile);
var mtlPath = mtlFile;
if (!path.isAbsolute(mtlPath)) {
mtlPath = path.join(inputPath, mtlFile);
}
Material.parse(mtlPath, function (materials) {
done(materials);
});