Skip to content
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

Merged
merged 3 commits into from Dec 28, 2017

Conversation

lilleyse
Copy link
Contributor

Fixes #54

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() {
Copy link
Contributor

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.

Copy link
Contributor Author

@lilleyse lilleyse Nov 29, 2017

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() {
Copy link
Contributor

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.

@lilleyse
Copy link
Contributor Author

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.');
Copy link
Contributor

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 catches 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.

Copy link
Contributor

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)?

@lilleyse
Copy link
Contributor Author

@likangning93 updated. I went with your suggestion here: #117 (comment).

@likangning93 likangning93 merged commit 365efa1 into master Dec 28, 2017
@likangning93 likangning93 deleted the resources-in-root branch December 28, 2017 18:19
lilleyse added a commit that referenced this pull request Nov 1, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants