Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make a 2D Soft-body physics engine?

The definition of rigid body in Box2d is

A chunk of matter that is so strong that the distance between any two bits of matter on the chunk is completely constant.

And this is exactly what i don't want as i would like to make 2D (maybe 3D eventually), elastic, deformable, breakable, and even sticky bodies.

What I'm hoping to get out of this community are resources that teach me the math behind how objects bend, break and interact. I don't care about the molecular or chemical properties of these objects, and often this is all I find when I try to search for how to calculate what a piece of wood, metal, rubber, goo, liquid, organic material, etc. might look like after a force is applied to it.

Also, I'm a very visual person, so diagrams and such are EXTREMELY HELPFUL for me.

================================================================================

Ignore these questions, they're old, and I'm only keeping them here for contextual purposes

1.Are there any simple 2D soft-body physics engines out there like this?
preferably free or opensource?

2.If not would it be possible to make my own without spending years on it?

3.Could i use existing engines like bullet and box2d as a start and simply transform their code, or would this just lead to more problems later, considering my 1 year of programming experience and bullet being 3D?

4.Finally, if i were to transform another library, would it be the best change box2D's already 2d code, Bullet's already soft code, or mixing both's source code?


Thanks!

like image 849
Griffin Avatar asked Jun 28 '11 04:06

Griffin


People also ask

How do you get a soft body in Godot?

To create a Soft Ball is to add a SoftBody node and add a mesh to it, in this case I used a sphere maded in Blender (I used a custom mesh because the sphere created dynamically by Godot is not completely closed, but just for a test you can use it).


1 Answers

(1) Both Bullet and PhysX have support for deformable objects in some capacity. Bullet is open source and PhysX is free to use. They both have ports for windows, mac, linux and all the major consoles.

(2) You could hack something together if you really know what you are doing, and it might even work. However, there will probably be bugs unless you have a damn good understanding of how Box2D's sequential impulse constraint solver works and what types of measures are going to be necessary to keep your system stable. That said, there are many ways to get deformable objects working with minimal fuss within a game-like environment. The first option is to take a second (or higher) order approximation of the deformation. This lets you deal with deformations in much the same way as you deal with rigid motions, only now you have a few extra degrees of freedom. See for example the following paper:

http://www.matthiasmueller.info/publications/MeshlessDeformations_SIG05.pdf

A second method is pressure soft bodies, which basically model the body as a set of particles with some distance constraints and pressure forces. This is what both PhysX and Bullet do, and it is a pretty standard technique by now (for example, Gish used it):

http://citeseerx.ist.psu.edu%2Fviewdoc%2Fdownload%3Fdoi%3D10.1.1.4.2828%26rep%3Drep1%26type%3Dpdf

If you google around, you can find lots of tutorials on implementing it, but I can't vouch for their quality. Finally, there has been a more recent push to trying to do deformable objects the `right' way using realistic elastic models and finite element type approaches. This is still an area of active research, so it is not for the faint of heart. For example, you could look at any number of the papers in this year's SIGGRAPH proceedings:

http://kesen.realtimerendering.com/sig2011.html

(3) Probably not. Though there are certain 2D style games that can work with a 3D physics engine (for example top down type games) for special effects.

(4) Based on what I just said, you should probably know the answer by now. If you are the adventurous sort and got some time to kill and the will to learn, then I say go for it! Of course it will be hard at first, but like anything it gets easier over time. Plus, learning new stuff is lots of fun!

On the other hand, if you just want results now, then don't do it. It will take a lot of time, and you will probably fail (a lot). If you just want to make games, then stick to the existing libraries and build on whatever abstractions it provides you.

like image 76
Mikola Avatar answered Sep 24 '22 02:09

Mikola