Merge pull request #1863 from hannobraun/model

Clean up model-related code in `fj-interop`
This commit is contained in:
Hanno Braun 2023-06-06 13:00:18 +02:00 committed by GitHub
commit c270824282
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 23 additions and 80 deletions

View File

@ -1,50 +0,0 @@
//! Debug information definitions for the Fornjot ecosystem
//!
//! Defines debug information that is used by other crates within the Fornjot
//! ecosystem. The types in here aren't very useful in themselves, but they
//! define an interface that other crates use to communicate between each other.
use fj_math::{Point, Segment};
/// Debug info from the CAD kernel that can be visualized
#[derive(Clone, Debug, Default)]
pub struct DebugInfo {
/// Rays being used during face triangulation
pub triangle_edge_checks: Vec<TriangleEdgeCheck>,
}
impl DebugInfo {
/// Construct an empty instance of `DebugInfo`
pub fn new() -> Self {
Self::default()
}
/// Clear all information within this instance
///
/// The resulting instance is the same, as if created by [`DebugInfo::new`],
/// but calling `clear` might be more efficient in regard to heap
/// allocations.
pub fn clear(&mut self) {
self.triangle_edge_checks.clear();
}
}
/// Record of a check to determine if a triangle edge is within a face
#[derive(Clone, Debug)]
pub struct TriangleEdgeCheck {
/// The origin of the ray used to perform the check
pub origin: Point<3>,
/// The points where the ray hit edges of the face
pub hits: Vec<Segment<3>>,
}
impl TriangleEdgeCheck {
/// Construct a new instance
pub fn new(origin: Point<3>) -> Self {
Self {
origin,
hits: Vec::new(),
}
}
}

View File

@ -11,7 +11,6 @@
#![warn(missing_docs)] #![warn(missing_docs)]
pub mod debug;
pub mod ext; pub mod ext;
pub mod mesh; pub mod mesh;
pub mod processed_shape; pub mod model;

View File

@ -0,0 +1,15 @@
//! An approximated model
use fj_math::{Aabb, Point};
use crate::mesh::Mesh;
/// An approximated model
#[derive(Clone, Debug)]
pub struct Model {
/// The triangle mesh that approximates the model
pub mesh: Mesh<Point<3>>,
/// The axis-aligned bounding box of the model
pub aabb: Aabb<3>,
}

View File

@ -1,18 +0,0 @@
//! A processed shape
use fj_math::{Aabb, Point};
use crate::{debug::DebugInfo, mesh::Mesh};
/// A processed shape
#[derive(Clone, Debug)]
pub struct ProcessedShape {
/// The axis-aligned bounding box of the shape
pub aabb: Aabb<3>,
/// The triangle mesh that approximates the original shape
pub mesh: Mesh<Point<3>>,
/// The debug info generated while processing the shape
pub debug_info: DebugInfo,
}

View File

@ -1,7 +1,7 @@
//! Viewer camera module //! Viewer camera module
use std::f64::consts::FRAC_PI_2; use std::f64::consts::FRAC_PI_2;
use fj_interop::{mesh::Mesh, processed_shape::ProcessedShape}; use fj_interop::{mesh::Mesh, model::Model};
use fj_math::{Aabb, Point, Scalar, Transform, Vector}; use fj_math::{Aabb, Point, Scalar, Transform, Vector};
use crate::screen::NormalizedScreenPosition; use crate::screen::NormalizedScreenPosition;
@ -82,7 +82,7 @@ impl Camera {
pub fn focus_point( pub fn focus_point(
&self, &self,
cursor: Option<NormalizedScreenPosition>, cursor: Option<NormalizedScreenPosition>,
shape: &ProcessedShape, shape: &Model,
) -> FocusPoint { ) -> FocusPoint {
self.calculate_focus_point(cursor, &shape.mesh) self.calculate_focus_point(cursor, &shape.mesh)
.unwrap_or_else(|| FocusPoint(shape.aabb.center())) .unwrap_or_else(|| FocusPoint(shape.aabb.center()))

View File

@ -1,4 +1,4 @@
use fj_interop::processed_shape::ProcessedShape; use fj_interop::model::Model;
use fj_math::Aabb; use fj_math::Aabb;
use tracing::warn; use tracing::warn;
@ -28,7 +28,7 @@ pub struct Viewer {
pub renderer: Renderer, pub renderer: Renderer,
/// The shape /// The shape
pub shape: Option<ProcessedShape>, pub shape: Option<Model>,
} }
impl Viewer { impl Viewer {
@ -60,7 +60,7 @@ impl Viewer {
} }
/// Handle the shape being updated /// Handle the shape being updated
pub fn handle_shape_update(&mut self, shape: ProcessedShape) { pub fn handle_shape_update(&mut self, shape: Model) {
self.renderer.update_geometry((&shape.mesh).into()); self.renderer.update_geometry((&shape.mesh).into());
let aabb = shape.aabb; let aabb = shape.aabb;

View File

@ -1,6 +1,4 @@
use fj_interop::{ use fj_interop::{mesh::Mesh, model::Model};
debug::DebugInfo, mesh::Mesh, processed_shape::ProcessedShape,
};
use fj_math::{Aabb, Point}; use fj_math::{Aabb, Point};
use fj_viewer::{ use fj_viewer::{
InputEvent, NormalizedScreenPosition, RendererInitError, Screen, InputEvent, NormalizedScreenPosition, RendererInitError, Screen,
@ -24,10 +22,9 @@ pub fn display(mesh: Mesh<Point<3>>, invert_zoom: bool) -> Result<(), Error> {
let window = Window::new(&event_loop)?; let window = Window::new(&event_loop)?;
let mut viewer = block_on(Viewer::new(&window))?; let mut viewer = block_on(Viewer::new(&window))?;
viewer.handle_shape_update(ProcessedShape { viewer.handle_shape_update(Model {
aabb: Aabb::<3>::from_points(mesh.vertices()), aabb: Aabb::<3>::from_points(mesh.vertices()),
mesh, mesh,
debug_info: DebugInfo::new(),
}); });
let mut held_mouse_button = None; let mut held_mouse_button = None;