-
-
Notifications
You must be signed in to change notification settings - Fork 119
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
Fix #1015 start gui independent of model #1095
Changes from all commits
ffcdb63
88621d2
284f7d7
ddbf0a3
a49e7df
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -29,7 +29,7 @@ use crate::window::{self, Window}; | |||||
|
||||||
/// Initializes a model viewer for a given model and enters its process loop. | ||||||
pub fn run( | ||||||
watcher: Watcher, | ||||||
watcher: Option<Watcher>, | ||||||
shape_processor: ShapeProcessor, | ||||||
mut status: StatusReport, | ||||||
) -> Result<(), Error> { | ||||||
|
@@ -46,39 +46,43 @@ pub fn run( | |||||
let mut draw_config = DrawConfig::default(); | ||||||
|
||||||
let mut shape = None; | ||||||
let mut camera = None; | ||||||
let mut camera = Camera::new(&Default::default()); | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
This would make it a bit more obvious what is being passed. |
||||||
let mut camera_update_once = watcher.is_some(); | ||||||
|
||||||
event_loop.run(move |event, _, control_flow| { | ||||||
trace!("Handling event: {:?}", event); | ||||||
|
||||||
if let Some(new_shape) = watcher.receive(&mut status) { | ||||||
match shape_processor.process(&new_shape) { | ||||||
Ok(new_shape) => { | ||||||
renderer.update_geometry( | ||||||
(&new_shape.mesh).into(), | ||||||
(&new_shape.debug_info).into(), | ||||||
new_shape.aabb, | ||||||
); | ||||||
if let Some(watcher) = &watcher { | ||||||
if let Some(new_shape) = watcher.receive(&mut status) { | ||||||
match shape_processor.process(&new_shape) { | ||||||
Ok(new_shape) => { | ||||||
renderer.update_geometry( | ||||||
(&new_shape.mesh).into(), | ||||||
(&new_shape.debug_info).into(), | ||||||
new_shape.aabb, | ||||||
); | ||||||
|
||||||
if camera.is_none() { | ||||||
camera = Some(Camera::new(&new_shape.aabb)); | ||||||
} | ||||||
if camera_update_once { | ||||||
camera_update_once = false; | ||||||
camera = Camera::new(&new_shape.aabb); | ||||||
} | ||||||
Comment on lines
+65
to
+68
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not sure I like I think maybe Then we could just create the camera using |
||||||
|
||||||
shape = Some(new_shape); | ||||||
} | ||||||
Err(err) => { | ||||||
// Can be cleaned up, once `Report` is stable: | ||||||
// https://doc.rust-lang.org/std/error/struct.Report.html | ||||||
shape = Some(new_shape); | ||||||
} | ||||||
Err(err) => { | ||||||
// Can be cleaned up, once `Report` is stable: | ||||||
// https://doc.rust-lang.org/std/error/struct.Report.html | ||||||
|
||||||
println!("Shape processing error: {}", err); | ||||||
println!("Shape processing error: {}", err); | ||||||
|
||||||
let mut current_err = &err as &dyn error::Error; | ||||||
while let Some(err) = current_err.source() { | ||||||
println!(); | ||||||
println!("Caused by:"); | ||||||
println!(" {}", err); | ||||||
let mut current_err = &err as &dyn error::Error; | ||||||
while let Some(err) = current_err.source() { | ||||||
println!(); | ||||||
println!("Caused by:"); | ||||||
println!(" {}", err); | ||||||
|
||||||
current_err = err; | ||||||
current_err = err; | ||||||
} | ||||||
} | ||||||
} | ||||||
} | ||||||
|
@@ -173,17 +177,17 @@ pub fn run( | |||||
window.window().request_redraw(); | ||||||
} | ||||||
Event::RedrawRequested(_) => { | ||||||
if let (Some(shape), Some(camera)) = (&shape, &mut camera) { | ||||||
if let Some(shape) = &shape { | ||||||
camera.update_planes(&shape.aabb); | ||||||
} | ||||||
|
||||||
if let Err(err) = renderer.draw( | ||||||
camera, | ||||||
&mut draw_config, | ||||||
window.window(), | ||||||
&mut status, | ||||||
) { | ||||||
warn!("Draw error: {}", err); | ||||||
} | ||||||
if let Err(err) = renderer.draw( | ||||||
&camera, | ||||||
&mut draw_config, | ||||||
window.window(), | ||||||
&mut status, | ||||||
) { | ||||||
warn!("Draw error: {}", err); | ||||||
} | ||||||
} | ||||||
_ => {} | ||||||
|
@@ -192,8 +196,7 @@ pub fn run( | |||||
// fj-viewer input events | ||||||
// These can fire multiple times per frame | ||||||
|
||||||
if let (Some(shape), Some(camera), Some(should_focus)) = | ||||||
(&shape, &camera, focus_event(&event)) | ||||||
if let (Some(shape), Some(should_focus)) = (&shape, focus_event(&event)) | ||||||
{ | ||||||
if should_focus { | ||||||
// Don't unnecessarily recalculate focus point | ||||||
|
@@ -212,10 +215,8 @@ pub fn run( | |||||
&held_mouse_button, | ||||||
&mut previous_cursor, | ||||||
); | ||||||
if let (Some(input_event), Some(fp), Some(camera)) = | ||||||
(input_event, focus_point, &mut camera) | ||||||
{ | ||||||
input_handler.handle_event(input_event, fp, camera); | ||||||
if let (Some(input_event), Some(fp)) = (input_event, focus_point) { | ||||||
input_handler.handle_event(input_event, fp, &mut camera); | ||||||
} | ||||||
}); | ||||||
} | ||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This could be made a bit more compact (but possible less clear) using
Option::map
. Not necessary to change anything, and I don't know if it would even be better. Just noting the possibility, because it stuck out to me.