diff --git a/CHANGES.md b/CHANGES.md index ae9afa0..68cdbe8 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -4,6 +4,7 @@ Change Log ### 3.?.? ????-??-?? * Added back `inputUpAxis` and `outputUpAxis`. [#211](https://github.com/AnalyticalGraphicsInc/obj2gltf/pull/211) +* Fixed handling of mtl and texture absolute paths. [#219](https://github.com/AnalyticalGraphicsInc/obj2gltf/pull/219) * Fixed specular image not being decoded when referenced by other textures. [#217](https://github.com/AnalyticalGraphicsInc/obj2gltf/pull/217) * Fixed parsing faces that reference non-existing attributes. [#218](https://github.com/AnalyticalGraphicsInc/obj2gltf/pull/218) diff --git a/lib/loadMtl.js b/lib/loadMtl.js index a4ee6f2..7a3d00d 100644 --- a/lib/loadMtl.js +++ b/lib/loadMtl.js @@ -89,7 +89,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) { diff --git a/lib/loadObj.js b/lib/loadObj.js index e893ab5..bb64340 100644 --- a/lib/loadObj.js +++ b/lib/loadObj.js @@ -478,7 +478,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) { diff --git a/specs/data/box-missing-mtllib/box-missing-mtllib.obj b/specs/data/box-missing-mtllib/box-missing-mtllib.obj index 5246261..9c9abcb 100644 --- a/specs/data/box-missing-mtllib/box-missing-mtllib.obj +++ b/specs/data/box-missing-mtllib/box-missing-mtllib.obj @@ -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 diff --git a/specs/data/box-missing-texture/box-missing-texture.mtl b/specs/data/box-missing-texture/box-missing-texture.mtl index c5c879f..177f90b 100644 --- a/specs/data/box-missing-texture/box-missing-texture.mtl +++ b/specs/data/box-missing-texture/box-missing-texture.mtl @@ -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 diff --git a/specs/lib/loadObjSpec.js b/specs/lib/loadObjSpec.js index 6fdf609..3a88628 100644 --- a/specs/lib/loadObjSpec.js +++ b/specs/lib/loadObjSpec.js @@ -1,5 +1,6 @@ 'use strict'; const Cesium = require('cesium'); +const path = require('path'); const loadObj = require('../../lib/loadObj'); const obj2gltf = require('../../lib/obj2gltf'); @@ -354,6 +355,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); @@ -431,6 +433,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);