Skip to content

Commit

Permalink
Merge pull request #1864 from hannobraun/viewer
Browse files Browse the repository at this point in the history
Adapt `fj-viewer` to model-related changes in `fj-interop`
  • Loading branch information
hannobraun authored Jun 6, 2023
2 parents c270824 + c8d5bef commit e872377
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 16 deletions.
6 changes: 3 additions & 3 deletions crates/fj-viewer/src/camera.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,10 +82,10 @@ impl Camera {
pub fn focus_point(
&self,
cursor: Option<NormalizedScreenPosition>,
shape: &Model,
model: &Model,
) -> FocusPoint {
self.calculate_focus_point(cursor, &shape.mesh)
.unwrap_or_else(|| FocusPoint(shape.aabb.center()))
self.calculate_focus_point(cursor, &model.mesh)
.unwrap_or_else(|| FocusPoint(model.aabb.center()))
}

fn calculate_focus_point(
Expand Down
23 changes: 11 additions & 12 deletions crates/fj-viewer/src/viewer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ pub struct Viewer {
/// The renderer
pub renderer: Renderer,

/// The shape
pub shape: Option<Model>,
/// The model
pub model: Option<Model>,
}

impl Viewer {
Expand All @@ -43,7 +43,7 @@ impl Viewer {
focus_point: None,
input_handler: InputHandler::default(),
renderer,
shape: None,
model: None,
})
}

Expand All @@ -59,12 +59,12 @@ impl Viewer {
}
}

/// Handle the shape being updated
pub fn handle_shape_update(&mut self, shape: Model) {
self.renderer.update_geometry((&shape.mesh).into());
/// Handle the model being updated
pub fn handle_model_update(&mut self, model: Model) {
self.renderer.update_geometry((&model.mesh).into());

let aabb = shape.aabb;
if self.shape.replace(shape).is_none() {
let aabb = model.aabb;
if self.model.replace(model).is_none() {
self.camera.init_planes(&aabb);
}
}
Expand All @@ -83,11 +83,10 @@ impl Viewer {

/// Compute and store a focus point, unless one is already stored
pub fn add_focus_point(&mut self) {
// Don't recompute the focus point unnecessarily.
if let Some(shape) = &self.shape {
if let Some(model) = &self.model {
if self.focus_point.is_none() {
self.focus_point =
Some(self.camera.focus_point(self.cursor, shape));
Some(self.camera.focus_point(self.cursor, model));
}
}
}
Expand All @@ -100,7 +99,7 @@ impl Viewer {
/// Draw the graphics
pub fn draw(&mut self) {
let aabb = self
.shape
.model
.as_ref()
.map(|shape| shape.aabb)
.unwrap_or_else(Aabb::default);
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 @@ -22,7 +22,7 @@ pub fn display(mesh: Mesh<Point<3>>, invert_zoom: bool) -> Result<(), Error> {
let window = Window::new(&event_loop)?;
let mut viewer = block_on(Viewer::new(&window))?;

viewer.handle_shape_update(Model {
viewer.handle_model_update(Model {
aabb: Aabb::<3>::from_points(mesh.vertices()),
mesh,
});
Expand Down

0 comments on commit e872377

Please sign in to comment.