Add Solid

This commit is contained in:
Hanno Braun 2025-01-21 20:20:20 +01:00
parent f4010867f4
commit 81e98ebbf0
4 changed files with 44 additions and 18 deletions

View File

@ -77,8 +77,4 @@ impl<'r, NewOps, T> ShapeExtender<'r, NewOps, T> {
new_ops: self.new_ops.push_right(op),
}
}
pub fn get_added(self) -> NewOps {
self.new_ops
}
}

View File

@ -4,7 +4,7 @@ use crate::{
geometry::{Shape, Sketch},
math::{Bivector, Plane, Point, Vector},
storage::Stores,
topology::Face,
topology::{Face, Solid},
};
pub fn model(shape: &mut Shape) {
@ -26,12 +26,6 @@ pub fn model(shape: &mut Shape) {
};
let bottom = top.flip(stores.get()).translate([0., 0., -1.], &mut stores);
let (bottom, top) = shape
.extend_with(stores.get::<Face>())
.add(bottom)
.add(top)
.get_added();
let [a, b, c, d] = bottom.vertices().collect_array().unwrap();
let [e, f, g, h] = top.vertices().collect_array().unwrap();
@ -45,10 +39,10 @@ pub fn model(shape: &mut Shape) {
},
);
shape
.extend_with(stores.get::<Face>())
.add(left)
.add(right)
.add(front)
.add(back);
let solid = Solid::new(
[bottom, top, left, right, front, back]
.map(|face| stores.get().insert(face)),
);
shape.extend_with(stores.get::<Solid>()).add(solid);
}

View File

@ -1,4 +1,5 @@
mod face;
mod solid;
mod vertex;
pub use self::{face::Face, vertex::Vertex};
pub use self::{face::Face, solid::Solid, vertex::Vertex};

View File

@ -0,0 +1,35 @@
use crate::geometry::{AnyOp, Handle, Operation, TriMesh};
use super::Face;
pub struct Solid {
faces: Vec<Handle<Face>>,
}
impl Solid {
pub fn new(faces: impl IntoIterator<Item = Handle<Face>>) -> Self {
Self {
faces: faces.into_iter().collect(),
}
}
}
impl Operation for Solid {
fn label(&self) -> &'static str {
"Solid"
}
fn tri_mesh(&self) -> TriMesh {
let mut tri_mesh = TriMesh::new();
for face in &self.faces {
tri_mesh = tri_mesh.merge(face.tri_mesh());
}
tri_mesh
}
fn children(&self) -> Vec<AnyOp> {
self.faces.iter().map(|face| face.to_any()).collect()
}
}