Crates.io | marching-cubes |
lib.rs | marching-cubes |
version | 0.1.2 |
source | src |
created_at | 2023-01-30 09:56:56.463057 |
updated_at | 2023-01-30 10:05:32.488676 |
description | A marching cubes implementation in Rust |
homepage | |
repository | https://github.com/therealnv6/marching-cubes |
max_upload_size | |
id | 771593 |
size | 34,895 |
A Rust implementation of the marching cubes algorithm for extracting isosurfaces from 3D volumetric data.
use marching_cubes::{MarchingCubes, GridCell, Triangle};
let grid = GridCell {
positions: [
[0.0, 0.0, 0.0],
[1.0, 0.0, 0.0],
[1.0, 1.0, 0.0],
[0.0, 1.0, 0.0],
[0.0, 0.0, 1.0],
[1.0, 0.0, 1.0],
[1.0, 1.0, 1.0],
[0.0, 1.0, 1.0]
],
value: [0.0, 0.5, 0.5, 1.0, 0.0, 1.0, 1.0, 0.0],
};
let mut triangles = vec![];
let isolevel = 0.5;
let mc = MarchingCubes::new(isolevel, grid);
let triangle_count = mc.polygonise(&mut triangles);
assert_eq!(triangle_count, 4);
The MarchingCubes
struct is the main entry point to the library.
new
method creates a new instance of the algorithm and takes two arguments: the 3D volumetric data as a nested array of scalar values and the isovalue used to extract the isosurface.polygonise
method executes the algorithm and returns the resulting vertices as a vector of 3D points.Note: The example code uses a 4x4x4 volume for simplicity, but in practice the volume size can be much larger and the algorithm will scale accordingly.