parry icon indicating copy to clipboard operation
parry copied to clipboard

Add mutable accessor for a VoxelSet's voxels.

Open dbenson24 opened this issue 10 months ago • 3 comments

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.

dbenson24 avatar Feb 06 '25 19:02 dbenson24

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)
}

dbenson24 avatar Feb 06 '25 19:02 dbenson24

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.

dbenson24 avatar Feb 19 '25 14:02 dbenson24

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.

dbenson24 avatar Feb 19 '25 15:02 dbenson24