Page 1 of 1

Sofy body exploding

Posted: Fri Jun 06, 2008 2:30 pm
by bob
Hi,

I'm playing around with the soft body library at the moment but am having some issues. The mesh I've created appears to 'shatter' when it collides with something. In fact even if it doesn't collide with anything over time it comes apart. I've used the softdemo code as a basis and have set up the soft body the same as the various bodies but with no luck. If I just use 'CreateEllipsoid' it behaves as expected, so it's presumably something to do with how I'm creating the mesh. Can anyone point me in the right direction? I'm presumably missing something totally obvious :)

Thanks.

Re: Sofy body exploding

Posted: Fri Jun 06, 2008 3:00 pm
by bob
More info:

If i call 'setPose( true, true )' then it holds together but it doesn't seem to have all of its vertices. Only certain chunks of the mesh are there.

Re: Sofy body exploding

Posted: Fri Jun 06, 2008 3:34 pm
by Bbilz
Is there any kind of documentation for the SoftBody stuff?
I have had similar troubles, and as there are many different variables in the soft body info it is sometimes difficult to figure out what each value is doing..

Just a brief explaination of what each variable in btSoftBody::Config actually does would be amazing!
Thanks

Re: Sofy body exploding

Posted: Fri Jun 06, 2008 4:11 pm
by Nathanael
@bob

Can you provide some code extract so that we can reproduce the problem?

@Bbilz

Soft bodies is still a very new feature, it will take some time before things settle in, right now too much changes occur to enable real documentations.
Here some help regarding btSoftBody::Config :

btSoftBody::Config::aeromodel; // Aerodynamic model (default: V_Point)
define what kind feature is used to compute aerodynamic forces.
btSoftBody::Config::kVCF; // Velocities correction factor (Baumgarte)
define the amount of correction per time step for drift solver (sometimes referred as ERP in rigid bodies solvers).
btSoftBody::Config::kDP; // Damping coefficient [0,1]
damping, zero = no damping, one= full damping.
btSoftBody::Config::kDG; // Drag coefficient [0,+inf]
[aerodynamic]=> is referred in http://en.wikipedia.org/wiki/Drag_%28force%29 as 'Cd', kDG=0 mean no drag.
btSoftBody::Config::kLF; // Lift coefficient [0,+inf]
[aerodynamic]=> is a factor of the lift force (http://en.wikipedia.org/wiki/Lift_%28force%29) kLF=0 mean no lift
btSoftBody::Config::kPR; // Pressure coefficient [-inf,+inf]
[aerodynamic]=> is a factor of pressure.
btSoftBody::Config::kVC; // Volume conversation coefficient [0,+inf]
when 'setPose(true,...)' as been called, define the magnitude of the force used to conserve volume.
btSoftBody::Config::kDF; // Dynamic friction coefficient [0,1]
friction, kDF=0 mean sliding, kDF=1 mean sticking.
btSoftBody::Config::kMT; // Pose matching coefficient [0,1]
when 'setPose(...,true)' as been called, define the factor used for pose matching.
btSoftBody::Config::kCHR; // Rigid contacts hardness [0,1]
define how 'soft' contact with rigid bodies are, kCHR=0 mean no penetration correction, 1 mean full correction.
btSoftBody::Config::kKHR; // Kinetic contacts hardness [0,1]
define how 'soft' contact with kinetic/static bodies are, kKHR=0 mean no penetration correction, 1 mean full correction.
btSoftBody::Config::kSHR; // Soft contacts hardness [0,1]
define how 'soft' contact with other soft bodies are, kSHR=0 mean no penetration correction, 1 mean full correction.
btSoftBody::Config::kAHR; // Anchors hardness [0,1]
define how 'soft' anchor constraint (joint) are, kAHR=0 mean no drift correction, 1 mean full correction.
btSoftBody::Config::maxvolume; // Maximum volume ratio for pose
--unused--
btSoftBody::Config::timescale; // Time scale
factor of time step, can be used to speed up, or slow down simulation, default=1.
btSoftBody::Config::viterations; // Velocities solver iterations
number of iterations for velocity solvers (if any).
btSoftBody::Config::piterations; // Positions solver iterations
number of iterations for position solvers (if any).
btSoftBody::Config::diterations; // Drift solver iterations
number of iterations for drift solvers (if any).
btSoftBody::Config::collisions; // Collisions flags
see btSoftBody::fCollision.
btSoftBody::Config::m_vsequence,m_psequence,m_dsequence;
define the order and type of solvers to apply for velocities, positions and drift, see btSoftBody::eVSolver for velocities, and btSoftBody::ePSolver for positions and drift.

I hope it help, if not, do not hesitate to ask more questions, and report problems.
Thanks for the feedback, Nat.

Re: Sofy body exploding

Posted: Mon Jun 09, 2008 10:17 am
by bob
This is the code I'm using to create the soft body. It's just copied from the SoftDemo project in Bullet.

If I leave all the settings as their defaults (set in the softbody constructor) the body breaks apart on contact with other meshes.

If I use the following settings the same thing happens (taken from Init_Volume in the SoftDemo project). If I uncomment the line setting the volume conservation coefficient then it seems to get stuck in the dvbt proximity function.

If I setPose( true, true ) then it doesn't break apart but only some sections of the mesh appear. For example only certain faces of a cube would be there but it holds together as if the whole mesh is there.

Code: Select all

        softbody = btSoftBodyHelpers::CreateFromTriMesh(
            softBodyWorldInfo,
            vertices,
            indices,
            triCount );

        softbody->m_materials[0]->m_kLST	=	0.45f; 
//	softbody->m_cfg.kVC				=	20;
        softbody->setPose( true, false );
        softbody->setTotalMass( 50.0f, false );
        softbody->generateBendingConstraints(2);
        softbody->setTotalMass(50,true); 

Thanks

Re: Sofy body exploding

Posted: Tue Jun 10, 2008 4:52 pm
by bob
So, after a bit more playing about I have a reproducible in the bullet softbody demo. I've hacked in a cube in the same format I'm using in my code and replaced one of the demo shapes with it. The cube in the demo is constructed using the CreateFromConvexHull function which is all fine. If I replace it with my cube and CreateFromTriMesh, the cube renders fine, but the faces don't hold together. The 2 triangles on each face do however hold together. I presume this is simply down to how i've constructed the mesh, and that the indices or vertices are in the wrong format.

Here is the code.

Cube data:

Code: Select all


static Real gVerticesCube[] = 
{
    -0.50000000,    -0.50000000	,    0.50000000	,
    0.50000000	,   -0.50000000	,    0.50000000	,
    -0.50000000	,    0.50000000	,    0.50000000	,

    0.50000000	,	0.50000000	,	0.50000000	,
	-0.50000000	,	0.50000000	,	0.50000000	,
	0.50000000	,	0.50000000	,	0.50000000	,

	-0.50000000	,	0.50000000	,	-0.50000000	,
	0.50000000	,	0.50000000	,	-0.50000000	,
	-0.50000000	,	0.50000000	,	-0.50000000	,

	0.50000000	,	0.50000000	,	-0.50000000	,
	-0.50000000	,	-0.50000000	,	-0.50000000	,
	0.50000000	,	-0.50000000	,	-0.50000000	,

	-0.50000000	,	-0.50000000	,	-0.50000000	,
	0.50000000	,	-0.50000000	,	-0.50000000	,
	-0.50000000	,	-0.50000000	,	0.50000000	,

	0.50000000	,	-0.50000000	,	0.50000000	,
	0.50000000	,	-0.50000000	,	0.50000000	,
	0.50000000	,	-0.50000000	,	-0.50000000	,

	0.50000000	,	0.50000000	,	0.50000000	,
	0.50000000	,	0.50000000	,	-0.50000000	,
	-0.50000000	,	-0.50000000	,	-0.50000000	,

	-0.50000000	,	-0.50000000	,	0.50000000	,
	-0.50000000	,	0.50000000	,	-0.50000000	,
	-0.50000000	,   0.50000000	,	0.50000000	
};

static int gIndicesCube[][3] =
{
    {0, 1, 2},
    {2, 1, 3},
    {4, 5, 6},
    {6, 5, 7},
    {8, 9, 10},
    {10, 9, 11},
    {12, 13, 14},
    {14, 13, 15},
    {16, 17, 18},
    {18, 17, 19},
    {20, 21, 22},
    {22, 21, 23}
};
Softbox creation:

Code: Select all

static btSoftBody* Ctor_SoftBox(SoftDemo* pdemo,const btVector3& p,const btVector3& s)
{
    /*  
	// Old function
	const btVector3	h=s*0.5;
	const btVector3	c[]={	p+h*btVector3(-1,-1,-1),
		p+h*btVector3(+1,-1,-1),
		p+h*btVector3(-1,+1,-1),
		p+h*btVector3(+1,+1,-1),
		p+h*btVector3(-1,-1,+1),
		p+h*btVector3(+1,-1,+1),
		p+h*btVector3(-1,+1,+1),
		p+h*btVector3(+1,+1,+1)};
	btSoftBody*		psb=btSoftBodyHelpers::CreateFromConvexHull(pdemo->m_softBodyWorldInfo,c,8);
	psb->generateBendingConstraints(2);
	pdemo->getSoftDynamicsWorld()->addSoftBody(psb);
	*/

    btSoftBody*		psb=btSoftBodyHelpers::CreateFromTriMesh( pdemo->m_softBodyWorldInfo, gVerticesCube, &gIndicesCube[0][0], 12 );
    psb->generateBendingConstraints(2);
    pdemo->getSoftDynamicsWorld()->addSoftBody(psb);

	return(psb);
}

Re: Sofy body exploding

Posted: Thu Jun 12, 2008 10:42 am
by Bbilz
I have had similar situations where soft bodies fall apart much like this, and I have never quite understood which values to change. The basic shapes generally seem to work, its just when you read in Tri meshes from external models that problems arise..

Are there any general guidelines and best practices to adhere to?
Just looking for a few nuggets of advice like 'always use setPose' or 'make sure that your volume conservation value is a decent size' or 'make sure you read in the trimesh correctly or the face normals might all point inwards'

Stuff like that .. :)

Re: Sofy body exploding

Posted: Thu Jun 12, 2008 12:14 pm
by Nathanael
@bob

The mesh you describe consist of 24 vertices's, btSoftBody doesn't weld anything, a cube should be made of 8 vertex, 12 triangles.

soft bodies expect consistent triangle orientation, normals pointing outward (triangle ABC, normal (B-A)x(C-a) ), and duplicated vertex mean disjoint during simulation.

If you get your mesh topology right, the only way that I'm aware of (fingers crossed :wink: ) to have a body 'explode' is by increasing kVC or kPR to much.

@Bbilz

setPose(bvolume,bframe):

setPose take the current state of the body (usually after creation, scaling, setting mass, etc...), and do two things depending of the value (true/false) of 'bvolume' and 'bframe'.

-bvolume set at true mean that you enable kVC and/or kPR based on the current volume of the body. keep in mind that volume mean closed, so check your meshes.
-bframe set at true mean the you enable kMT (shape matching), based on the current body shape (current orientation/translation doesn't matter, just node positions relative to each others).

You need to call setPose(...,true) only when you want to use shape matching (kMT), and setPose(true,...) when you want to use pressure forces (kPR) and/or volume conservation forces (kVC).

I hope it help, thanks for the feedback.
Nathanael.

Re: Sofy body exploding

Posted: Fri Jun 13, 2008 11:06 am
by bob
Aha, I see. Thanks :)

I have it working as expected now, though there seems to be a major impact on performance. A cyclinder with 80 triangles takes my framerate down from about 40 to 20. The demo project clearly has a a lot more going on with far less impact on frame rate. Are there particular settings or shapes that may affect framerate this severely. Or any other factors I should be taking into account?

Thanks!