Soft Body Physics for AmmoJSPlugin

#1

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

7 Likes
#2

Hell YEAHHH!

1 Like
#3

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

3 Likes
#4

Ropes now available Create Soft Bodies - Babylon.js Documentation

2 Likes
#5

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

1 Like
#6

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

#7

This is really amazing. This looks so promising !

1 Like
#8

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
#9

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?

#10

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.

#11

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

#12

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

#13

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
#14

Any chance of a simple PG example?

#15

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

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

1 Like
#16

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

#17

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.