Add mutable accessor for a VoxelSet's voxels.
This is to allow external code to call into VHACD with a set of voxels that it computes without forcing it to generate a bunch of geometry to then get revoxelized.
I would also be interested in adding the following helper to SharedShape if it looks reasonable to you
impl SharedShape {
pub fn voxel_convex_decomposition(voxels: VoxelSet, config: &VHACDConfig) -> SharedShape {
let decomp = VHACD::from_voxels(config, voxels);
let mut parts = Vec::new();
for vertices in decomp.compute_convex_hulls(0) {
if let Some(convex) = SharedShape::convex_polyline(vertices) {
parts.push((Isometry::identity(), convex));
}
}
SharedShape::compound(parts)
}
I think that just documenting this potential concern could be enough? This is a pretty low level API, and if you give VHACD an incorrect VoxelSet and get bad results it's on you. It'll also be up to the caller to keep the voxels unique and within the dimensions.
I opted to just expose the vec because it was the smallest change. I think another API that would probably work for most would be some way to populate the VoxelSet from an iterator. Maybe something like set_voxels(voxels: impl Iter<Item=Voxel>) which recalculates the min_bb right after
For intersections that should always be empty since there is no original geometry to intersect with.
The use case I'm specifically working on trying to improve is the current technique that people are using to generate colliders for sprites. Right now you have to try and convert the pixels into a set of lines to feed in to the voxelizer before getting the decomposition. If you just feed the pixels of the sprite into the decomp as voxels, you get to skip the performance cost of the voxelization and any inaccuracies introduced by the multiple conversions.