Soft Body Physics for AmmoJSPlugin

Beginnings of soft body physics available (Ammo plugin only) Create Soft Bodies - Babylon.js Documentation

9 Likes

Hell YEAHHH!

1 Like

Anchoring a cloth to a rigid body is now available Create Soft Bodies - Babylon.js Documentation

3 Likes

Ropes now available Create Soft Bodies - Babylon.js Documentation

2 Likes

really impressive !
The possibility to use an extruded shape is amazing. Maybe could this also work with a tube ?

1 Like

@jerome I could have have used a tube (if I had remembered about it) and then just passed the path parameter. The we could not have had fun shapes like this Babylon.js Playground

It would work with any shape that is built from a path, even extrudecustomshape, since the basics are
take path points and pass to Ammo as node points. Ammo updates node points, read node points from Ammo into path, update shape using path points plus parameters used to build shape. This does mean that for every execute step there is a call to the shape builder, which means the particular shape builder used has to be written into the Ammo plugin. Tube and ExtrudeCustomShape could be built in as long as the plugin had a method of distinguishing which to use. My thoughts are that ExtrudeShape is probably sufficient, however adding the rotation and scaling parameters might be fun.

1 Like

This is really amazing. This looks so promising !

1 Like

https://www.babylonjs-playground.com/#MCGMPW#1
I like the dynamic deformations that still occur a while after the shape has landed on the box

1 Like

Is it possible to pull a vertex of a softbody mesh (like a sphere) so it deforms, then springs back to shape when you let go?

Mmm good question. Don’t know off hand how you might do this or if possible. Playing around with setting and removing anchors may be worth a try. Sorry I cannot be more helpful.

What do you mean by removing anchors?

I’m thinking anchors would do the job 'cos I could attach them to vertices and pull the anchor, but as far as I know, you can only add anchors to cloth (ground) but not things like spheres.

I tried sticking an object inside the softbody and moving that object but that doesn’t work. As soon as the object is inside the other it causes a collision.

Also attaching a rope and pulling the rope, but that doesn’t deform the softbody

Sorry anchors was more of a guess than anything else and even then it would mean getting into native code. I learnt just enough about Ammo to do the basic softbody for the plugin and this was mainly through looking at existing code for Threejs. Docs for ammo are few and far between bulletjs is the best you can do. Don’t know if this might help Bullet Collision Detection & Physics Library: Class Members

Otherwise there is not much more I can add

Actually I was wrong, you can stick a mesh into a softbody. Just make the mesh a SpherebodyImposter, apply forces to it. Make sure the softbody margin is high so it doesn’t break apart.

1 Like

Any chance of a simple PG example?

https://www.babylonjs-playground.com/#480ZBN#74

I’m trying to make it act like a bubble that’s being pulled.

3 Likes

Checking out the ammo plugin repo Babylon.js/ammoJSPlugin.ts at master · BabylonJS/Babylon.js · GitHub

I think if I can access the the soft body vertex data I can pull vertices away from the body (towards its normal) and then it’ll spring back into position. I don’t know how to do that though. That code doesn’t seem to be in the compiled ammo.js file

Several issues here.

Using the plugin the softbody node data is copied only on initialisation of the impostor The mesh vertex data copies the softbody node data each frame so amending the mesh vertex data during the render loop with have no affect on the node data and any amendment of the node data would produce a totally new softbody shape.

The ammojs file only contains the compiled native code for ammo from GitHub - kripken/ammo.js: Direct port of the Bullet physics engine to JavaScript using Emscripten
The compiled Ammo plugin is in https://raw.githubusercontent.com/BabylonJS/Babylon.js/master/dist/preview%20release/babylon.max.js
Find AmmoJSPlugin.prototype._softbodyOrClothStep and AmmoJSPlugin.prototype._softVertexData and AmmoJSPlugin.prototype._createSoftbody in Babylon.max.js

EDIT IMHO you are not going to do any better than in you PG above.

Hello JohnK,

I’m looking for a way to deform a mesh on collision like when you shoot in a soda can or when a car crashes into a wall etc …
I tried to use the softbody plugin but it transforms your mesh into an elastic body that deforms and returns back to its initial shape, this is not realistic for what I want to do.

Is there a way to keep mesh deformation on collision ?

thanks a lot.

Sorry not that I know of. I suppose it might be possible to read the vertices of the mesh at the point of collision and create a new mesh deformed mesh but very tricky.

Maybe @Cedric ?