Marching cubes

This commit is contained in:
mars 2022-03-07 22:12:40 -07:00
parent f88e3e7158
commit 53041b3bf4
3 changed files with 558 additions and 3 deletions

View File

@ -10,6 +10,7 @@ mod handle;
mod mesh;
mod model;
mod pool;
mod procgen;
mod renderer;
mod scene;
mod shader;
@ -52,6 +53,78 @@ impl WorldState for Grid {
}
}
struct Metaballs {
mesh: MeshInstance,
}
impl Metaballs {
fn new(mut ren: &mut Renderer) -> Self {
use procgen::marching_cubes::*;
let metaballs = vec![
glam::Vec3A::new(-5., -5., 2.),
glam::Vec3A::new(8., 0.0, -1.),
glam::Vec3A::new(1., 5., -3.),
];
let field = |x: i32, y: i32, z: i32| {
let c = glam::Vec3A::new(x as f32, y as f32, z as f32);
let mut sum = 0.0;
for ball in metaballs.iter() {
sum += 1.0 / ball.distance(c);
}
sum - 0.4
};
let r = 20;
let domain = MarchDomain {
min: Vec3::new(-r, -r, -r),
max: Vec3::new(r, r, r),
};
let vertices = marching_cubes(field, &domain);
let vertices: Vec<mesh::Vertex> = vertices
.iter()
.map(|v| mesh::Vertex {
position: v.position.into(),
normal: v.normal.into(),
tex_coords: [0.0; 2],
})
.collect();
let indices = (0..(vertices.len() as u32)).collect();
let mesh_data = mesh::MeshData {
vertices, indices
};
let albedo_data = pool::TextureData {
width: 8,
height: 8,
data: vec![0xff; 256],
};
let mesh = ren.load_mesh(&mesh_data);
let albedo = ren.load_texture(&albedo_data);
let material = ren.load_material(&pool::MaterialData { albedo, metallic_roughness: albedo });
let mesh = scene::MeshInstance {
mesh, material, transform: glam::Mat4::IDENTITY,
};
Self { mesh }
}
}
impl WorldState for Metaballs {
fn update(&mut self) {}
fn render(&self) -> Vec<MeshInstance> {
vec![self.mesh]
}
}
struct Planet {
speed: f32,
offset: f32,
@ -153,7 +226,8 @@ fn main() {
let mut is_grabbed = false;
let mut ren = pollster::block_on(make_window_renderer(&window));
// let mut state: Box<dyn WorldState> = Box::new(Planets::new(&mut ren));
let mut state: Box<dyn WorldState> = Box::new(Grid::new(&mut ren));
// let mut state: Box<dyn WorldState> = Box::new(Grid::new(&mut ren));
let mut state: Box<dyn WorldState> = Box::new(Metaballs::new(&mut ren));
let lights = vec![
PointLight {
@ -172,18 +246,26 @@ fn main() {
center: glam::Vec3A::new(0.0, 5.0, -7.0),
intensity: glam::Vec3A::new(0.0, 0.0, 100.0),
},
PointLight {
center: glam::Vec3A::new(0.0, 50.0, 0.0),
intensity: glam::Vec3A::new(1000.0, 1000.0, 1000.0),
},
];
event_loop.run(move |event, _, control_flow| match event {
Event::RedrawRequested(_) => {
let scene = Scene { meshes: &state.render(), point_lights: &lights };
let scene = Scene {
meshes: &state.render(),
point_lights: &lights,
};
match ren.render(&camera, &scene) {
Ok(_) => {}
Err(wgpu::SurfaceError::Lost) => ren.resize(ren.size),
Err(wgpu::SurfaceError::OutOfMemory) => *control_flow = ControlFlow::Exit,
Err(wgpu::SurfaceError::Timeout) => {}
Err(e) => println!("error: {:?}", e),
};
},
}
Event::MainEventsCleared => {
camera.update();
state.update();

View File

@ -0,0 +1,472 @@
// Copyright (c) 2022 Marceline Cramer
// SPDX-License-Identifier: AGPL-3.0-or-later
// largely based on http://paulbourke.net/geometry/polygonise/
// TODO the Vec3 generic is pretty redundant, glam provides these types
use std::collections::HashMap;
#[derive(Copy, Clone, Debug, Eq, Hash, PartialEq)]
pub struct Vec3<T> {
pub x: T,
pub y: T,
pub z: T,
}
impl<T: Copy> Vec3<T> {
pub fn new(x: T, y: T, z: T) -> Self {
Self { x, y, z }
}
pub fn to_array(&self) -> [T; 3] {
[self.x, self.y, self.z]
}
}
impl Vec3<f32> {
pub fn to_glam(self) -> glam::Vec3A {
glam::Vec3A::new(self.x, self.y, self.z)
}
}
impl From<Vec3<i32>> for Vec3<f32> {
fn from(other: Vec3<i32>) -> Self {
Self {
x: other.x as f32,
y: other.y as f32,
z: other.z as f32,
}
}
}
impl<T: Copy> From<Vec3<T>> for [T; 3] {
fn from(other: Vec3<T>) -> Self {
other.to_array()
}
}
#[derive(Copy, Clone, Debug, Hash)]
pub struct MarchDomain {
pub min: Vec3<i32>,
pub max: Vec3<i32>,
}
#[derive(Copy, Clone, Debug)]
pub struct Vertex {
pub position: Vec3<f32>,
pub normal: Vec3<f32>,
}
// TODO support a set of march domains
// TODO use index buffer
// TODO cache shared vertices using HashMap<Edge, Vec3<f32>>
pub fn marching_cubes(
scalar_field: impl Fn(i32, i32, i32) -> f32,
domain: &MarchDomain,
) -> Vec<Vertex> {
let samples = sample_corners(scalar_field, domain);
let test = |corner| samples[&corner] > 0.0;
// TODO this could be optimized using single-edge interpolation
// TODO improve with glam vector math
let interp = |cube: Vec3<i32>, edge_index| {
let (c1, c2) = edge_coords(cube, edge_index);
let v1 = samples[&c1];
let v2 = samples[&c2];
let p1: Vec3<f32> = c1.into();
let p2: Vec3<f32> = c2.into();
let mu = v1 / (v1 - v2);
Vec3 {
x: p1.x + mu * (p2.x - p1.x),
y: p1.y + mu * (p2.y - p1.y),
z: p1.z + mu * (p2.z - p1.z),
}
};
let mut vertices = Vec::new();
for x in domain.min.x..domain.max.x {
for y in domain.min.y..domain.max.y {
for z in domain.min.z..domain.max.z {
let cube = Vec3::new(x, y, z);
let index = configuration_index(cube, test);
let edges = CUBE_CONFIGURATIONS[index];
// TODO use Paul Bourke's edge table to share a cube's triangle vertices
let mut ntriangle = 0;
loop {
let e1 = edges[ntriangle];
if e1 < 0 {
break;
}
let p1 = interp(cube, e1);
let p2 = interp(cube, edges[ntriangle + 1]);
let p3 = interp(cube, edges[ntriangle + 2]);
let n = {
let p1 = p1.to_glam();
let p2 = p2.to_glam();
let p3 = p3.to_glam();
let n = (p2 - p1).cross(p3 - p1).normalize();
Vec3 {
x: n.x,
y: n.y,
z: n.z,
}
};
let n1 = n;
let n2 = n;
let n3 = n;
vertices.push(Vertex {
position: p1,
normal: n1,
});
vertices.push(Vertex {
position: p2,
normal: n2,
});
vertices.push(Vertex {
position: p3,
normal: n3,
});
ntriangle += 3;
}
}
}
}
vertices
}
fn sample_corners(
scalar_field: impl Fn(i32, i32, i32) -> f32,
domain: &MarchDomain,
) -> HashMap<Vec3<i32>, f32> {
let mut samples = HashMap::new();
for x in domain.min.x..=domain.max.x {
for y in domain.min.y..=domain.max.y {
for z in domain.min.z..=domain.max.z {
let s = scalar_field(x, y, z);
let c = Vec3::new(x, y, z);
samples.insert(c, s);
}
}
}
samples
}
#[rustfmt::skip]
fn corner_coords(cube: Vec3<i32>, corner_index: i8) -> Vec3<i32> {
match corner_index {
0 => cube,
1 => Vec3 { y: cube.y + 1, ..cube },
2 => Vec3 { x: cube.x + 1, y: cube.y + 1, ..cube },
3 => Vec3 { x: cube.x + 1, ..cube },
4 => Vec3 { z: cube.z + 1, ..cube },
5 => Vec3 { y: cube.y + 1, z: cube.z + 1, ..cube },
6 => Vec3 { x: cube.x + 1, y: cube.y + 1, z: cube.z + 1 },
7 => Vec3 { x: cube.x + 1, z: cube.z + 1, ..cube },
index => unreachable!("invalid corner index {}", index),
}
}
fn edge_coords(cube: Vec3<i32>, edge_index: i8) -> (Vec3<i32>, Vec3<i32>) {
let c = corner_coords;
match edge_index {
0 => (c(cube, 0), c(cube, 1)),
1 => (c(cube, 1), c(cube, 2)),
2 => (c(cube, 2), c(cube, 3)),
3 => (c(cube, 3), c(cube, 0)),
4 => (c(cube, 4), c(cube, 5)),
5 => (c(cube, 5), c(cube, 6)),
6 => (c(cube, 6), c(cube, 7)),
7 => (c(cube, 7), c(cube, 4)),
8 => (c(cube, 0), c(cube, 4)),
9 => (c(cube, 1), c(cube, 5)),
10 => (c(cube, 2), c(cube, 6)),
11 => (c(cube, 3), c(cube, 7)),
_ => unreachable!("invalid edge index"),
}
}
fn configuration_index(cube: Vec3<i32>, test: impl Fn(Vec3<i32>) -> bool) -> usize {
let s = |cube, corner| test(corner_coords(cube, corner)) as usize;
s(cube, 0)
| (s(cube, 1) << 1)
| (s(cube, 2) << 2)
| (s(cube, 3) << 3)
| (s(cube, 4) << 4)
| (s(cube, 5) << 5)
| (s(cube,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