|
5 | 5 | // |
6 | 6 |
|
7 | 7 | // |
| 8 | +// version 0.9.20: Fixes creating per-face material using `usemtl`(#68) |
8 | 9 | // version 0.9.17: Support n-polygon and crease tag(OpenSubdiv extension) |
9 | 10 | // version 0.9.16: Make tinyobjloader header-only |
10 | 11 | // version 0.9.15: Change API to handle no mtl file case correctly(#58) |
@@ -978,21 +979,19 @@ bool LoadObj(std::vector<shape_t> &shapes, // [output] |
978 | 979 | sscanf(token, "%s", namebuf); |
979 | 980 | #endif |
980 | 981 |
|
981 | | - // Create face group per material. |
982 | | - bool ret = |
983 | | - exportFaceGroupToShape(shape, vertexCache, v, vn, vt, faceGroup, tags, |
984 | | - material, name, true, triangulate); |
985 | | - if (ret) { |
986 | | - shapes.push_back(shape); |
987 | | - } |
988 | | - shape = shape_t(); |
989 | | - faceGroup.clear(); |
990 | | - |
| 982 | + int newMaterialId = -1; |
991 | 983 | if (material_map.find(namebuf) != material_map.end()) { |
992 | | - material = material_map[namebuf]; |
| 984 | + newMaterialId = material_map[namebuf]; |
993 | 985 | } else { |
994 | 986 | // { error!! material not found } |
995 | | - material = -1; |
| 987 | + } |
| 988 | + |
| 989 | + if (newMaterialId != material) { |
| 990 | + // Create per-face material |
| 991 | + exportFaceGroupToShape(shape, vertexCache, v, vn, vt, faceGroup, tags, |
| 992 | + material, name, true, triangulate); |
| 993 | + faceGroup.clear(); |
| 994 | + material = newMaterialId; |
996 | 995 | } |
997 | 996 |
|
998 | 997 | continue; |
|
0 commit comments