{"id":18829355,"url":"https://github.com/inspirateur/binary-greedy-meshing","last_synced_at":"2025-07-31T08:41:42.061Z","repository":{"id":250850591,"uuid":"835610704","full_name":"Inspirateur/binary-greedy-meshing","owner":"Inspirateur","description":"A port of https://github.com/cgerikj/binary-greedy-meshing to Rust.","archived":false,"fork":false,"pushed_at":"2024-12-09T14:26:23.000Z","size":55,"stargazers_count":13,"open_issues_count":3,"forks_count":5,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-04-08T22:34:39.610Z","etag":null,"topics":["greedy-meshing","meshing","voxel"],"latest_commit_sha":null,"homepage":"https://crates.io/crates/binary-greedy-meshing","language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Inspirateur.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-07-30T07:23:16.000Z","updated_at":"2025-02-16T18:45:07.000Z","dependencies_parsed_at":"2024-08-04T20:25:02.355Z","dependency_job_id":"edcc4e61-1293-4518-a219-bbe8434fc9b2","html_url":"https://github.com/Inspirateur/binary-greedy-meshing","commit_stats":null,"previous_names":["inspirateur/binary-greedy-meshing"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Inspirateur%2Fbinary-greedy-meshing","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Inspirateur%2Fbinary-greedy-meshing/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Inspirateur%2Fbinary-greedy-meshing/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Inspirateur%2Fbinary-greedy-meshing/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Inspirateur","download_url":"https://codeload.github.com/Inspirateur/binary-greedy-meshing/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248815940,"owners_count":21165987,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["greedy-meshing","meshing","voxel"],"created_at":"2024-11-08T01:44:28.051Z","updated_at":"2025-07-31T08:41:42.034Z","avatar_url":"https://github.com/Inspirateur.png","language":"Rust","funding_links":[],"categories":[],"sub_categories":[],"readme":"# binary-greedy-meshing\nOriginally a port of [Binary Greedy Meshing v2](https://github.com/cgerikj/binary-greedy-meshing) to Rust, with additional improvements such as support for transparent blocks.\n\n## How to use\nThis crate is used in the Bevy voxel game [Riverbed](https://github.com/Inspirateur/riverbed), you can check out the code for usage examples.\n\n### Minimal example\n```rust\nuse binary_greedy_meshing as bgm;\nuse std::collections::BTreeSet;\n\nfn main() {\n    // This is a flattened 3D array of u16 in ZXY order, of size 64^3 \n    // (it represents a 62^3-sized chunk that is padded with neighbor information)\n    let mut voxels = [0; bgm::CS_P3];\n    // Add 2 voxels of value \"1\" at position 0;0;0 and 0;1;0\n    voxels[bgm::pad_linearize(0, 0, 0)] = 1;\n    voxels[bgm::pad_linearize(0, 1, 0)] = 1;\n    // Add 1 voxel of value \"2\" at position 0;2;0\n    voxels[bgm::pad_linearize(0, 1, 0)] = 2;\n    // Say the value 2 is transparent\n    let transparent_blocks = BTreeSet::from([2]);\n    // Contain useful buffers that can be cached and cleared \n    // with mesh_data.clear() to avoid re-allocation\n    let mut mesher = bgm::MeshData::new();\n    // 2 methods are available for the meshing:\n    // The \"mesh\" method only takes the voxel buffer and a BTreeSet signaling the transparent values\n    // mesher.mesh(\u0026voxels, transparent_blocks);\n    // The \"fast_mesh\" method is ~4x faster\n    // but requires maintaining an opacity and transparency mask for the chunk\n    let opaque_mask = bgm::compute_opaque_mask(voxels.as_slice(), \u0026transparent_blocks);\n    let trans_mask = bgm::compute_transparent_mask(voxels.as_slice(), \u0026transparent_blocks);\n    mesher.fast_mesh(\u0026voxels, \u0026opaque_mask, \u0026trans_mask);\n    // Both methods have the same \"output\" which is stored in mesher.quads\n}\n```\n\n### What to do with `mesh_data.quads`\n`mesh_data.quads` is a `[Vec\u003cu64\u003e; 6]`, 1 Vec\u003cu64\u003e per face type, each u64 encoding all the information of a quad in the following manner:\n```rust\n(v_type \u003c\u003c 32) | (h \u003c\u003c 24) | (w \u003c\u003c 18) | (z \u003c\u003c 12) | (y \u003c\u003c 6) | x\n```\n\nThe face groups correspond to Up, Down, Right, Left, Front, Back, in this order. (assuming right handed Y up)\n\nThe fastest way of rendering quads is using instancing (check [this video](https://www.youtube.com/watch?v=40JzyaOYJeY) 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:\n- [src/render/mesh_utils.rs](https://github.com/Inspirateur/riverbed/blob/main/src/render/mesh_utils.rs) for Face+Quad =\u003e vertices conversion\n- [src/render/mesh_chunks.rs](https://github.com/Inspirateur/riverbed/blob/main/src/render/mesh_chunks.rs) for the rest of the meshing code (+ LOD)\n\n## Benchmarks\nrunning `cargo bench` on AMD Ryzen 5 5500 3.60 GHz:\n- \"fast_mesh\" with opaque voxels only: **60 µs**\n- \"mesh\" with opaque voxels only: **300 µs**\n- \"fast_mesh\" with opaque \u0026 transparents voxels: **85 µs**\n- \"mesh\" with opaque \u0026 transparents voxels: **310 µs**\n\nThis 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).\n\nThe meshing is also ~30x faster than [block-mesh-rs](https://github.com/bonsairobo/block-mesh-rs) which took **~3ms** to greedy mesh a chunk on my machine.\n\n*chunk sizes are 62^3 (64^3 with padding), this crate doesn't support other sizes.*\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Finspirateur%2Fbinary-greedy-meshing","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Finspirateur%2Fbinary-greedy-meshing","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Finspirateur%2Fbinary-greedy-meshing/lists"}