From f399e82b9dd85a7eb775c12f95ff3cb966d79780 Mon Sep 17 00:00:00 2001 From: Sean Lilley Date: Sat, 26 Oct 2019 20:42:12 -0400 Subject: [PATCH 1/2] Handle absolute paths properly --- lib/loadMtl.js | 2 +- lib/loadObj.js | 2 +- specs/data/box-missing-mtllib/box-missing-mtllib.obj | 2 +- specs/data/box-missing-texture/box-missing-texture.mtl | 2 +- specs/lib/loadObjSpec.js | 3 +++ 5 files changed, 7 insertions(+), 4 deletions(-) diff --git a/lib/loadMtl.js b/lib/loadMtl.js index e220536..945f303 100644 --- a/lib/loadMtl.js +++ b/lib/loadMtl.js @@ -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) { diff --git a/lib/loadObj.js b/lib/loadObj.js index 1052017..a40d26b 100644 --- a/lib/loadObj.js +++ b/lib/loadObj.js @@ -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) { 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 ca6f046..6810a57 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'); @@ -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); From 5f012d4f5ad91a47bdf2502e7f37221de2686ef5 Mon Sep 17 00:00:00 2001 From: Sean Lilley Date: Sat, 26 Oct 2019 20:59:03 -0400 Subject: [PATCH 2/2] Update CHANGES --- CHANGES.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGES.md b/CHANGES.md index df7736c..2b0c981 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -4,6 +4,7 @@ Change Log ### 3.?.? - 2019-??-?? * 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) ### 3.0.4 - 2019-07-22