Skip to content

Commit

Permalink
Merge pull request #1893 from hannobraun/viewer
Browse files Browse the repository at this point in the history
Clean up `fj_viewer`
  • Loading branch information
hannobraun authored Jun 19, 2023
2 parents 9633746 + 0cf9f07 commit e3fb60d
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 140 deletions.
17 changes: 4 additions & 13 deletions crates/fj-viewer/src/graphics/renderer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
45 changes: 0 additions & 45 deletions crates/fj-viewer/src/graphics/vertices.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
use bytemuck::{Pod, Zeroable};
use fj_interop::mesh::{Index, Mesh};
use fj_math::{Point, Vector};

#[derive(Debug)]
pub struct Vertices {
Expand All @@ -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<fj_math::Point<3>>> for Vertices {
Expand Down
7 changes: 2 additions & 5 deletions crates/fj-viewer/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
};
53 changes: 0 additions & 53 deletions crates/fj-viewer/src/status_report.rs

This file was deleted.

39 changes: 16 additions & 23 deletions crates/fj-viewer/src/viewer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<NormalizedScreenPosition>,

/// The draw config
pub draw_config: DrawConfig,

/// The focus point
pub focus_point: Option<FocusPoint>,

/// The input handler
pub input_handler: InputHandler,

/// The renderer
pub renderer: Renderer,

/// The model
pub model: Option<Model>,
camera: Camera,
cursor: Option<NormalizedScreenPosition>,
draw_config: DrawConfig,
focus_point: Option<FocusPoint>,
renderer: Renderer,
model: Option<Model>,
}

impl Viewer {
Expand All @@ -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<NormalizedScreenPosition> {
self.cursor
}

/// Toggle the "draw model" setting
pub fn toggle_draw_model(&mut self) {
self.draw_config.draw_model = !self.draw_config.draw_model;
Expand Down
2 changes: 1 addition & 1 deletion crates/fj-window/src/display.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit e3fb60d

Please sign in to comment.