mirror of
https://github.com/hannobraun/Fornjot
synced 2025-03-01 02:25:59 +00:00
Merge pull request #1864 from hannobraun/viewer
Adapt `fj-viewer` to model-related changes in `fj-interop`
This commit is contained in:
commit
e872377e0a
@ -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(
|
||||
|
@ -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 {
|
||||
@ -43,7 +43,7 @@ impl Viewer {
|
||||
focus_point: None,
|
||||
input_handler: InputHandler::default(),
|
||||
renderer,
|
||||
shape: None,
|
||||
model: None,
|
||||
})
|
||||
}
|
||||
|
||||
@ -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);
|
||||
}
|
||||
}
|
||||
@ -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));
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -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);
|
||||
|
@ -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,
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user