aboutsummaryrefslogtreecommitdiff
path: root/src/client/lua_api
diff options
context:
space:
mode:
Diffstat (limited to 'src/client/lua_api')
-rw-r--r--src/client/lua_api/phys/bphysmodel.cpp31
1 files changed, 20 insertions, 11 deletions
diff --git a/src/client/lua_api/phys/bphysmodel.cpp b/src/client/lua_api/phys/bphysmodel.cpp
index 6307d3a..2bf65fb 100644
--- a/src/client/lua_api/phys/bphysmodel.cpp
+++ b/src/client/lua_api/phys/bphysmodel.cpp
@@ -62,18 +62,27 @@ static int newbphysmodel(lua_State* L){
printf("bphysnode, createing the physics body\n");
//Create the physics body
IMesh *pmesh = smgr->getMesh(ppath);
- IMeshBuffer *b = pmesh->getMeshBuffer(0);
- u32 bi = b->getVertexCount();
+ printf("We have %d mesh buffers\n",pmesh->getMeshBufferCount());
+ u32 meshcount = pmesh->getMeshBufferCount();
btTriangleMesh* trimesh = new btTriangleMesh();
- for(u32 i = 0; i < bi; i+= 3){
- printf("Getting triangle %u of %u\n",i,bi);
- vector3df p1 = b->getPosition(i + 0);
- vector3df p2 = b->getPosition(i + 1);
- vector3df p3 = b->getPosition(i + 2);
- btVector3 b1 = btVector3(p1.X,p1.Y,p1.Z);
- btVector3 b2 = btVector3(p2.X,p2.Y,p2.Z);
- btVector3 b3 = btVector3(p3.X,p3.Y,p3.Z);
- trimesh->addTriangle(b1,b2,b3);
+ for(u32 meshnum = 0; meshnum < meshcount; meshnum++){
+ IMeshBuffer *b = pmesh->getMeshBuffer(meshnum);
+ //assert(b->getVertexType() == video::EVT_STANDARD);
+ u32 bi = b->getIndexCount();
+ u16 *indices = b->getIndices();
+ for(u32 i = 0; i < bi; i+= 3){
+ printf("Getting triangle %u of %u\n",i,bi);
+ u16 i1 = indices[i];
+ u16 i2 = indices[i + 1];
+ u16 i3 = indices[i + 2];
+ vector3df p1 = b->getPosition(i1);
+ vector3df p2 = b->getPosition(i2);
+ vector3df p3 = b->getPosition(i3);
+ btVector3 b1 = btVector3(p1.X,p1.Y,p1.Z) ;
+ btVector3 b2 = btVector3(p2.X,p2.Y,p2.Z) ;
+ btVector3 b3 = btVector3(p3.X,p3.Y,p3.Z) ;
+ trimesh->addTriangle(b1,b2,b3);
+ }
}
printf("Done building trimesh\n");
btCollisionShape *shape = new btBvhTriangleMeshShape(trimesh,true);