btSoftBodyHelpers::CreateFromTriMesh - Ogre version?

wingated
Posts: 3
Joined: Wed Sep 16, 2009 12:10 pm

Re: btSoftBodyHelpers::CreateFromTriMesh - Ogre version?

Post by wingated »

Not yet -- haven't revisited this issue yet. Hopefully someday soon... :)
User avatar
Garibalde
Posts: 44
Joined: Fri Dec 18, 2009 6:06 pm
Location: Montreal

Re: btSoftBodyHelpers::CreateFromTriMesh - Ogre version?

Post by Garibalde »

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: Select all

btScalar vertices[newVertexCount * 3];
Changed to:

Code: Select all

btScalar *vertices = new btScalar[newVertexCount * 3];
Also here
Old code:

Code: Select all

int indexes[indexCount];
Changed to:

Code: Select all

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
User avatar
Garibalde
Posts: 44
Joined: Fri Dec 18, 2009 6:06 pm
Location: Montreal

Re: btSoftBodyHelpers::CreateFromTriMesh - Ogre version?

Post by Garibalde »

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
User avatar
Garibalde
Posts: 44
Joined: Fri Dec 18, 2009 6:06 pm
Location: Montreal

Re: btSoftBodyHelpers::CreateFromTriMesh - Ogre version?

Post by Garibalde »

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: Select all

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: Select all

(*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
User avatar
Garibalde
Posts: 44
Joined: Fri Dec 18, 2009 6:06 pm
Location: Montreal

Re: btSoftBodyHelpers::CreateFromTriMesh - Ogre version?

Post by Garibalde »

I found my problem i was not adding the soft body to the world. I added this line after the create()

Code: Select all

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
Ugras
Posts: 34
Joined: Wed Dec 30, 2009 8:30 pm

Re: btSoftBodyHelpers::CreateFromTriMesh - Ogre version?

Post by Ugras »

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
NazguL86
Posts: 1
Joined: Tue Apr 27, 2010 1:06 am

Re: btSoftBodyHelpers::CreateFromTriMesh - Ogre version?

Post by NazguL86 »

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

Re: btSoftBodyHelpers::CreateFromTriMesh - Ogre version?

Post by JayAr »

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.
Antodologo
Posts: 21
Joined: Sat Feb 06, 2010 3:40 am

Re: btSoftBodyHelpers::CreateFromTriMesh - Ogre version?

Post by Antodologo »

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

Re: btSoftBodyHelpers::CreateFromTriMesh - Ogre version?

Post by JayAr »

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: Select all

      // 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: Select all

		// 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: Select all

		softBody->updateOgreMesh();
Here is a picture from the demo, its a softbody Cube wrapped around a stone
Image
You do not have the required permissions to view the files attached to this post.
Antodologo
Posts: 21
Joined: Sat Feb 06, 2010 3:40 am

Re: btSoftBodyHelpers::CreateFromTriMesh - Ogre version?

Post by Antodologo »

Thank you!

I will post again when I get some results. Right now I am working on a different part ;)
rs_kryptik61636
Posts: 7
Joined: Thu Jan 20, 2011 11:44 pm

Re: btSoftBodyHelpers::CreateFromTriMesh - Ogre version?

Post by rs_kryptik61636 »

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

Re: btSoftBodyHelpers::CreateFromTriMesh - Ogre version?

Post by JayAr »

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
rs_kryptik61636
Posts: 7
Joined: Thu Jan 20, 2011 11:44 pm

Re: btSoftBodyHelpers::CreateFromTriMesh - Ogre version?

Post by rs_kryptik61636 »

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

Re: btSoftBodyHelpers::CreateFromTriMesh - Ogre version?

Post by JayAr »

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