mirror of
https://github.com/hannobraun/Fornjot
synced 2025-07-19 16:36:09 +00:00
commit
e3fb60d16a
@ -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);
|
||||
|
@ -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<fj_math::Point<3>>> for Vertices {
|
||||
|
@ -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,
|
||||
};
|
||||
|
@ -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<String>,
|
||||
}
|
||||
|
||||
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::<String>()
|
||||
}
|
||||
|
||||
/// Reset status
|
||||
pub fn clear_status(&mut self) {
|
||||
self.status.clear();
|
||||
}
|
||||
}
|
@ -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 {
|
||||
@ -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;
|
||||
|
@ -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 {
|
||||
|
Loading…
x
Reference in New Issue
Block a user