Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add mutable accessor for a VoxelSet's voxels. #314

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

dbenson24
Copy link

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.

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
Copy link
Author

dbenson24 commented Feb 6, 2025

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

Copy link
Contributor

@Vrixyz Vrixyz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is reasonable, but I'm a bit worried about how to keep "invariants" true, I believe an incorrect min_bb_voxelsor intersections is asking for trouble, what's your stance on that?

@dbenson24
Copy link
Author

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
Copy link
Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants