mirror of
https://github.com/hannobraun/Fornjot
synced 2025-02-12 10:15:51 +00:00
Merge pull request #462 from hannobraun/mesh
Make some simplifications in `Mesh`
This commit is contained in:
commit
b15a5f8766
@ -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) {
|
||||
|
@ -71,7 +71,7 @@ impl From<&Mesh<fj_math::Point<3>>> 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;
|
||||
|
@ -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<fj_math::Triangle<3>>,
|
||||
) -> 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<Point<3>>; 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<Point<3>> {
|
||||
/// Add a triangle to the mesh
|
||||
pub fn push_triangle(
|
||||
&mut self,
|
||||
triangle: impl Into<fj_math::Triangle<3>>,
|
||||
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<fj_math::Triangle<3>>, color: Color) -> Self {
|
||||
let inner = inner.into();
|
||||
Self { inner, color }
|
||||
}
|
||||
}
|
||||
|
||||
/// RGBA color
|
||||
pub type Color = [u8; 4];
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user