Hi everyone,
I am building a scene with physics for a robotics simulation project using Three and Enable3d / Ammo Physics. I have successfully setup several basic meshes (cubes, cylinders, spheres), and added physics for them using Enable3d’s physics.add.existing
, however I’m running into issues with more complex shapes that use BufferGeometry. I’ve tried importing a .glb file, as well as manually creating a BufferGeometry.
Currently the behavior that I’m seeing is:
- Kinematic bodies refuse to move (they jitter but then snap back to their original positions, like a non-kinematic body would)
- Debug mode does not show any bounding boxes around objects (tried ‘hacd’, ‘convexMesh’, ‘concaveMesh’ and other shapes)
- ‘box’ shape works but results in a box that is just 1x1x1 positioned at the origin
So my question is, does anyone know if Enable3d supports BufferGeometry currently? Or alternatively is there another way to import models from Blender etc. in a way that Enable3d is able to understand.
Here’s my code:
const geom = new Three.BufferGeometry()
const rawVertices = new Float32Array(
_.flatten([
[-1.0, 1.0, -1.0],
[-1.0, -1.0, 1.0],
[1.0, 1.0, 1.0],
//
[1.0, 1.0, 1.0],
[1.0, -1.0, -1.0],
[-1.0, 1.0, -1.0],
//
[-1.0, -1.0, 1.0],
[1.0, -1.0, -1.0],
[1.0, 1.0, 1.0],
//
[-1.0, 1.0, -1.0],
[1.0, -1.0, -1.0],
[-1.0, -1.0, 1.0],
])
)
// itemSize = 3 because there are 3 values (components) per vertex
geom.setAttribute(
'position',
new Three.BufferAttribute(rawVertices, 3)
)
geom.computeVertexNormals()
const mesh = new Three.Mesh(geom, material)
scene.add(mesh)
physics.add.existing(mesh, { shape: 'hacd', collisionFlags: 2 })
Also, if this is not the right forum for these types of questions, I apologize in advance. Happy to take this elsewhere.