dimforge / ncollide

2 and 3-dimensional collision detection library in Rust.
https://ncollide.org
Apache License 2.0
921 stars 107 forks source link

BVH trait definition is hard to implement when bounding volumes are generated on demand #363

Open bonsairobo opened 3 years ago

bonsairobo commented 3 years ago

My use case is that I have a voxel octree which needs to be very memory efficient. So I can't store an AABB for every single voxel. That's 6 floats, i.e. 24 bytes per voxel.

Rather, voxel presence is encoded in bitsets, and the efficiency is such that a single voxel can be stored in far less than 1 bit per voxel.

So the issue is that when I tried to impl BVH for this octree, I could not implement fn content(&self, node: Self::Node) -> (&BV, Option<&T>) because it returns a reference to a bounding volume. I could easily generate an AABB for a given voxel, but it would not live long enough to return a reference. The only hack I can think of is to keep an AABB temporary variable on self that gets unsafely mutated to overcome &self, but that may be unsound depending on the code that's using this structure.