New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Attempt to load missing resources by looking in the same directory as the obj #117
Conversation
ce1ca89
to
2c21105
Compare
lib/loadMtl.js
Outdated
@@ -222,6 +222,11 @@ function loadMaterialTexture(material, name, texturePath, textureOptions, mtlDir | |||
texturePromise = Promise.resolve(); | |||
} else { | |||
texturePromise = loadTexture(texturePath, textureOptions) | |||
.catch(function() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this also happen if options.secure && outsideDirectory
?
Also not sure this should happen as a generic catch
, since loadTexture
can also reject due to a pngjs
or jpegjs
error. So technically this could cause the wrong texture to be loaded if the intended texture fails due to decode-related problems, although that'd probably be a pretty contrived case.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this also happen if options.secure && outsideDirectory?
Yes definitely. I pushed a fix for that.
Also not sure this should happen as a generic catch, since loadTexture can also reject due to a pngjs or jpegjs error. So technically this could cause the wrong texture to be loaded if the intended texture fails due to decode-related problems, although that'd probably be a pretty contrived case.
I also considered this but didn't think it would ever really happen.
lib/loadObj.js
Outdated
return loadMtl(mtlPath, options) | ||
.catch(function() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same concern about using a generic catch
here.
Updated. |
lib/loadMtl.js
Outdated
// Try looking for the texture in the same directory as the obj | ||
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.'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also not sure this should happen as a generic catch, since loadTexture can also reject due to a pngjs or jpegjs error. So technically this could cause the wrong texture to be loaded if the intended texture fails due to decode-related problems, although that'd probably be a pretty contrived case.
I also considered this but didn't think it would ever really happen.
Agreed that the case described above is unlikely, but, using generic catch
es like this right now can also make the logged output message inaccurate, which makes the input harder for the user to fix.
For example, this message could log either because the texture couldn't be found at all (described), because it was corrupted, or because it was found in the root but was corrupted.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe sufficient to log the error in addition to a more general warning for basename(texturePath)
?
fb1f5a0
to
138c3f6
Compare
138c3f6
to
e2db0ac
Compare
@likangning93 updated. I went with your suggestion here: #117 (comment). |
Fixes #54