Wednesday, February 17, 2010

Soft Bodies

Soft Body dropping on ground:


Soft Body being poked on the ground:


I've decided not to fight blogspot for now and just go youtube...
Also a note I forgot to mention on the last post, to keep the size of the video down I'm recording at 30 fps. The actual simulation runs just fine at 60...

This is a video of my pressure model soft body.
First of all, this is all done with debug drawing. The black points are the point masses, the white lines are the springs, the red triangles are the faces, and the black lines are the normals of the faces.
Secondly, this is using Euler integration. I'm sure the results will look a lot better with Verlet or some higher order integrator. Another interesting thing I could do at some point is to construct the sphere using a geosphere instead of the standard stacks and slices approach. For all who do not know what geospheres are, they are spheres made of equilateral triangles. Doing this will make the simulation work a bit better because the lengths of the springs will be more standardized. The same issue will still crop up as seen on the video with the top of the sphere, since many points have to connect to one point. This causes extra osculation that is hard to get rid of with just an Euler integrator.

So how does it work? Well a soft body is very close to a cloth. Well how's a cloth made? A cloth is basically a set of point masses connected by springs. That's it, you just have to make sure that you have all the necessary springs (like next next neighbor) to make a cloth function properly. Now a soft body is just a wrapped cloth, without the next next neighbors, that you put a wind force inside of. More details are in these papers on the actual implementation:
http://www.ep.liu.se/ecp/010/007/ecp01007.pdf
http://panoramix.ift.uni.wroc.pl/~maq/soft2d/howtosoftbody.pdf

But basically you just apply forces to the points on each face while enforcing the ideal gas law pv = nrt. The exact specifics, as I've said before, I'll not go into details on because the paper does a better job than I will. Now how do I do collision with this thing? Well first, I just approximate the volume with the AABB of the soft body, which is used for the pressure model. I then use that as an early out to test with other objects AABB's. If the two AABB's intersect, then I just do point vs. object and resolve the impulse. At the moment I have the intersection limited to just OBB's, but I will add more at a later date.

So in conclusion for now, soft bodies are a very cool thing to have and something I would highly recommend implementing. The only issue is that it's hard to get any good use out of them or make them a key feature in a game. Also, if you use Euler, stability can be a bit of a problem as springs like to explode if you set values to high or to low.

Edit: was just bored so I re-added the ability to poke soft bodies, but this time I actually ray cast with each face and apply a force on those points...video link added to the top.

1 comment: