From 7f9cd7ef7c4282be5c1bcbdf5affa1a683af5cd9 Mon Sep 17 00:00:00 2001 From: InventorXtreme Date: Sun, 24 Mar 2024 22:41:38 -0400 Subject: [PATCH] raaaaaaa --- c3d.c | 2 +- c3dtypes.h | 19 +++++++++++++++++++ reader.c | 18 +++++++++++++++--- reader.h | 2 ++ 4 files changed, 37 insertions(+), 4 deletions(-) diff --git a/c3d.c b/c3d.c index 71dc040..e6825bc 100644 --- a/c3d.c +++ b/c3d.c @@ -488,7 +488,7 @@ int main() { bool run3d = true; if (true) { - Object3D t = ReadObjectFromFile("teapot.obj"); + Object3D t = ReadObjectFromFile("mario.obj"); for (int i = 0; i < t.triangles->length; i++) { // printf("t: %f\n", t.triangles->arr[i].a.x); TriArrayAppend(&tarr, t.triangles->arr[i]); diff --git a/c3dtypes.h b/c3dtypes.h index 9299ad6..19601df 100644 --- a/c3dtypes.h +++ b/c3dtypes.h @@ -22,7 +22,19 @@ struct Tri { Vector3 c; Color color; + + + Vector2 auv; + Vector2 buv; + Vector2 cuv; + }; + +struct Mat { + char * name; + char * file; +} + typedef struct Tri Tri; struct Tri2D { @@ -30,11 +42,18 @@ struct Tri2D { Vector2 b; Vector2 c; + + float adepth; float bdepth; float cdepth; Color color; + + + Vector2 auv; + Vector2 buv; + Vector2 cuv; }; typedef struct Tri2D Tri2D; diff --git a/reader.c b/reader.c index 2bfe17b..cf3c9a3 100644 --- a/reader.c +++ b/reader.c @@ -9,6 +9,15 @@ int TestFunc(int x) { return x; } +Vector3 BreakDownObjTriElement(char * vert) { + int vertex = 0; + int vertextexture = 0; + int normal = 0; + + sscanf(vert, "%i/%i/%i", &vertex, &vertextexture, &normal); + return (Vector3) {vertex, vertextexture, normal}; +} + Object3D ReadObjectFromFile(char * fname) { Object3D out; Vector3 *VertexArray = malloc(10000 * sizeof(Vector3)); @@ -42,6 +51,9 @@ Object3D ReadObjectFromFile(char * fname) { VertexArray[VertexArrayLength].z = atof(v3)*100; VertexArrayLength = VertexArrayLength + 1; } + if (strcmp(objtype, "vt") == 0) { + + } if (strcmp(objtype, "f") == 0 ) { // TODO: append face to triarry Tri temptri; @@ -51,15 +63,15 @@ Object3D ReadObjectFromFile(char * fname) { temptri.b = VertexArray[ atoi(v2) - 1]; temptri.c = VertexArray[ atoi(v3) - 1]; - printf("OLINE: %s\n", t); - printf("adding tri A: %d, B: %d, C: %d\n", atoi(v1), atoi(v2) , atoi(v3) ); + //printf("OLINE: %s\n", t); + //printf("adding tri A: %d, B: %d, C: %d\n", atoi(v1), atoi(v2) , atoi(v3) ); temptri.color = GREEN; TriArrayAppend(&tarr, temptri); } // need to bring in triarray functions into their own file } - + printf("Loaded model %s with %d tris\n", fname, tarr.length); return out; // TODO: use file object and read each line diff --git a/reader.h b/reader.h index aec50a7..7719fa5 100644 --- a/reader.h +++ b/reader.h @@ -4,4 +4,6 @@ int TestFunc(int x); Object3D ReadObjectFromFile(char * fname); + + #endif