mirror of
https://github.com/hannobraun/Fornjot
synced 2025-09-15 13:47:58 +00:00
Return mesh::Triangle
from triangulate
This commit is contained in:
parent
19cb64b2ce
commit
0972ddcbc4
@ -1,6 +1,7 @@
|
||||
use std::f64::consts::FRAC_PI_2;
|
||||
|
||||
use fj_math::{Aabb, Scalar, Triangle};
|
||||
use fj_interop::mesh::Triangle;
|
||||
use fj_math::{Aabb, Scalar};
|
||||
use nalgebra::{Point, TAffine, Transform, Translation, Vector};
|
||||
use parry3d_f64::query::{Ray, RayCast as _};
|
||||
use winit::dpi::PhysicalPosition;
|
||||
@ -130,7 +131,7 @@ impl Camera {
|
||||
&self,
|
||||
window: &Window,
|
||||
cursor: Option<PhysicalPosition<f64>>,
|
||||
triangles: &[Triangle<3>],
|
||||
triangles: &[Triangle],
|
||||
) -> FocusPoint {
|
||||
let cursor = match cursor {
|
||||
Some(cursor) => cursor,
|
||||
@ -147,10 +148,11 @@ impl Camera {
|
||||
let mut min_t = None;
|
||||
|
||||
for triangle in triangles {
|
||||
let t =
|
||||
triangle
|
||||
.to_parry()
|
||||
.cast_local_ray(&ray, f64::INFINITY, true);
|
||||
let t = triangle.inner.to_parry().cast_local_ray(
|
||||
&ray,
|
||||
f64::INFINITY,
|
||||
true,
|
||||
);
|
||||
|
||||
if let Some(t) = t {
|
||||
if t <= min_t.unwrap_or(t) {
|
||||
|
@ -1,9 +1,8 @@
|
||||
use bytemuck::{Pod, Zeroable};
|
||||
use fj_interop::{
|
||||
debug::DebugInfo,
|
||||
mesh::{Index, Mesh},
|
||||
mesh::{Index, Mesh, Triangle},
|
||||
};
|
||||
use fj_math::Triangle;
|
||||
use nalgebra::{vector, Point};
|
||||
|
||||
#[derive(Debug)]
|
||||
@ -67,15 +66,15 @@ impl Vertices {
|
||||
}
|
||||
}
|
||||
|
||||
impl From<&Vec<Triangle<3>>> for Vertices {
|
||||
fn from(triangles: &Vec<Triangle<3>>) -> Self {
|
||||
impl From<&Vec<Triangle>> for Vertices {
|
||||
fn from(triangles: &Vec<Triangle>) -> Self {
|
||||
let mut mesh = Mesh::new();
|
||||
|
||||
for triangle in triangles {
|
||||
let [a, b, c] = triangle.points();
|
||||
let [a, b, c] = triangle.inner.points();
|
||||
|
||||
let normal = (b - a).cross(&(c - a)).normalize();
|
||||
let color = triangle.color();
|
||||
let color = triangle.color;
|
||||
|
||||
mesh.push((a, normal, color));
|
||||
mesh.push((b, normal, color));
|
||||
|
@ -1,6 +1,6 @@
|
||||
use std::time::Instant;
|
||||
|
||||
use fj_math::Triangle;
|
||||
use fj_interop::mesh::Triangle;
|
||||
use winit::{
|
||||
dpi::PhysicalPosition,
|
||||
event::{
|
||||
@ -121,7 +121,7 @@ impl Handler {
|
||||
now: Instant,
|
||||
camera: &mut Camera,
|
||||
window: &Window,
|
||||
triangles: &[Triangle<3>],
|
||||
triangles: &[Triangle],
|
||||
) {
|
||||
let focus_point = camera.focus_point(window, self.cursor, triangles);
|
||||
|
||||
|
@ -9,9 +9,10 @@ use std::path::PathBuf;
|
||||
use std::{collections::HashMap, time::Instant};
|
||||
|
||||
use fj_host::Model;
|
||||
use fj_interop::mesh::Triangle;
|
||||
use fj_interop::{debug::DebugInfo, mesh::Mesh};
|
||||
use fj_kernel::algorithms::triangulate;
|
||||
use fj_math::{Aabb, Scalar, Triangle};
|
||||
use fj_math::{Aabb, Scalar};
|
||||
use fj_operations::ToShape as _;
|
||||
use futures::executor::block_on;
|
||||
use tracing::{trace, warn};
|
||||
@ -87,7 +88,7 @@ fn main() -> anyhow::Result<()> {
|
||||
let mut mesh_maker = Mesh::new();
|
||||
|
||||
for triangle in shape.triangles {
|
||||
for vertex in triangle.points() {
|
||||
for vertex in triangle.inner.points() {
|
||||
mesh_maker.push(vertex);
|
||||
}
|
||||
}
|
||||
@ -309,7 +310,7 @@ impl ShapeProcessor {
|
||||
|
||||
struct ProcessedShape {
|
||||
aabb: Aabb<3>,
|
||||
triangles: Vec<Triangle<3>>,
|
||||
triangles: Vec<Triangle>,
|
||||
debug_info: DebugInfo,
|
||||
}
|
||||
|
||||
|
@ -2,8 +2,8 @@ mod delaunay;
|
||||
mod polygon;
|
||||
mod ray;
|
||||
|
||||
use fj_interop::debug::DebugInfo;
|
||||
use fj_math::{Scalar, Triangle};
|
||||
use fj_interop::{debug::DebugInfo, mesh::Triangle};
|
||||
use fj_math::Scalar;
|
||||
|
||||
use crate::{shape::Shape, topology::Face};
|
||||
|
||||
@ -15,7 +15,7 @@ use super::FaceApprox;
|
||||
pub fn triangulate(
|
||||
mut shape: Shape,
|
||||
tolerance: Scalar,
|
||||
out: &mut Vec<Triangle<3>>,
|
||||
out: &mut Vec<Triangle>,
|
||||
debug_info: &mut DebugInfo,
|
||||
) {
|
||||
for face in shape.topology().faces() {
|
||||
@ -63,26 +63,18 @@ pub fn triangulate(
|
||||
|
||||
out.extend(triangles.into_iter().map(|triangle| {
|
||||
let points = triangle.map(|point| point.canonical());
|
||||
let mut t = Triangle::from(points);
|
||||
t.set_color(*color);
|
||||
t
|
||||
Triangle::new(points, *color)
|
||||
}));
|
||||
}
|
||||
Face::Triangles(triangles) => {
|
||||
out.extend(triangles.iter().map(|triangle| {
|
||||
let mut t = triangle.inner;
|
||||
t.set_color(triangle.color);
|
||||
t
|
||||
}))
|
||||
}
|
||||
Face::Triangles(triangles) => out.extend(triangles),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use fj_interop::debug::DebugInfo;
|
||||
use fj_math::{Scalar, Triangle};
|
||||
use fj_interop::{debug::DebugInfo, mesh::Triangle};
|
||||
use fj_math::Scalar;
|
||||
|
||||
use crate::{geometry::Surface, shape::Shape, topology::Face};
|
||||
|
||||
@ -152,18 +144,22 @@ mod tests {
|
||||
super::triangulate(shape, tolerance, &mut triangles, &mut debug_info);
|
||||
|
||||
for triangle in &mut triangles {
|
||||
*triangle = triangle.normalize();
|
||||
*triangle = Triangle {
|
||||
inner: triangle.inner.normalize(),
|
||||
..*triangle
|
||||
};
|
||||
}
|
||||
|
||||
Triangles(triangles)
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
struct Triangles(Vec<Triangle<3>>);
|
||||
struct Triangles(Vec<Triangle>);
|
||||
|
||||
impl Triangles {
|
||||
fn contains(&self, triangle: impl Into<Triangle<3>>) -> bool {
|
||||
let triangle = triangle.into().normalize();
|
||||
fn contains(&self, triangle: impl Into<fj_math::Triangle<3>>) -> bool {
|
||||
let triangle =
|
||||
Triangle::new(triangle.into().normalize(), [255, 0, 0, 255]);
|
||||
self.0.contains(&triangle)
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user