diff --git a/src/lib.rs b/src/lib.rs index bdf00ff..71f1f57 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -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; -type Vec2 = Vector2; +pub type Vec3 = Vector3; +pub type Vec2 = Vector2; -#[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 diff --git a/src/voxelize.rs b/src/voxelize.rs index f76066b..ecf722d 100644 --- a/src/voxelize.rs +++ b/src/voxelize.rs @@ -4,6 +4,54 @@ use pbr::ProgressBar; use std::path::{Path, PathBuf}; +#[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 + } +} + fn recursively_subdivide(triangle : Triangle, area_cutoff : f32, buf : &mut Vec) { if triangle.area() < area_cutoff { buf.push(triangle); diff --git a/src/tests.rs b/tests/tests.rs similarity index 99% rename from src/tests.rs rename to tests/tests.rs index e35f82b..ce675eb 100644 --- a/src/tests.rs +++ b/tests/tests.rs @@ -1,6 +1,9 @@ -use super::*; +use bzvx::*; -use super::voxelize::*; +use bzvx::voxelize::*; +use bzvx::voxelize::Triangle; + +use cgmath::InnerSpace; use pbr::ProgressBar;