#mesh #heightmap #graphics

height-mesh

一个用于从2D高度图生成3D网格的小型crate

1 个不稳定版本

0.1.0 2021年9月29日

#924 in 图形API

MIT/Apache

8KB
72

height-mesh

一个用于从2D高度图生成3D网格的小型crate。

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());

许可证:MIT OR Apache-2.0


lib.rs:

一个用于从2D高度图生成3D网格的小型crate。

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());

依赖项

~74KB