From 16ce8ad46d62bf3ca408958a9159ff78868d419b Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Mon, 19 Jun 2023 13:40:55 +0200 Subject: [PATCH 1/9] Remove unused struct field --- crates/fj-viewer/src/viewer.rs | 4 ---- 1 file changed, 4 deletions(-) diff --git a/crates/fj-viewer/src/viewer.rs b/crates/fj-viewer/src/viewer.rs index 7abf32eb1a..90843c3fc4 100644 --- a/crates/fj-viewer/src/viewer.rs +++ b/crates/fj-viewer/src/viewer.rs @@ -21,9 +21,6 @@ pub struct Viewer { /// The focus point pub focus_point: Option, - /// The input handler - pub input_handler: InputHandler, - /// The renderer pub renderer: Renderer, @@ -41,7 +38,6 @@ impl Viewer { cursor: None, draw_config: DrawConfig::default(), focus_point: None, - input_handler: InputHandler::default(), renderer, model: None, }) From cb44acfe3f86c454f2645013065b57255722e759 Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Mon, 19 Jun 2023 13:41:28 +0200 Subject: [PATCH 2/9] Add `Viewer::cursor` --- crates/fj-viewer/src/viewer.rs | 5 +++++ crates/fj-window/src/display.rs | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/crates/fj-viewer/src/viewer.rs b/crates/fj-viewer/src/viewer.rs index 90843c3fc4..85d7b027c1 100644 --- a/crates/fj-viewer/src/viewer.rs +++ b/crates/fj-viewer/src/viewer.rs @@ -43,6 +43,11 @@ impl Viewer { }) } + /// 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 9a665f0dba..a6d67a5173 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 { From a86b129b3f0b99021e8bb95e3430f0a6b4cf67d7 Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Mon, 19 Jun 2023 13:41:44 +0200 Subject: [PATCH 3/9] Remove unused `pub`s --- crates/fj-viewer/src/viewer.rs | 23 ++++++----------------- 1 file changed, 6 insertions(+), 17 deletions(-) diff --git a/crates/fj-viewer/src/viewer.rs b/crates/fj-viewer/src/viewer.rs index 85d7b027c1..eec039b9e8 100644 --- a/crates/fj-viewer/src/viewer.rs +++ b/crates/fj-viewer/src/viewer.rs @@ -9,23 +9,12 @@ use crate::{ /// 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 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 { From 47e39cb9afaf36eda7c01ae6064cddf85b743a63 Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Mon, 19 Jun 2023 13:45:31 +0200 Subject: [PATCH 4/9] Remove unused error variant --- crates/fj-viewer/src/graphics/renderer.rs | 4 ---- 1 file changed, 4 deletions(-) diff --git a/crates/fj-viewer/src/graphics/renderer.rs b/crates/fj-viewer/src/graphics/renderer.rs index 20f32a6703..cfad172973 100644 --- a/crates/fj-viewer/src/graphics/renderer.rs +++ b/crates/fj-viewer/src/graphics/renderer.rs @@ -413,8 +413,4 @@ pub enum DrawError { /// 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), } From 5f1b923bba227c4d322e8b18d81f43614a140d05 Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Mon, 19 Jun 2023 13:46:38 +0200 Subject: [PATCH 5/9] Simplify `DrawError` --- crates/fj-viewer/src/graphics/renderer.rs | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/crates/fj-viewer/src/graphics/renderer.rs b/crates/fj-viewer/src/graphics/renderer.rs index cfad172973..cdd8d0b6cb 100644 --- a/crates/fj-viewer/src/graphics/renderer.rs +++ b/crates/fj-viewer/src/graphics/renderer.rs @@ -407,10 +407,5 @@ pub enum RendererInitError { /// /// Describes errors related to non initialization graphics errors. #[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), -} +#[error("Error acquiring output surface: {0}")] +pub struct DrawError(#[from] wgpu::SurfaceError); From 608702930a621deca27c53fe052cd3a280be02b8 Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Mon, 19 Jun 2023 13:47:49 +0200 Subject: [PATCH 6/9] Update doc comment --- crates/fj-viewer/src/graphics/renderer.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/crates/fj-viewer/src/graphics/renderer.rs b/crates/fj-viewer/src/graphics/renderer.rs index cdd8d0b6cb..fada903f8b 100644 --- a/crates/fj-viewer/src/graphics/renderer.rs +++ b/crates/fj-viewer/src/graphics/renderer.rs @@ -403,9 +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)] #[error("Error acquiring output surface: {0}")] pub struct DrawError(#[from] wgpu::SurfaceError); From ad44552cae8a190119e7f5eb367bb720b3c618e2 Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Mon, 19 Jun 2023 13:48:34 +0200 Subject: [PATCH 7/9] Remove unused code --- crates/fj-viewer/src/graphics/vertices.rs | 45 ----------------------- 1 file changed, 45 deletions(-) diff --git a/crates/fj-viewer/src/graphics/vertices.rs b/crates/fj-viewer/src/graphics/vertices.rs index d7f76c4a47..057af30f8e 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 { From da46baa209e52b57c36a3ec65847ee4b83c5c316 Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Mon, 19 Jun 2023 13:49:42 +0200 Subject: [PATCH 8/9] Remove unused re-exports --- crates/fj-viewer/src/lib.rs | 5 ++--- crates/fj-viewer/src/viewer.rs | 7 +++++-- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/crates/fj-viewer/src/lib.rs b/crates/fj-viewer/src/lib.rs index c9d8885034..c5b399409c 100644 --- a/crates/fj-viewer/src/lib.rs +++ b/crates/fj-viewer/src/lib.rs @@ -19,9 +19,8 @@ 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/viewer.rs b/crates/fj-viewer/src/viewer.rs index eec039b9e8..95f423bbee 100644 --- a/crates/fj-viewer/src/viewer.rs +++ b/crates/fj-viewer/src/viewer.rs @@ -3,8 +3,11 @@ 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 From 0cf9f0786730c778de2af97b4e1d0f55117e76be Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Mon, 19 Jun 2023 13:51:44 +0200 Subject: [PATCH 9/9] Remove unused code --- crates/fj-viewer/src/lib.rs | 2 - crates/fj-viewer/src/status_report.rs | 53 --------------------------- 2 files changed, 55 deletions(-) delete mode 100644 crates/fj-viewer/src/status_report.rs diff --git a/crates/fj-viewer/src/lib.rs b/crates/fj-viewer/src/lib.rs index c5b399409c..6819762f71 100644 --- a/crates/fj-viewer/src/lib.rs +++ b/crates/fj-viewer/src/lib.rs @@ -15,13 +15,11 @@ mod camera; mod graphics; mod input; mod screen; -mod status_report; mod viewer; pub use self::{ 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 a2055f3eca..0000000000 --- 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(); - } -}