From a5062e3999d60f943c39e4bda6bbc9ae6b0a372d Mon Sep 17 00:00:00 2001 From: Alexander Date: Mon, 29 Jun 2020 16:25:01 -0400 Subject: Updates to model loader to work with new api Tinyobjloader-c modified it's api(backwards incompatable), modify the call to fit the new api. --- src/shared/lua_api/phys/bphysmodel.cpp | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) (limited to 'src/shared/lua_api') diff --git a/src/shared/lua_api/phys/bphysmodel.cpp b/src/shared/lua_api/phys/bphysmodel.cpp index 375d68b..a813e17 100644 --- a/src/shared/lua_api/phys/bphysmodel.cpp +++ b/src/shared/lua_api/phys/bphysmodel.cpp @@ -28,6 +28,17 @@ extern std::list Objects; //btTriangleMesh *trimesh = new btTriangleMesh(); //} +static void get_file_data(const char* filename, char **data, size_t *len){ + FILE *objfile = fopen(filename,"rb"); + fseek(objfile,0,SEEK_END); + *len = (size_t)ftell(objfile); + //printf("model data is %d long\n",(int)data_len); + fseek(objfile,0,SEEK_SET); + *data = (char*)malloc(sizeof(char) * *len); + fread(*data , sizeof(char), *len, objfile); + fclose(objfile); +} + //TODO: This will break in the future, see github.com/syoyo/tinyobjloader-c/issues/16 //"physicfile",mass[,position][,lookat] :: ud_rigidbody void makebphysmodel(lua_State *L){ @@ -66,7 +77,7 @@ void makebphysmodel(lua_State *L){ fread(objdata, sizeof(char), data_len, objfile); fclose(objfile); //printf("About to tinyobj_parse_obj\n"); - int err = tinyobj_parse_obj(&attrib, &shapes, &meshcount, &materials, &num_materials, objdata, data_len, TINYOBJ_FLAG_TRIANGULATE); + int err = tinyobj_parse_obj(&attrib, &shapes, &meshcount, &materials, &num_materials, ppath, get_file_data, TINYOBJ_FLAG_TRIANGULATE); //printf("Finished parsing tinyobj\n"); if(err != TINYOBJ_SUCCESS){ printf("Tinyobj failed to load model:%s\n",ppath); -- cgit v1.2.3-70-g09d2