From 64b1fcb3e7e55e55bb8da8cd9f5c3d9d4d92fdb8 Mon Sep 17 00:00:00 2001 From: sanine Date: Sun, 18 Sep 2022 16:09:24 -0500 Subject: add normal pushing --- src/import/import.c | 18 +++++++++++ src/import/import.test.c | 84 ++++++++++++++++++++++++++++++++++++++++++------ 2 files changed, 93 insertions(+), 9 deletions(-) (limited to 'src') diff --git a/src/import/import.c b/src/import/import.c index 2debc3a..a68ac05 100644 --- a/src/import/import.c +++ b/src/import/import.c @@ -47,11 +47,24 @@ void push_mesh(lua_State *L, struct aiMesh mesh) int vertices = lua_gettop(L); pop_count += 1; + int normals = 0; + if (mesh.mNormals != NULL) { + lua_createtable(L, count, 0); + normals = lua_gettop(L); + pop_count += 1; + } + /* populate vertices */ for (int i=0; imVertices[0] = (struct aiVector3D) { 0, 0, 0 }; @@ -278,6 +320,29 @@ void test_faces(lua_State *L, int meshtbl) } +void create_normals(struct aiMesh *mesh) +{ + /* these normals are deliberately not, uh, normalized + * in order to distinguish them for the purposes of testing. + * (this could also happen in real life -- assimp won't normalize + * normals taken straight from the object file) + */ + mesh->mNormals[0] = (struct aiVector3D) { 0, 0.1, 0 }; + mesh->mNormals[1] = (struct aiVector3D) { 0, 0.2, 0 }; + mesh->mNormals[2] = (struct aiVector3D) { 0, 0.4, 0 }; + mesh->mNormals[3] = (struct aiVector3D) { 0, 1.0, 0 }; +} + + +void test_normals(lua_State *L, int meshtbl) +{ + check_vector(L, meshtbl, "normals", 1, 0, 0.1, 0); + check_vector(L, meshtbl, "normals", 2, 0, 0.2, 0); + check_vector(L, meshtbl, "normals", 3, 0, 0.4, 0); + check_vector(L, meshtbl, "normals", 4, 0, 1.0, 0); +} + + void test_nil(lua_State *L, int meshtbl, const char *field) { lua_getfield(L, meshtbl, field); @@ -297,4 +362,5 @@ void suite_import() lily_run_test(test_push_mesh); lily_run_test(test_push_mesh_faces); + lily_run_test(test_push_mesh_normals); } -- cgit v1.2.1