diff --git a/crates/fj-viewer/src/graphics/renderer.rs b/crates/fj-viewer/src/graphics/renderer.rs index 20f32a670..fada903f8 100644 --- a/crates/fj-viewer/src/graphics/renderer.rs +++ b/crates/fj-viewer/src/graphics/renderer.rs @@ -403,18 +403,9 @@ pub enum RendererInitError { RequestDevice(#[from] wgpu::RequestDeviceError), } -/// Graphics rendering error +/// Draw error /// -/// Describes errors related to non initialization graphics errors. +/// Returned by [`Renderer::draw`]. #[derive(Error, Debug)] -pub enum DrawError { - /// Surface drawing error. - /// - /// See - [wgpu::SurfaceError](https://docs.rs/wgpu/latest/wgpu/enum.SurfaceError.html) - #[error("Error acquiring output surface: {0}")] - Surface(#[from] wgpu::SurfaceError), - - /// Text rasterisation error. - #[error("Error drawing text: {0}")] - Text(String), -} +#[error("Error acquiring output surface: {0}")] +pub struct DrawError(#[from] wgpu::SurfaceError); diff --git a/crates/fj-viewer/src/graphics/vertices.rs b/crates/fj-viewer/src/graphics/vertices.rs index d7f76c4a4..057af30f8 100644 --- a/crates/fj-viewer/src/graphics/vertices.rs +++ b/crates/fj-viewer/src/graphics/vertices.rs @@ -1,6 +1,5 @@ use bytemuck::{Pod, Zeroable}; use fj_interop::mesh::{Index, Mesh}; -use fj_math::{Point, Vector}; #[derive(Debug)] pub struct Vertices { @@ -23,50 +22,6 @@ impl Vertices { pub fn indices(&self) -> &[Index] { self.indices.as_slice() } - - pub fn push_line( - &mut self, - line: [Point<3>; 2], - normal: [f32; 3], - color: [f32; 4], - ) { - let line = line.into_iter().map(|point| Vertex { - position: point.coords.components.map(|scalar| scalar.into_f32()), - normal, - color, - }); - - self.vertices.extend(line); - - self.indices.push(self.indices.len() as u32); - self.indices.push(self.indices.len() as u32); - } - - pub fn push_cross( - &mut self, - position: Point<3>, - normal: [f32; 3], - color: [f32; 4], - ) { - let d = 0.05; - - self.push_line( - [ - position - Vector::from([d, 0., 0.]), - position + Vector::from([d, 0., 0.]), - ], - normal, - color, - ); - self.push_line( - [ - position - Vector::from([0., d, 0.]), - position + Vector::from([0., d, 0.]), - ], - normal, - color, - ); - } } impl From<&Mesh>> for Vertices { diff --git a/crates/fj-viewer/src/lib.rs b/crates/fj-viewer/src/lib.rs index c9d888503..6819762f7 100644 --- a/crates/fj-viewer/src/lib.rs +++ b/crates/fj-viewer/src/lib.rs @@ -15,14 +15,11 @@ mod camera; mod graphics; mod input; mod screen; -mod status_report; mod viewer; pub use self::{ - camera::Camera, - graphics::{DrawConfig, Renderer, RendererInitError}, - input::{InputEvent, InputHandler}, + graphics::RendererInitError, + input::InputEvent, screen::{NormalizedScreenPosition, Screen, ScreenSize}, - status_report::StatusReport, viewer::Viewer, }; diff --git a/crates/fj-viewer/src/status_report.rs b/crates/fj-viewer/src/status_report.rs deleted file mode 100644 index a2055f3ec..000000000 --- a/crates/fj-viewer/src/status_report.rs +++ /dev/null @@ -1,53 +0,0 @@ -//! Struct to store and update status messages - -use std::collections::VecDeque; - -use chrono::Local; - -/// Struct to store and update status messages -#[derive(Default)] -pub struct StatusReport { - status: VecDeque, -} - -impl StatusReport { - /// Create a new `StatusReport` instance with a blank status - pub fn new() -> Self { - Self::default() - } - - /// Update the status - pub fn update_status(&mut self, status: &str) { - let date = { - let date = Local::now(); - format!("{}", date.format("[%H:%M:%S.%3f]")) - }; - let empty_space = " ".repeat(date.chars().count()); - - let mut rendered = String::new(); - for (i, line) in status.lines().enumerate() { - let prefix = if i == 0 { &date } else { &empty_space }; - rendered.push_str(&format!("\n{prefix} {line}")); - } - - self.status.push_back(rendered); - if self.status.len() > 5 { - for _ in 0..(self.status.len() - 5) { - self.status.pop_front(); - } - } - } - - /// Get current status - pub fn status(&self) -> String { - self.status - .iter() - .map(std::string::ToString::to_string) - .collect::() - } - - /// Reset status - pub fn clear_status(&mut self) { - self.status.clear(); - } -} diff --git a/crates/fj-viewer/src/viewer.rs b/crates/fj-viewer/src/viewer.rs index 7abf32eb1..95f423bbe 100644 --- a/crates/fj-viewer/src/viewer.rs +++ b/crates/fj-viewer/src/viewer.rs @@ -3,32 +3,21 @@ use fj_math::Aabb; use tracing::warn; use crate::{ - camera::FocusPoint, Camera, DrawConfig, InputEvent, InputHandler, - NormalizedScreenPosition, Renderer, RendererInitError, Screen, ScreenSize, + camera::{Camera, FocusPoint}, + graphics::{DrawConfig, Renderer}, + input::InputHandler, + InputEvent, NormalizedScreenPosition, RendererInitError, Screen, + ScreenSize, }; /// The Fornjot model viewer pub struct Viewer { - /// The camera - pub camera: Camera, - - /// The cursor - pub cursor: Option, - - /// The draw config - pub draw_config: DrawConfig, - - /// The focus point - pub focus_point: Option, - - /// The input handler - pub input_handler: InputHandler, - - /// The renderer - pub renderer: Renderer, - - /// The model - pub model: Option, + camera: Camera, + cursor: Option, + draw_config: DrawConfig, + focus_point: Option, + renderer: Renderer, + model: Option, } impl Viewer { @@ -41,12 +30,16 @@ impl Viewer { cursor: None, draw_config: DrawConfig::default(), focus_point: None, - input_handler: InputHandler::default(), renderer, model: None, }) } + /// Access the cursor + pub fn cursor(&self) -> Option { + self.cursor + } + /// Toggle the "draw model" setting pub fn toggle_draw_model(&mut self) { self.draw_config.draw_model = !self.draw_config.draw_model; diff --git a/crates/fj-window/src/display.rs b/crates/fj-window/src/display.rs index 9a665f0db..a6d67a517 100644 --- a/crates/fj-window/src/display.rs +++ b/crates/fj-window/src/display.rs @@ -32,7 +32,7 @@ pub fn display(model: Model, invert_zoom: bool) -> Result<(), Error> { &event, &window, &held_mouse_button, - &mut viewer.cursor, + &mut viewer.cursor(), invert_zoom, ); if let Some(input_event) = input_event {