diff options
author | sanine <sanine.not@pm.me> | 2022-09-27 17:00:46 -0500 |
---|---|---|
committer | sanine <sanine.not@pm.me> | 2022-09-27 17:00:46 -0500 |
commit | d822cf5b786776788cace9c3f9b2be9df41812e9 (patch) | |
tree | a1afdd5894495b2ac89cf4f45d5fa26bfa2ca3f3 /src/import | |
parent | 0745aeb35bee22f52b812869cf77995ff1ba373b (diff) |
fix uninitialized memory bug in mesh loading and add suzanne.dae
Diffstat (limited to 'src/import')
-rw-r--r-- | src/import/import.c | 37 | ||||
-rw-r--r-- | src/import/import.h | 6 |
2 files changed, 43 insertions, 0 deletions
diff --git a/src/import/import.c b/src/import/import.c index 306601e..a093068 100644 --- a/src/import/import.c +++ b/src/import/import.c @@ -1,9 +1,41 @@ #include <lua.h> #include <honeysuckle.h> #include <assimp/scene.h> +#include <assimp/cimport.h> +#include <assimp/postprocess.h> #include "import.h" +#ifndef LILY_TEST_H + +static void push_scene(lua_State *L, struct aiScene *scene); + +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); + if (scene == NULL) + hs_throw_error(L, "failed to load file '%s'", filename); + + push_scene(L, (struct aiScene*) scene); + return 1; +} + + +void setup_import(lua_State *L, int honey_tbl) +{ + hs_create_table(L, + hs_str_cfunc("importFile", import_file), + ); + + lua_setfield(L, honey_tbl, "import"); +} + +#endif + + static void push_vector(lua_State *L, struct aiVector3D vec) { hs_create_table(L, @@ -119,6 +151,8 @@ static void push_mesh(lua_State *L, struct aiMesh *mesh) lua_pushinteger(L, mesh->mNumUVComponents[i]); lua_rawseti(L, uv_components, i+1); } + else + uv_channels[i] = 0; } /* --=== populate vertices ===-- */ @@ -251,3 +285,6 @@ static void push_scene(lua_State *L, struct aiScene *scene) hs_str_tbl("meshes", meshtbl), ); } + + + diff --git a/src/import/import.h b/src/import/import.h index e69de29..a1bb081 100644 --- a/src/import/import.h +++ b/src/import/import.h @@ -0,0 +1,6 @@ +#ifndef HONEY_IMPORT_H +#define HONEY_IMPORT_H + +void setup_import(lua_State *L, int honey_tbl); + +#endif |