-
-
Notifications
You must be signed in to change notification settings - Fork 618
MTL with multiple materials may use incorrect Kd value #391
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
Comments
You should first investigate MTL spec https://paulbourke.net/dataformats/mtl/ for the expected behavior. If there is no info in the spec, then you should investigate how other obj importers(at least meshlab and Blender) interprets it. |
I'd point you to the code itself. https://github.com/tinyobjloader/tinyobjloader/blob/release/tiny_obj_loader.h#L2082-L2084 The " There are two other local variables In this case, regardless of what the spec is, the implementation of this library does not do what it intends to. For example, if you reverse the order of the material declarations, the |
Thank you for the updated description. So the issue itself is simply Background & expected behavior of Kd valueJust for the record, The logic of Kd value in tinyobj is:
|
Thanks! I realized by your question that my original problem statement was incomplete. So, it all looks like it'll be squared away nicely. |
The issue
tl;dr not all per-material state is being reset each time.
Specifically, by rule, if a material specifies
map_Kd
but doesn't specifykd
, it should use a default white. However, if a previous material in the file has specified akd
value, than the subsequent material that only specifies the map picks a black color. This is because the diffuse color gets reset, but the parser's understanding of whether the material has defined the diffuse color is not reset. Therefore, it mistakenly believes the last material has defined the diffuse color and the default-initialized black is used instead of what should be white.To Reproduce
Obj:
Material library
bad_diffuse.mtl
(Use arbitrary file for
test.png
-- it must exist.)The material associated with
has_map
will have an all-black diffuse.-- EDITED block --
I realized the initial problem statement was incomplete, so I've added the following:
On the other hand, if the declaration of the two materials is reversed, so that the
has_map
material comes first, then the resulting material will have a white-ish diffuse color.So, the defect has two symptoms:
map_Kd
but notkd
may end up black because the diffuse color defaults to black.-- End of EDITED block --
Expected behavior
The material should have the default diffuse color (0.6, 0.6, 0.6).
Environment
The text was updated successfully, but these errors were encountered: