From d444d1c98fdefea6cf0aff50eb9b58d4dbcea6ed Mon Sep 17 00:00:00 2001 From: sanine Date: Fri, 16 Sep 2022 00:55:53 -0500 Subject: begin assimp bindings --- CMakeLists.txt | 6 +++++- libs/assimp/CMakeLists.txt | 2 +- src/import/CMakeLists.txt | 10 ++++++++++ src/import/import.c | 14 ++++++++++++++ src/import/import.h | 0 src/import/import.test.c | 44 ++++++++++++++++++++++++++++++++++++++++++++ 6 files changed, 74 insertions(+), 2 deletions(-) create mode 100644 src/import/CMakeLists.txt create mode 100644 src/import/import.c create mode 100644 src/import/import.h create mode 100644 src/import/import.test.c diff --git a/CMakeLists.txt b/CMakeLists.txt index 03e227b..e60f517 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -18,6 +18,9 @@ include_directories( ${LIB_ROOT}/glfw-3.3.8/include ${LIB_ROOT}/cglm/include ${LIB_ROOT}/miniaudio + ${LIB_ROOT}/assimp/include + # needed for assimp's config.h + ${CMAKE_BINARY_DIR}/libs/assimp/include ) # disable byte-alignment in cglm @@ -29,7 +32,7 @@ link_directories(${LIB_ROOT}/honeysuckle) link_directories(${LIB_ROOT}/glfw-3.3.8/src) add_subdirectory(${LIB_ROOT}/lua-5.1.5) -#add_subdirectory(${LIB_ROOT}/assimp) +add_subdirectory(${LIB_ROOT}/assimp) add_subdirectory(${LIB_ROOT}/honeysuckle) add_subdirectory(${LIB_ROOT}/cglm) add_subdirectory(${LIB_ROOT}/glfw-3.3.8) @@ -68,3 +71,4 @@ add_subdirectory(${SRC_ROOT}/logging) add_subdirectory(${SRC_ROOT}/options) add_subdirectory(${SRC_ROOT}/test) add_subdirectory(${SRC_ROOT}/util) +add_subdirectory(${SRC_ROOT}/import) diff --git a/libs/assimp/CMakeLists.txt b/libs/assimp/CMakeLists.txt index 434746e..e591f83 100644 --- a/libs/assimp/CMakeLists.txt +++ b/libs/assimp/CMakeLists.txt @@ -86,7 +86,7 @@ OPTION( ASSIMP_NO_EXPORT ) OPTION( ASSIMP_BUILD_ZLIB "Build your own zlib" - OFF + ON ) OPTION( ASSIMP_BUILD_ASSIMP_TOOLS "If the supplementary tools for Assimp are built in addition to the library." diff --git a/src/import/CMakeLists.txt b/src/import/CMakeLists.txt new file mode 100644 index 0000000..fc35779 --- /dev/null +++ b/src/import/CMakeLists.txt @@ -0,0 +1,10 @@ +project(honey_engine) + +target_sources(honey PUBLIC + ${CMAKE_CURRENT_LIST_DIR}/import.c +) + + +target_sources(test PUBLIC + ${CMAKE_CURRENT_LIST_DIR}/import.test.c +) diff --git a/src/import/import.c b/src/import/import.c new file mode 100644 index 0000000..cc22616 --- /dev/null +++ b/src/import/import.c @@ -0,0 +1,14 @@ +#include +#include +#include +#include "import.h" + + +void push_vector(lua_State *L, struct aiVector3D vec) +{ + hs_create_table(L, + hs_str_num("x", vec.x), + hs_str_num("y", vec.y), + hs_str_num("z", vec.z), + ); +} diff --git a/src/import/import.h b/src/import/import.h new file mode 100644 index 0000000..e69de29 diff --git a/src/import/import.test.c b/src/import/import.test.c new file mode 100644 index 0000000..efa6b84 --- /dev/null +++ b/src/import/import.test.c @@ -0,0 +1,44 @@ +#include +#include +#include +#include "test/honey-test.h" + + +#include "import.c" + + +void test_push_vector() +{ + lua_State *L = luaL_newstate(); + struct aiVector3D v; + v.x = 1.5; + v.y = 2.0; + v.z = 3.6; + + push_vector(L, v); + + lily_assert_int_equal(lua_type(L, -1), LUA_TTABLE); + + lua_getfield(L, -1, "x"); + lily_assert_int_equal(lua_type(L, -1), LUA_TNUMBER); + lily_assert_float_equal(lua_tonumber(L, -1), 1.5, 0.1); + lua_pop(L, 1); + + lua_getfield(L, -1, "y"); + lily_assert_int_equal(lua_type(L, -1), LUA_TNUMBER); + lily_assert_float_equal(lua_tonumber(L, -1), 2.0, 0.1); + lua_pop(L, 1); + + lua_getfield(L, -1, "z"); + lily_assert_int_equal(lua_type(L, -1), LUA_TNUMBER); + lily_assert_float_equal(lua_tonumber(L, -1), 3.6, 0.1); + lua_pop(L, 1); + + lua_close(L); +} + + +void suite_import() +{ + lily_run_test(test_push_vector); +} -- cgit v1.2.1