Hi,
so here is my example code of an Ogre Mesh converted to a Bullet Softbody.
I dont know if you can get it to work immediately, I didnt do anything with premake, its just my Visual Studio project.
However the important files are
main.cpp (in btOgreSoftbodyDemo\demo folder). It contains my example.
BtOgreExtras.h
BtOgreGP.h
BtOgrePG.h
BtOgreSoftBody.h
MeshUtils.cpp
meshutils.h
Unopyable.h
In main.cpp you will need to set the directory with the materials and meshes manually.
If you are just interested in the example code of converting an OgreMesh to a Softbody, here it is (from main.cpp in the files):
Code:
// First create the physics World
mBroadphase = new btAxisSweep3(btVector3(-10000,-10000,-10000), btVector3(10000,10000,10000), 1024);
mCollisionConfig = new btSoftBodyRigidBodyCollisionConfiguration();
mDispatcher = new btCollisionDispatcher(mCollisionConfig);
mSolver = new btSequentialImpulseConstraintSolver();
btDiscreteDynamicsWorld* phyWorld = new btSoftRigidDynamicsWorld(mDispatcher, mBroadphase, mSolver, mCollisionConfig);
phyWorld->getDispatchInfo().m_enableSPU = true;
phyWorld->setGravity(btVector3(0,-9.8,0));
Now the important part. Converting Ogre Mesh to Softbody:
Code:
// Put in your own Ogre mesh here if you like
Ogre::Entity *ogreMeshEntity = mSceneMgr->createEntity("ogreMeshEntity", "YourMesh.mesh");
Ogre::SceneNode* node = mSceneMgr->getRootSceneNode()->createChildSceneNode();
node->attachObject(ogreMeshEntity);
// Softbody
m_softBodyWorldInfo.air_density = (btScalar)1.2;
m_softBodyWorldInfo.m_gravity.setValue(0,-9.81,0);
m_softBodyWorldInfo.m_dispatcher = mDispatcher;
m_softBodyWorldInfo.m_sparsesdf.Reset();
m_softBodyWorldInfo.m_broadphase = mBroadphase;
m_softBodyWorldInfo.m_sparsesdf.Initialize();
BtOgre::BtOgreSoftBody *softBody = new BtOgre::BtOgreSoftBody(&m_softBodyWorldInfo);
Ogre::MeshPtr myMesh = ogreMeshEntity->getMesh();
// You need the MeshUtils class here
MeshData MyMeshData = *(MeshUtils::getMeshData(myMesh));
// Every Triangle has 3 Indices pointing to its Vertices
unsigned long* indices = new unsigned long[MyMeshData.triangleCount*3];
// I had to do this to point to the vertices and indices.
MeshUtils::meshBuffersToArrays(myMesh, MyMeshData.vertices, indices);
btSoftBody* psb = Globals::softBody->create(ogreMeshEntity,
MyMeshData.vertexCount,
MyMeshData.vertices,
MyMeshData.triangleCount*3,
(unsigned int*)indices);
btSoftBody::Material* pm=psb->appendMaterial();
pm->m_kLST = 0.1;
psb->m_cfg.piterations = 2;
psb->m_cfg.kDF = 0.5;
psb->m_cfg.collisions |= btSoftBody::fCollision::VF_SS;
psb->generateClusters(0);
psb->randomizeConstraints();
psb->setTotalMass(100,true);
phyWorld->addSoftBody(psb);
and in the frameStarted Method, or any method that is called every frame you need to do (after stepSimulation):
Code:
softBody->updateOgreMesh();
Here is a picture from the demo, its a softbody Cube wrapped around a stone
