Skip to content

Commit

Permalink
Reset current material index before finding new one
Browse files Browse the repository at this point in the history
This matches the old behaviour. I don't think it's necessary, but I
think it may help track down bugs if there are any issues in here.
  • Loading branch information
vkoskiv committed Nov 7, 2023
1 parent 29d8602 commit 846ae0f
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/utils/loaders/formats/wavefront/wavefront.c
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ static struct coord parseCoord(lineBuffer *line) {
// f v1//vn1 v2//vn2 v3//vn3
// Or a quad:
// f v1//vn1 v2//vn2 v3//vn3 v4//vn4
size_t parsePolygons(lineBuffer *line, struct poly *buf) {
static inline size_t parse_polys(lineBuffer *line, struct poly *buf) {
char container[LINEBUFFER_MAXSIZE];
lineBuffer batch = { .buf = container };
size_t polycount = line->amountOf.tokens - 3;
Expand Down Expand Up @@ -152,7 +152,7 @@ struct mesh *parseWavefront(const char *filePath, size_t *finalMeshCount, struct
} else if (stringEquals(first, "s")) {
// Smoothing groups. We don't care about these, we always smooth.
} else if (stringEquals(first, "f")) {
size_t count = parsePolygons(&line, polybuf);
size_t count = parse_polys(&line, polybuf);
for (size_t i = 0; i < count; ++i) {
struct poly p = polybuf[i];
//TODO: Check if we actually need the file totals here
Expand All @@ -164,6 +164,7 @@ struct mesh *parseWavefront(const char *filePath, size_t *finalMeshCount, struct
}
} else if (stringEquals(first, "usemtl")) {
char *name = peekNextToken(&line);
current_material_idx = 0;
for (size_t i = 0; i < mtllib.count; ++i) {
if (stringEquals(mtllib.items[i].name, name)) {
current_material_idx = i;
Expand Down

0 comments on commit 846ae0f

Please sign in to comment.