Load vertex normals indices
This commit is contained in:
parent
e01c1397bc
commit
d323c0ae14
16
src/obj.c
16
src/obj.c
@ -115,10 +115,8 @@ Model load_obj_file(Arena *arena, const char *filename, const char *texture) {
|
||||
f32 nx, ny, nz;
|
||||
f32 u, v;
|
||||
u64 fp0, fp1, fp2;
|
||||
u64 vn0, vn1, vn2;
|
||||
u64 tx0, tx1, tx2;
|
||||
u64 ign_0_2;
|
||||
u64 ign_1_2;
|
||||
u64 ign_2_2;
|
||||
while (fgets(line, 8191, fp) != NULL) {
|
||||
sscanf(line, "%s", identifier);
|
||||
if (strncmp(identifier, "v", 8) == 0) {
|
||||
@ -139,12 +137,15 @@ Model load_obj_file(Arena *arena, const char *filename, const char *texture) {
|
||||
coord.v = v;
|
||||
list_append(V2f, arena, model.texture_coordinates, coord);
|
||||
} else if (strncmp(identifier, "f", 8) == 0) {
|
||||
sscanf(line + 2, "%lu/%lu/%lu %lu/%lu/%lu %lu/%lu/%lu", &fp0, &tx0,
|
||||
&ign_0_2, &fp1, &tx1, &ign_1_2, &fp2, &tx2, &ign_2_2);
|
||||
sscanf(line + 2, "%lu/%lu/%lu %lu/%lu/%lu %lu/%lu/%lu", &fp0, &tx0, &vn0,
|
||||
&fp1, &tx1, &vn1, &fp2, &tx2, &vn2);
|
||||
// OBJ indices start from 1
|
||||
triangle.p0 = fp0 - 1;
|
||||
triangle.p1 = fp1 - 1;
|
||||
triangle.p2 = fp2 - 1;
|
||||
triangle.n0 = vn0 - 1;
|
||||
triangle.n1 = vn1 - 1;
|
||||
triangle.n2 = vn2 - 1;
|
||||
triangle.tx0 = tx0 - 1;
|
||||
triangle.tx1 = tx1 - 1;
|
||||
triangle.tx2 = tx2 - 1;
|
||||
@ -202,6 +203,11 @@ internal void render_triangle(const Triangle *triangle, const Model *model,
|
||||
list_get(model->vertices, triangle->p1),
|
||||
list_get(model->vertices, triangle->p2),
|
||||
};
|
||||
V3f normals[TRIANGLE_VERTICES] = {
|
||||
list_get(model->normals, triangle->n0),
|
||||
list_get(model->normals, triangle->n1),
|
||||
list_get(model->normals, triangle->n2),
|
||||
};
|
||||
V2f coordinates[TRIANGLE_VERTICES] = {
|
||||
list_get(model->texture_coordinates, triangle->tx0),
|
||||
list_get(model->texture_coordinates, triangle->tx1),
|
||||
|
Loading…
Reference in New Issue
Block a user