Struct Voxels

Source
pub struct Voxels { /* private fields */ }
Expand description

A shape made of axis-aligned, uniformly sized cubes (aka. voxels).

§What are Voxels?

Voxels (volumetric pixels) are 3D cubes (or 2D squares) arranged on a regular grid. Think of them as 3D building blocks, like LEGO bricks or Minecraft blocks. Each voxel has:

  • A position on an integer grid (e.g., (0, 0, 0), (1, 2, 3))
  • A uniform size (e.g., 1.0 × 1.0 × 1.0 meters)
  • A state: filled (solid) or empty (air)

§When to Use Voxels?

Voxels are ideal for:

  • Minecraft-style worlds: Block-based terrain and structures
  • Destructible environments: Easy to add/remove individual blocks
  • Procedural generation: Grid-based algorithms for caves, terrain, dungeons
  • Volumetric data: Medical imaging, scientific simulations
  • Retro aesthetics: Pixel art style in 3D

Voxels may NOT be ideal for:

  • Smooth organic shapes (use meshes instead)
  • Very large sparse worlds (consider octrees or chunk-based systems)
  • Scenes requiring fine geometric detail at all scales

§The Internal Edges Problem

When an object slides across a flat surface made of voxels, it can snag on the edges between adjacent voxels, causing jerky motion. Parry’s Voxels shape solves this by tracking neighbor relationships: it knows which voxel faces are internal (adjacent to another voxel) vs external (exposed to air), allowing smooth collision response.

§Memory Efficiency

The internal storage uses sparse chunks, storing only one byte per voxel for neighborhood information. Empty regions consume minimal memory. This is much more efficient than storing a triangle mesh representation of all voxel surfaces.

§Examples

§Basic Usage: Creating a Voxel Shape

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

// Create a simple 3×3×3 cube of voxels
let voxel_size = Vector3::new(1.0, 1.0, 1.0);
let mut coords = Vec::new();
for x in 0..3 {
    for y in 0..3 {
        for z in 0..3 {
            coords.push(Point3::new(x, y, z));
        }
    }
}

let voxels = Voxels::new(voxel_size, &coords);
println!("Created voxel shape with {} voxels", coords.len());

§Creating Voxels from World-Space Points

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

// Sample points in world space (e.g., from a point cloud)
let points = vec![
    Point3::new(0.1, 0.2, 0.3),
    Point3::new(1.5, 2.1, 3.7),
    Point3::new(0.8, 0.9, 1.2),
];

// Create voxels with 0.5 unit size - nearby points merge into same voxel
let voxels = Voxels::from_points(Vector3::new(0.5, 0.5, 0.5), &points);
println!("Created voxel shape from {} points", points.len());

§Querying Voxel State

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)],
);

// Check if a specific grid position is filled
if let Some(state) = voxels.voxel_state(Point3::new(0, 0, 0)) {
    println!("Voxel is filled!");
    println!("Type: {:?}", state.voxel_type());
    println!("Free faces: {:?}", state.free_faces());
} else {
    println!("Voxel is empty or outside the domain");
}

// Convert world-space point to grid coordinates
let world_point = Point3::new(1.3, 0.7, 0.2);
let grid_coord = voxels.voxel_at_point(world_point);
println!("Point at {:?} is in voxel {:?}", world_point, grid_coord);

§Iterating Through Voxels

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

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

// Iterate through all non-empty voxels
for voxel in voxels.voxels() {
    if !voxel.state.is_empty() {
        println!("Voxel at grid {:?}, world center {:?}",
                 voxel.grid_coords, voxel.center);
    }
}

§Modifying Voxels Dynamically

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

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

// Add a new voxel
voxels.set_voxel(Point3::new(1, 0, 0), true);

// Remove a voxel
voxels.set_voxel(Point3::new(0, 0, 0), false);

// Check the result
assert!(voxels.voxel_state(Point3::new(0, 0, 0)).unwrap().is_empty());
assert!(!voxels.voxel_state(Point3::new(1, 0, 0)).unwrap().is_empty());

§Spatial Queries

use parry3d::shape::Voxels;
use parry3d::bounding_volume::Aabb;
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), Point3::new(2, 0, 0)],
);

// Find voxels intersecting an AABB
let query_aabb = Aabb::new(Point3::new(-0.5, -0.5, -0.5), Point3::new(1.5, 1.5, 1.5));
let count = voxels.voxels_intersecting_local_aabb(&query_aabb)
    .filter(|v| !v.state.is_empty())
    .count();
println!("Found {} voxels in AABB", count);

// Get the overall domain bounds
let [mins, maxs] = voxels.domain();
println!("Voxel grid spans from {:?} to {:?}", mins, maxs);

§See Also

Implementations§

Source§

impl Voxels

Source

pub fn aabb(&self, pos: &Isometry<f32>) -> Aabb

Computes the world-space Aabb of this set of voxels, transformed by pos.

Source

pub fn local_aabb(&self) -> Aabb

Computes the local-space Aabb of this set of voxels.

Source§

impl Voxels

Source

pub fn bounding_sphere(&self, pos: &Isometry<f32>) -> BoundingSphere

Computes the world-space bounding sphere of this set of voxels, transformed by pos.

Source

pub fn local_bounding_sphere(&self) -> BoundingSphere

Computes the local-space bounding sphere of this set of voxels.

Source§

impl Voxels

Source

pub fn new(voxel_size: Vector<f32>, grid_coordinates: &[Point<i32>]) -> Self

Initializes a voxel shape from grid coordinates.

This is the primary constructor for creating a Voxels shape. You provide:

  • voxel_size: The physical dimensions of each voxel (e.g., 1.0 × 1.0 × 1.0 meters)
  • grid_coordinates: Integer grid positions for each filled voxel
§Coordinate System

Each voxel with grid coordinates (x, y, z) will be positioned such that:

  • Its minimum corner (bottom-left-back) is at (x, y, z) * voxel_size
  • Its center is at ((x, y, z) + 0.5) * voxel_size
  • Its maximum corner is at ((x, y, z) + 1) * voxel_size

For example, with voxel_size = 2.0 and grid coord (1, 0, 0):

  • Minimum corner: (2.0, 0.0, 0.0)
  • Center: (3.0, 1.0, 1.0)
  • Maximum corner: (4.0, 2.0, 2.0)
§Examples
use parry3d::shape::Voxels;
use nalgebra::{Point3, Vector3};

// Create a 2×2×2 cube of voxels with 1.0 unit size
let voxels = Voxels::new(
    Vector3::new(1.0, 1.0, 1.0),
    &[
        Point3::new(0, 0, 0), Point3::new(1, 0, 0),
        Point3::new(0, 1, 0), Point3::new(1, 1, 0),
        Point3::new(0, 0, 1), Point3::new(1, 0, 1),
        Point3::new(0, 1, 1), Point3::new(1, 1, 1),
    ],
);

// Verify the first voxel's center position
let center = voxels.voxel_center(Point3::new(0, 0, 0));
assert_eq!(center, Point3::new(0.5, 0.5, 0.5));
use parry3d::shape::Voxels;
use nalgebra::{Point3, Vector3};

// Create a line of voxels along the X axis
let voxels = Voxels::new(
    Vector3::new(0.5, 0.5, 0.5),
    &[Point3::new(0, 0, 0), Point3::new(1, 0, 0), Point3::new(2, 0, 0)],
);

// Query the domain (bounding grid coordinates)
// Note: domain is aligned to internal chunk boundaries for efficiency
let [mins, maxs] = voxels.domain();
assert_eq!(mins, Point3::new(0, 0, 0));
// maxs will be chunk-aligned (chunks are 8x8x8), so it includes more space
assert!(maxs.x >= 3 && maxs.y >= 1 && maxs.z >= 1);
Source

pub fn from_points(voxel_size: Vector<f32>, points: &[Point<f32>]) -> Self

Computes a voxel shape from a set of world-space points.

This constructor converts continuous world-space coordinates into discrete grid coordinates by snapping each point to the voxel grid. Multiple points can map to the same voxel.

§How it Works

Each point is converted to grid coordinates by:

  1. Dividing the point’s coordinates by voxel_size
  2. Taking the floor to get integer grid coordinates
  3. Removing duplicates (multiple points in the same voxel become one voxel)

For example, with voxel_size = 1.0:

  • Point (0.3, 0.7, 0.9) → Grid (0, 0, 0)
  • Point (1.1, 0.2, 0.5) → Grid (1, 0, 0)
  • Point (0.9, 0.1, 0.8) → Grid (0, 0, 0) (merges with first)
§Use Cases
  • Converting point clouds into voxel representations
  • Creating voxel shapes from scattered data
  • Simplifying complex point sets into uniform grids
§Examples
use parry3d::shape::Voxels;
use nalgebra::{Point3, Vector3};

// Sample points in world space
let points = vec![
    Point3::new(0.1, 0.2, 0.3),   // → Grid (0, 0, 0)
    Point3::new(0.7, 0.8, 0.9),   // → Grid (0, 0, 0) - same voxel!
    Point3::new(1.2, 0.3, 0.1),   // → Grid (1, 0, 0)
    Point3::new(0.5, 1.5, 0.2),   // → Grid (0, 1, 0)
];

// Create voxels with 1.0 unit size
let voxels = Voxels::from_points(Vector3::new(1.0, 1.0, 1.0), &points);

// Only 3 unique voxels created (first two points merged)
let filled_count = voxels.voxels()
    .filter(|v| !v.state.is_empty())
    .count();
assert_eq!(filled_count, 3);
use parry3d::shape::Voxels;
use nalgebra::{Point3, Vector3};

// Higher resolution voxelization
let points = vec![
    Point3::origin(),
    Point3::new(1.0, 1.0, 1.0),
];

// Smaller voxels = finer detail
let voxels = Voxels::from_points(Vector3::new(0.5, 0.5, 0.5), &points);

// First point at grid (0,0,0), second at grid (2,2,2) due to smaller voxel size
assert!(voxels.voxel_state(Point3::new(0, 0, 0)).is_some());
assert!(voxels.voxel_state(Point3::new(2, 2, 2)).is_some());
Source

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

The semi-open range of grid coordinates covered by this voxel shape.

Returns [mins, maxs] where the domain is the semi-open interval [mins, maxs), meaning mins is included but maxs is excluded. This provides conservative bounds on the range of voxel grid coordinates that might be filled.

This is useful for:

  • Determining the spatial extent of the voxel shape
  • Pre-allocating storage for processing voxels
  • Clipping operations to valid regions
§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(2, 3, 1)],
);

let [mins, maxs] = voxels.domain();
assert_eq!(mins, Point3::new(0, 0, 0));
// Domain is conservative and chunk-aligned
assert!(maxs.x > 2 && maxs.y > 3 && maxs.z > 1);

// Iterate through filled voxels (more efficient than iterating domain)
for voxel in voxels.voxels() {
    if !voxel.state.is_empty() {
        println!("Filled voxel at {:?}", voxel.grid_coords);
    }
}
Source

pub fn voxel_size(&self) -> Vector<f32>

The size of each voxel part this Voxels shape.

Source

pub fn scaled(self, scale: &Vector<f32>) -> Self

Scale this shape.

Source

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.

Source

pub fn voxel_aabb(&self, key: Point<i32>) -> Aabb

The AABB of the voxel with the given quantized key.

Source

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

Returns the state of the voxel at the given grid coordinates.

Returns None if the voxel doesn’t exist in this shape’s internal storage, or Some(VoxelState) containing information about whether the voxel is filled and which of its neighbors are also filled.

§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)],
);

// Query an existing voxel
if let Some(state) = voxels.voxel_state(Point3::new(0, 0, 0)) {
    assert!(!state.is_empty());
    println!("Voxel type: {:?}", state.voxel_type());
}

// Query a non-existent voxel
assert!(voxels.voxel_state(Point3::new(10, 10, 10)).is_none());
Source

pub fn voxel_at_point(&self, point: Point<f32>) -> Point<i32>

Calculates the grid coordinates of the voxel containing the given world-space point.

This conversion is independent of whether the voxel is actually filled or empty - it simply determines which grid cell the point falls into based on the voxel size.

§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)],
);

// Point in first voxel (center at 0.5, 0.5, 0.5)
assert_eq!(voxels.voxel_at_point(Point3::new(0.3, 0.7, 0.2)), Point3::new(0, 0, 0));

// Point just inside second voxel boundary
assert_eq!(voxels.voxel_at_point(Point3::new(1.0, 0.0, 0.0)), Point3::new(1, 0, 0));

// Negative coordinates work too
assert_eq!(voxels.voxel_at_point(Point3::new(-0.5, -0.5, -0.5)), Point3::new(-1, -1, -1));
use parry3d::shape::Voxels;
use nalgebra::{Point3, Vector3};

// With non-uniform voxel size
let voxels = Voxels::new(
    Vector3::new(2.0, 0.5, 1.0),
    &[],
);

// X coordinate divided by 2.0, Y by 0.5, Z by 1.0
assert_eq!(voxels.voxel_at_point(Point3::new(3.0, 1.2, 0.8)), Point3::new(1, 2, 0));
Source

pub fn voxel_at_flat_id(&self, id: u32) -> Option<Point<i32>>

Gets the voxel at the given flat voxel index.

Source

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].

Source

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.

Source

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.

Source

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.

Source

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

Source

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.

Source

pub fn linear_index(&self, voxel_key: Point<i32>) -> Option<VoxelIndex>

The linearized index associated to the given voxel key.

Source

pub fn voxel_center(&self, key: Point<i32>) -> Point<f32>

The world-space center position of the voxel with the given grid coordinates.

Returns the center point regardless of whether the voxel is actually filled.

§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)],
);

// Center of voxel at origin
assert_eq!(voxels.voxel_center(Point3::new(0, 0, 0)), Point3::new(0.5, 0.5, 0.5));

// Center of voxel at (1, 2, 3)
assert_eq!(voxels.voxel_center(Point3::new(1, 2, 3)), Point3::new(1.5, 2.5, 3.5));
Source§

impl Voxels

Source

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.

Source

pub fn set_voxel(&mut self, key: Point<i32>, is_filled: bool) -> VoxelState

Adds or removes a voxel at the specified grid coordinates.

This is the primary method for dynamically modifying a voxel shape. It can:

  • Add a new voxel by setting is_filled = true
  • Remove an existing voxel by setting is_filled = false

The method automatically updates the neighborhood information for the affected voxel and all its neighbors to maintain correct collision detection behavior.

§Returns

The previous VoxelState of the voxel before modification. This allows you to detect whether the operation actually changed anything.

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

let mut voxels = Voxels::new(Vector3::new(1.0, 1.0, 1.0), &[]);

// Add a voxel at (0, 0, 0)
let prev_state = voxels.set_voxel(Point3::new(0, 0, 0), true);
assert!(prev_state.is_empty()); // Was empty before

// Verify it was added
let state = voxels.voxel_state(Point3::new(0, 0, 0)).unwrap();
assert!(!state.is_empty());
§Removing Voxels
use parry3d::shape::Voxels;
use nalgebra::{Point3, Vector3};

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

// Remove the voxel at (0, 0, 0)
voxels.set_voxel(Point3::new(0, 0, 0), false);

// Verify it was removed
let state = voxels.voxel_state(Point3::new(0, 0, 0)).unwrap();
assert!(state.is_empty());
§Building Shapes Dynamically
use parry3d::shape::Voxels;
use nalgebra::{Point3, Vector3};

let mut voxels = Voxels::new(Vector3::new(1.0, 1.0, 1.0), &[]);

// Build a 3×3 floor
for x in 0..3 {
    for z in 0..3 {
        voxels.set_voxel(Point3::new(x, 0, z), true);
    }
}

// Count filled voxels
let filled = voxels.voxels()
    .filter(|v| !v.state.is_empty())
    .count();
assert_eq!(filled, 9);
§Detecting Changes
use parry3d::shape::Voxels;
use nalgebra::{Point3, Vector3};

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

// Try to add a voxel that already exists
let prev = voxels.set_voxel(Point3::new(0, 0, 0), true);
if !prev.is_empty() {
    println!("Voxel was already filled!");
}
Source

pub fn crop(&mut self, domain_mins: Point<i32>, domain_maxs: Point<i32>)

Crops the voxel shape in-place to a rectangular region.

Removes all voxels outside the specified grid coordinate bounds [domain_mins, domain_maxs] (inclusive on both ends). This is useful for:

  • Extracting a sub-region of a larger voxel world
  • Removing voxels outside a region of interest
  • Implementing chunk-based world management
§Examples
use parry3d::shape::Voxels;
use nalgebra::{Point3, Vector3};

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

// Keep only voxels in the range [1, 2]
voxels.crop(Point3::new(1, 0, 0), Point3::new(2, 0, 0));

// Only two voxels remain
let count = voxels.voxels()
    .filter(|v| !v.state.is_empty())
    .count();
assert_eq!(count, 2);
Source

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.

Source

pub fn split_with_box(&self, aabb: &Aabb) -> (Option<Self>, Option<Self>)

Splits this voxel shape into two separate shapes based on an AABB.

Partitions the voxels into two groups:

  • Inside: Voxels whose centers fall inside the given aabb
  • Outside: All remaining voxels

Returns (Some(inside), Some(outside)), or None for either if that partition is empty.

§Use Cases
  • Spatial partitioning for physics simulation
  • Implementing destructible objects (remove the “inside” part on explosion)
  • Chunk-based world management
  • Level-of-detail systems
§Examples
use parry3d::shape::Voxels;
use parry3d::bounding_volume::Aabb;
use nalgebra::{Point3, Vector3};

let voxels = Voxels::new(
    Vector3::new(1.0, 1.0, 1.0),
    &[
        Point3::new(0, 0, 0),  // Center at (0.5, 0.5, 0.5)
        Point3::new(2, 0, 0),  // Center at (2.5, 0.5, 0.5)
        Point3::new(4, 0, 0),  // Center at (4.5, 0.5, 0.5)
    ],
);

// Split at X = 3.0
let split_box = Aabb::new(
    Point3::new(-10.0, -10.0, -10.0),
    Point3::new(3.0, 10.0, 10.0),
);

let (inside, outside) = voxels.split_with_box(&split_box);

// First two voxels inside, last one outside
assert!(inside.is_some());
assert!(outside.is_some());
Source§

impl Voxels

Source

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.

Source

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

Source

pub fn total_memory_size(&self) -> usize

An approximation of the memory usage (in bytes) for this struct plus the memory it allocates dynamically.

Source

pub fn heap_memory_size(&self) -> usize

An approximation of the memory dynamically-allocated by this struct.

Source§

impl Voxels

Source

pub fn to_outline(&self) -> (Vec<Point<f32>>, Vec<[u32; 2]>)

Outlines this voxels shape as a set of polylines.

The outline is such that only convex edges are output in the polyline.

Source

pub fn iter_outline(&self, f: impl FnMut(Point<f32>, Point<f32>))

Outlines this voxels shape using segments.

The outline is such that only convex edges are output in the polyline.

Source§

impl Voxels

Source

pub fn to_trimesh(&self) -> (Vec<Point<f32>>, Vec<[u32; 3]>)

Computes an unoptimized mesh representation of this shape.

Each free face of each voxel will result in two triangles. No effort is made to merge adjacent triangles on large flat areas.

Trait Implementations§

Source§

impl Clone for Voxels

Source§

fn clone(&self) -> Voxels

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 Debug for Voxels

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl PointQuery for Voxels

Source§

fn project_local_point(&self, pt: &Point<f32>, solid: bool) -> PointProjection

Projects a point on self. Read more
Source§

fn project_local_point_and_get_feature( &self, pt: &Point<f32>, ) -> (PointProjection, FeatureId)

Projects a point on the boundary of 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>

Projects a point onto the shape, with a maximum distance limit. Read more
Source§

fn project_point_with_max_dist( &self, m: &Isometry<f32>, pt: &Point<f32>, solid: bool, max_dist: f32, ) -> Option<PointProjection>

Projects a point on 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

Computes the minimal distance between a point and self.
Source§

fn contains_local_point(&self, pt: &Point<f32>) -> bool

Tests if the given point is inside of self.
Source§

fn project_point( &self, m: &Isometry<f32>, pt: &Point<f32>, solid: bool, ) -> PointProjection

Projects a point on self transformed by m.
Source§

fn distance_to_point( &self, m: &Isometry<f32>, pt: &Point<f32>, solid: bool, ) -> f32

Computes the minimal distance between a point and self transformed by m.
Source§

fn project_point_and_get_feature( &self, m: &Isometry<f32>, pt: &Point<f32>, ) -> (PointProjection, FeatureId)

Projects a point on the boundary of self transformed by m and returns the id of the feature the point was projected on.
Source§

fn contains_point(&self, m: &Isometry<f32>, pt: &Point<f32>) -> bool

Tests if the given point is inside of self transformed by m.
Source§

impl RayCast for Voxels

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 Shape for Voxels

Source§

fn compute_local_aabb(&self) -> Aabb

Computes the Aabb of this shape.
Source§

fn compute_local_bounding_sphere(&self) -> BoundingSphere

Computes the bounding-sphere of this shape.
Source§

fn clone_dyn(&self) -> Box<dyn Shape>

Clones this shape into a boxed trait-object. Read more
Source§

fn scale_dyn( &self, scale: &Vector<f32>, _num_subdivisions: u32, ) -> Option<Box<dyn Shape>>

Scales this shape by scale into a boxed trait-object. Read more
Source§

fn mass_properties(&self, density: f32) -> MassProperties

Compute the mass-properties of this shape given its uniform density.
Source§

fn shape_type(&self) -> ShapeType

Gets the type tag of this shape.
Source§

fn as_typed_shape(&self) -> TypedShape<'_>

Gets the underlying shape as an enum.
Source§

fn ccd_thickness(&self) -> f32

Source§

fn ccd_angular_thickness(&self) -> f32

Source§

fn clone_box(&self) -> Box<dyn Shape>

👎Deprecated: renamed to clone_dyn
Clones this shape into a boxed trait-object. Read more
Source§

fn compute_aabb(&self, position: &Isometry<f32>) -> Aabb

Computes the Aabb of this shape with the given position.
Source§

fn compute_bounding_sphere(&self, position: &Isometry<f32>) -> BoundingSphere

Computes the bounding-sphere of this shape with the given position.
Source§

fn is_convex(&self) -> bool

Is this shape known to be convex? Read more
Source§

fn as_support_map(&self) -> Option<&dyn SupportMap>

Converts this shape into its support mapping, if it has one.
Source§

fn as_composite_shape(&self) -> Option<&dyn CompositeShape>

Source§

fn as_polygonal_feature_map(&self) -> Option<(&dyn PolygonalFeatureMap, f32)>

Converts this shape to a polygonal feature-map, if it is one.
Source§

fn feature_normal_at_point( &self, _feature: FeatureId, _point: &Point<f32>, ) -> Option<Unit<Vector<f32>>>

The shape’s normal at the given point located on a specific feature.
Source§

fn compute_swept_aabb( &self, start_pos: &Isometry<f32>, end_pos: &Isometry<f32>, ) -> Aabb

Computes the swept Aabb of this shape, i.e., the space it would occupy by moving from the given start position to the given end position.

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