aboutsummaryrefslogtreecommitdiff
path: root/src/shared
diff options
context:
space:
mode:
Diffstat (limited to 'src/shared')
-rw-r--r--src/shared/lua_api/phys/bphysmodel.cpp13
1 files changed, 12 insertions, 1 deletions
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<btRigidBody*> 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);