diff options
Diffstat (limited to 'src/import')
-rw-r--r-- | src/import/import.c | 11 | ||||
-rw-r--r-- | src/import/import_mesh.test.c | 17 |
2 files changed, 18 insertions, 10 deletions
diff --git a/src/import/import.c b/src/import/import.c index a093068..becb1fe 100644 --- a/src/import/import.c +++ b/src/import/import.c @@ -15,7 +15,10 @@ int import_file(lua_State *L) char *filename; hs_parse_args(L, hs_str(filename)); - const struct aiScene *scene = aiImportFile(filename, aiProcess_Triangulate | aiProcess_FlipUVs); + const struct aiScene *scene = aiImportFile( + filename, + aiProcess_Triangulate | aiProcess_FlipUVs + ); if (scene == NULL) hs_throw_error(L, "failed to load file '%s'", filename); @@ -53,7 +56,11 @@ static void push_face(lua_State *L, struct aiFace face) for (int i=0; i<face.mNumIndices; i++) { /* add one to the index bc lua is 1-indexed */ - lua_pushinteger(L, face.mIndices[i]+1); + /* the above comment is WRONG WRONG WRONG!! + * lua is indeed 1-indexed, but this data is being interpreted + * by *opengl* not lua. we should not add 1!! + */ + lua_pushinteger(L, face.mIndices[i]); lua_rawseti(L, tbl, i+1); } } diff --git a/src/import/import_mesh.test.c b/src/import/import_mesh.test.c index fdbfbf0..7dc8624 100644 --- a/src/import/import_mesh.test.c +++ b/src/import/import_mesh.test.c @@ -55,18 +55,19 @@ void test_push_face() lily_assert_int_equal(lua_objlen(L, facetbl), 6); /* the numbers should be one higher because of lua's 1-indexing */ + /* WRONG! the numbers should be 0-indexed because they will be interpreted by opengl */ lua_rawgeti(L, facetbl, 1); - lily_assert_int_equal(lua_tointeger(L, -1), 1); + lily_assert_int_equal(lua_tointeger(L, -1), 0); lua_rawgeti(L, facetbl, 2); - lily_assert_int_equal(lua_tointeger(L, -1), 2); + lily_assert_int_equal(lua_tointeger(L, -1), 1); lua_rawgeti(L, facetbl, 3); - lily_assert_int_equal(lua_tointeger(L, -1), 3); + lily_assert_int_equal(lua_tointeger(L, -1), 2); lua_rawgeti(L, facetbl, 4); - lily_assert_int_equal(lua_tointeger(L, -1), 4); + lily_assert_int_equal(lua_tointeger(L, -1), 3); lua_rawgeti(L, facetbl, 5); - lily_assert_int_equal(lua_tointeger(L, -1), 5); + lily_assert_int_equal(lua_tointeger(L, -1), 4); lua_rawgeti(L, facetbl, 6); - lily_assert_int_equal(lua_tointeger(L, -1), 6); + lily_assert_int_equal(lua_tointeger(L, -1), 5); lua_close(L); } @@ -414,8 +415,8 @@ static int check_face(lua_State *L, int meshtbl, const char *field, int index, void test_faces(lua_State *L, int meshtbl) { - check_face(L, meshtbl, "faces", 1, 1, 2, 4); - check_face(L, meshtbl, "faces", 2, 1, 4, 3); + check_face(L, meshtbl, "faces", 1, 0, 1, 3); + check_face(L, meshtbl, "faces", 2, 0, 3, 2); } |