diff --git a/fj-app/src/camera.rs b/fj-app/src/camera.rs index 069a5cf86..63246471d 100644 --- a/fj-app/src/camera.rs +++ b/fj-app/src/camera.rs @@ -1,7 +1,7 @@ use std::f64::consts::FRAC_PI_2; use fj_interop::mesh::Mesh; -use fj_math::{Aabb, Scalar}; +use fj_math::{Aabb, Scalar, Triangle}; use nalgebra::{Point, TAffine, Transform, Translation, Vector}; use parry3d_f64::query::{Ray, RayCast as _}; use winit::dpi::PhysicalPosition; @@ -148,11 +148,9 @@ impl Camera { let mut min_t = None; for triangle in mesh.triangles() { - let t = triangle.inner.to_parry().cast_local_ray( - &ray, - f64::INFINITY, - true, - ); + let t = Triangle::from_points(triangle.points) + .to_parry() + .cast_local_ray(&ray, f64::INFINITY, true); if let Some(t) = t { if t <= min_t.unwrap_or(t) { diff --git a/fj-app/src/graphics/vertices.rs b/fj-app/src/graphics/vertices.rs index 43a2c8610..ad9c2d0f8 100644 --- a/fj-app/src/graphics/vertices.rs +++ b/fj-app/src/graphics/vertices.rs @@ -71,7 +71,7 @@ impl From<&Mesh>> for Vertices { let mut m = Mesh::new(); for triangle in mesh.triangles() { - let [a, b, c] = triangle.inner.points(); + let [a, b, c] = triangle.points; let normal = (b - a).cross(&(c - a)).normalize(); let color = triangle.color; diff --git a/fj-interop/src/mesh.rs b/fj-interop/src/mesh.rs index b65874fa9..e92ab4a79 100644 --- a/fj-interop/src/mesh.rs +++ b/fj-interop/src/mesh.rs @@ -36,16 +36,14 @@ where /// Determine whether the mesh contains the provided triangle /// - /// Returns true, if a triangle with any combination of the points of the - /// provided triangle is part of the mesh. - pub fn contains_triangle( - &self, - triangle: impl Into>, - ) -> bool { - let triangle = triangle.into().normalize(); + /// Returns true, if a triangle with any combination of the provided points + /// is part of the mesh. + pub fn contains_triangle(&self, points: [impl Into>; 3]) -> bool { + let triangle = fj_math::Triangle::from_points(points).normalize(); for t in &self.triangles { - if triangle == t.inner.normalize() { + let t = fj_math::Triangle::from_points(t.points).normalize(); + if triangle == t { return true; } } @@ -71,18 +69,12 @@ where impl Mesh> { /// Add a triangle to the mesh - pub fn push_triangle( - &mut self, - triangle: impl Into>, - color: Color, - ) { - let triangle = triangle.into(); - - for point in triangle.points() { + pub fn push_triangle(&mut self, points: [Point<3>; 3], color: Color) { + for point in points { self.push_vertex(point); } - self.triangles.push(Triangle::new(triangle, color)); + self.triangles.push(Triangle { points, color }); } } @@ -107,20 +99,12 @@ pub type Index = u32; /// Extension of [`fj_math::Triangle`] that also includes a color. #[derive(Clone, Copy, Debug, Eq, PartialEq, Ord, PartialOrd)] pub struct Triangle { - /// The non-color part of the triangle - pub inner: fj_math::Triangle<3>, + /// The points of the triangle + pub points: [Point<3>; 3], /// The color of the triangle pub color: Color, } -impl Triangle { - /// Construct a new instance of `Triangle` - pub fn new(inner: impl Into>, color: Color) -> Self { - let inner = inner.into(); - Self { inner, color } - } -} - /// RGBA color pub type Color = [u8; 4]; diff --git a/fj-kernel/src/algorithms/triangulation/mod.rs b/fj-kernel/src/algorithms/triangulation/mod.rs index dba7a53b7..b388561c0 100644 --- a/fj-kernel/src/algorithms/triangulation/mod.rs +++ b/fj-kernel/src/algorithms/triangulation/mod.rs @@ -69,7 +69,7 @@ pub fn triangulate( } Face::Triangles(triangles) => { for &(triangle, color) in triangles { - mesh.push_triangle(triangle, color); + mesh.push_triangle(triangle.points(), color); } } }