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 objects 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(
primitive_geometry: VoxelPrimitiveGeometry,
voxel_size: Vector<f32>,
grid_coordinates: &[Point<i32>],
) -> Self
pub fn new( primitive_geometry: VoxelPrimitiveGeometry, 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(
primitive_geometry: VoxelPrimitiveGeometry,
voxel_size: Vector<f32>,
points: &[Point<f32>],
) -> Self
pub fn from_points( primitive_geometry: VoxelPrimitiveGeometry, 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 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.
Sourcepub fn extents(&self) -> Vector<f32>
pub fn extents(&self) -> Vector<f32>
The extents of the total axis-aligned volume covered by this Voxels
shape.
This accounts for all the voxels reserved in the internal buffer of self
, including empty
ones.
Sourcepub fn domain_center(&self) -> Point<f32>
pub fn domain_center(&self) -> Point<f32>
The center of this shape’s domain (accounting for both empty and filled voxels).
Sourcepub fn set_voxel_size(&mut self, size: Vector<f32>)
pub fn set_voxel_size(&mut self, size: Vector<f32>)
Sets the size of each voxel along each local coordinate axis.
If Self::primitive_geometry
is VoxelPrimitiveGeometry::PseudoBall
, then all voxels
must be square, and only size.x
is taken into account for setting the size.
Sourcepub fn domain(&self) -> [&Point<i32>; 2]
pub fn domain(&self) -> [&Point<i32>; 2]
The valid semi-open range of voxel grid indices.
With let [mins, maxs] = voxels.domain();
the valid indices along the dimension i
are
all the indices in the range mins[i]..maxs[i]
(i.e. maxs[i]
is excluded).
Sourcepub fn dimensions(&self) -> Vector<u32>
pub fn dimensions(&self) -> Vector<u32>
The number of voxels along each coordinate axis.
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 primitive_geometry(&self) -> VoxelPrimitiveGeometry
pub fn primitive_geometry(&self) -> VoxelPrimitiveGeometry
The shape each voxel is assumed to have.
Sourcepub fn try_set_voxel(
&mut self,
key: Point<i32>,
is_filled: bool,
) -> Option<VoxelState>
pub fn try_set_voxel( &mut self, key: Point<i32>, is_filled: bool, ) -> Option<VoxelState>
Sets the voxel at the given grid coordinates, returning None
if it lies outside Self::domain
.
See Self::set_voxel
for a method that automatically resizes the internal
storage of self
if the key is out of the valid bounds.
Sourcepub fn set_voxel(
&mut self,
key: Point<i32>,
is_filled: bool,
) -> Option<VoxelState>
pub fn set_voxel( &mut self, key: Point<i32>, is_filled: bool, ) -> Option<VoxelState>
Inserts a voxel at the given key, even if it is out of the bounds of this shape.
If is_filed
is true
and the key lies out of the bounds on this shape, the internal
voxels storage will be resized automatically. If a resize happens, the cost of the insertion
is O(n)
where n
is the capacity of self
. If no resize happens, then the cost of
insertion is O(1)
.
Use Self::try_set_voxel
instead for a version that will be a no-op if the provided
coordinates are outside the Self::domain
, avoiding potential internal reallocations.
Sourcepub fn resize_domain(
&mut self,
domain_mins: Point<i32>,
domain_maxs: Point<i32>,
)
pub fn resize_domain( &mut self, domain_mins: Point<i32>, domain_maxs: Point<i32>, )
Set the model domain.
The domain can be smaller or larger than the current one. Voxels in any overlap between the current and new domain will be preserved.
If for any index i
, domain_maxs[i] <= domain_mins[i]
, then the new domain is invalid
and this operation will result in a no-op.
Sourcepub fn with_resized_domain(
&self,
domain_mins: Point<i32>,
domain_maxs: Point<i32>,
) -> Option<Self>
pub fn with_resized_domain( &self, domain_mins: Point<i32>, domain_maxs: Point<i32>, ) -> Option<Self>
Clone this voxels shape with a new size.
The domain can be smaller or larger than the current one. Voxels in any overlap between the current and new domain will be preserved.
If for any index i
, domain_maxs[i] <= domain_mins[i]
, then the new domain is invalid
and this operation returns None
.
Sourcepub fn is_voxel_in_bounds(&self, key: Point<i32>) -> bool
pub fn is_voxel_in_bounds(&self, key: Point<i32>) -> bool
Checks if the given key is within Self::domain
.
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>) -> VoxelState
pub fn voxel_state(&self, key: Point<i32>) -> VoxelState
Returns the state of a given voxel.
Panics if the key is out of the bounds defined by Self::domain
.
Sourcepub fn voxel_at_point_unchecked(&self, point: Point<f32>) -> Point<i32>
pub fn voxel_at_point_unchecked(&self, point: Point<f32>) -> Point<i32>
Calculates the grid coordinates of the voxel containing the given point
, regardless
of Self::domain
.
Sourcepub fn voxel_at_point(&self, pt: Point<f32>) -> Option<Point<i32>>
pub fn voxel_at_point(&self, pt: Point<f32>) -> Option<Point<i32>>
Gets the key of the voxel containing the given pt
.
Note that the returned key might address a voxel that is empty.
None
is returned if the point is out of the domain of self
.
Sourcepub fn clamp_voxel(&self, key: Point<i32>) -> Point<i32>
pub fn clamp_voxel(&self, key: Point<i32>) -> Point<i32>
Clamps an arbitrary voxel into the valid domain of self
.
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 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.
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>) -> u32
pub fn linear_index(&self, voxel_key: Point<i32>) -> u32
The linearized index associated to the given voxel key.
Sourcepub fn voxel_at_id(&self, linear_index: u32) -> Point<i32>
pub fn voxel_at_id(&self, linear_index: u32) -> Point<i32>
The key of the voxel at the given linearized index.
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
impl Shape for Voxels
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_dyn
Source§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 SimdCompositeShape>
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.