# Soft Body Physics for AmmoJSPlugin

**URL:** https://forum.babylonjs.com/t/soft-body-physics-for-ammojsplugin/1613
**Category:** Announcements
**Created:** [February 26, 2019, 9:42am UTC](https://forum.babylonjs.com/t/soft-body-physics-for-ammojsplugin/1613 "2019-02-26T09:42:05Z")
**Posts on this page:** 20
**Page:** 1

<div class="post-metadata">

### Author: ![JohnK](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/johnk/32/26764_2.png) [@JohnK](https://forum.babylonjs.com/u/JohnK)
#### Post date: [February 26, 2019, 9:42am UTC](https://forum.babylonjs.com/t/soft-body-physics-for-ammojsplugin/1613/1 "2019-02-26T09:42:05Z")

</div>

Beginnings of soft body physics available (Ammo plugin only) [Create Soft Bodies - Babylon.js Documentation](https://doc.babylonjs.com/how_to/soft_bodies)

---

<div class="post-metadata">

### Author: ![Deltakosh](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/deltakosh/32/26635_2.png) [@Deltakosh](https://forum.babylonjs.com/u/Deltakosh)
#### Post date: [February 26, 2019, 3:22pm UTC](https://forum.babylonjs.com/t/soft-body-physics-for-ammojsplugin/1613/2 "2019-02-26T15:22:44Z")

</div>

Hell YEAHHH!

---

<div class="post-metadata">

### Author: ![JohnK](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/johnk/32/26764_2.png) [@JohnK](https://forum.babylonjs.com/u/JohnK)
#### Post date: [March 1, 2019, 5:00pm UTC](https://forum.babylonjs.com/t/soft-body-physics-for-ammojsplugin/1613/3 "2019-03-01T17:00:44Z")

</div>

Anchoring a cloth to a rigid body is now available [Create Soft Bodies - Babylon.js Documentation](https://doc.babylonjs.com/how_to/soft_bodies#anchors)

---

<div class="post-metadata">

### Author: ![JohnK](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/johnk/32/26764_2.png) [@JohnK](https://forum.babylonjs.com/u/JohnK)
#### Post date: [March 6, 2019, 5:03pm UTC](https://forum.babylonjs.com/t/soft-body-physics-for-ammojsplugin/1613/4 "2019-03-06T17:03:51Z")

</div>

Ropes now available [Create Soft Bodies - Babylon.js Documentation](https://doc.babylonjs.com/how_to/soft_bodies#the-rope-soft-body)

---

<div class="post-metadata">

### Author: ![jerome](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/jerome/32/22_2.png) [@jerome](https://forum.babylonjs.com/u/jerome)
#### Post date: [March 6, 2019, 7:17pm UTC](https://forum.babylonjs.com/t/soft-body-physics-for-ammojsplugin/1613/5 "2019-03-06T19:17:58Z")

</div>

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

---

<div class="post-metadata">

### Author: ![JohnK](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/johnk/32/26764_2.png) [@JohnK](https://forum.babylonjs.com/u/JohnK)
#### Post date: [March 7, 2019, 10:00am UTC](https://forum.babylonjs.com/t/soft-body-physics-for-ammojsplugin/1613/6 "2019-03-07T10:00:46Z")

</div>

@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](https://www.babylonjs-playground.com/#MCGMPW)

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.

---

<div class="post-metadata">

### Author: ![jerome](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/jerome/32/22_2.png) [@jerome](https://forum.babylonjs.com/u/jerome)
#### Post date: [March 7, 2019, 10:15am UTC](https://forum.babylonjs.com/t/soft-body-physics-for-ammojsplugin/1613/7 "2019-03-07T10:15:43Z")

</div>

This is really amazing. This looks so promising !

---

<div class="post-metadata">

### Author: ![jerome](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/jerome/32/22_2.png) [@jerome](https://forum.babylonjs.com/u/jerome)
#### Post date: [March 7, 2019, 10:21am UTC](https://forum.babylonjs.com/t/soft-body-physics-for-ammojsplugin/1613/8 "2019-03-07T10:21:38Z")

</div>

[https://www.babylonjs-playground.com/#MCGMPW#1](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

---

<div class="post-metadata">

### Author: ![ozRocker](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/ozrocker/32/186_2.png) [@ozRocker](https://forum.babylonjs.com/u/ozRocker)
#### Post date: [April 8, 2019, 7:40am UTC](https://forum.babylonjs.com/t/soft-body-physics-for-ammojsplugin/1613/9 "2019-04-08T07:40:50Z")

</div>

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?

---

<div class="post-metadata">

### Author: ![JohnK](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/johnk/32/26764_2.png) [@JohnK](https://forum.babylonjs.com/u/JohnK)
#### Post date: [April 8, 2019, 8:05am UTC](https://forum.babylonjs.com/t/soft-body-physics-for-ammojsplugin/1613/10 "2019-04-08T08:05:21Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![ozRocker](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/ozrocker/32/186_2.png) [@ozRocker](https://forum.babylonjs.com/u/ozRocker)
#### Post date: [April 8, 2019, 8:21am UTC](https://forum.babylonjs.com/t/soft-body-physics-for-ammojsplugin/1613/11 "2019-04-08T08:21:57Z")

</div>

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

---

<div class="post-metadata">

### Author: ![JohnK](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/johnk/32/26764_2.png) [@JohnK](https://forum.babylonjs.com/u/JohnK)
#### Post date: [April 8, 2019, 8:55am UTC](https://forum.babylonjs.com/t/soft-body-physics-for-ammojsplugin/1613/12 "2019-04-08T08:55:00Z")

</div>

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](https://pybullet.org/Bullet/BulletFull/functions.html)

Otherwise there is not much more I can add

---

<div class="post-metadata">

### Author: ![ozRocker](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/ozrocker/32/186_2.png) [@ozRocker](https://forum.babylonjs.com/u/ozRocker)
#### Post date: [April 8, 2019, 11:45am UTC](https://forum.babylonjs.com/t/soft-body-physics-for-ammojsplugin/1613/13 "2019-04-08T11:45:01Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![JohnK](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/johnk/32/26764_2.png) [@JohnK](https://forum.babylonjs.com/u/JohnK)
#### Post date: [April 8, 2019, 11:59am UTC](https://forum.babylonjs.com/t/soft-body-physics-for-ammojsplugin/1613/14 "2019-04-08T11:59:11Z")

</div>

Any chance of a simple PG example?

---

<div class="post-metadata">

### Author: ![ozRocker](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/ozrocker/32/186_2.png) [@ozRocker](https://forum.babylonjs.com/u/ozRocker)
#### Post date: [April 8, 2019, 12:17pm UTC](https://forum.babylonjs.com/t/soft-body-physics-for-ammojsplugin/1613/15 "2019-04-08T12:17:58Z")

</div>

[https://www.babylonjs-playground.com/#480ZBN#74](https://www.babylonjs-playground.com/#480ZBN#74)

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

---

<div class="post-metadata">

### Author: ![ozRocker](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/ozrocker/32/186_2.png) [@ozRocker](https://forum.babylonjs.com/u/ozRocker)
#### Post date: [April 8, 2019, 3:44pm UTC](https://forum.babylonjs.com/t/soft-body-physics-for-ammojsplugin/1613/16 "2019-04-08T15:44:08Z")

</div>

Checking out the ammo plugin repo [Babylon.js/ammoJSPlugin.ts at master · BabylonJS/Babylon.js · GitHub](https://github.com/BabylonJS/Babylon.js/blob/master/src/Physics/Plugins/ammoJSPlugin.ts)

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

---

<div class="post-metadata">

### Author: ![JohnK](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/johnk/32/26764_2.png) [@JohnK](https://forum.babylonjs.com/u/JohnK)
#### Post date: [April 8, 2019, 4:33pm UTC](https://forum.babylonjs.com/t/soft-body-physics-for-ammojsplugin/1613/17 "2019-04-08T16:33:48Z")

</div>

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](https://github.com/kripken/ammo.js/)  
The compiled Ammo plugin is in [https://raw.githubusercontent.com/BabylonJS/Babylon.js/master/dist/preview%20release/babylon.max.js](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.

---

<div class="post-metadata">

### Author: ![DJousto](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/djousto/32/7034_2.png) [@DJousto](https://forum.babylonjs.com/u/DJousto)
#### Post date: [February 24, 2020, 7:41am UTC](https://forum.babylonjs.com/t/soft-body-physics-for-ammojsplugin/1613/18 "2020-02-24T07:41:47Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![JohnK](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/johnk/32/26764_2.png) [@JohnK](https://forum.babylonjs.com/u/JohnK)
#### Post date: [February 24, 2020, 8:48am UTC](https://forum.babylonjs.com/t/soft-body-physics-for-ammojsplugin/1613/19 "2020-02-24T08:48:29Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![Deltakosh](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/deltakosh/32/26635_2.png) [@Deltakosh](https://forum.babylonjs.com/u/Deltakosh)
#### Post date: [February 24, 2020, 4:51pm UTC](https://forum.babylonjs.com/t/soft-body-physics-for-ammojsplugin/1613/20 "2020-02-24T16:51:34Z")

</div>

Maybe @Cedric ?

[Next page](https://forum.babylonjs.com/t/soft-body-physics-for-ammojsplugin/1613.md?page=2)
