Closed terrac closed 6 years ago
Using a different physics engine would be feasible, if there's an engine that supports colliding with voxels in a performant way (i.e., not by having a cube for every solid voxel or similar).
I experimented with extending cannon to support this, but didn't get far enough for it to be usable.
I noticed that cannon js actually has a voxel demo on its demo list http://schteppe.github.io/cannon.js/examples/threejs_voxel_fps.html
which appears to have a VoxelLandscape.js file
Yes, that demo creates boxes (in the physics engine) for each solid voxel.
https://github.com/schteppe/cannon.js/blob/master/examples/js/VoxelLandscape.js#L196
It looks like maybe ammo.js with btBvhTriangleMeshShape might work. Looking at the bullet documentation it says it is optimized for static landscapes.
I'm not really sure how much effort it would take though, and it isn't currently a bablyon js physics plugin.
Yeah, I think that'll be ammo's version of the feature where the engine parses a mesh and makes it into one or more convex polygons to use for hit testing. I haven't tried any of these things but I'd expect it to be even slower than having a bunch of cubes, since polygons are usually the slowest option in physics engines.
Basically I think any of these approaches could be made to work in a strictly limited sized world, like in the threejs voxel demo, but I don't think any of them scale up. AFAIK the way to do it performantly is to have a voxel collision body type, like I was making in the cannon issue above. I got it to work in a minimal case but I didn't really have time to make it work fully (I only implemented voxel-sphere collisions, I didn't handle any other primitives).
BTW: not having a babylon plugin for ammo doesn't affect what we're talking about - in noa
the physics and the rendering are separate and don't know about each other.
I was looking at the babylon js physics plugins and I was wondering if you had any intention of allowing for swapping between physics engines via the babylon js physics plugin system.