Skip to content

Commit

Permalink
Merge pull request #219 from AnalyticalGraphicsInc/absolute-paths
Browse files Browse the repository at this point in the history
Handle mtl and texture absolute paths
  • Loading branch information
Omar Shehata authored Oct 29, 2019
2 parents 341797b + dd163b7 commit 4df7c2a
Show file tree
Hide file tree
Showing 6 changed files with 8 additions and 4 deletions.
1 change: 1 addition & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
2 changes: 1 addition & 1 deletion lib/loadMtl.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion lib/loadObj.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion specs/data/box-missing-mtllib/box-missing-mtllib.obj
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion specs/data/box-missing-texture/box-missing-texture.mtl
Original file line number Diff line number Diff line change
Expand Up @@ -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
3 changes: 3 additions & 0 deletions specs/lib/loadObjSpec.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
'use strict';
const Cesium = require('cesium');
const path = require('path');

const loadObj = require('../../lib/loadObj');
const obj2gltf = require('../../lib/obj2gltf');
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 4df7c2a

Please sign in to comment.