From 8322e00ae685ea623ab6ac5a6cebcfa2d22fbf93 Mon Sep 17 00:00:00 2001 From: Jiahao Li Date: Mon, 27 Dec 2021 19:18:14 +0800 Subject: Fix mtllib reloading: load an mtl file only once (#327) --- tiny_obj_loader.h | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/tiny_obj_loader.h b/tiny_obj_loader.h index 38c8bd7..7d0c384 100644 --- a/tiny_obj_loader.h +++ b/tiny_obj_loader.h @@ -657,6 +657,7 @@ bool ParseTextureNameAndOption(std::string *texname, texture_option_t *texopt, #include #include #include +#include #include #include @@ -2445,6 +2446,7 @@ bool LoadObj(attrib_t *attrib, std::vector *shapes, std::string name; // material + std::set material_filenames; std::map material_map; int material = -1; @@ -2735,6 +2737,11 @@ bool LoadObj(attrib_t *attrib, std::vector *shapes, } else { bool found = false; for (size_t s = 0; s < filenames.size(); s++) { + if (material_filenames.count(filenames[s]) > 0) { + found = true; + continue; + } + std::string warn_mtl; std::string err_mtl; bool ok = (*readMatFn)(filenames[s].c_str(), materials, @@ -2749,6 +2756,7 @@ bool LoadObj(attrib_t *attrib, std::vector *shapes, if (ok) { found = true; + material_filenames.insert(filenames[s]); break; } } @@ -2993,6 +3001,7 @@ bool LoadObjWithCallback(std::istream &inStream, const callback_t &callback, std::stringstream errss; // material + std::set material_filenames; std::map material_map; int material_id = -1; // -1 = invalid @@ -3138,6 +3147,11 @@ bool LoadObjWithCallback(std::istream &inStream, const callback_t &callback, } else { bool found = false; for (size_t s = 0; s < filenames.size(); s++) { + if (material_filenames.count(filenames[s]) > 0) { + found = true; + continue; + } + std::string warn_mtl; std::string err_mtl; bool ok = (*readMatFn)(filenames[s].c_str(), &materials, @@ -3153,6 +3167,7 @@ bool LoadObjWithCallback(std::istream &inStream, const callback_t &callback, if (ok) { found = true; + material_filenames.insert(filenames[s]); break; } } -- cgit v1.2.3