From 353d60d3ebc353aef474633e7064067a2ef343ce Mon Sep 17 00:00:00 2001 From: sanine Date: Wed, 22 Feb 2023 01:02:45 -0600 Subject: implement and demo basic obj loading --- src/import/import.c | 193 ++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 186 insertions(+), 7 deletions(-) (limited to 'src') diff --git a/src/import/import.c b/src/import/import.c index f860396..e2fc250 100644 --- a/src/import/import.c +++ b/src/import/import.c @@ -1,21 +1,200 @@ #include -#include +#include +#include "util/util.h" #include "import.h" #define TINYOBJ_LOADER_C_IMPLEMENTATION #include -int dummy(lua_State *L) + +void read_file(void *ctx, const char *filename, int is_mtl, const char *obj_filename, char **buf, size_t *len) { - return 0; + FILE *f = fopen(filename, "rb"); + fseek(f, 0, SEEK_END); + *len = ftell(f); + fseek(f, 0, SEEK_SET); + + *buf = malloc(*len); + fread(*buf, *len, 1, f); + fclose(f); } -void setup_import(lua_State *L, int honey_tbl) +static void push_float_array(lua_State *L, float *arr, size_t len) +{ + lua_createtable(L, len, 0); + int tbl = lua_gettop(L); + for (int i=0; i