|
@@ -15,6 +15,7 @@
|
|
|
#include <array.h>
|
|
|
#include <display.h>
|
|
|
#include <triangle.h>
|
|
|
+#include <texture.h>
|
|
|
#include <mesh.h>
|
|
|
|
|
|
#define N_CUBE_VERTICES (8)
|
|
@@ -109,6 +110,26 @@ static uint32_t objFileLoaderLoadedVerticesTexture = 0;
|
|
|
static uint32_t objFileLoaderLoadedFaces = 0;
|
|
|
static uint32_t objFileLoaderTotalTri = 0;
|
|
|
|
|
|
+static void updateFaceUVValues()
|
|
|
+{
|
|
|
+ uint32_t i;
|
|
|
+ uint32_t faceCount = arrayGetSize(mesh.faces);
|
|
|
+
|
|
|
+ if (arrayGetSize(mesh.textureVertices) > 0)
|
|
|
+ {
|
|
|
+ for (i = 0 ; i < faceCount ; i++)
|
|
|
+ {
|
|
|
+ face_t *face = &mesh.faces[i];
|
|
|
+
|
|
|
+ face->a_uv.u = mesh.textureVertices[face->at].u;
|
|
|
+ face->a_uv.v = mesh.textureVertices[face->at].v;
|
|
|
+ face->b_uv.u = mesh.textureVertices[face->bt].u;
|
|
|
+ face->b_uv.v = mesh.textureVertices[face->bt].v;
|
|
|
+ face->c_uv.u = mesh.textureVertices[face->ct].u;
|
|
|
+ face->c_uv.v = mesh.textureVertices[face->ct].v;
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|
|
|
|
|
|
void loadOBJFile(const char *filepath)
|
|
|
{
|
|
@@ -149,6 +170,8 @@ void loadOBJFile(const char *filepath)
|
|
|
Log(TLOG_VERBOSE, "OBJLoader", "Number of created triangles : %lu", objFileLoaderTotalTri);
|
|
|
|
|
|
free(fileBuff);
|
|
|
+
|
|
|
+ updateFaceUVValues();
|
|
|
}
|
|
|
else
|
|
|
{
|
|
@@ -327,7 +350,7 @@ int objFileLoaderExecuteLine(int argc, char *argv[], uint32_t currentLine)
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
- vec2_t vertex = { atof(argv[1]), atof(argv[2]) };
|
|
|
+ tex2_t vertex = { atof(argv[1]), atof(argv[2]) };
|
|
|
arrayAdd(mesh.textureVertices, vertex);
|
|
|
objFileLoaderLoadedVerticesTexture++;
|
|
|
ret = 0;
|
|
@@ -348,7 +371,12 @@ int objFileLoaderExecuteLine(int argc, char *argv[], uint32_t currentLine)
|
|
|
objFileLoaderTotalTri++;
|
|
|
objFileLoaderLoadedFaces++;
|
|
|
|
|
|
- face_t face = { v[1], v[2], v[3], .colour = MAKE_RGB(45, 170, 10) };
|
|
|
+ face_t face =
|
|
|
+ {
|
|
|
+ .a = v[1], .b = v[2], .c = v[3],
|
|
|
+ .at = vt[1], .bt = vt[2], .ct = vt[3],
|
|
|
+ .colour = MAKE_RGB(45, 170, 10)
|
|
|
+ };
|
|
|
arrayAdd(mesh.faces, face);
|
|
|
ret = 0;
|
|
|
}
|
|
@@ -358,7 +386,10 @@ int objFileLoaderExecuteLine(int argc, char *argv[], uint32_t currentLine)
|
|
|
/* This is not a triangle, so we need to fan it */
|
|
|
for(i = 2; i < (argc - 1); i++)
|
|
|
{
|
|
|
- face_t face = { v[1], v[i], v[i + 1], .colour = MAKE_RGB(45, 170, 10) };
|
|
|
+ face_t face = {
|
|
|
+ .a = v[1], .b = v[i], .c = v[i + 1],
|
|
|
+ .at = vt[1], .bt = vt[i], .ct = vt[i + 1],
|
|
|
+ .colour = MAKE_RGB(45, 170, 10) };
|
|
|
arrayAdd(mesh.faces, face);
|
|
|
|
|
|
objFileLoaderTotalTri++;
|