Don't create new shape by usemtl. Fixes #68.

This commit is contained in:
Syoyo Fujita
2016-03-12 02:14:52 +09:00
parent 31611161df
commit 0adca078ba
2 changed files with 12 additions and 12 deletions

View File

@@ -139,6 +139,7 @@ TestLoadObj(
}
if (!ret) {
printf("Failed to load/parse .obj.\n");
return false;
}

View File

@@ -5,6 +5,7 @@
//
//
// version 0.9.20: Fixes creating per-face material using `usemtl`(#68)
// version 0.9.17: Support n-polygon and crease tag(OpenSubdiv extension)
// version 0.9.16: Make tinyobjloader header-only
// 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]
sscanf(token, "%s", namebuf);
#endif
// Create face group per material.
bool ret =
exportFaceGroupToShape(shape, vertexCache, v, vn, vt, faceGroup, tags,
material, name, true, triangulate);
if (ret) {
shapes.push_back(shape);
}
shape = shape_t();
faceGroup.clear();
int newMaterialId = -1;
if (material_map.find(namebuf) != material_map.end()) {
material = material_map[namebuf];
newMaterialId = material_map[namebuf];
} else {
// { error!! material not found }
material = -1;
}
if (newMaterialId != material) {
// Create per-face material
exportFaceGroupToShape(shape, vertexCache, v, vn, vt, faceGroup, tags,
material, name, true, triangulate);
faceGroup.clear();
material = newMaterialId;
}
continue;