binary-greedy-meshing
Originally a port of Binary Greedy Meshing v2 to Rust, with additional improvements such as support for transparent blocks.
How to use
This crate is used in the Bevy voxel game Riverbed, you can check out the code for usage examples.
Minimal example
use binary_greedy_meshing as bgm;
use BTreeSet;
What to do with mesh_data.quads
mesh_data.quads
is a [Vec<u64>; 6]
, 1 Vec per face type, each u64 encoding all the information of a quad in the following manner:
| | | | | x
The face groups correspond to Up, Down, Right, Left, Front, Back, in this order. (assuming right handed Y up)
The fastest way of rendering quads is using instancing (check this video to learn more about the topic), but if it's not available you can still convert the quads to vertices and indices making a regular mesh, see this Riverbed files for an example of this:
- src/render/mesh_utils.rs for Face+Quad => vertices conversion
- src/render/mesh_chunks.rs for the rest of the meshing code (+ LOD)
Benchmarks
running cargo bench
on AMD Ryzen 5 5500 3.60 GHz:
- "fast_mesh" with opaque voxels only: 60 µs
- "mesh" with opaque voxels only: 300 µs
- "fast_mesh" with opaque & transparents voxels: 85 µs
- "mesh" with opaque & transparents voxels: 310 µs
This is in line with the 50-200μs performance range reported from the original C version of the library (which doesn't yet support transparency).
The meshing is also ~30x faster than block-mesh-rs which took ~3ms to greedy mesh a chunk on my machine.
chunk sizes are 623 (643 with padding), this crate doesn't support other sizes.