Crates.io | height-mesh |
lib.rs | height-mesh |
version | 0.1.0 |
source | src |
created_at | 2021-09-29 01:01:13.966876 |
updated_at | 2021-09-29 01:01:13.966876 |
description | A small crate to generate a 3D mesh from a 2D heightmap. |
homepage | |
repository | https://github.com/bonsairobo/height-mesh-rs |
max_upload_size | |
id | 457842 |
size | 20,200 |
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