[SOLVED] Soft body volume calculation problem

User avatar
dphil
Posts: 237
Joined: Tue Jun 29, 2010 10:27 pm

[SOLVED] Soft body volume calculation problem

Post by dphil »

I've been trying to use the "pressure" coefficient (kPR) in a soft body - to emulate the behaviour in the "Pressure" bullet soft body demo - without any luck. Every time I change kPR to anything other than 0, the soft body gets extremely unstable and explodes. Since kPR is used very little in the source code, I was able to find pretty much only one place that could cause problems, namely this line in btSoftBody.cpp:

Code: Select all

ivolumetp       =       1/btFabs(volume)*kPR;
Up until this point, my simulations had been using a kPR of 0, so ivolumetp - which contributes to node forces, and hence is a likely culprit for explosion - always got zero'd out. However even when I try very small values of kPR, the soft body blows up. So on a hunch I printed the output of softBody->getVolume(), which is where the value for "volume" in the above line of code comes from. Sure enough, I was getting values like 0.000001, 0.000027, and 0.000153 on three separate tests, which cause the quotient in the first part of the ivolumetp calculation to be very large. I don't believe those volumes should be correct. The soft body I was testing was a rough sphere shape of diameter 5 (in 2 of the tests) and 10 (in the 3rd test), so it should definitely have a much larger volume than the values I was getting. The only thing I could think of was that the vertices were in the wrong order, but reversing them just gave me negative (though equally small) volume values, so I assume my first vertex winding order was indeed correct.

If anyone has any clues/ideas as to what is going on here, I'd much appreciate it.
Last edited by dphil on Mon Apr 04, 2011 6:04 am, edited 1 time in total.
User avatar
Erwin Coumans
Site Admin
Posts: 4221
Joined: Sun Jun 26, 2005 6:43 pm
Location: California, USA

Re: Soft body volume calculation problem

Post by Erwin Coumans »

I'm not familiar with the pressure/kPR part of the BulletSoftBody library contribution either and haven't looked into that part yet.

Have you double-checked the differences of the values of kPR and mesh structure in the Bullet pressure demo with yours?
If you find anything, please report it here,
Thanks!
Erwin
User avatar
dphil
Posts: 237
Joined: Tue Jun 29, 2010 10:27 pm

Re: Soft body volume calculation problem

Post by dphil »

Found the problem. I am using btOgreSoftBody to make a soft body from a supplied mesh. The mesh I'm using is using 2-sided faces, giving 2 normals for each face (for rendering purposes), meaning that volume calculations were cancelling out due to +/- normal directions for each face, leaving the volume calculated as a very small number which presumably is just an artefact of calculation inaccuracies, and should technically be 0. I'm 99% sure this was my problem anyway. I recreated a similar mesh with only 1-sided faces and it works fine.

Still, when I use the new mesh (which I made to be a very close approximation of the one the Pressure demo creates, in terms of shape, size and # vertices) with the exact same parameters as that in the Pressure demo, I don't get the same, nice smooth "blobby" results. My shape tends to oscillate a bit too much when I start the simulation, and inverts itself and then just sorta lies there jittering in a partially crumpled mess (though intact portions of the mesh do seem to be appropriately jelly-like). It flies wildly off into space if I use the same kPR (2500) as in the demo (values under ~200 give me relative stability, sort of). However, the behaviour is much better now, and the volume is shown to be calculating correctly, so I guess it's not a big deal; I guess I just have to figure out my own parameter settings to make it work well. The only other difference is that I'm running 2.77 while the demo I'm observing is from 2.76, though I don't imagine there should be a difference for the soft body mechanics(?).
User avatar
dphil
Posts: 237
Joined: Tue Jun 29, 2010 10:27 pm

Re: Soft body volume calculation problem

Post by dphil »

Ok, managed to match the Pressure demo behaviour. After accounting for the 2-sided faces to get the correct absolute-valued volume, it seems the remaining erratic behaviour and mesh inversion had to do with sign of the volume, which in my case was negative. So, using a kPR of 2500 - as in the demo - was actually applying a negative pressure, hence inverting my mesh before stabilizing. So I simply apply a kPR of -2500 and I get a nice result with no inversion. I don't think it's a bug; seems this is just due to the particular vertex winding order used for your mesh (since the sign of the volume depends on the vertex order). So all in all it seems one needs to be particularly sensitive to mesh design for the purpose of soft body pressure dynamics.
shomy2k11
Posts: 24
Joined: Thu Sep 08, 2011 1:59 am

Re: Soft body volume calculation problem

Post by shomy2k11 »

I too have the same problem. Softbodies are unstable when i set kPR to anything greater than zero. I'm loading a mesh in wavefront .obj model format. I've included the model as a zip file. Help please.
You do not have the required permissions to view the files attached to this post.