binary-greedy-meshing
For now this is simply a port of Binary Greedy Meshing v2 to Rust, but API improvements are planned for the future (see issues).
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;
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)
Performance
Profiling info from Riverbed's usage of the crate on Intel(R) Xeon(R) CPU E5-1650 v3 @ 3.50GHz:
- opacity mask building: 300μs (can be cached)
- meshing + quad => vertices/index conversion: 300μs
This is in line with the 50-200μs range reported (for meshing only) by folks from the original C version of the library.
The meshing is also ~15x faster than block-mesh-rs which took ~4.5ms to greedy mesh a chunk on my machine (also tested with Riverbed);
but the comparison isn't completely fair because block-mesh-rs properly supports transparency and this crate doesn't
(although I don't expect transparency to multiply meshing time by more than x2)
chunk sizes are 623 (643 with padding), this crate doesn't support other sizes.