summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/image/image.c3
-rw-r--r--src/import/import.c37
-rw-r--r--src/import/import.h6
-rw-r--r--src/main.c2
4 files changed, 47 insertions, 1 deletions
diff --git a/src/image/image.c b/src/image/image.c
index cf08625..a8a0502 100644
--- a/src/image/image.c
+++ b/src/image/image.c
@@ -1,6 +1,7 @@
#include <lua.h>
#include <honeysuckle.h>
-#define STB_IMAGE_IMPLEMENTATION
+/* assimp provides its own stb_image implementation */
+/*#define STB_IMAGE_IMPLEMENTATION*/
#include "stb_image.h"
#include "image.h"
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
diff --git a/src/main.c b/src/main.c
index e11a0c6..618b30c 100644
--- a/src/main.c
+++ b/src/main.c
@@ -6,6 +6,7 @@
#include "gl/gl.h"
#include "glm/glm.h"
#include "image/image.h"
+#include "import/import.h"
#include "logging/logging.h"
#include "options/options.h"
@@ -29,6 +30,7 @@ int main(int argc, char **argv)
setup_gl(L, honey_index);
setup_glm(L, honey_index);
setup_image(L, honey_index);
+ setup_import(L, honey_index);
setup_logging(L, honey_index);
setup_window(L, honey_index);
lua_setglobal(L, "honey");