Soft Body broken when source model is glTF
See original GitHub issueWhen using glTF files as soft bodies they end up having very strange behavior. More specifically, despite how the soft body properties are set, they crumple like paper and their collision detection breaks and they fall through other objects. Multiple soft bodies inserted into the scene this way also don’t interact with each-other in any logical fashion.
Repro Because this bug requires an external glTF model, I’m not able to easily reproduce it in the sandbox. Instead, allow me to provide sample files and code here:
import * as BABYLON from 'babylonjs'
import 'babylonjs-loaders'
function init() {
var canvas = document.getElementById('renderCanvas')
var engine = new BABYLON.Engine(canvas, true, { preserveDrawingBuffer: true, stencil: true })
var scene = new BABYLON.Scene(engine)
scene.enablePhysics(new BABYLON.Vector3(0,-9.81, 0), new BABYLON.AmmoJSPlugin())
scene.debugLayer.show()
var camera = new BABYLON.ArcRotateCamera("Camera", 3 * Math.PI / 2, Math.PI / 2.5, 15, BABYLON.Vector3.Zero(), scene);
camera.setTarget(BABYLON.Vector3.Zero())
camera.attachControl(canvas, false)
var light = new BABYLON.HemisphericLight('light1', new BABYLON.Vector3(0, 1, 0), scene)
var options = {
mass: 1,
friction: 0.1,
restitution: 0.3,
pressure: 2000,
velocityIterations: 40,
positionIterations: 40,
stiffness: 0.9,
damping: 0.01
}
var ground = BABYLON.MeshBuilder.CreateBox('ground', {width: 5, height:0.2, depth: 5}, scene)
ground.physicsImpostor = new BABYLON.PhysicsImpostor(ground, BABYLON.PhysicsImpostor.BoxImpostor, { mass: 0, friction: 0.5, restitution: 0 }, scene)
BABYLON.SceneLoader.ImportMeshAsync('', 'assets/glb/box.glb', '', scene).then(model => {
var targetMesh = model.meshes[1]
targetMesh.parent = null
targetMesh.forceSharedVertices()
targetMesh.physicsImpostor = new BABYLON.PhysicsImpostor(targetMesh, BABYLON.PhysicsImpostor.BoxImpostor, { mass: 10 }, scene)
})
BABYLON.SceneLoader.ImportMeshAsync('', 'assets/glb/soft.glb', '', scene).then(model => {
var targetMesh = model.meshes[1]
targetMesh.parent = null
targetMesh.forceSharedVertices()
targetMesh.position.y = 3
targetMesh.physicsImpostor = new BABYLON.PhysicsImpostor(targetMesh, BABYLON.PhysicsImpostor.SoftbodyImpostor, options, scene)
})
window.addEventListener('resize', () => {
engine.resize()
})
engine.runRenderLoop(() => {
scene.render()
})
}
init()
Screenshots
Desktop (please complete the following information):
- OS: Tested on both OSX and Linux
- Browser Tested on both Chrome and FireFox
Additional context I’m not the developer who discovered this bug, I just translated the information, so my description may not be accurate. If you are unable to replicate the issue or find my description to be inaccurate or lacking please let me know and I will try to get a better description or have the developer make a sample that can be viewed easily in the sandbox.
Issue Analytics
- State:
- Created 3 years ago
- Comments:8 (5 by maintainers)
Top GitHub Comments
" so if just copying the above and pasting it on the forum would be sufficient I’ll do so" That would be perfect!
I have posted on the forums: https://forum.babylonjs.com/t/soft-body-issues-when-importing-a-gltf-model/12501