Softbody motion issues

User avatar
SynapticBytes
Posts: 74
Joined: Thu Feb 10, 2011 8:27 pm

Re: Matching softbodies to 3D objects - no motionstate?

Post by SynapticBytes »

*sigh* no joy

1. Changed to 1/120th step, no difference
2. Added another dropped rigid body cylinder, same height and size as the softbody cylinder. It drops and sticks flat, as it should.

I also went through and disabled my simulation tick callback, my graphic model updating and anything else that wasn't straight step simulation code, and the rotation still happens. I'm assuming the softbody setup is valid, as the debug draw lines seem to show a correct mesh. Here are the current parameters I set of the softbody after it is created.

Code: Select all

	sBody->m_materials[0]->m_kLST = 1;
	sBody->m_materials[0]->m_kVST = 1;
	// sBody->m_cfg.kVCF = 50;
	// sBody->m_cfg.kDP = 1;
	// sBody->m_cfg.kDG = 5;
	// sBody->m_cfg.kLF = 5;
	// sBody->m_cfg.kPR = 5;
	// sBody->m_cfg.kVC = 5;
	// sBody->m_cfg.kDF = 1.0;
	// sBody->m_cfg.kMT = 1;
	// sBody->m_cfg.kCHR = 1;
	// sBody->m_cfg.KHR = 1;
	// sBody->m_cfg.SHR = 1;
	sBody->m_cfg.kSRHR_CL		=	0.7f;
	sBody->m_cfg.kSR_SPLT_CL	=	0.2f;
	sBody->m_cfg.collisions	=	btSoftBody::fCollision::CL_SS + btSoftBody::fCollision::CL_RS + btSoftBody::fCollision::CL_SELF;
	sBody->generateClusters(0);
	// sBody->m_cfg.diterations = 20;
	// sBody->m_cfg.collisions	=	btSoftBody::fCollision::SDF_RS + btSoftBody::fCollision::CL_SS + btSoftBody::fCollision::CL_SELF;

	sBody->generateBendingConstraints(2,sBody->m_materials[0]);
	//	
	sBody->getCollisionShape()->setMargin(btScalar(0.05));
	sBody->setTotalMass(1);
I've fiddled with the values of most of them to varying degrees, but nothing seems to change the rotation, apart from forcing it to slow with some of the settings like drag. But doing that messes the normal simulation to a degree where it's unusable. Also some of the settings like friction visually look like they are fighting against the body. It's trying to turn and friction holds it back for a a fraction of a second, but then it steps over the threshold and gets stuck on the next "bit", causing a stuttering rotation, instead of a smoother rotation with no values set.

I might go check through all my code again see if something extraneous is being hit that I've missed somehow, but I'm running out of ideas.
Mako_energy02
Posts: 171
Joined: Sun Jan 17, 2010 4:47 am

Re: Matching softbodies to 3D objects - no motionstate?

Post by Mako_energy02 »

Well from that test we at least know something softbody specific is going on. Although I am running out of ideas as well. Something else I saw while looking through the API you can try is setting the number of iterations on the SoftBody Solver:

http://bulletphysics.com/Bullet/BulletF ... olver.html
User avatar
SynapticBytes
Posts: 74
Joined: Thu Feb 10, 2011 8:27 pm

Re: Matching softbodies to 3D objects - no motionstate?

Post by SynapticBytes »

I had tried all the solver iteration paramaters yesterday, varying them from 0, 1 -> 20. No real difference except velocity, and raising it made my body fall through the plane.

I've spent all last night stripping my code to use the SoftDemo code. The fact there seems to be bugs in the SoftDemo source doesn't help, but I eventually crated a world using the SoftDemo parameters, and created the ellipsoid soft body using the code from SoftDemo, although i reduces the number of nodes to 64 to make it smaller.

Once I finally go the code running again, I've spent all morning stepping through some world->stepSimulation steps, line by line. With the ellipsoid, it has no clusters, and is only affects by it's pressure setting, which is 2500. Using this value, the rotations happen, but it does first one way for a couple of seconds, then stops and goes back the other way. Dropping the pressure down to 100 makes the ellipsoid half-deflate, but then it sits on the plane without moving.

This code in btSoftBody.cpp seems to be the key area that updates node velocities

Code: Select all

	/* Prepare				*/ 
	m_sst.sdt		=	dt*m_cfg.timescale;
	m_sst.isdt		=	1/m_sst.sdt;
	m_sst.velmrg	=	m_sst.sdt*3;
	m_sst.radmrg	=	getCollisionShape()->getMargin();
	m_sst.updmrg	=	m_sst.radmrg*(btScalar)0.25;
	/* Forces				*/ 
	addVelocity(m_worldInfo->m_gravity*m_sst.sdt);
	applyForces();
	/* Integrate			*/ 
	for(i=0,ni=m_nodes.size();i<ni;++i)
	{
		Node&	n=m_nodes[i];
		n.m_q	=	n.m_x;
		n.m_v	+=	n.m_f*n.m_im*m_sst.sdt;
		n.m_x	+=	n.m_v*m_sst.sdt;
		n.m_f	=	btVector3(0,0,0);
	}
m_sst is the solver state. It's a bit hard deciphering the exact impact of these yet, as a lot has to do with clusters, which aren't used on this body. These are the values calculated at runtime for a 1/120th timestep.

Code: Select all

		sdt	0.0083333338	float
		isdt	119.99999	float
		velmrg	0.025000002	float
		radmrg	0.25000000	float
		updmrg	0.062500000	float
the "mrg" values are margins used in various places to tell what is in or out of the margin.

addVelocity simply adds the gravity * timestep to each nodes m_v value, if it's inverse mass m_im is > 0.

applyForces is where all the action happens with the pressure, volume and aero values, with the end result being that the node force accumulator, m_f has values set based on the amount of each of these forces present, based on shape volume or area * parameter.

After those two, as you can see above, the new node velocity is accumulated from the current velocity + force * inverse mass * timestep. The new node position is then accumulated with the velocity * timestep, and the force accumulator is reset.

So, from that, as long as gravity or pressure (in this case) is set, there is going to be a position change. I'm trying to find where the forces are damped and resisted by other objects, but somehow I keep missing it. Its a long slow process stepping through every line of code execution trying to decide if it's relevant or not.

One thing I can say from what I've seen so far, I don't think it's my specific code causing the issue Either it's all down to parameter tweaking, or there's some bug in the bullet code, but then why does the SoftDemo code run fine, and why does it run at all given there are bugs in the source code????

Back to head scratching.
User avatar
SynapticBytes
Posts: 74
Joined: Thu Feb 10, 2011 8:27 pm

Re: Matching softbodies to 3D objects - no motionstate?

Post by SynapticBytes »

You know what, after studying the running SoftDemo in a bit more detail, I think it actually exhibits the same behaviour, it's just hard to see as there is very little stillness in the demo's. The single torus or the bunnies sits on a flat plane and looks motionless, but after 5 minutes of running, you can see they have definitely shifted position. More telling, the 3 linked Torii on the flat plane continues to slide sideways long after it should have stopped. Even so, the demo movements are nowhere near as extreme as mine.

I also noted that the moving forces are much greater when sliding over a dynamic rigid body than a static one for some reason, with all other parameters being the same.

I'll continue to investigate, as I must for a little while longer, or I'm going to have to throw softbodies off the roadmap for my bullet plugin. Surely someone else must have used soft bodies who can either confirm or deny my issues?

*EDIT*

Some more friction investigation. Still can't find where it actually gets applied or how.

Oh, one other observation. The more gravity there is, the faster the motion. Zero gravity and there is no motion. Why would gravity be applying force in a direction other than the direction of gravity?
User avatar
SynapticBytes
Posts: 74
Joined: Thu Feb 10, 2011 8:27 pm

Re: Softbody motion issues

Post by SynapticBytes »

Well I have finally had a bit more luck, after finding this post.

http://bulletphysics.org/Bullet/phpBB3/ ... w=previous

Seems I'm not the only one who has experienced these issues, and just changing the number of clusters to a small value (3 - 5 seems to work for my small models) has reduced most of the motion, and it now just has the small deviations that the SoftDemo examples show. I assumed the more clusters the better, but it doesn't seem that way.

So, while still not perfect compared to rigid bodies, it's probably good enough for now and I can get back to the issue of 3D object matching.
User avatar
SynapticBytes
Posts: 74
Joined: Thu Feb 10, 2011 8:27 pm

Re: Softbody motion issues

Post by SynapticBytes »

Right well, here I am back again.

Reducing clusters works well for simple shapes, but as soon as I throw a complex mesh at it, we're back to major struggles trying to stop it wandering off randomly. A cluster size of 1 is the only thing that has stopped my bigger mesh, and that's unacceptable as it makes it virtually a rigid body.

I'm going through multiple tests of different parameters values to get it to stabilise, but it shouldn't be this hard, having to try dozens of parameters combo's for every different mesh!!