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

5

29

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?

Kimbra answered 28/6, 2011 at 4:57 Comment(3)
4. I don't believe there would be a "simple" physics engine that does what you're asking. As Bruce mentioned, a generic non-rigid physics engine would be extremely complex. However, it could/would be a good exercise to implement some special cases. For example, you could simulate a sheet of rubber using a grid of nodes connected by springs.Bucharest
Well, I know writing your own physics engine takes very long time. It takes years. The time required is going down however once the techniques required are becoming more well known. Even solving the equations required for movement of "points" needs category theory and pullbacks, so it's not generally considered very easy.Haydenhaydn
Voting to close as too broad.Harass
E
17

(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.

Elroyels answered 28/6, 2011 at 5:54 Comment(4)
what about 2d physic engines, i need an engine at bullets level, but designed for 2d implementation.Kimbra
Well, I don't know of any good soft body simulators for 2D. I think the current route people take is to roll their own. That said, 2D is much easier to work in than 3D, so if you want to give it a shot it could be a good learning experience. I would google around a bit and study up on pressure soft bodies if you are really keen on doing this.Elroyels
could you take a look at my newly revised question 3? it asks if i could transform a 3d physics api to 2dKimbra
I updated it, but the answer is that it is probably not going to work out so well. To do 2D you would have to add a bunch of constraints in, and the system would become very illposed/slow.Elroyels
I
5

Quick and partial answer:

  • rigid body are easy to model due to their property (you can use physic tools, like "Torseur+ (link on french on wikipedia, english equivalent points to screw theory) to modelate forces applying at any point in your element.
  • in comparison, non-solid elements move from almost solid (think very hard rubber : it can move but is almost solid) to almost liquid (think very soft ruber, latex). Meaning that dynamical properties applying to that knd of objects are much complex and depend of the nature of the object
  • Take the example of a spring : it's easy to model independantly (f=k.x), but creating a generic tool able to model that specific case is a nightmare (especially if you think of corner cases : extension is not infinite, compression reaches a lower point, material is non linear...)
  • as far as I know, when dealing with "elastic" materials, people do their own modelisation for their own purpose (a generic one does not exist)

now the answers:

  1. Probably not, not that I know at least
  2. not easily, see previously why
  3. Unless you got high level background in elastic materials, I fear it's gonna be painful

Hope this helped

Illiterate answered 28/6, 2011 at 5:14 Comment(2)
could you take a look at my newly revised question 3? it asks if i could transform a 3d physics api to 2d.Kimbra
well, other answer is way better documenting than mine, upping him.Illiterate
T
4

Some specific cases such as deformable balls can be simulated pretty well using spring-joint bodies: enter image description here

Here is an implementation example with cocos2d: http://2sa-studio.blogspot.com/2014/05/soft-bodies-with-cocos2d-v3.html

Tuner answered 2/7, 2014 at 12:21 Comment(0)
H
2

Depending on the complexity of the deformable objects that you need, you might be able to emulate them using box2d, constraining rigid bodies with joints or springs. I did it in the past using a box2d clone for xna (farseer) and it worked nicely. Hope this helps.

Hibernicism answered 7/7, 2011 at 21:21 Comment(0)
T
1

The physics of your question breaks down into two different topics:

  1. Inelastic Collisions: The math here is easy, and you could write a pretty decent library yourself without too much work for 2D points/balls. (And with more work, you could learn the physics for extended bodies.)
  2. Materials Bending and Breaking: This will be hard. In general, you will have to model many of the topics in Mechanical Engineering:
    1. Continuum Mechanics
    2. Structural Analysis
    3. Failure Analysis
    4. Stress Analysis
    5. Strain Analysis

I am not being glib. Modeling the bending and breaking of materials is, in general, a very detailed and varied topic. It will take a long time. And the only way to succeed will be to understand the science well enough that you can make clever shortcuts in limiting the scope of the science you need to model in your game.

However, the other half of your problem (modeling Inelastic Collisions) is a much more achievable goal.

Good luck!

Theodolite answered 4/10, 2012 at 20:57 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.