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(
|
pub fn focus_point(
|
||||||
&self,
|
&self,
|
||||||
cursor: Option<NormalizedScreenPosition>,
|
cursor: Option<NormalizedScreenPosition>,
|
||||||
shape: &Model,
|
model: &Model,
|
||||||
) -> FocusPoint {
|
) -> FocusPoint {
|
||||||
self.calculate_focus_point(cursor, &shape.mesh)
|
self.calculate_focus_point(cursor, &model.mesh)
|
||||||
.unwrap_or_else(|| FocusPoint(shape.aabb.center()))
|
.unwrap_or_else(|| FocusPoint(model.aabb.center()))
|
||||||
}
|
}
|
||||||
|
|
||||||
fn calculate_focus_point(
|
fn calculate_focus_point(
|
||||||
|
@ -27,8 +27,8 @@ pub struct Viewer {
|
|||||||
/// The renderer
|
/// The renderer
|
||||||
pub renderer: Renderer,
|
pub renderer: Renderer,
|
||||||
|
|
||||||
/// The shape
|
/// The model
|
||||||
pub shape: Option<Model>,
|
pub model: Option<Model>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Viewer {
|
impl Viewer {
|
||||||
@ -43,7 +43,7 @@ impl Viewer {
|
|||||||
focus_point: None,
|
focus_point: None,
|
||||||
input_handler: InputHandler::default(),
|
input_handler: InputHandler::default(),
|
||||||
renderer,
|
renderer,
|
||||||
shape: None,
|
model: None,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -59,12 +59,12 @@ impl Viewer {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Handle the shape being updated
|
/// Handle the model being updated
|
||||||
pub fn handle_shape_update(&mut self, shape: Model) {
|
pub fn handle_model_update(&mut self, model: Model) {
|
||||||
self.renderer.update_geometry((&shape.mesh).into());
|
self.renderer.update_geometry((&model.mesh).into());
|
||||||
|
|
||||||
let aabb = shape.aabb;
|
let aabb = model.aabb;
|
||||||
if self.shape.replace(shape).is_none() {
|
if self.model.replace(model).is_none() {
|
||||||
self.camera.init_planes(&aabb);
|
self.camera.init_planes(&aabb);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -83,11 +83,10 @@ impl Viewer {
|
|||||||
|
|
||||||
/// Compute and store a focus point, unless one is already stored
|
/// Compute and store a focus point, unless one is already stored
|
||||||
pub fn add_focus_point(&mut self) {
|
pub fn add_focus_point(&mut self) {
|
||||||
// Don't recompute the focus point unnecessarily.
|
if let Some(model) = &self.model {
|
||||||
if let Some(shape) = &self.shape {
|
|
||||||
if self.focus_point.is_none() {
|
if self.focus_point.is_none() {
|
||||||
self.focus_point =
|
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
|
/// Draw the graphics
|
||||||
pub fn draw(&mut self) {
|
pub fn draw(&mut self) {
|
||||||
let aabb = self
|
let aabb = self
|
||||||
.shape
|
.model
|
||||||
.as_ref()
|
.as_ref()
|
||||||
.map(|shape| shape.aabb)
|
.map(|shape| shape.aabb)
|
||||||
.unwrap_or_else(Aabb::default);
|
.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 window = Window::new(&event_loop)?;
|
||||||
let mut viewer = block_on(Viewer::new(&window))?;
|
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()),
|
aabb: Aabb::<3>::from_points(mesh.vertices()),
|
||||||
mesh,
|
mesh,
|
||||||
});
|
});
|
||||||
|
Loading…
Reference in New Issue
Block a user