Skip to main content

Crate lunar_bsp_build

Crate lunar_bsp_build 

Source
Expand description

offline BSP tree and PVS compiler for Lunar levels.

call from your crate’s build.rs to compile a level mesh into a binary blob that BspLevel can load at runtime with zero parsing cost.

§build.rs example

fn main() {
    let blob = lunar_bsp_build::compile_bsp_file("assets/levels/level1.glb").unwrap();
    let out = std::path::PathBuf::from(std::env::var("OUT_DIR").unwrap());
    std::fs::write(out.join("level1.bsp"), blob).unwrap();
    println!("cargo:rerun-if-changed=assets/levels/level1.glb");
}

then in your game:

let level = BspLevel::from_binary(include_bytes!(concat!(env!("OUT_DIR"), "/level1.bsp")))
    .expect("level bsp corrupt");
app.insert_resource(level);

§area ids

name your GLTF meshes with an areaN_ prefix (e.g. area0_floor, area1_corridor) to automatically assign area ids. meshes without this prefix are untagged and treated as always-visible geometry.

portal hints let you override the auto-detected portals or add portals where the geometry auto-detection misses connections.

Re-exports§

pub use portal::BspPortalHint;

Modules§

gltf
GLTF/GLB level mesh loader.
partition
SAH k-d tree construction for offline BSP compilation.
portal
portal extraction for BSP compilation.
pvs
ray-sampling PVS (potentially-visible set) computation.

Structs§

BspCompileConfig
configuration for the BSP compiler.
BspInputMesh
a mesh to include in the BSP compilation.

Functions§

compile_bsp
compile a set of meshes into a BSP blob.
compile_bsp_file
compile a GLTF/GLB level file into a BSP blob using default settings.
compile_bsp_file_with_config
compile a GLTF/GLB level file with explicit portal hints and compile config.