Make voxel collision queries generic over the voxel storage with a VoxelQuery trait - #445
Open
0xbeefd1ed wants to merge 9 commits into
Open
Make voxel collision queries generic over the voxel storage with a VoxelQuery trait#4450xbeefd1ed wants to merge 9 commits into
0xbeefd1ed wants to merge 9 commits into
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Parry's voxel collision algorithms were written directly against a concrete
Voxelsshape. Anyone with their own sparse voxel structure (a chunked grid, an octree, a VDB-style tree) had to copy it into aVoxelsbefore they could get contacts, intersection tests, or shape-casts against it.This PR introduces a
VoxelQuerytrait that abstracts the storage, and rewrites the voxel query functions to take anyV: ?Sized + VoxelQueryinstead of&Voxels. The existingVoxelsshape implements the trait, so calls that pass a&Voxelskeep working unchanged.What changed
VoxelQuerytrait (src/shape/voxels/voxel_query.rs). Implementors providevoxel_size,domain, andvoxels_in_range. Grid helpers (voxel_at_point,voxel_center,voxel_aabb,voxel_range_intersecting_local_aabb,align_aabb_to_grid,local_aabb, and the aabb-based iterators) have default implementations derived from those three.QueriedVoxeltrait, the per-voxel view a storage hands out through theVoxelQuery::Voxel<'a>associated type. Views may borrow from the storage, so a sparse tree can computevoxel_state()lazily from leaf-local context. The cheapvoxel_type()is what bulk iteration reads; the fullvoxel_state()is only requested for contact-candidate voxels.contact_manifolds_voxels_{shape,ball,composite_shape,voxels},intersection_test_{voxels_shape,shape_voxels},cast_shapes_{voxels_shape,shape_voxels},cast_shapes_nonlinear_{voxels_shape,shape_voxels}, andMassProperties::from_voxelsnow take aVoxelQuerystorage. The 2D and 3Dto_outline,to_polyline, andto_trimeshconversions read throughQueriedVoxelas well.VoxelsimplementsVoxelQuerywithVoxelDataas its view, andVoxelDataimplementsQueriedVoxel.VoxelState::with_filled_neighbors(AxisMask)builds a filled voxel's state from the set of its filled axis-aligned neighbors, for storages that only track occupancy.DefaultforVoxelType(Empty) andVoxelState(EMPTY).contact_manifolds_voxels_ballis now re-exported fromparry::queryalongside the other voxel manifold functions.Test plan
cargo test -p parry2dandcargo test -p parry3dpass on all four crate variants.cargo test --docpasses, including the newVoxelState::with_filled_neighborsexample.RUSTDOCFLAGS="-D warnings" cargo doc --workspace --no-depspasses.issue_345,issue_373,issue_382,issue_404) still pass against theVoxelsimplementation of the trait.