Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clean up fj_viewer #1893

Merged
merged 9 commits into from
Jun 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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