pub struct Voxels { /* private fields */ }Expand description
A shape made of axis-aligned, uniformly sized, cubes (aka. voxels).
This shape is specialized to handle voxel worlds and voxelized obojects efficiently why ensuring that collision-detection isn’t affected by the so-called “internal edges problem” that can create artifacts when another object rolls or slides against a flat voxelized surface.
The internal storage is compact (but not sparse at the moment), storing only one byte per voxel in the allowed domain. This has a generally smaller memory footprint than a mesh representation of the voxels.
Implementations§
Source§impl Voxels
impl Voxels
Sourcepub fn bounding_sphere(&self, pos: &Isometry<f32>) -> BoundingSphere
pub fn bounding_sphere(&self, pos: &Isometry<f32>) -> BoundingSphere
Computes the world-space bounding sphere of this set of voxels, transformed by pos.
Sourcepub fn local_bounding_sphere(&self) -> BoundingSphere
pub fn local_bounding_sphere(&self) -> BoundingSphere
Computes the local-space bounding sphere of this set of voxels.
Source§impl Voxels
impl Voxels
Sourcepub fn new(voxel_size: Vector<f32>, grid_coordinates: &[Point<i32>]) -> Self
pub fn new(voxel_size: Vector<f32>, grid_coordinates: &[Point<i32>]) -> Self
Initializes a voxel shapes from the voxels grid coordinates.
Each voxel will have its bottom-left-back corner located at
grid_coordinates * voxel_size; and its center at (grid_coordinates + 0.5) * voxel_size.
Sourcepub fn from_points(voxel_size: Vector<f32>, points: &[Point<f32>]) -> Self
pub fn from_points(voxel_size: Vector<f32>, points: &[Point<f32>]) -> Self
Computes a voxels shape from the set of points.
The points are mapped to a regular grid centered at the provided point with smallest
coordinates, and with grid cell size equal to scale. It is OK if multiple points
fall into the same grid cell.
Sourcepub fn domain(&self) -> [Point<i32>; 2]
pub fn domain(&self) -> [Point<i32>; 2]
The semi-open range of voxels in shape.
This provides conservative bounds on the range of voxel indices that might be set to filled.
Sourcepub fn voxel_size(&self) -> Vector<f32>
pub fn voxel_size(&self) -> Vector<f32>
The size of each voxel part this Voxels shape.
Sourcepub fn chunk_ref(&self, chunk_id: u32) -> VoxelsChunkRef<'_>
pub fn chunk_ref(&self, chunk_id: u32) -> VoxelsChunkRef<'_>
A reference to the chunk with id chunk_id.
Panics if the chunk doesn’t exist.
Sourcepub fn voxel_aabb(&self, key: Point<i32>) -> Aabb
pub fn voxel_aabb(&self, key: Point<i32>) -> Aabb
The AABB of the voxel with the given quantized key.
Sourcepub fn voxel_state(&self, key: Point<i32>) -> Option<VoxelState>
pub fn voxel_state(&self, key: Point<i32>) -> Option<VoxelState>
Returns the state of a given voxel.
Sourcepub fn voxel_at_point(&self, point: Point<f32>) -> Point<i32>
pub fn voxel_at_point(&self, point: Point<f32>) -> Point<i32>
Calculates the grid coordinates of the voxel containing the given point, regardless
of whether this voxel is filled oor empty.
Sourcepub fn voxel_at_flat_id(&self, id: u32) -> Option<Point<i32>>
pub fn voxel_at_flat_id(&self, id: u32) -> Option<Point<i32>>
Gets the voxel at the given flat voxel index.
Sourcepub fn voxel_range_intersecting_local_aabb(
&self,
aabb: &Aabb,
) -> [Point<i32>; 2]
pub fn voxel_range_intersecting_local_aabb( &self, aabb: &Aabb, ) -> [Point<i32>; 2]
The range of grid coordinates of voxels intersecting the given AABB.
The returned range covers both empty and non-empty voxels, and is not limited to the
bounds defined by Self::domain.
The range is semi, open, i.e., the range along each dimension i is understood as
the semi-open interval: range[0][i]..range[1][i].
Sourcepub fn voxel_range_aabb(&self, mins: Point<i32>, maxs: Point<i32>) -> Aabb
pub fn voxel_range_aabb(&self, mins: Point<i32>, maxs: Point<i32>) -> Aabb
The AABB of a given range of voxels.
The AABB is computed independently of Self::domain and independently of whether
the voxels contained within are empty or not.
Sourcepub fn align_aabb_to_grid(&self, aabb: &Aabb) -> Aabb
pub fn align_aabb_to_grid(&self, aabb: &Aabb) -> Aabb
Aligns the given AABB with the voxelized grid.
The aligned is calculated such that the returned AABB has corners lying at the grid
intersections (i.e. matches voxel corners) and fully contains the input aabb.
Sourcepub fn voxels_intersecting_local_aabb(
&self,
aabb: &Aabb,
) -> impl Iterator<Item = VoxelData> + '_
pub fn voxels_intersecting_local_aabb( &self, aabb: &Aabb, ) -> impl Iterator<Item = VoxelData> + '_
Iterates through every voxel intersecting the given aabb.
Returns the voxel’s linearized id, center, and state.
Sourcepub fn voxels(&self) -> impl Iterator<Item = VoxelData> + '_
pub fn voxels(&self) -> impl Iterator<Item = VoxelData> + '_
The center point of all the voxels in this shape (including empty ones).
The voxel data associated to each center is provided to determine what kind of voxel it is (and, in particular, if it is empty or full).
Sourcepub fn voxels_in_range(
&self,
mins: Point<i32>,
maxs: Point<i32>,
) -> impl Iterator<Item = VoxelData> + '_
pub fn voxels_in_range( &self, mins: Point<i32>, maxs: Point<i32>, ) -> impl Iterator<Item = VoxelData> + '_
Iterate through the data of all the voxels within the given (semi-open) voxel grid indices.
Note that this yields both empty and non-empty voxels within the range. This does not
include any voxel that falls outside Self::domain.
Sourcepub fn linear_index(&self, voxel_key: Point<i32>) -> Option<VoxelIndex>
pub fn linear_index(&self, voxel_key: Point<i32>) -> Option<VoxelIndex>
The linearized index associated to the given voxel key.
Source§impl Voxels
impl Voxels
Sourcepub fn set_voxel_size(&mut self, new_size: Vector<f32>)
pub fn set_voxel_size(&mut self, new_size: Vector<f32>)
Sets the size of each voxel along each local coordinate axis.
Since the internal spatial acceleration structure needs to be updated, this
operation runs in O(n) time, where n is the number of voxels.
Sourcepub fn set_voxel(&mut self, key: Point<i32>, is_filled: bool) -> VoxelState
pub fn set_voxel(&mut self, key: Point<i32>, is_filled: bool) -> VoxelState
Inserts or remove a voxel from this shape.
Return the previous VoxelState of this voxel.
Sourcepub fn crop(&mut self, domain_mins: Point<i32>, domain_maxs: Point<i32>)
pub fn crop(&mut self, domain_mins: Point<i32>, domain_maxs: Point<i32>)
Crops in-place the voxel shape with a rectangular domain.
This removes every voxels out of the [domain_mins, domain_maxs] bounds.
Sourcepub fn cropped(
&self,
domain_mins: Point<i32>,
domain_maxs: Point<i32>,
) -> Option<Self>
pub fn cropped( &self, domain_mins: Point<i32>, domain_maxs: Point<i32>, ) -> Option<Self>
Returns a cropped version of this voxel shape with a rectangular domain.
This removes every voxels out of the [domain_mins, domain_maxs] bounds.
Sourcepub fn split_with_box(&self, aabb: &Aabb) -> (Option<Self>, Option<Self>)
pub fn split_with_box(&self, aabb: &Aabb) -> (Option<Self>, Option<Self>)
Splits this voxels shape into two subshapes.
The first subshape contains all the voxels which centers are inside the aabb.
The second subshape contains all the remaining voxels.
Source§impl Voxels
impl Voxels
Sourcepub fn propagate_voxel_change(
&mut self,
other: &mut Self,
voxel: Point<i32>,
origin_shift: Vector<i32>,
)
pub fn propagate_voxel_change( &mut self, other: &mut Self, voxel: Point<i32>, origin_shift: Vector<i32>, )
Merges voxel state (neighborhood) information of a given voxel (and all its neighbors)
from self and other, to account for a recent change to the given voxel in self.
This is designed to be called after self was modified with Voxels::set_voxel.
This is the same as Voxels::combine_voxel_states but localized to a single voxel and its
neighbors.
Sourcepub fn combine_voxel_states(
&mut self,
other: &mut Self,
origin_shift: Vector<i32>,
)
pub fn combine_voxel_states( &mut self, other: &mut Self, origin_shift: Vector<i32>, )
Merges voxel state (neighborhood) information of each voxel from self and other.
This allows each voxel from one shape to be aware of the presence of neighbors belonging to the other so that collision detection is capable of transitioning between the boundaries of one shape to the other without hitting an internal edge.
Both voxels shapes are assumed to have the same Self::voxel_size.
If other lives in a coordinate space with a different origin than self, then
origin_shift represents the distance (as a multiple of the voxel_size) from the origin
of self to the origin of other. Therefore, a voxel with coordinates key on other
will have coordinates key + origin_shift on self.
Source§impl Voxels
impl Voxels
Sourcepub fn total_memory_size(&self) -> usize
pub fn total_memory_size(&self) -> usize
An approximation of the memory usage (in bytes) for this struct plus the memory it allocates dynamically.
Sourcepub fn heap_memory_size(&self) -> usize
pub fn heap_memory_size(&self) -> usize
An approximation of the memory dynamically-allocated by this struct.
Trait Implementations§
Source§impl PointQuery for Voxels
impl PointQuery for Voxels
Source§fn project_local_point(&self, pt: &Point<f32>, solid: bool) -> PointProjection
fn project_local_point(&self, pt: &Point<f32>, solid: bool) -> PointProjection
self. Read moreSource§fn project_local_point_and_get_feature(
&self,
pt: &Point<f32>,
) -> (PointProjection, FeatureId)
fn project_local_point_and_get_feature( &self, pt: &Point<f32>, ) -> (PointProjection, FeatureId)
self and returns the id of the
feature the point was projected on.Source§fn project_local_point_with_max_dist(
&self,
pt: &Point<f32>,
solid: bool,
max_dist: f32,
) -> Option<PointProjection>
fn project_local_point_with_max_dist( &self, pt: &Point<f32>, solid: bool, max_dist: f32, ) -> Option<PointProjection>
self, unless the projection lies further than the given max distance. Read moreSource§fn project_point_with_max_dist(
&self,
m: &Isometry<f32>,
pt: &Point<f32>,
solid: bool,
max_dist: f32,
) -> Option<PointProjection>
fn project_point_with_max_dist( &self, m: &Isometry<f32>, pt: &Point<f32>, solid: bool, max_dist: f32, ) -> Option<PointProjection>
self transformed by m, unless the projection lies further than the given max distance.Source§fn distance_to_local_point(&self, pt: &Point<f32>, solid: bool) -> f32
fn distance_to_local_point(&self, pt: &Point<f32>, solid: bool) -> f32
self.Source§fn contains_local_point(&self, pt: &Point<f32>) -> bool
fn contains_local_point(&self, pt: &Point<f32>) -> bool
self.Source§fn project_point(
&self,
m: &Isometry<f32>,
pt: &Point<f32>,
solid: bool,
) -> PointProjection
fn project_point( &self, m: &Isometry<f32>, pt: &Point<f32>, solid: bool, ) -> PointProjection
self transformed by m.Source§fn distance_to_point(
&self,
m: &Isometry<f32>,
pt: &Point<f32>,
solid: bool,
) -> f32
fn distance_to_point( &self, m: &Isometry<f32>, pt: &Point<f32>, solid: bool, ) -> f32
self transformed by m.Source§fn project_point_and_get_feature(
&self,
m: &Isometry<f32>,
pt: &Point<f32>,
) -> (PointProjection, FeatureId)
fn project_point_and_get_feature( &self, m: &Isometry<f32>, pt: &Point<f32>, ) -> (PointProjection, FeatureId)
self transformed by m and returns the id of the
feature the point was projected on.Source§impl RayCast for Voxels
impl RayCast for Voxels
Source§fn cast_local_ray_and_get_normal(
&self,
ray: &Ray,
max_time_of_impact: f32,
solid: bool,
) -> Option<RayIntersection>
fn cast_local_ray_and_get_normal( &self, ray: &Ray, max_time_of_impact: f32, solid: bool, ) -> Option<RayIntersection>
Source§fn cast_local_ray(
&self,
ray: &Ray,
max_time_of_impact: f32,
solid: bool,
) -> Option<f32>
fn cast_local_ray( &self, ray: &Ray, max_time_of_impact: f32, solid: bool, ) -> Option<f32>
Source§fn intersects_local_ray(&self, ray: &Ray, max_time_of_impact: f32) -> bool
fn intersects_local_ray(&self, ray: &Ray, max_time_of_impact: f32) -> bool
Source§fn cast_ray(
&self,
m: &Isometry<f32>,
ray: &Ray,
max_time_of_impact: f32,
solid: bool,
) -> Option<f32>
fn cast_ray( &self, m: &Isometry<f32>, ray: &Ray, max_time_of_impact: f32, solid: bool, ) -> Option<f32>
Source§fn cast_ray_and_get_normal(
&self,
m: &Isometry<f32>,
ray: &Ray,
max_time_of_impact: f32,
solid: bool,
) -> Option<RayIntersection>
fn cast_ray_and_get_normal( &self, m: &Isometry<f32>, ray: &Ray, max_time_of_impact: f32, solid: bool, ) -> Option<RayIntersection>
Source§impl Shape for Voxels
Available on crate feature alloc only.
impl Shape for Voxels
alloc only.Source§fn compute_local_aabb(&self) -> Aabb
fn compute_local_aabb(&self) -> Aabb
Aabb of this shape.Source§fn compute_local_bounding_sphere(&self) -> BoundingSphere
fn compute_local_bounding_sphere(&self) -> BoundingSphere
Source§fn scale_dyn(
&self,
scale: &Vector<f32>,
_num_subdivisions: u32,
) -> Option<Box<dyn Shape>>
fn scale_dyn( &self, scale: &Vector<f32>, _num_subdivisions: u32, ) -> Option<Box<dyn Shape>>
scale into a boxed trait-object. Read moreSource§fn mass_properties(&self, density: f32) -> MassProperties
fn mass_properties(&self, density: f32) -> MassProperties
Source§fn shape_type(&self) -> ShapeType
fn shape_type(&self) -> ShapeType
Source§fn as_typed_shape(&self) -> TypedShape<'_>
fn as_typed_shape(&self) -> TypedShape<'_>
fn ccd_thickness(&self) -> f32
fn ccd_angular_thickness(&self) -> f32
Source§fn clone_box(&self) -> Box<dyn Shape>
fn clone_box(&self) -> Box<dyn Shape>
clone_dynSource§fn compute_aabb(&self, position: &Isometry<f32>) -> Aabb
fn compute_aabb(&self, position: &Isometry<f32>) -> Aabb
Aabb of this shape with the given position.Source§fn compute_bounding_sphere(&self, position: &Isometry<f32>) -> BoundingSphere
fn compute_bounding_sphere(&self, position: &Isometry<f32>) -> BoundingSphere
Source§fn as_support_map(&self) -> Option<&dyn SupportMap>
fn as_support_map(&self) -> Option<&dyn SupportMap>
fn as_composite_shape(&self) -> Option<&dyn CompositeShape>
Source§fn as_polygonal_feature_map(&self) -> Option<(&dyn PolygonalFeatureMap, f32)>
fn as_polygonal_feature_map(&self) -> Option<(&dyn PolygonalFeatureMap, f32)>
Auto Trait Implementations§
impl Freeze for Voxels
impl RefUnwindSafe for Voxels
impl Send for Voxels
impl Sync for Voxels
impl Unpin for Voxels
impl UnwindSafe for Voxels
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>, which can then be
downcast into Box<dyn ConcreteType> where ConcreteType implements Trait.Source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait> (where Trait: Downcast) to Rc<Any>, which can then be further
downcast into Rc<ConcreteType> where ConcreteType implements Trait.Source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.Source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.Source§impl<T> DowncastSend for T
impl<T> DowncastSend for T
Source§impl<T> DowncastSync for T
impl<T> DowncastSync for T
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
Source§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
self from the equivalent element of its
superset. Read moreSource§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
self is actually part of its subset T (and can be converted to it).Source§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
self.to_subset but without any property checks. Always succeeds.Source§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
self to the equivalent element of its superset.