|
|
|
|
@ -3,16 +3,15 @@
|
|
|
|
|
#[cfg(feature="benchtest")] |
|
|
|
|
extern crate test; |
|
|
|
|
|
|
|
|
|
mod access; |
|
|
|
|
mod raycast; |
|
|
|
|
mod csg; |
|
|
|
|
mod voxelize; |
|
|
|
|
mod encode; |
|
|
|
|
mod compress; |
|
|
|
|
mod generate; |
|
|
|
|
pub mod access; |
|
|
|
|
pub mod raycast; |
|
|
|
|
pub mod csg; |
|
|
|
|
pub mod voxelize; |
|
|
|
|
pub mod encode; |
|
|
|
|
pub mod compress; |
|
|
|
|
pub mod generate; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
mod tests; |
|
|
|
|
#[cfg(all(test, feature = "benchtest"))] |
|
|
|
|
mod bench; |
|
|
|
|
|
|
|
|
|
@ -30,56 +29,10 @@ use serde::{Serialize, Deserialize};
|
|
|
|
|
|
|
|
|
|
pub const MAX_DAG_DEPTH : usize = 16; |
|
|
|
|
|
|
|
|
|
type Vec3 = Vector3<f32>; |
|
|
|
|
type Vec2 = Vector2<f32>; |
|
|
|
|
pub type Vec3 = Vector3<f32>; |
|
|
|
|
pub type Vec2 = Vector2<f32>; |
|
|
|
|
|
|
|
|
|
#[derive(Copy, Clone, PartialEq, Debug, Default, Serialize, Deserialize)] |
|
|
|
|
pub struct Material { |
|
|
|
|
pub albedo : [f32; 3], |
|
|
|
|
pub metalness : f32, |
|
|
|
|
pub emission : [f32; 3], |
|
|
|
|
pub roughness : f32, |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
#[derive(Debug, Clone)] |
|
|
|
|
pub struct Triangle { |
|
|
|
|
pub points : [Vec3; 3], |
|
|
|
|
pub uv : [Vec2; 3], |
|
|
|
|
pub normal : Vec3, |
|
|
|
|
pub mat : u16, |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
impl Default for Triangle { |
|
|
|
|
fn default() -> Self { |
|
|
|
|
Triangle { |
|
|
|
|
points : [Vec3::zero(); 3], |
|
|
|
|
uv : [Vec2::zero(); 3], |
|
|
|
|
normal : Vec3::zero(), |
|
|
|
|
mat : 0, |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
impl Triangle { |
|
|
|
|
fn area(&self) -> f32 { |
|
|
|
|
// calculate the area of the triangle using heron's formula
|
|
|
|
|
let a = self.points[0].distance(self.points[1]); |
|
|
|
|
let b = self.points[1].distance(self.points[2]); |
|
|
|
|
let c = self.points[2].distance(self.points[0]); |
|
|
|
|
|
|
|
|
|
let s = 0.5 * (a + b + c); |
|
|
|
|
|
|
|
|
|
(s * (s - a) * (s - b) * (s - c)).sqrt() |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
fn pos_center(&self) -> Vec3 { |
|
|
|
|
(self.points[0] + self.points[1] + self.points[2]) / 3.0 |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
fn uv_center(&self) -> Vec2 { |
|
|
|
|
(self.uv[0] + self.uv[1] + self.uv[2]) / 3.0 |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
use voxelize::Triangle; |
|
|
|
|
|
|
|
|
|
// this is a redefinition of the type in the voxel.glsl shader.
|
|
|
|
|
// these redefinition shenanigans are necessary because serde can't quite derive
|
|
|
|
|
|