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
fix texture paths and parse texture map options #109
Conversation
When the mtl has statements like `map_Bump -bm 0.2 ./foo.jpg` then the options end up in the texture path. eg: `/bar/-bm 0.2/foo.jpg`. This commit fixes the path and parses the options.
When the mtl has statements like ```map_Bump -bm 0.2 ./foo.jpg``` then the options end up in the texture path. eg: ```./-bm 0.2/foo.jpg```. This commit fixes the path and parses the options.
Thanks @timknip, I'll check this out soon. Have you sent in a CLA https://github.com/AnalyticalGraphicsInc/obj2gltf#contributions? |
lib/loadMtl.js
Outdated
var currPart = null; | ||
|
||
mapOptions.reduce(function (p, part) { | ||
if (/-/.test(part)) { |
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.
Guess that should be a better regexp. It may now catch negative values.
Hi @lilleyse, I just signed and send this agreement to |
Yup that's enough. |
Thanks again for the pull request @timknip, we received your CLA! |
@pjcozzi @lilleyse Best see this PR as a head's up. Its bit hackish code. I'm not into glTF enough to actually do something with these parsed texture map options. For example the
Also here: no clue how to map this to glTF. If you have some ideas on this, i would love to hear. |
This happens when in `*.mtl` a relative texture path does not have a `./` prefix. eg: map_bump -bm 0.1 foo.jpg
For now we should just ignore the texture options since they aren't super common and I also can't think of how to map most of them to glTF (except maybe the |
Going along with that, my main suggestion for the code is to ignore those values and get the correct texture path (with options filtered out) during the parsing stage. Each map parse has a line like:
that could become something like:
Is the path always listed after the options? If so the regex could be simpler too. Sorry that these suggestions mean a lot of the code in the PR may be removed, but I think simplicity is best in this case. |
@lilleyse Yes, path is always last. Latest commit simply strips the options from the texture name. Only downside is that the code assumes textures don't have spaces in its name. The problem is that many options have optional params. eg: |
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.
Thanks for the edits @timknip, just one style comment.
lib/loadMtl.js
Outdated
return name.split(/\s+/).pop(); | ||
} | ||
return name; | ||
} |
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.
Use 4 spaces for each indent rather than 2.
Thanks! Looks good. |
When the mtl has statements like
map_Bump -bm 0.2 ./foo.jpg
thenthe options end up in the texture path.
eg:
./-bm 0.2/foo.jpg
.This commit fixes the path and parses the options.
Note:
loadMaterialTexture
is probably a bad location to do this, but i needed a solution fast.Tests / eslint all pass.