#Cannon.js with GLTF model?

6 messages · Page 1 of 1 (latest)

lost void
#

I'm making an FPS game, and I'm using Cannon.js as the physics engine. I recently figured out how to do this with simple objects, such as BoxGeometry, SphereGgeometry, and PlaneGeometry, but what about a loaded model? I saw this post, but I get the error THREE.Geometry is not a constructor (its deprecated im pretty sure: https://github.com/schteppe/cannon.js/issues/444)

Here is my code:

const loader = new THREE.GLTFLoader();

loader.load(`Assets/Maps/mapone.glb`, function ( gltf ) {
        gltf.scene.scale.set(40, 40, 40);
        scene.add(gltf.scene);  
        let g = new THREE.Geometry().fromBufferGeometry(gltf)
        console.log(g)
});

All help is appreciated! Thanks!

GitHub

A lightweight 3D physics engine written in JavaScript. - Issues · schteppe/cannon.js

spiral isle
#

now the bad news, the library is still technically inferior to modern variants, while original cannon cannot handle convexpolyhedron shapes (mesh hulls, you need them for gltf) at all, cannon-es can but it's just too slow.

#

i would also suggest you use react + three which has a large eco system around physics, vanilla has practically nothing in that regard. you can merely wrap a physicsbody around your model and it will figure out the hulls automatically, there is nothing to be done. https://codesandbox.io/s/rapier-physics-7e9y1b

Rapier physics by drcmda using @react-three/drei, @react-three/fiber, @react-three/rapier, @types/react, @types/three, leva, react, react-dom, react-scripts