Handle absolute paths properly

This commit is contained in:
Sean Lilley 2019-10-26 20:42:12 -04:00
parent b7cbda42d8
commit f399e82b9d
5 changed files with 7 additions and 4 deletions

View File

@ -88,7 +88,7 @@ function loadMtl(mtlPath, options) {
texturePath = texturePath.split(/\s+/).pop();
}
texturePath = texturePath.replace(/\\/g, '/');
return path.normalize(path.join(mtlDirectory, texturePath));
return path.normalize(path.resolve(mtlDirectory, texturePath));
}
function parseLine(line) {

View File

@ -469,7 +469,7 @@ function finishLoading(nodes, mtlPaths, objPath, usesMaterials, options) {
function normalizeMtlPath(mtlPath, objDirectory) {
mtlPath = mtlPath.replace(/\\/g, '/');
return path.normalize(path.join(objDirectory, mtlPath));
return path.normalize(path.resolve(objDirectory, mtlPath));
}
function loadMtls(mtlPaths, objPath, options) {

View File

@ -1,6 +1,6 @@
# Blender v2.78 (sub 0) OBJ File: ''
# www.blender.org
mtllib box.mtl
mtllib /box.mtl
o Cube
v -1.000000 -1.000000 1.000000
v -1.000000 1.000000 1.000000

View File

@ -10,4 +10,4 @@ Ke 0.000000 0.000000 0.000000
Ni 1.000000
d 1.000000
illum 2
map_Kd cesium.png
map_Kd /cesium.png

View File

@ -1,5 +1,6 @@
'use strict';
const Cesium = require('cesium');
const path = require('path');
const loadObj = require('../../lib/loadObj');
const obj2gltf = require('../../lib/obj2gltf');
@ -350,6 +351,7 @@ describe('loadObj', () => {
const data = await loadObj(objMissingMtllibPath, options);
expect(data.materials.length).toBe(0);
expect(spy.calls.argsFor(0)[0].indexOf('ENOENT') >= 0).toBe(true);
expect(spy.calls.argsFor(0)[0].indexOf(path.resolve('/box.mtl')) >= 0).toBe(true);
expect(spy.calls.argsFor(1)[0].indexOf('Attempting to read the material file from within the obj directory instead.') >= 0).toBe(true);
expect(spy.calls.argsFor(2)[0].indexOf('ENOENT') >= 0).toBe(true);
expect(spy.calls.argsFor(3)[0].indexOf('Could not read material file') >= 0).toBe(true);
@ -427,6 +429,7 @@ describe('loadObj', () => {
const baseColorTexture = data.materials[0].pbrMetallicRoughness.baseColorTexture;
expect(baseColorTexture).toBeUndefined();
expect(spy.calls.argsFor(0)[0].indexOf('ENOENT') >= 0).toBe(true);
expect(spy.calls.argsFor(0)[0].indexOf(path.resolve('/cesium.png')) >= 0).toBe(true);
expect(spy.calls.argsFor(1)[0].indexOf('Attempting to read the texture file from within the obj directory instead.') >= 0).toBe(true);
expect(spy.calls.argsFor(2)[0].indexOf('ENOENT') >= 0).toBe(true);
expect(spy.calls.argsFor(3)[0].indexOf('Could not read texture file') >= 0).toBe(true);