## Soft-body mesh / subdivision surface / physics simulation

A place for users of OGRE to discuss ideas and experiences of utilitising OGRE in their games / demos / applications.
KingPrawnVindaloo
Greenskin
Posts: 100
Joined: Mon Apr 18, 2005 11:05 pm
Location: Kent, UK
Contact:

### Soft-body mesh / subdivision surface / physics simulation

Hi All,

I'm just playing around with some ideas and knocking together some conceptual stuff to see if my ideas are worth pursuing. Just thinking out loud, but if anyone want to chip in:

As part of a game, I'm thinking of simulating a ball. Easy enough - what with newton and ode etc. But, I want to give it a bit more character, and to have exaggerated squash/stretch characteristics, such as those which are taught in animation classes.

So - what I'm thinking is having a 12-pointed *ball* - thinking a geomesh from 3ds - with a mass at each of the points and a springy joint constraint connecting them all along the edges and a constraint for each to the ball's center, so you end up with like a beach ball. I could then tweak the features of that system to get the springiness etc that I'm looking for. I haven't done that yet, but I thinki it should work - will try 2moro.

Once I'm happy with that, I would want a mesh to be affected by that system. So, at it's simplest, I could have a 12 point mesh, with each of the vertices affected by one of the system's mass points.

I've previously used bones to manipulate vertices within Ogre, and I've played around with an idea in 3DS which goes a little like this: have a bone for each vertex. All the bones sprout from the center of the ball so that their end-points meet at the ball's outer vertices. This could be achieved by applying a skin modifier in 3ds so that each bone simply affects one vertex and then scaling/rotating the bones to get the desired effect within Ogre.

Once this is done, then the simple mesh can be subdivided to smooth the ball's surface out. I couple of iterations should be enough. I have code that I can adapt to subdivide a mesh. Once the mesh is subdivided, the vertices etc can then be pushed over to the GPU for displaying. I'm not sure how this works but I guess thats roughly it.

So - in theory this will all work. But. Obviously it's not the neatest solution.

What I'm thinking is:

Drop the bones. Far too unnecessary. Is it possible to get straight in and manipulate the vertices without bones? I'll assume that it is.

With that in mind, I assume that the work to do the subdivision work will be expensive each frame, and so would it be possible to transfer this work somehow to the GPU? I have a GEForce4ti and I think that runs 1.1 shaders or something.

I'm pretty certain it can be done one way or the other, but obviously I'd like to stay away from unnecessary work. Just a pointer or two should do.

Does anyone have similar experience that they could share?

:wumpus:
OGRE Retired Team Member
Posts: 3067
Joined: Tue Feb 10, 2004 12:53 pm
Location: The Netherlands
x 1
I've done this for one of my toy projects (which I still want to make into a game one day)
I animated an arbitrary (closed, obviously) mesh as if it's a balloon using cloth simulation (springs) and HardwareVertexBuffers. No bones involved.
It works with spheres of various sizes, and even a dinosaur. Haven't tried to compile it in a while though.

Is this kind of what you want to do? (except that I don't do any kind of subdivision, as it was not needed, the cloth simulation just maps 1:1 on the mesh. You could of course use the mass points as bones as well, in which case you can do larger meshes, but I never tried that yet)

walaber
OGRE Expert User
Posts: 829
Joined: Sat Oct 02, 2004 2:20 pm
Location: California, USA
Contact:
I also think simply adjusting the vertex data by hand would be the simplest and most versatile solution.

if you're interested, there is an excellent paper/tutorial on soft-body physics in both 2D and 3D (with source and explanations) on the following page:

http://panoramix.ift.uni.wroc.pl/~maq/eng/index.php look under "soft body", there's a lot of really interesting material there.

I too have always wanted to make some kind of 3D game similar to "Gish", with a soft-body main character. one day I may try to implement soft body physics in conjunction with Newton

KingPrawnVindaloo
Greenskin
Posts: 100
Joined: Mon Apr 18, 2005 11:05 pm
Location: Kent, UK
Contact:
Thanks, guys - that's it walaber - Gish is the sort of thing I'm going for. Not as the main character, but a pairing that you inderectly influence through widgets and gadgets. Like Mario and Luigi with Luigi stuck in a bubble, say.

I was thinking of doing the subdivision after deforming the base mesh (like a control lattice), as the final mesh deforms much more realistically than by apoplying a deform to a more complicated base mesh. Thanks for the link, looks like plenty of info on there.

Lioric
Posts: 295
Joined: Fri Aug 06, 2004 10:25 pm
I dont think that a system as you decribed can work without any problems, softbody dynamics are far too complex to represent with a simple system, and in an interactive system you have to simulate a large variety of problems and you cant hardcode all the posble variables, so you simulator has to be stable and accurate as you can

If you try your apprach, i recomend to implement at least a pressure volume model to keep the objects shape

Assuming that you are using a explicit method for the simulator, with a spring-mass system (with particles/nodes) how you will deal with the over-elongation problem? with euler or even with RK4 integrators, you cant use high spring constants, you have to do a post integration step correction method, or probably its better to implement a semi-implicit method to filter the high-frecuency instabilities

Probably a finite element method from numerical analisis can give you good results

Lioric

ahmedali
Gnome
Posts: 302
Joined: Fri Feb 20, 2004 8:52 pm
Location: Lahore, Pakistan
I think the easiest solution will be to use a 3d lattice grid to deform your mesh. And use verlet intigration and constraints to deform the lattice.

:wumpus:
OGRE Retired Team Member
Posts: 3067
Joined: Tue Feb 10, 2004 12:53 pm
Location: The Netherlands
x 1
Lioric wrote:I dont think that a system as you decribed can work without any problems, softbody dynamics are far too complex to represent with a simple system, and in an interactive system you have to simulate a large variety of problems and you cant hardcode all the posble variables, so you simulator has to be stable and accurate as you can
It worked fine for me with a simple verlet integrator; then again, I didn't try to achieve realism. Just some convincing balloon effect. (and indeed, it screwed up with some meshes, but generally they kept their original shape quite well, for example the Stanford Bunny

I never had an over-elongation problem because there was no such thing. Set the pressure to very low and the mesh collapsed, set the pressure to very high and uhh.. the thing becomes bigger and bigger. This could be repeated without any stability problems. The relative distance between the nodes was enough to keep the original shape, more or less.

For *real* cloth/soft body simulation you certainly need more than that, I agree, but to keep things realtime it's always nice to simplify.

Lioric
Posts: 295
Joined: Fri Aug 06, 2004 10:25 pm
But what happened when for example the mesh is not totally in the surface, for example half mesh is on a table and the other half is not ?

Did you use a big matrix to store the vertex relative positions ? that is alot of memory on mid complex meshes, because you have to store for each vertex their respective neighbors relative positions, did you use some optimization on this ?

So i assume you have implemented a presure volume model

Lioric

:wumpus:
OGRE Retired Team Member
Posts: 3067
Joined: Tue Feb 10, 2004 12:53 pm
Location: The Netherlands
x 1
Lioric wrote:But what happened when for example the mesh is not totally in the surface, for example half mesh is on a table and the other half is not ?
It rolls off the table, like you'd expect (ie the part that's falling of the table pulls the rest of the mesh into oblivion with it)
Did you use a big matrix to store the vertex relative positions ? that is alot of memory on mid complex meshes, because you have to store for each vertex their respective neighbors relative positions, did you use some optimization on this ?
No big matrix, just a list of springs, the nodes they connect to, and their 'preferred' length. As I said, I used a simple verlet integrator so no sparse matrix math/constraint solving was needed. It hardly takes more memory than the mesh itself.
The simulation was really low on CPU time, the thing that does take quite a lot of resources is collision with the environment. (not to mention self collision)
So i assume you have implemented a presure volume model
Kind of, it estimates the volume from the bounding box and some other simple constraints. Then there's an outward normal force depending on the surface size of a facet.

KingPrawnVindaloo
Greenskin
Posts: 100
Joined: Mon Apr 18, 2005 11:05 pm
Location: Kent, UK
Contact:
I've been playing with this over the last day or so, trying to get something rigged up with the ODE and Newton joints etc, but I think I'm going to have to go down the road of rolling my own.

I've found plenty of math papers on the equations/concepts etc and I'm about to nip out and get a book on physics.

Ideally - if I crack it, and again I don't know how possible this is, I would like to get it integrated into ODE. At the end of the day, its one thing having a nice physics simulation if it doesn't interact with the rest of the app.

I'm thinking of starting small, just getting a nice spring working, then I'll try to get that into ODE without using a kludge of their other joints. Then I'll worry about the internal pressure calcs etc

I know it's not crucial to the ideas I have in mind, but now I've started to wonder about it, I'm kinda obsessed with getting it working. It'll also be a good point for me to stop and revisit my old physics classes and learn some new stuff.

@:wumpus: I feel cheeky asking, and I would totally understand if you didn't want to share, but would it be possible to take a sneak at the code you created? /fingers crossed

:wumpus:
OGRE Retired Team Member
Posts: 3067
Joined: Tue Feb 10, 2004 12:53 pm
Location: The Netherlands
x 1
My idea was to use ODE as well, but I ended up not using it. Although I use ODE for the collision, ODE has no spring constraint simple enough for a thing like this But you already noticed it seems.

I'll see if I can turn that specific code into something readable without releasing the entire source.
here:
http://orion.servicez.org/ogre/airball-min.tar.gz

It is not compilable but should contain everything that's interesting for the balloon physics.

KingPrawnVindaloo
Greenskin
Posts: 100
Joined: Mon Apr 18, 2005 11:05 pm
Location: Kent, UK
Contact:
Thanks a lot - I'm sure that will come in very handy indeed. I'm just poring over some old textbooks at the moment to re-acquaint myself with stuff that I've forgotten.

Thanks again.