Physics Simulation Forum

 

All times are UTC




Post new topic Reply to topic  [ 39 posts ]  Go to page Previous  1, 2, 3  Next
Author Message
PostPosted: Fri Nov 20, 2009 1:41 pm 
Offline

Joined: Wed Sep 16, 2009 12:10 pm
Posts: 3
Not yet -- haven't revisited this issue yet. Hopefully someday soon... :)


Top
 Profile  
 
PostPosted: Mon Jan 04, 2010 2:40 am 
Offline
User avatar

Joined: Fri Dec 18, 2009 6:06 pm
Posts: 44
Location: Montreal
I am trying to use this btOgreSoftbody.cpp and h-file posted above. I came across two problems when compiling the cpp file. I will post the fix here.

The compile spit out "btogresoftbody.cpp(95) : error C2057: expected constant expression"

Old code:
Code:
btScalar vertices[newVertexCount * 3];


Changed to:
Code:
btScalar *vertices = new btScalar[newVertexCount * 3];


Also here
Old code:
Code:
int indexes[indexCount];


Changed to:
Code:
int *indexes = new int[indexCount];


I hope the changes are correct. If anyone can provide some code to help me speed up
creating a softbody using this. I would be very greatful.

Thanks.
Garibalde


Top
 Profile  
 
PostPosted: Fri Jan 08, 2010 4:28 am 
Offline
User avatar

Joined: Fri Dec 18, 2009 6:06 pm
Posts: 44
Location: Montreal
I am trying to add a simple softbody to my simulation using BtOgreSoftBody
I cant seem to get it to work. Can someone please post a sample of code on
how to get a simple object to be rendered in Ogre using the BtOgreSoftBody.
I would be very grateful.

Does the BtOgreSoftBody file posted earlier work? I am having a difficult time
understanding how to use them.

Thanks
Garibalde


Top
 Profile  
 
PostPosted: Sun Jan 10, 2010 9:30 am 
Offline
User avatar

Joined: Fri Dec 18, 2009 6:06 pm
Posts: 44
Location: Montreal
I think i have got further.

I can see the object i am rendering (soft body). However it just floats in the air and is
not effected by gravity. other objects (rigid bodies) i have fall to the ground when
initialized suspended. Here is my code to create a soft body

Code:
ObjData->mObjSoftBody = new BtOgre::BtOgreSoftBody(Globals::phyWorldInfo);

MeshData MyMeshData;
Ogre::MeshPtr myMesh = MyEntity->getMesh();
Ogre::Mesh* pMesh = myMesh.get();

getMeshInformation(   pMesh,
            MyMeshData.vertex_count,
            MyMeshData.vertices,
            MyMeshData.index_count,
            MyMeshData.indices,
                 Ogre::Vector3::ZERO,
            Ogre::Quaternion::IDENTITY,
            Ogre::Vector3((float)ObjData->AxisScaling[0],
                                                     (float)ObjData->AxisScaling[1],
                                                     (float)ObjData->AxisScaling[2]));         

ObjData->mObjSoftBody->create(   MyEntity,
                 MyMeshData.vertex_count,
               MyMeshData.vertices,
               MyMeshData.index_count,
               (unsigned int*)MyMeshData.indices);

ObjData->mObjSoftBody->updateOgreMesh();


I then in my framestarted at the end i call.
Code:
(*p)->mObjSoftBody->updateOgreMesh();


So updateOgremesh() is called every frame. Still i the object does not fall. I am not sure what is
wrong here can someone help.

Thanks
Garibalde


Top
 Profile  
 
PostPosted: Mon Jan 11, 2010 5:30 am 
Offline
User avatar

Joined: Fri Dec 18, 2009 6:06 pm
Posts: 44
Location: Montreal
I found my problem i was not adding the soft body to the world. I added this line after the create()

Code:
Globals::PhyWorld->addSoftBody(Objdata->mObjSoftBody->mSoftBody);


Now the physics works with the soft body. however collision between Rigid and soft do not work.
But soft bodies fall due to gravity and also wrap shape when applied by an external force.

Anyone know why soft body and rigid body collisions do not work.. they pass through each other in
free fall.

Thanks.
Garibalde


Top
 Profile  
 
PostPosted: Thu Mar 25, 2010 1:31 pm 
Offline

Joined: Wed Dec 30, 2009 8:30 pm
Posts: 34
Dear all,
1) I was just having a quick look at the thread. Probably a newbie question but I just wanted to ask, where is the file Uncopyable.h located? It is included in BtOgreSoftBody.h.
2) Would you please refer a document/web site about soft body - rigid body collision, besides the books referred in the bullet user manual

Best regards
Ugras


Top
 Profile  
 
PostPosted: Tue Apr 27, 2010 1:09 am 
Offline

Joined: Tue Apr 27, 2010 1:06 am
Posts: 1
Hello,

I have the same problem as Ugras. I'd like to know where the Uncopyable.h file is located / where is it possible to download it ?

Could anyone post an example of code that is able to use the soft bodies in ogre?

Thank you!


Top
 Profile  
 
PostPosted: Tue Nov 02, 2010 1:43 pm 
Offline

Joined: Tue Nov 02, 2010 1:28 pm
Posts: 9
Hi,

I had the same problem, the Softbodies were just falling through the floor. However it is working now!

I tried to implement a SoftBody in the BtOgre-Demo posted in this thread:

http://www.ogre3d.org/forums/viewtopic.php?f=5&t=46856

I also implemented the BtOgreSoftbody from this Thread here.

To enable the Softbodies to interact with Rigid Bodies I had to change the following line from the demo code:

mCollisionConfig = new btDefaultCollisionConfiguration(); //<-wrong

to:

mCollisionConfig = new btSoftBodyRigidBodyCollisionConfiguration(); //right

To get the Uncopyable.h I googled for this file and just implemented it.
I also had to get this MeshData Class from here:
http://pastebin.com/zYbDxxx6

With it, you can get the vertices and indices from an Ogre Mesh. See Garibaldes Post for how to do it. Though I had do it a little differently to get the indices: I used the function MeshUtils::meshBuffersToArrays() to get the indices.

Maybe I post the some working code later.


Top
 Profile  
 
PostPosted: Wed Dec 08, 2010 3:54 am 
Offline

Joined: Sat Feb 06, 2010 3:40 am
Posts: 18
Hi

Is there any final version of all that code to try it out? It would be nice to know the current state of the experiment including bugs and/or the TODO list

Any example code to test it? I would love to see it working with an Ogre mesh.

Thank you in advance ;)


Top
 Profile  
 
PostPosted: Tue Dec 14, 2010 4:07 pm 
Offline

Joined: Tue Nov 02, 2010 1:28 pm
Posts: 9
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
Image


Attachments:
btOgreSoftbodyDemo.rar [1.53 MiB]
Downloaded 240 times
Top
 Profile  
 
PostPosted: Wed Dec 15, 2010 2:23 am 
Offline

Joined: Sat Feb 06, 2010 3:40 am
Posts: 18
Thank you!

I will post again when I get some results. Right now I am working on a different part ;)


Top
 Profile  
 
PostPosted: Thu Jan 20, 2011 11:50 pm 
Offline

Joined: Thu Jan 20, 2011 11:44 pm
Posts: 7
I scaled down the model in OGRE using mObjectNode->scale(...) where mObjectNode is the scene node of the soft body's corresponding OGRE entity, but when I run the program and I switch on the debug drawer I noticed that the entity has been scaled down but the collision shape hasn't. Does anyone know how to scale the collision shape for the soft body? I am using BtOgre and am following JayAr's example code (btOgreSoftbodyDemo.rar).


Top
 Profile  
 
PostPosted: Mon Jan 24, 2011 3:17 pm 
Offline

Joined: Tue Nov 02, 2010 1:28 pm
Posts: 9
Instead of scaling mObjectNode try this:

btSoftBody* psb = ...;
psb->scale(btVector3(...));

I just tried it, it should scale both the Object Node and the Softbody


Top
 Profile  
 
PostPosted: Wed Jan 26, 2011 8:08 pm 
Offline

Joined: Thu Jan 20, 2011 11:44 pm
Posts: 7
JayAr wrote:
Instead of scaling mObjectNode try this:

btSoftBody* psb = ...;
psb->scale(btVector3(...));

I just tried it, it should scale both the Object Node and the Softbody


Hey, works like a charm. Thanks a lot! :D


Top
 Profile  
 
PostPosted: Mon Jan 31, 2011 12:14 pm 
Offline

Joined: Tue Nov 02, 2010 1:28 pm
Posts: 9
Now the only thing I need is this:
I can import my own Mesh and make a Softbody out of it. But now I need do to the opposite. Make a Softbody with Bullet and make a corresponding mesh for it: I need a Bullet-Softbody as a patch. With Bullet Softbodies you can create patches, with which I want to simulate a ping pong net. It works but I can only see it with the debugger because I dont have a mesh for it. So I need to make a mesh and put the pointer of the Softbody somehow to the vertices of the mesh in the right order.
It should work somehow but I havent tried it yet


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 39 posts ]  Go to page Previous  1, 2, 3  Next

All times are UTC


Who is online

Users browsing this forum: Bing [Bot], Google [Bot], Pacha and 3 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Group