- Notifications
You must be signed in to change notification settings - Fork1
ZERDICORP/soft_body_simulation
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
I have only two words for you: INCREDIBLY COOL!
I've always wanted to create some kind of simulation related to physics.
And finally,I did it!
P.S. The work I have done is not perfect.
I didn't go deep into formulas.
I didn't try to create a comprehensive universal soft body engine.
Not at all.
I am driven only by wild curiosity, what are you talking about? :D
Everything written below is just acrooked interpretation of the coolest articles onsoft body physics.
Want two-page formulas and buzzwords? Google it! :3Who seeks will find.
Whoever goes will come.
Those who google will not notice the answer in the first link.
Well, let's understand howsoft body simulation works.
First, we need to understandwhat the body itself is. And by the way, it won't take long to find the answer (that's why I'm here lol):
- Particles
Yes,particles are everywhere.
It is from these little freaks that everything around us consists: the phone that you hold in your hands, and the hands themselves.
And, you know, if you want to create asoft body, you don't have tobeat around the bush -steal the idea from nature!
So, okay, we have particles. But what exactly are they?
Here is the basic set of properties for eachparticle:
- location
- velocity
I mean, it's pretty primitive.
We have a particle location(x, y) and avelocity vector.
It remains for each frame to update the location, adding velocity to it.
It's all? Do we have a soft body?
Lol, no.. :D
Having onlyparticles, you can get, for example, agas, but obviously not asoft body, because, as you know, a body is a body, because it is anordered set of interconnected particles (crystal lattice).
And, if we were making a regularrigid body, we wouldn't even have to tie anything.
But here's asoft body..
It should behave likejelly, or any othersoft object, that is,deform, and then recover.
And the«Spring Mass System» will help us to achieve this effect.
I will not retellsmart definitions from Wikipedia, but I will explain in simple words:
Our task is tosplit the particles into pairs. Each pair forms aspring.
Next, we need to go through all thesprings (pairs of two particles) and, based on some data, calculate thenext position of the particles in space.
Thus, theparticles become bound to each other.
And thesystem of spring masses allows you to achieve the effect ofjelly, since when the particles move away from each other, they are forced to move towards each other (spring compression), otherwise, if the particles are too close to each other (closer than a certain distance /state of rest), they forced to move in opposite directions (stretching the spring).
Summarizing the above, we have:
- Particles
- Springs (a pair of two particles)
This is actually enough to create asoft body.
Well, let's briefly go through the main steps:
- Createparticles.
- Connect them withsprings.
- Iterate through the springs every frame and apply allsorts of tricky formulas to achieve the spring effect (move away the particles - they return to each other; bring the particles closer - they push each other with all their might; stretch the spring and release it - it will contract and stretch, makingharmonic oscillations, until it reaches astate of rest).
Apart from thespring mass system, you will probably need agravity simulation (just add a constant to the y-axis of the velocity vector every frame), acollision resolution algorithm (because you don't want your soft body to fall forever) anda lot of curiosity (no way without it)!

But How DO Soft Body Simulations Work? by Gonkee
About
In my opinion - one of the coolest simulations!