Skip to content

Commit c428208

Browse files
committed
feat: add support for parry’s new Voxels collider shape
1 parent 18b3029 commit c428208

File tree

3 files changed

+37
-5
lines changed

3 files changed

+37
-5
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
### Added
44

5+
- Added support for parry’s new `Voxels` collider shape with `ColliderBuilder::voxels` and
6+
`ColliderBuilder::voxelized_mesh`.
57
- `MeshConverter` now implements `Copy`.
68

79
## v0.24.0 (10 April 2025)

src/geometry/collider.rs

Lines changed: 34 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
use crate::dynamics::{CoefficientCombineRule, MassProperties, RigidBodyHandle};
2+
#[cfg(feature = "dim3")]
3+
use crate::geometry::HeightFieldFlags;
24
use crate::geometry::{
35
ActiveCollisionTypes, BroadPhaseProxyIndex, ColliderBroadPhaseData, ColliderChanges,
46
ColliderFlags, ColliderMassProps, ColliderMaterial, ColliderParent, ColliderPosition,
@@ -10,10 +12,8 @@ use crate::pipeline::{ActiveEvents, ActiveHooks};
1012
use crate::prelude::ColliderEnabled;
1113
use na::Unit;
1214
use parry::bounding_volume::{Aabb, BoundingVolume};
13-
use parry::shape::{Shape, TriMeshBuilderError, TriMeshFlags};
14-
15-
#[cfg(feature = "dim3")]
16-
use crate::geometry::HeightFieldFlags;
15+
use parry::shape::{Shape, TriMeshBuilderError, TriMeshFlags, VoxelPrimitiveGeometry};
16+
use parry::transformation::voxelization::FillMode;
1717

1818
#[cfg_attr(feature = "serde-serialize", derive(Serialize, Deserialize))]
1919
#[derive(Clone, Debug)]
@@ -573,6 +573,36 @@ impl ColliderBuilder {
573573
Self::new(SharedShape::halfspace(outward_normal))
574574
}
575575

576+
/// Initializes a collider made of voxels.
577+
///
578+
/// Each voxel has the size `voxel_size` and centers given by `centers`.
579+
/// The `primitive_geometry` controls the behavior of collision detection at voxels boundaries.
580+
pub fn voxels(
581+
primitive_geometry: VoxelPrimitiveGeometry,
582+
centers: &[Point<Real>],
583+
voxel_size: Real,
584+
) -> Self {
585+
Self::new(SharedShape::voxels(primitive_geometry, centers, voxel_size))
586+
}
587+
588+
/// Initializes a voxels obtained from the decomposition of the given trimesh (in 3D)
589+
/// or polyline (in 2D) into voxelized convex parts.
590+
pub fn voxelized_mesh(
591+
primitive_geometry: VoxelPrimitiveGeometry,
592+
vertices: &[Point<Real>],
593+
indices: &[[u32; DIM]],
594+
voxel_size: Real,
595+
fill_mode: FillMode,
596+
) -> Self {
597+
Self::new(SharedShape::voxelized_mesh(
598+
primitive_geometry,
599+
vertices,
600+
indices,
601+
voxel_size,
602+
fill_mode,
603+
))
604+
}
605+
576606
/// Initialize a new collider builder with a cylindrical shape defined by its half-height
577607
/// (along the Y axis) and its radius.
578608
#[cfg(feature = "dim3")]

src/geometry/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ pub use self::narrow_phase::NarrowPhase;
1717

1818
pub use parry::bounding_volume::BoundingVolume;
1919
pub use parry::query::{PointQuery, PointQueryWithLocation, RayCast, TrackedContact};
20-
pub use parry::shape::SharedShape;
20+
pub use parry::shape::{SharedShape, VoxelPrimitiveGeometry, VoxelState, VoxelType, Voxels};
2121

2222
use crate::math::{Real, Vector};
2323

0 commit comments

Comments
 (0)