Google

Does OgreBullet support soft body simulation?

Discussion about the Bullet binding layer, OgreBullet

Moderators: OGRE Team, OgreBullet Moderators

Does OgreBullet support soft body simulation?

Postby sms1986 » Mon Jun 23, 2008 7:05 pm

Bullet 2.69 has support for soft body simulation, and what about OgreBullet? Can OgreBullet also handle it?
If not, is there a prevision for when it will be implemented?
Thanks!
sms1986
Gnoblar
 
Posts: 4
Kudos: 0
Joined: 16 Jun 2008

Postby nord666 » Sun Sep 28, 2008 10:32 pm

Hi,

i know you created this topic 2-3 months ago but i will answer it anyway.

I dont think OgreBullet has SoftBody..
Anyway, you should use pure Bullet to use it's full power. OgreBullet contain the minimum to easily use Bullet with Ogre, not thw whole stuff.

I hope i correctly answered your question
Dell XPS M1530 :
- Intel(R) Core(TM)2 Duo CPU T7500 @ 2.20GHz
- NVIDIA GeForce 8600M GT 256 MB
- RAM : 2 GB
- HDD : 120 GB
- Vista & Kubuntu with 2 monitors
User avatar
nord666
Kobold
 
Posts: 34
Kudos: 0
Joined: 21 May 2008

Postby imajia » Sun Sep 28, 2008 11:42 pm

Using the softbody part of bullet is easier than it it might seem in the beginning. After creating the softbody, you have to update your Ogre mesh, so that the changes are visible. Below is an example of how this could be done. The example doesn't work for all meshes, but it is just an example ;)

Code: Select all
void BulletFrameListener::updateOgreMeshFromBulletMesh(btSoftBody *softBody)
{
    //retrieve the vertex data from the softbody.
    SoftBody *ogreSoftBody= static_cast<SoftBody*>(softBody->getUserPointer());
    MeshPtr mesh= ogreSoftBody->getEntity()->getMesh();
    Ogre::SubMesh* submesh = mesh->getSubMesh(0);
    Ogre::VertexData* vertex_data = submesh->useSharedVertices ? mesh->sharedVertexData : submesh->vertexData;

    if (!submesh->useSharedVertices)
    {
        const Ogre::VertexElement* posElem =vertex_data->vertexDeclaration->findElementBySemantic(Ogre::VES_POSITION);
        Ogre::HardwareVertexBufferSharedPtr vbuf= vertex_data->vertexBufferBinding->getBuffer(posElem->getSource());
        const unsigned int vSize = (unsigned int)vbuf->getVertexSize();
        unsigned char* vertex =static_cast<unsigned char*>(vbuf->lock(Ogre::HardwareBuffer::HBL_DISCARD));

        float* pReal;

        //get the vertex data from bullet.
        btSoftBody::tNodeArray&   nodes(softBody->m_nodes);

        //now we simply update the coords of the vertices. Of course this only works
        //properly when the Ogre data and the Bullet data have the same number of vertices
        //and when they are in the same order. It seems that bullet doesn't shuffle the
        //vertices, but this is only an observation!
        for (int j=0;j<nodes.size();++j)
        {
            posElem->baseVertexPointerToElement(vertex, &pReal);
            vertex += vSize;
            *pReal++= nodes[j].m_x.x();
            *pReal++= nodes[j].m_x.y();
            *pReal++= nodes[j].m_x.z();
        }
        vbuf->unlock();
    }
}


The interesting part is softBody->m_nodes. You can directly access the verticx information of Bullet using the variable m_nodes. The screenshot shows an example of how it might look like. The performance is fine, there is no relevant drop in the FPS. At least as long as your mesh doesn't have to many vertices or you have to many softbodies which can collide.
As the first try might fail, the usage of the debug draw feature of bullet helps a lot. In the Wiki there is an example. Helps a lot to find out where your bullet object really is...

Image
imajia
Gnoblar
 
Posts: 3
Kudos: 0
Joined: 10 Sep 2008

Postby ricardo_arango » Sat Oct 25, 2008 9:20 pm

Hi,

Just One question (edited)

Is it possible to somehow share vertices, so updating the vertices in bullet automatically updates the vertices in the mesh?

Thanks
ricardo_arango
Halfling
 
Posts: 46
Kudos: 0
Joined: 28 Jan 2006

Re: Does OgreBullet support soft body simulation?

Postby mbykovskyy » Fri Jan 30, 2009 7:07 pm

Don't know if I should've started my own thread, but by looking at imajia's code I can't seem to comprehend why the new vertex data written manual to the buffer is not overwritten by Ogre during rendering. This code is obviously in the FrameListener, so it's called before Ogre does any rendering. And also if you discard the whole buffer isn't there a danger that vertices from other meshes might get discarded as well?
mbykovskyy
Gnoblar
 
Posts: 4
Kudos: 0
Joined: 30 Jan 2009

Re: Does OgreBullet support soft body simulation?

Postby jacmoe » Fri Jan 30, 2009 8:04 pm

No, that's fine. Because it only modifies the vertex buffer of a mesh. Actually, a submesh of a mesh.
In Ogre, all meshes have their own vertex/index buffers, most of them are using separate vertex/index buffers per submesh. :wink:
/* when invited to a free lunch, you should not complain about the quality of the caviar */
Ogitor Scenebuilder - powered by Ogre, presented by Qt, Fueled by Passion.
User avatar
jacmoe
Site Admin
 
Posts: 240
Kudos: 4
Joined: 23 Sep 2005
Location: Holmegaard, Denmark

Re: Does OgreBullet support soft body simulation?

Postby mbykovskyy » Sat Jan 31, 2009 1:11 pm

I see! Thanks jacmoe, that clear some clouds in my head. So, can I safely assume that these vertex buffers will stay valid throughout application runtime, so if I store pointers to mesh vertices as opposed to their value, these pointers will point to a valid data?
mbykovskyy
Gnoblar
 
Posts: 4
Kudos: 0
Joined: 30 Jan 2009

Re: Does OgreBullet support soft body simulation?

Postby tuan kuranes » Mon Feb 02, 2009 9:30 am

Code: Select all
So, can I safely assume that these vertex buffers will stay valid throughout application runtime, so if I store pointers to mesh vertices as opposed to their value, these pointers will point to a valid data?

No. most likely Vertex Data lies on Gpu, and if you "read" it from there you would get a freshly new memcpi'ed array.
Better keep a complete vertex data buffer on you side and upload it after each modification from simulation.
User avatar
tuan kuranes
Site Admin
 
Posts: 1793
Kudos: 0
Joined: 23 Sep 2005
Location: Haute Garonne, France

Re: Does OgreBullet support soft body simulation?

Postby mbykovskyy » Mon Feb 02, 2009 10:20 am

Better keep a complete vertex data buffer on you side and upload it after each modification from simulation.

That's what I'll do so. Thanks tuan.
mbykovskyy
Gnoblar
 
Posts: 4
Kudos: 0
Joined: 30 Jan 2009

Re: Does OgreBullet support soft body simulation?

Postby lgvier » Sat Apr 04, 2009 9:17 am

Hello,

Did someone manage to do the opposite - creating a btSoftBody from a mesh?
I have it almost working, but some vertices are not shared on the mesh, so I don't know how to link the triangles - It ends up loading the triangles correctly, but not linked to each other, so the object 'falls apart' on the simulation.

Here's my current code (two versions with the same result):

Code: Select all
// using btSoftBodyHelpers::CreateFromTriMesh
   btScalar vertices[mVertexCount * 3];
   int i,j;
   for(i=0, j=0; i < mVertexCount; i++)
   {
      Vector3 v =  mVertexBuffer[i];
      vertices[j++] = v.x;
      vertices[j++] = v.y;
      vertices[j++] = v.z;
   }
   
   int ntriangles = mIndexCount / 3;
   int *indexes = (int*) mIndexBuffer;
   return btSoftBodyHelpers::CreateFromTriMesh(*worldInfo, vertices, indexes, ntriangles);

Code: Select all
// doing basically what btSoftBodyHelpers::CreateFromTriMesh does
   unsigned int ntriangles = mIndexCount / 3;
   
   btAlignedObjectArray<bool>      chks;
   btAlignedObjectArray<btVector3>   vtx;
   chks.resize(mVertexCount*mVertexCount,false);
   vtx.resize(mVertexCount);
   
   unsigned int maxidx = mVertexCount;
   
   int i, j;
   for(i=0; i < mVertexCount; i++)
   {
      vtx[i] = Convert::toBullet(mVertexBuffer[i]);
   }
   
   btSoftBody*      psb=new btSoftBody(worldInfo,vtx.size(),&vtx[0],0);
   
#define IDX(_x_,_y_) ((_y_)*maxidx+(_x_))
   
   for( i=0; i < mIndexCount; i+=3)
   {
      const int idx[]={mIndexBuffer[i],mIndexBuffer[i+1],mIndexBuffer[i+2]};
      for(int j=2,k=0;k<3;j=k++)
      {
         if(!chks[IDX(idx[j],idx[k])])
         {
            chks[IDX(idx[j],idx[k])]=true;
            chks[IDX(idx[k],idx[j])]=true;
            psb->appendLink(idx[j],idx[k]);
         }
      }
      printf("face %d %d %d \n", idx[0],idx[1],idx[2]);
      psb->appendFace(idx[0],idx[1],idx[2]);
      
   }
   
#undef IDX
   
   psb->randomizeConstraints();
   return(psb);


Any ideas?
Thanks
-Geovani
lgvier
Gnoblar
 
Posts: 6
Kudos: 0
Joined: 04 Apr 2009
Location: Porto Alegre, Brazil

Re: Does OgreBullet support soft body simulation?

Postby mbykovskyy » Sat Apr 04, 2009 10:35 am

I think you just need to set your SoftBody material properties. Try tweaking these values

Code: Select all
//   _softBody->m_cfg.kDP = 0.001;  // Damping coefficient
   _softBody->m_cfg.kDF = 0.5;  // Dynamic friction coefficient
//   _softBody->m_cfg.kMT = 0.01;  // Pose matching coefficient
//   _softBody->m_cfg.kPR = 2500;
//   _softBody->m_cfg.kCHR = 1;  // Rigid contacts hardness
//   _softBody->m_cfg.kKHR = 0.8;  // Kinetic contacts hardness
//   _softBody->m_cfg.kSHR = 1;  // Soft contacts hardness
   _softBody->m_cfg.piterations = 2;  // Positions solver iterations
   _softBody->m_materials[0]->m_kLST = 0.45;

   btSoftBody::Material* softBodyMaterial = _softBody->appendMaterial();
   softBodyMaterial->m_kLST = 0.5;  // Linear stiffness coefficient
   softBodyMaterial->m_kAST = 0.1;  // Area/Angular stiffness coefficient
   softBodyMaterial->m_kVST = 0.5;  // Volume stiffness coefficient

   btScalar mass(WorldMetricsHelper::kg(60));
   _softBody->setTotalMass(mass, true);
//   _softBody->setPose(false, true);  // XXX Set current state as a pose
//   _softBody->generateBendingConstraints(2, softBodyMaterial);
   _softBody->randomizeConstraints();
mbykovskyy
Gnoblar
 
Posts: 4
Kudos: 0
Joined: 30 Jan 2009

Re: Does OgreBullet support soft body simulation?

Postby lgvier » Sat Apr 04, 2009 2:18 pm

Hi,

Thanks but it didn't work :(
The triangles are not linked to each other, so they act like they were independent objects.. I'll try to capture a video later.
If I bind them together with btSoftBody->appendLink(idx[j],idx[k]) the pieces that I linked work, but then I'd have to do all the links manually, triangle by triangle...

Cheers
Geovani
lgvier
Gnoblar
 
Posts: 6
Kudos: 0
Joined: 04 Apr 2009
Location: Porto Alegre, Brazil

Re: Does OgreBullet support soft body simulation?

Postby lgvier » Mon Apr 06, 2009 8:05 am

Hello,

I got it working by removing the duplicated vertices before creating the soft body.

More detais here:
http://www.bulletphysics.com/Bullet/php ... f=9&t=3428

Thanks
Geovani
lgvier
Gnoblar
 
Posts: 6
Kudos: 0
Joined: 04 Apr 2009
Location: Porto Alegre, Brazil

Re: Does OgreBullet support soft body simulation?

Postby boyamer » Fri Aug 14, 2009 4:05 pm

could you post your full code here?

Thanks
User avatar
boyamer
Greenskin
 
Posts: 141
Kudos: 2
Joined: 24 Jan 2009

Re: Does OgreBullet support soft body simulation?

Postby NazguL86 » Tue Apr 27, 2010 7:31 pm

I was trying to use Igvier softbody solution, but I cannot really figure out how to create a simple softbody.

Could anyone post an example how to use and create a softbody ?

Help would me much appreciated :)
NazguL86
Gnoblar
 
Posts: 12
Kudos: 0
Joined: 30 Mar 2010


Return to OgreBullet

Who is online

Users browsing this forum: Google Adsense [Bot] and 2 guests

cron