mirror of
https://github.com/hannobraun/Fornjot
synced 2025-05-06 02:48:27 +00:00
Add Solid
This commit is contained in:
parent
f4010867f4
commit
81e98ebbf0
@ -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
|
||||
}
|
||||
}
|
||||
|
@ -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);
|
||||
}
|
||||
|
@ -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};
|
||||
|
35
experiments/2024-12-09/src/topology/solid.rs
Normal file
35
experiments/2024-12-09/src/topology/solid.rs
Normal 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()
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user