diff --git a/lib/loadMtl.js b/lib/loadMtl.js index 021d9ec..8a3bcd6 100644 --- a/lib/loadMtl.js +++ b/lib/loadMtl.js @@ -220,18 +220,23 @@ function loadMaterialTexture(material, name, texturePath, textureOptions, mtlDir var shallowPath = path.resolve(path.join(mtlDirectory, path.basename(texturePath))); if (options.secure && outsideDirectory(texturePath, mtlDirectory)) { // Try looking for the texture in the same directory as the obj + options.logger('Texture file is outside of the mtl directory and the secure flag is true. Attempting to read the texture file from within the obj directory instead.'); texturePromise = loadTexture(shallowPath, textureOptions) - .catch(function() { - options.logger('Could not read texture file at ' + texturePath + ' because it is outside of the mtl directory and the secure flag is true. This texture will be ignored.'); + .catch(function(error) { + options.logger(error.message); + options.logger('Could not read texture file at ' + shallowPath + '. This texture will be ignored'); }); } else { texturePromise = loadTexture(texturePath, textureOptions) - .catch(function() { + .catch(function(error) { // Try looking for the texture in the same directory as the obj + options.logger(error.message); + options.logger('Could not read texture file at ' + texturePath + '. Attempting to read the texture file from within the obj directory instead.'); return loadTexture(shallowPath, textureOptions); }) - .catch(function() { - options.logger('Could not read texture file at ' + texturePath + '. This texture will be ignored.'); + .catch(function(error) { + options.logger(error.message); + options.logger('Could not read texture file at ' + shallowPath + '. This texture will be ignored.'); }); } texturePromiseMap[texturePath] = texturePromise; diff --git a/lib/loadObj.js b/lib/loadObj.js index 1bdd79a..6aeb521 100644 --- a/lib/loadObj.js +++ b/lib/loadObj.js @@ -519,25 +519,30 @@ function loadMtls(mtlPaths, objPath, options) { var shallowPath = path.resolve(path.join(objDirectory, path.basename(mtlPath))); if (options.secure && outsideDirectory(mtlPath, objDirectory)) { // Try looking for the .mtl in the same directory as the obj + options.logger('The material file is outside of the obj directory and the secure flag is true. Attempting to read the material file from within the obj directory instead.'); return loadMtl(shallowPath, options) .then(function(materialsInMtl) { materials = materials.concat(materialsInMtl); }) - .catch(function() { - options.logger('Could not read mtl file at ' + mtlPath + ' because it is outside of the obj directory and the secure flag is true. Using default material instead.'); + .catch(function(error) { + options.logger(error.message); + options.logger('Could not read material file at ' + shallowPath + '. Using default material instead.'); }); } return loadMtl(mtlPath, options) - .catch(function() { + .catch(function(error) { // Try looking for the .mtl in the same directory as the obj + options.logger(error.message); + options.logger('Could not read material file at ' + mtlPath + '. Attempting to read the material file from within the obj directory instead.'); return loadMtl(shallowPath, options); }) .then(function(materialsInMtl) { materials = materials.concat(materialsInMtl); }) - .catch(function() { - options.logger('Could not read mtl file at ' + mtlPath + '. Using default material instead.'); + .catch(function(error) { + options.logger(error.message); + options.logger('Could not read material file at ' + shallowPath + '. Using default material instead.'); }); }, {concurrency : 10}) .then(function() { diff --git a/specs/lib/loadMtlSpec.js b/specs/lib/loadMtlSpec.js index eb6ebb6..f491e90 100644 --- a/specs/lib/loadMtlSpec.js +++ b/specs/lib/loadMtlSpec.js @@ -209,7 +209,9 @@ describe('loadMtl', function() { var material = materials[0]; var baseColorTexture = material.pbrMetallicRoughness.baseColorTexture; expect(baseColorTexture).toBeUndefined(); - expect(spy.calls.argsFor(0)[0].indexOf('Could not read texture file') >= 0).toBe(true); + expect(spy.calls.argsFor(0)[0].indexOf('Texture file is outside of the mtl directory and the secure flag is true. Attempting to read the texture file from within the obj directory instead') >= 0).toBe(true); + expect(spy.calls.argsFor(1)[0].indexOf('ENOENT') >= 0).toBe(true); + expect(spy.calls.argsFor(2)[0].indexOf('Could not read texture file') >= 0).toBe(true); }), done).toResolve(); }); diff --git a/specs/lib/loadObjSpec.js b/specs/lib/loadObjSpec.js index 5abb287..c23a11c 100644 --- a/specs/lib/loadObjSpec.js +++ b/specs/lib/loadObjSpec.js @@ -298,7 +298,10 @@ describe('loadObj', function() { expect(loadObj(objMissingMtllibPath, options) .then(function(data) { expect(data.materials.length).toBe(0); - expect(spy.calls.argsFor(0)[0].indexOf('Could not read mtl file') >= 0).toBe(true); + expect(spy.calls.argsFor(0)[0].indexOf('ENOENT') >= 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); }), done).toResolve(); }); @@ -324,8 +327,9 @@ describe('loadObj', function() { expect(loadObj(objExternalResourcesPath, options) .then(function(data) { expect(data.materials.length).toBe(1); // obj references 2 materials, one of which is outside the input directory - expect(spy.calls.argsFor(0)[0].indexOf('Could not read mtl file') >= 0).toBe(true); - expect(spy.calls.argsFor(1)[0].indexOf('Could not read texture file') >= 0).toBe(true); + expect(spy.calls.argsFor(0)[0].indexOf('The material file is outside of the obj directory and the secure flag is true. Attempting to read the material file from within the obj directory instead.') >= 0).toBe(true); + expect(spy.calls.argsFor(1)[0].indexOf('ENOENT') >= 0).toBe(true); + expect(spy.calls.argsFor(2)[0].indexOf('Could not read material file') >= 0).toBe(true); }), done).toResolve(); }); @@ -371,7 +375,10 @@ describe('loadObj', function() { .then(function(data) { var baseColorTexture = data.materials[0].pbrMetallicRoughness.baseColorTexture; expect(baseColorTexture).toBeUndefined(); - expect(spy.calls.argsFor(0)[0].indexOf('Could not read texture file') >= 0).toBe(true); + expect(spy.calls.argsFor(0)[0].indexOf('ENOENT') >= 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); }), done).toResolve(); }); diff --git a/specs/lib/obj2gltfSpec.js b/specs/lib/obj2gltfSpec.js index be16cf2..d54b5bc 100644 --- a/specs/lib/obj2gltfSpec.js +++ b/specs/lib/obj2gltfSpec.js @@ -124,7 +124,7 @@ describe('obj2gltf', function() { }; expect(obj2gltf(missingMtllibObjPath, options) .then(function() { - expect(lastMessage.indexOf('Could not read mtl file') >= 0).toBe(true); + expect(lastMessage.indexOf('Could not read material file') >= 0).toBe(true); }), done).toResolve(); });