-
-
Notifications
You must be signed in to change notification settings - Fork 624
Fix mtllib reloading: load an mtl file only once #327
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
Conversation
@li-plus Awesome!
I see. Let us give some time to figure out the solution. It may require adding extra data structure and may break current API design to support multiple |
Thanks for your attention! Just to be clear, multiple
I have finally worked out a solution: memorize all the |
I just figured out a simpler way. When multiple |
Awesome! Let us give some time to review the PR |
@li-plus After reading the .obj spec https://en.wikipedia.org/wiki/Wavefront_.obj_file The spec says
So the spec itself allows multiple definition of
You need to revert PR to the version of this: Cache |
@syoyo You are correct. I reverted this PR to cache mtllib filenames, which supports multiple mtllib files in multiple statements. The behavior does not change except for no reloading the same file. |
@li-plus Thanks! Merged! |
Hi, thanks for this awesome tool to load obj files. I am using tinyobjloader for my tiny renderer, but I have met some problems on the "Living Room" scene from McGuire Computer Graphics Archive. Its obj file defines the same mtllib 181 times, and tinyobjloader will reload the file the same number of times! This mtllib file has 42 newmtl statements, so finally
reader.GetMaterials()
returns 7602 materials, causing my renderer OOM since it needs to load all texture maps of all materials.This PR attempts to solve this issue by loading one mtl file only once. I record the filenames following "mtllib" in an
std::set<std::string>
so that the previously loaded mtl files will be skipped to avoid reloading. It should cover most scenarios in obj files. Limitations are that there might be different representations for the same file, e.g.,./mtl/scene.mtl
and./mtl/../mtl/scene.mtl
, but it is rare in obj files.