Struct VoxelsChunkRef

Source
pub struct VoxelsChunkRef<'a> {
    pub my_id: usize,
    pub parent: &'a Voxels,
    pub states: &'a [VoxelState; 256],
    pub key: &'a Point<i32>,
}
Expand description

A reference to a chunk of voxels within a Voxels shape.

§What is a Chunk?

To efficiently manage large voxel worlds, Parry internally divides the voxel grid into fixed-size chunks. Each chunk contains a small region of voxels (e.g., 8×8×8 in 3D or 16×16 in 2D). This chunking provides:

  • Spatial acceleration: Quick queries using a BVH of chunks
  • Memory efficiency: Empty chunks are not stored
  • Cache locality: Nearby voxels are stored together

A VoxelsChunkRef provides read-only access to a single chunk’s data, allowing you to query voxels within that chunk without iterating through the entire voxel shape.

§When to Use

You typically don’t create VoxelsChunkRef directly. Instead, you get them from:

  • Voxels::chunk_ref: Get a specific chunk by ID
  • BVH traversal for spatial queries on large voxel worlds

§Examples

use parry3d::shape::Voxels;
use nalgebra::{Point3, Vector3};

let voxels = Voxels::new(
    Vector3::new(1.0, 1.0, 1.0),
    &[Point3::new(0, 0, 0), Point3::new(1, 0, 0)],
);

// Get a chunk reference (chunk IDs come from BVH traversal)
let chunk_ref = voxels.chunk_ref(0);

// Query voxels within this chunk
for voxel in chunk_ref.voxels() {
    if !voxel.state.is_empty() {
        println!("Voxel at {:?}", voxel.grid_coords);
    }
}

// Get chunk's AABB
let aabb = chunk_ref.local_aabb();
println!("Chunk bounds: {:?}", aabb);

Fields§

§my_id: usize

The linear index of this chunk within the Voxels shape.

§parent: &'a Voxels

The voxel shape this chunk is part of.

§states: &'a [VoxelState; 256]

The fill status of each voxel from this chunk.

§key: &'a Point<i32>

The spatial index of this chunk.

Implementations§

Source§

impl<'a> VoxelsChunkRef<'a>

Source

pub fn local_aabb(&self) -> Aabb

The AABB of this chunk of voxels.

Note that this return the AABB of the whole chunk, without taking into account the fact that some voxels are empty.

Source

pub fn domain(&self) -> [Point<i32>; 2]

The domain of this chunk of voxels.

Source

pub fn voxel_at_point_unchecked(&self, pt: Point<f32>) -> Point<i32>

Returns the spatial index of the voxel containing the given point.

Source

pub fn voxel_state(&self, voxel_key: Point<i32>) -> Option<VoxelState>

The state of the voxel with key voxel_key.

Source

pub fn clamp_voxel(&self, voxel_key: Point<i32>) -> Point<i32>

Clamps the voxel_key so it is within the bounds of self.

Source

pub fn voxel_aabb_unchecked(&self, voxel_key: Point<i32>) -> Aabb

The AABB of the voxel with this key.

Returns a result even if the voxel doesn’t belong to this chunk.

Source

pub fn flat_id(&self, voxel_key: Point<i32>) -> Option<u32>

Convert a voxel index (expressed relative to the main Voxels shape, not relative to the chunk alone) into a flat index within a voxel chunk.

Returns None if the voxel isn’t part of this chunk.

Source

pub fn voxels(&self) -> impl Iterator<Item = VoxelData> + '_

Iterates through all the voxels in this chunk.

Note that this only yields non-empty voxels within the range. This does not include any voxel that falls outside Self::domain.

Source

pub fn voxels_in_range( self, mins: Point<i32>, maxs: Point<i32>, ) -> impl Iterator<Item = VoxelData> + use<'a>

Iterate through the data of all the voxels within the given (semi-open) voxel grid indices.

Note that this only yields non-empty voxels within the range. This does not include any voxel that falls outside Self::domain.

Trait Implementations§

Source§

impl<'a> Clone for VoxelsChunkRef<'a>

Source§

fn clone(&self) -> VoxelsChunkRef<'a>

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<'a> RayCast for VoxelsChunkRef<'a>

Source§

fn cast_local_ray_and_get_normal( &self, ray: &Ray, max_time_of_impact: f32, solid: bool, ) -> Option<RayIntersection>

Computes the time of impact, and normal between this transformed shape and a ray.
Source§

fn cast_local_ray( &self, ray: &Ray, max_time_of_impact: f32, solid: bool, ) -> Option<f32>

Computes the time of impact between this transform shape and a ray.
Source§

fn intersects_local_ray(&self, ray: &Ray, max_time_of_impact: f32) -> bool

Tests whether a ray intersects this transformed shape.
Source§

fn cast_ray( &self, m: &Isometry<f32>, ray: &Ray, max_time_of_impact: f32, solid: bool, ) -> Option<f32>

Computes the time of impact between this transform shape and a ray.
Source§

fn cast_ray_and_get_normal( &self, m: &Isometry<f32>, ray: &Ray, max_time_of_impact: f32, solid: bool, ) -> Option<RayIntersection>

Computes the time of impact, and normal between this transformed shape and a ray.
Source§

fn intersects_ray( &self, m: &Isometry<f32>, ray: &Ray, max_time_of_impact: f32, ) -> bool

Tests whether a ray intersects this transformed shape.
Source§

impl<'a> Copy for VoxelsChunkRef<'a>

Auto Trait Implementations§

§

impl<'a> Freeze for VoxelsChunkRef<'a>

§

impl<'a> RefUnwindSafe for VoxelsChunkRef<'a>

§

impl<'a> Send for VoxelsChunkRef<'a>

§

impl<'a> Sync for VoxelsChunkRef<'a>

§

impl<'a> Unpin for VoxelsChunkRef<'a>

§

impl<'a> UnwindSafe for VoxelsChunkRef<'a>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> Downcast for T
where T: Any,

Source§

fn into_any(self: Box<T>) -> Box<dyn Any>

Converts 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>

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

Converts &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)

Converts &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
where T: Any + Send,

Source§

fn into_any_send(self: Box<T>) -> Box<dyn Any + Send>

Converts Box<Trait> (where Trait: DowncastSend) to Box<dyn Any + Send>, which can then be downcast into Box<ConcreteType> where ConcreteType implements Trait.
Source§

impl<T> DowncastSync for T
where T: Any + Send + Sync,

Source§

fn into_any_sync(self: Box<T>) -> Box<dyn Any + Sync + Send>

Converts Box<Trait> (where Trait: DowncastSync) to Box<dyn Any + Send + Sync>, which can then be downcast into Box<ConcreteType> where ConcreteType implements Trait.
Source§

fn into_any_arc(self: Arc<T>) -> Arc<dyn Any + Sync + Send>

Converts Arc<Trait> (where Trait: DowncastSync) to Arc<Any>, which can then be downcast into Arc<ConcreteType> where ConcreteType implements Trait.
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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 more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<SS, SP> SupersetOf<SS> for SP
where SS: SubsetOf<SP>,

Source§

fn to_subset(&self) -> Option<SS>

The inverse inclusion map: attempts to construct self from the equivalent element of its superset. Read more
Source§

fn is_in_subset(&self) -> bool

Checks if self is actually part of its subset T (and can be converted to it).
Source§

fn to_subset_unchecked(&self) -> SS

Use with care! Same as self.to_subset but without any property checks. Always succeeds.
Source§

fn from_subset(element: &SS) -> SP

The inclusion map: converts self to the equivalent element of its superset.
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.