height-mesh 0.1.0

A small crate to generate a 3D mesh from a 2D heightmap.
Documentation
  • Coverage
  • 100%
    8 out of 8 items documented1 out of 4 items with examples
  • Size
  • Source code size: 20.30 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 339.01 kB This is the summed size of all files generated by rustdoc for all configured targets
  • Links
  • bonsairobo/height-mesh-rs
    16 0 0
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • bonsairobo

height-mesh

A small crate to generate a 3D mesh from a 2D heightmap.

use height_mesh::ndshape::{ConstShape, ConstShape2u32};
use height_mesh::{height_mesh, HeightMeshBuffer};

// A 64^2 chunk with 1-voxel boundary padding.
type ChunkShape = ConstShape2u32<66, 66>;

// This chunk will cover just a single quadrant of a parabola.
let mut sdf = [1.0; ChunkShape::SIZE as usize];
for i in 0u32..ChunkShape::SIZE {
    let [x, y] = ChunkShape::delinearize(i);
    sdf[i as usize] = ((x * x + y * y) as f32).sqrt();
}

let mut buffer = HeightMeshBuffer::default();
height_mesh(&sdf, &ChunkShape {}, [0; 2], [65; 2], &mut buffer);

// Some triangles were generated.
assert!(!buffer.indices.is_empty());

License: MIT OR Apache-2.0