diff options
| author | Alexander Pickering <alex@cogarr.net> | 2018-10-31 12:32:49 -0400 |
|---|---|---|
| committer | Alexander Pickering <alex@cogarr.net> | 2018-10-31 12:32:49 -0400 |
| commit | 133e620665037ea2b66da65c67716b290711bfde (patch) | |
| tree | 5b6ce3bf6f0134e22bf4386740aa2f797e07a530 | |
| parent | 4a797a4226893b382ffc3c1f92e844f6743c7220 (diff) | |
| download | brokengine-133e620665037ea2b66da65c67716b290711bfde.tar.gz brokengine-133e620665037ea2b66da65c67716b290711bfde.tar.bz2 brokengine-133e620665037ea2b66da65c67716b290711bfde.zip | |
Fixed loading physics models
| -rw-r--r-- | src/client/lua_api/phys/bphysmodel.cpp | 31 |
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); |
