mirror of
https://github.com/hannobraun/Fornjot
synced 2025-05-06 19:08:28 +00:00
Split function into simpler ones
This commit is contained in:
parent
2a43f8bc24
commit
08b44c4928
@ -10,7 +10,8 @@ use crate::{
|
||||
pub fn triangulate(vertices: &[Handle<Vertex>], surface: &Plane) -> TriMesh {
|
||||
// This is a placeholder implementation that only supports convex faces.
|
||||
|
||||
let triangles = triangles(vertices, surface);
|
||||
let points = points(vertices, surface);
|
||||
let triangles = triangles(&points);
|
||||
|
||||
let mut mesh = TriMesh::new();
|
||||
mesh.triangles.extend(triangles);
|
||||
@ -18,12 +19,13 @@ pub fn triangulate(vertices: &[Handle<Vertex>], surface: &Plane) -> TriMesh {
|
||||
mesh
|
||||
}
|
||||
|
||||
fn triangles(vertices: &[Handle<Vertex>], surface: &Plane) -> Vec<Triangle> {
|
||||
let mut triangulation = spade::ConstrainedDelaunayTriangulation::<_>::new();
|
||||
|
||||
triangulation
|
||||
.add_constraint_edges(
|
||||
vertices.iter().map(|vertex| {
|
||||
fn points(
|
||||
vertices: &[Handle<Vertex>],
|
||||
surface: &Plane,
|
||||
) -> Vec<TriangulationPoint> {
|
||||
vertices
|
||||
.iter()
|
||||
.map(|vertex| {
|
||||
// Here, we project a 3D point (from the vertex) into the face's
|
||||
// surface, creating a 2D point. Through the surface, this 2D
|
||||
// point has a position in 3D space.
|
||||
@ -47,9 +49,15 @@ fn triangles(vertices: &[Handle<Vertex>], surface: &Plane) -> Vec<Triangle> {
|
||||
point_surface,
|
||||
point_vertex: vertex.point,
|
||||
}
|
||||
}),
|
||||
true,
|
||||
)
|
||||
})
|
||||
.collect()
|
||||
}
|
||||
|
||||
fn triangles(points: &[TriangulationPoint]) -> Vec<Triangle> {
|
||||
let mut triangulation = spade::ConstrainedDelaunayTriangulation::<_>::new();
|
||||
|
||||
triangulation
|
||||
.add_constraint_edges(points.iter().copied(), true)
|
||||
.unwrap();
|
||||
|
||||
triangulation
|
||||
|
Loading…
Reference in New Issue
Block a user