Skip to content

Commit bc42bc4

Browse files
committed
Don't create new shape by usemtl. Fixes #68.
1 parent 3161116 commit bc42bc4

2 files changed

Lines changed: 12 additions & 12 deletions

File tree

test.cc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,7 @@ TestLoadObj(
139139
}
140140

141141
if (!ret) {
142+
printf("Failed to load/parse .obj.\n");
142143
return false;
143144
}
144145

tiny_obj_loader.h

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
//
66

77
//
8+
// version 0.9.20: Fixes creating per-face material using `usemtl`(#68)
89
// version 0.9.17: Support n-polygon and crease tag(OpenSubdiv extension)
910
// version 0.9.16: Make tinyobjloader header-only
1011
// 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]
978979
sscanf(token, "%s", namebuf);
979980
#endif
980981

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;
991983
if (material_map.find(namebuf) != material_map.end()) {
992-
material = material_map[namebuf];
984+
newMaterialId = material_map[namebuf];
993985
} else {
994986
// { 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;
996995
}
997996

998997
continue;

0 commit comments

Comments
 (0)