• Stars
    star
    195
  • Rank 199,374 (Top 4 %)
  • Language
    Rust
  • License
    MIT License
  • Created about 3 years ago
  • Updated 7 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Generate voxel block meshes in Rust.

block-mesh

Crates.io Docs.rs

Fast algorithms for generating voxel block meshes.

Mesh Examples

Two algorithms are included:

  • visible_block_faces: very fast but suboptimal meshes
  • greedy_quads: not quite as fast, but far fewer triangles are generated

Benchmarks show that visible_block_faces generates about 40 million quads per second on a single core of a 2.5 GHz Intel Core i7. Assuming spherical input data, greedy_quads can generate a more optimal version of the same mesh with 1/3 of the quads, but it takes about 3 times longer. To run the benchmarks yourself, cd bench/ && cargo bench.

Example Code

use block_mesh::ndshape::{ConstShape, ConstShape3u32};
use block_mesh::{greedy_quads, GreedyQuadsBuffer, MergeVoxel, Voxel, VoxelVisibility, RIGHT_HANDED_Y_UP_CONFIG};

#[derive(Clone, Copy, Eq, PartialEq)]
struct BoolVoxel(bool);

const EMPTY: BoolVoxel = BoolVoxel(false);
const FULL: BoolVoxel = BoolVoxel(true);

impl Voxel for BoolVoxel {
    fn get_visibility(&self) -> VoxelVisibility {
        if *self == EMPTY {
            VoxelVisibility::Empty
        } else {
            VoxelVisibility::Opaque
        }
    }
}

impl MergeVoxel for BoolVoxel {
    type MergeValue = Self;
    type MergeValueFacingNeighbour = Self;

    fn merge_value(&self) -> Self::MergeValue {
        *self
    }

    fn merge_value_facing_neighbour(&self) -> Self::MergeValueFacingNeighbour {
        *self
    }
}

// A 16^3 chunk with 1-voxel boundary padding.
type ChunkShape = ConstShape3u32<18, 18, 18>;

// This chunk will cover just a single octant of a sphere SDF (radius 15).
let mut voxels = [EMPTY; ChunkShape::SIZE as usize];
for i in 0..ChunkShape::SIZE {
    let [x, y, z] = ChunkShape::delinearize(i);
    voxels[i as usize] = if ((x * x + y * y + z * z) as f32).sqrt() < 15.0 {
        FULL
    } else {
        EMPTY
    };
}

let mut buffer = GreedyQuadsBuffer::new(voxels.len());
greedy_quads(
    &voxels,
    &ChunkShape {},
    [0; 3],
    [17; 3],
    &RIGHT_HANDED_Y_UP_CONFIG.faces,
    &mut buffer
);

// Some quads were generated.
assert!(buffer.quads.num_quads() > 0);

License: MIT OR Apache-2.0

More Repositories

1

building-blocks

A voxel library for real-time applications.
Rust
367
star
2

smooth-bevy-cameras

Bevy camera controllers with buttery, exponential smoothing.
Rust
284
star
3

fast-surface-nets-rs

A fast isosurface extraction algorithm.
Rust
100
star
4

feldspar

Procedural voxel worlds for Bevy Engine.
Rust
70
star
5

grid-tree-rs

Pixel quadtrees and voxel octrees
Rust
47
star
6

bevy_triplanar_splatting

Triplanar Mapping and Material Blending for Bevy Engine
WGSL
28
star
7

bevy_metrics_dashboard

bevy + metrics + egui_plot
Rust
21
star
8

building-blocks-editor

Voxel map editor using building-blocks and bevy.
Rust
17
star
9

bevy_rider

Classic Line Rider implemented with the Bevy engine and Rapier 2D.
Rust
17
star
10

ilattice3

Data types, structures, and algorithms for 3D integer lattices (voxels)
Rust
16
star
11

height-mesh-rs

A small crate to generate a 3D mesh from a 2D heightmap.
Rust
16
star
12

ndshape-rs

Linearization of N-dimensional array indices.
Rust
15
star
13

ilattice-rs

Generic math on integer lattices
Rust
9
star
14

ilattice3-mesh

Meshing algorithms for ilattice3.
Rust
9
star
15

grid-ray-rs

Rust implementation of Amantides and Woo algorithm for casting a ray through pixels or voxels.
Rust
8
star
16

rkyv_impl

Attribute macro for implementing methods on both Foo and ArchivedFoo.
Rust
8
star
17

feldspar-editor

A level editor for the Feldspar voxel plugin.
Rust
7
star
18

sled-snapshots

Incremental backups of sled trees.
Rust
7
star
19

octree_dual_contour

Rust
6
star
20

projectris

Shadow Tetris.
Rust
6
star
21

trashbot

Autonomous trash disposal.
C++
6
star
22

mxnet-neural-style

Implementation of Gatys, Ecker, and Bethge's Neural Style algorithm, made with MXNet's Julia interface.
Julia
5
star
23

legion-task

Fork-join multitasking for Legion ECS.
Rust
5
star
24

specs-task

Fork-join multitasking for SPECS ECS
Rust
5
star
25

ndcopy-rs

N-dimensional array memcpy.
Rust
5
star
26

grid-db-rs

Quadtree and octree databases built on sled.
Rust
5
star
27

mmap-cache-rs

A read-only, memory-mapped cache.
Rust
3
star
28

ilattice3-wfc

Wave Function Collapse for ilattice3
Rust
3
star
29

material-converter

Easily harvest free PBR materials from the Internet and convert them into the material format you need.
Rust
2
star
30

megadodge_mayhem

Bevy Jam 4. Command an army of dodgeball players.
Rust
1
star
31

wgpu-isosurface

Rust
1
star
32

kv-par-merge-sort-rs

Sort (key, value) data sets that don't fit in memory
Rust
1
star
33

qef

3D quadric error functions in Rust
Rust
1
star
34

dotfiles

My Unix user configuration.
Shell
1
star
35

nocturne

A cross-platform, MIDI-controlled music synthesizer written in Rust.
Rust
1
star