Softbody help

Post Reply
stig atle
Posts: 10
Joined: Sat May 10, 2014 9:22 am

Softbody help

Post by stig atle »

I'm trying to implement softbody in my application, I do have support for all rigidbodies, and they work as expected.
However when I now try to add support for Softbodies I'm stuck at it just crashing as soon as I add the softbody to the 'world'.

I've tried to look around at the examples and such, and I tried to make it as easy as possible, right now I'm using the mesh from one of the bunny samples, I simply want to load it in (I'm serializing out again, so as of right now I do not worry about getting the simulation visualized).

My current code is like this:

Code: Select all

#include <btBulletDynamicsCommon.h>
#include <btBulletCollisionCommon.h>
#include <BulletSoftBody\btSoftBody.h>
#include "BulletSoftBody/btSoftBodyRigidBodyCollisionConfiguration.h"
#include "BulletSoftBody/btSoftBodyHelpers.h"
#include "BulletSoftBody/btSoftRigidDynamicsWorld.h"
#include "Demos\GimpactTestDemo\BunnyMesh.h"

btDiscreteDynamicsWorld* dynamicsWorld;
broadphase = new btDbvtBroadphase();
collisionConfiguration = new btDefaultCollisionConfiguration();
dispatcher = new btCollisionDispatcher(collisionConfiguration);
solver = new btSequentialImpulseConstraintSolver;
dynamicsWorld = new btDiscreteDynamicsWorld(dispatcher,broadphase,solver,collisionConfiguration);
dynamicsWorld->setGravity(btVector3(0,-10,0));
//Add softbody bunny
btSoftBody*	psb = btSoftBodyHelpers::CreateFromTriMesh(((btSoftRigidDynamicsWorld*)dynamicsWorld)->getWorldInfo(), gVerticesBunny,&gIndicesBunny[0][0],BUNNY_NUM_TRIANGLES);

//It crashes when I run the following function:											
((btSoftRigidDynamicsWorld*)dynamicsWorld)->addSoftBody(psb); 
It does not provide any useful information to me there, so I'm a bit lost as to what I'm doing wrong.
User avatar
Erwin Coumans
Site Admin
Posts: 4232
Joined: Sun Jun 26, 2005 6:43 pm
Location: California, USA
Contact:

Re: Softbody help

Post by Erwin Coumans »

You cannot cast from btDiscreteDynamicsWorld to btSoftRigidDynamicsWorld. Try creating a btSoftRigidDynamicsWorld instead.

Good luck!
Erwin
stig atle
Posts: 10
Joined: Sat May 10, 2014 9:22 am

Re: Softbody help

Post by stig atle »

Thanks, I now did that and it does not crash anymore.
stig atle
Posts: 10
Joined: Sat May 10, 2014 9:22 am

Re: Softbody help

Post by stig atle »

This is my current code:

Code: Select all

btSoftRigidDynamicsWorld* dynamicsWorldSoft;
//Same in paramters as which I use for the rigidbodies
dynamicsWorldSoft = new btSoftRigidDynamicsWorld(dispatcher, broadphase, solver, collisionConfiguration);
dynamicsWorldSoft->setGravity(btVector3(0, -10, 0));
dynamicsWorldSoft->getWorldInfo().m_sparsesdf.Initialize();
dynamicsWorldSoft->getDispatchInfo().m_enableSPU = true;

Code: Select all

//creating and inserting the bunny
btSoftBody*	psb = btSoftBodyHelpers::CreateFromTriMesh(dynamicsWorldSoft->getWorldInfo(), gVerticesBunny, &gIndicesBunny[0][0], BUNNY_NUM_TRIANGLES);
btSoftBody::Material*	pm = psb->appendMaterial();
pm->m_kLST = 0.5;
pm->m_flags -= btSoftBody::fMaterial::DebugDraw;
psb->generateBendingConstraints(2, pm);
psb->m_cfg.piterations = 2;
psb->m_cfg.kDF = 0.5;
psb->m_cfg.collisions |= btSoftBody::fCollision::VF_SS;
psb->randomizeConstraints();
btMatrix3x3	m;
m.setEulerZYX(0, 10, 0);
psb->transform(btTransform(m));
psb->scale(btVector3(1, 1, 1));
psb->setTotalMass(10, true);

dynamicsWorldSoft->addSoftBody(psb);

Then in my 'update' loop I call this - with same parameters as with rigidbodies:

Code: Select all

dynamicsWorldSoft->stepSimulation(fixedTimeStep, maxSubsteps);
I do not have debugdraw yet, so the way I 'see' what's going on is either directly in the simulation, or serialize out to a file.
I tried to serialize softbody world, but it does not output any shapes, just a blank file.
when I serialize the rigidbody world it works fine, so I suspect the bunny does not get added properly?

Any ideas?
stig atle
Posts: 10
Joined: Sat May 10, 2014 9:22 am

Re: Softbody help

Post by stig atle »

I've tried to look through the demos and all that, but I fail to see what I'm doing wrong.

I have attached two '.bullet' files, one being the dynamics world serialized,
one other being the softbody (which is the rabbit as the code above shows)..

The rabbit fails to load in 'debug' viewers.
the dynamics one loads fine.

Something is at least working in the bunny bullet output, since the filesize is obviously much bigger.

the falling cube is 1x1x1 M, so if I've understood the 'Bunny' trimesh code then the bunny is about the same size or smaller.
The bunny is placed in 0 0 0 by the code I have, and by the looks of it if you load the bunny that way it would be below my cube, is that correct?
Attachments
sample-output.zip
(108.77 KiB) Downloaded 158 times
c6burns
Posts: 149
Joined: Fri May 24, 2013 6:08 am

Re: Softbody help

Post by c6burns »

I do not have debugdraw yet
You are trying to get softbodies working but you haven't taken care of debug draw. You are trying to cartwheel before you walk.
stig atle
Posts: 10
Joined: Sat May 10, 2014 9:22 am

Re: Softbody help

Post by stig atle »

Well, I do use standalone 'debug' viewers, and they do not load the softbody either, so right now debug draw would not help regardless.
stig atle
Posts: 10
Joined: Sat May 10, 2014 9:22 am

Re: Softbody help

Post by stig atle »

c6burns you where right, and I apologize if I was a bit harsh of my critique of your previous answer, and thanks for pointing it out because it made me sit down properly and focus on the debugdraw implementation.

Been spending the last night on it, I do currently print out the line verts in the drawline function.

For 'dynamics' world I get this:

Code: Select all


Debugger line draw v1 -> -0.358720 0.165031 12.536750 
Debugger line draw v2 -> 0.641279 0.166378 12.536750 
Debugger line draw v1 -> -0.358720 0.165031 12.536750 
Debugger line draw v2 -> -0.357374 -0.834968 12.536750 
etc
And for my softbody world I get:

Code: Select all

Debugger line draw v1 -> 0.000000 0.000000 0.000000 
Debugger line draw v2 -> 1.000000 0.000000 0.000000 
Debugger line draw v1 -> 0.000000 0.000000 0.000000 
Debugger line draw v2 -> 0.000000 0.000000 1.000000 
Debugger line draw v1 -> 0.000000 0.000000 0.000000 
Debugger line draw v2 -> 0.000000 1.000000 0.000000 
Debugger line draw v1 -> -0.040242 -0.441409 -0.777998 
Debugger line draw v2 -> 0.067817 -0.350547 -0.776310 
Debugger line draw v1 -> 0.668047 0.482219 -0.092238 
Debugger line draw v2 -> 0.714960 0.495960 -0.095357 
Debugger line draw v1 -> 0.316604 0.205471 -0.816178 
Debugger line draw v2 -> 0.238813 0.135499 -0.720787 
Debugger line draw v1 -> -0.493799 -0.528509 -0.433099 
Debugger line draw v2 -> -0.683490 -0.537426 -0.455532 
Debugger line draw v1 -> -0.234526 -0.604101 -0.272659 
Debugger line draw v2 -> -0.462705 -0.591918 -0.194972 
Debugger line draw v1 -> 0.711090 0.056486 0.374090 
etc
So at least now I know the softbody object does exist in the softbody world.
I'm gonna work on drawing the lines in the view now, so that I can actually see it, then move on from there.
c6burns
Posts: 149
Joined: Fri May 24, 2013 6:08 am

Re: Softbody help

Post by c6burns »

No worries. I did a very simple implementation of btsoftbody in Ogre and there was no way I ever would have completed it without debug drawing (and a lot of debugging and referencing the softbody samples)
stig atle
Posts: 10
Joined: Sat May 10, 2014 9:22 am

Re: Softbody help

Post by stig atle »

I have it working now.
The issue I had with it not being drawn was a stupid bug related to my graphics card combined with the driver 3dsmax uses.
I'm developing on my laptop (I'm at our camper), so I was actually pleased with the bug because then I can make code that handles it accordingly.

I have a screenshot and some more information here:

http://bullet4max.com/?p=192

And thanks again, I appreciate it.
Post Reply