Add basic box brush generator

This commit is contained in:
Jarrod Doyle 2023-09-22 09:30:27 +01:00
parent 73495fcde6
commit 8488a75bd0
Signed by: Jayrude
GPG Key ID: 38B57B16E7C0ADF7
1 changed files with 14 additions and 8 deletions

View File

@ -1,11 +1,11 @@
use csg::{ use csg::{
brush::{self, Brush, BrushPlane, MaterialId, TextureProjection}, brush::{Brush, BrushPlane, MaterialId, TextureProjection},
glam::{self}, glam::{self, Vec3},
plane::Plane, plane::Plane,
}; };
fn main() { fn generate_box_brush(position: Vec3, extent: Vec3) -> Brush {
let points = vec![ let normals = vec![
glam::vec3(1.0, 0.0, 0.0), glam::vec3(1.0, 0.0, 0.0),
glam::vec3(-1.0, 0.0, 0.0), glam::vec3(-1.0, 0.0, 0.0),
glam::vec3(0.0, 1.0, 0.0), glam::vec3(0.0, 1.0, 0.0),
@ -15,9 +15,11 @@ fn main() {
]; ];
let mut brush_planes = vec![]; let mut brush_planes = vec![];
for point in &points { for normal in &normals {
let point = position + *normal * extent;
brush_planes.push(BrushPlane { brush_planes.push(BrushPlane {
plane: Plane::from_point_normal(*point, *point), plane: Plane::from_point_normal(point, *normal),
material: MaterialId("Epic".to_string()), material: MaterialId("Epic".to_string()),
tex_projection: TextureProjection::default(), tex_projection: TextureProjection::default(),
}); });
@ -25,9 +27,13 @@ fn main() {
println!("Plane: {:?}", brush_planes.last().unwrap().plane); println!("Plane: {:?}", brush_planes.last().unwrap().plane);
} }
let brush = Brush { Brush {
planes: brush_planes, planes: brush_planes,
}; }
}
fn main() {
let brush = generate_box_brush(Vec3::new(1.0, 0.0, 0.0), Vec3::new(1.0, 2.0, 1.0));
let vs = brush.get_vertices(); let vs = brush.get_vertices();
println!("Vertices: {vs:?}"); println!("Vertices: {vs:?}");