@@ -657,6 +657,7 @@ bool ParseTextureNameAndOption(std::string *texname, texture_option_t *texopt,
657
657
#include < cstring>
658
658
#include < fstream>
659
659
#include < limits>
660
+ #include < set>
660
661
#include < sstream>
661
662
#include < utility>
662
663
@@ -2445,6 +2446,7 @@ bool LoadObj(attrib_t *attrib, std::vector<shape_t> *shapes,
2445
2446
std::string name;
2446
2447
2447
2448
// material
2449
+ std::set<std::string> material_filenames;
2448
2450
std::map<std::string, int > material_map;
2449
2451
int material = -1 ;
2450
2452
@@ -2735,6 +2737,11 @@ bool LoadObj(attrib_t *attrib, std::vector<shape_t> *shapes,
2735
2737
} else {
2736
2738
bool found = false ;
2737
2739
for (size_t s = 0 ; s < filenames.size (); s++) {
2740
+ if (material_filenames.count (filenames[s]) > 0 ) {
2741
+ found = true ;
2742
+ continue ;
2743
+ }
2744
+
2738
2745
std::string warn_mtl;
2739
2746
std::string err_mtl;
2740
2747
bool ok = (*readMatFn)(filenames[s].c_str (), materials,
@@ -2749,6 +2756,7 @@ bool LoadObj(attrib_t *attrib, std::vector<shape_t> *shapes,
2749
2756
2750
2757
if (ok) {
2751
2758
found = true ;
2759
+ material_filenames.insert (filenames[s]);
2752
2760
break ;
2753
2761
}
2754
2762
}
@@ -2993,6 +3001,7 @@ bool LoadObjWithCallback(std::istream &inStream, const callback_t &callback,
2993
3001
std::stringstream errss;
2994
3002
2995
3003
// material
3004
+ std::set<std::string> material_filenames;
2996
3005
std::map<std::string, int > material_map;
2997
3006
int material_id = -1 ; // -1 = invalid
2998
3007
@@ -3138,6 +3147,11 @@ bool LoadObjWithCallback(std::istream &inStream, const callback_t &callback,
3138
3147
} else {
3139
3148
bool found = false ;
3140
3149
for (size_t s = 0 ; s < filenames.size (); s++) {
3150
+ if (material_filenames.count (filenames[s]) > 0 ) {
3151
+ found = true ;
3152
+ continue ;
3153
+ }
3154
+
3141
3155
std::string warn_mtl;
3142
3156
std::string err_mtl;
3143
3157
bool ok = (*readMatFn)(filenames[s].c_str (), &materials,
@@ -3153,6 +3167,7 @@ bool LoadObjWithCallback(std::istream &inStream, const callback_t &callback,
3153
3167
3154
3168
if (ok) {
3155
3169
found = true ;
3170
+ material_filenames.insert (filenames[s]);
3156
3171
break ;
3157
3172
}
3158
3173
}
0 commit comments