But How DO Soft Body Simulations Work?

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
in computer simulations of the physics in solid objects there are two main types of bodies which act as a representation of whatever object is being simulated while it's physically impossible for a rigid body to exist in real life it presents a simplicity that makes it convenient and optimal to use as a representation of most hard objects soft bodies take care of what rigid bodies lack the capability to represent shapes that are elastic can be deformed and can be compressed this is inspecto and in this video i attempt to find out exactly how soft bodies work and explain it to anyone else who's also been curious about them this video will present the implementation of soft bodies in 2d for the sake of simplicity but these principles can be extended to 3d as well let's start off by going over the representation of motion that we'll use in our simulated environment our body will be made of a bunch of mass points each storing its own position velocity force and mass force is used instead of acceleration as it's equal to mass times acceleration as newton's second law of motion describes this means the mass variable can be used to alter how heavy it is and consequently how it behaves and here's how these values will be updated every frame first we set the force to zero as force is recalculated every frame rather than accumulated across frames then we add on different forces such as gravity and the forces we'll cover later like spring force since the gravity force is proportional to the mass of the object and acts more like an acceleration it must be multiplied by the object's mass when it's applied next we add the force divided by the mass then multiplied by the delta time to the velocity this is the value which accumulates across frames unlike force lastly we add velocity times delta time to the position and the object is moved this simple way of updating velocity and position is known as euler integration and is widely used in game development to represent mass and elasticity two of the most fundamental properties of a soft body there aren't many models better suited than the spring mass model this is a model involving a spring connecting two mass points and the data that needs to be stored by the spring includes a reference to the two mass points that it connects its stiffness its rest length and its damping factor hooke's law states that the force produced by the spring is simply equal to the difference between its current length which is the distance between the two points and its resting length and this difference is multiplied by its stiffness conventionally hooke's law is either written with a negative sign to represent the force the spring produces or without a negative sign to represent the force being applied on the spring however this only applies to a simplified model where only the length of the spring is considered in our 2d world where we are concerned with the individual positions of the two mass points it's more convenient to not use the negative sign if the spring is too long and the masses have to come closer the force is positive while if the spring is too short and the masses have to move farther apart the force is negative the issue with such a simple spring mass system is that even if it's just displaced by a little bit it'll move in simple harmonic motion and never stop its energy is conserved and there's simply nothing to make it come to a stop hence we need to add damping which is a force proportional to how fast the spring's length changes acting in the opposite direction of the change in length this slows the spring down and would be equivalent to something like air resistance in real life let's call our mass points a and b and there's an easy way to figure out how fast they're moving towards or away from each other given their positions and velocities we first find the normalized direction vector from one point to the other let's just say b minus a normalized then we find the corresponding velocity difference which is just b's velocity minus a's velocity not normalized all we need to find is the dot product between these two vectors whenever the points are moving away from each other and the damp force should act in the direction facing each other the two vectors will point in the same direction and that results in a positive dot product if they're moving towards each other and the damp force should act in the direction away from each other the two vectors will face away from each other making a negative dot product if the distance between them is not changing the dot product is zero now we just multiply this dot product with our damping factor and add it to the spring force which we previously found we'll call this sum between the spring force and the damp force the total spring force to convert this total spring force into two-dimensional movement for each mass point we can multiply it by the normalized direction vector to the other mass this way a positive force means the mass points move towards each other while a negative one means they move away from each other let's quickly cover collision collision is usually done between polygons but the use of mass points to constitute our soft body means we can just implement collision between a point and a polygon which is much simpler and simply run it for every point in the body at the start of every collision detection algorithm should be a rough detection step which can save the computer the effort of analyzing polygons which are way too far away to even be considered here we can just see whether the point is within the bounding box of each polygon using its minimum and maximum x and y values and only if it's in the bounding box will continue on then there's an easy way to know if the point is within the polygon called ray casting if you were to draw a line from anywhere outside the polygon to the point if it intersects an odd number of edges it's inside the polygon and if it intersects an even number of edges it's outside the polygon this works for convex polygons concave polygons even ones with holes in them we won't go into the details of implementation but as a tip using an axis aligned vertical or horizontal line is easier to implement than using a diagonal one now this raycasting method involves looping through every edge of the polygon to check for an intersection during this loop just add an additional step that finds the closest point on each edge to the mass point and keep track of the closest points out of all the edges at the end if the point is inside the polygon just push it out to that aforementioned closest point and use the normalized push vector as a normal vector to reflect its velocity off of since it's the closest point on the edge that normal vector will be perpendicular to the edge anyway now we've got a spring mass system with damping and we've got collision but we still don't have a soft body this next step however quickly brings it all together you see any solid filled in elastic body such as a piece of rubber a chunk of jelly and a gummy bear is made of many little particles molecules to be exact stuck together in three dimensions so of course it would make sense that to simulate this type of soft body we should use a whole bunch of particles as well here's where the spring mass system fits into our purposes perfectly as long as we make a bunch of masses and connect them all with springs that's basically an elastic object we're not concerned with the actual molecular structure of real life objects but just need a structure that helps our particles keep their shape since a polygon with given side lengths must be a triangle for it to maintain all its angles we need a spring connection pattern that involves triangles here we'll use boxes with crosses inside them they're nice and symmetrical and can be seen in real life structures such as transmission towers and even the eiffel tower all we have to do is get all the springs to generate their spring force and there we go we've got a working solid soft body in order to prevent the spring structure from collapsing into itself we can add self-collision give each mass point a radius and if a mass point travels too close to another one simply push it away also using this normalized push vector to reflect its velocity be careful if the distance is zero though just skip the collision step for that frame to avoid dividing by zero or else your simulation might break this also goes for any step involving division by a distance that might be zero this video is only meant as an introduction to the world of soft bodies the simulation model presented is one of the simplest and easiest to understand but it definitely doesn't cover every possible feature a soft body can have and is also not the only way you can implement a soft body for example another soft body model is the pressure spring mass model as opposed to the particle spring mass model we covered this is better suited for hollow bodies which rely on air pressure to keep their shape such as balloons and yoga balls so only the perimeter of the body is made with springs and masses every frame the volume or area of the body has to be calculated a whole another process that can be done in different ways which is then used to calculate a pressure force using the ideal gas law which is then applied to every mass point in the direction of the spring's normal vectors the motion integration in this case euler integration also leaves a bit more to be desired in terms of accuracy as there's only so many frames a second you can run a soft body simulation at only being able to update velocity and position values 60 times a second is equivalent to approximating the area under a curve using rectangles and with stiffness and damping values that are too high the simulation is bound to explode [Music] researchers in the field have been working on other ways of integrating motion such as euler implicit integration hewn predictor corrector integration and midpoint integration which are more accurate but much more complicated even other than that we haven't even covered features like plasticity friction and different spring network structures it's clear to see that there's so much more to learn in the world of soft body physics but hopefully this video has given you a general idea of what this field of computer science entails
Info
Channel: Gonkee
Views: 301,047
Rating: undefined out of 5
Keywords: inspecto, soft, body, simulation
Id: kyQP4t_wOGI
Channel Id: undefined
Length: 10min 46sec (646 seconds)
Published: Sun Jan 03 2021
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.