mirror of
https://github.com/CesiumGS/obj2gltf.git
synced 2024-11-23 08:34:14 -05:00
Support absolute paths
This commit is contained in:
parent
d38b3bc82f
commit
87c8d2efb2
@ -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)) {
|
||||
|
16
lib/gltf.js
16
lib/gltf.js
@ -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 = {
|
||||
|
@ -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);
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user