mirror of
https://github.com/CesiumGS/obj2gltf.git
synced 2024-11-23 08:34:14 -05:00
More accurate error messages
This commit is contained in:
parent
57a95a6623
commit
e2db0ac59d
@ -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;
|
||||
|
@ -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() {
|
||||
|
@ -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();
|
||||
});
|
||||
|
||||
|
@ -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();
|
||||
});
|
||||
|
||||
|
@ -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();
|
||||
});
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user