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

Adapt fj-viewer to model-related changes in fj-interop #1864

Merged
merged 8 commits into from
Jun 6, 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
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