Skip to content

Commit

Permalink
Merge pull request #1865 from hannobraun/display
Browse files Browse the repository at this point in the history
Expect `Model` in `fj_window::display`
  • Loading branch information
hannobraun authored Jun 6, 2023
2 parents e872377 + 8b5709e commit dbfdc1a
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 12 deletions.
10 changes: 3 additions & 7 deletions crates/fj-window/src/display.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
use fj_interop::{mesh::Mesh, model::Model};
use fj_math::{Aabb, Point};
use fj_interop::model::Model;
use fj_viewer::{
InputEvent, NormalizedScreenPosition, RendererInitError, Screen,
ScreenSize, Viewer,
Expand All @@ -17,15 +16,12 @@ use winit::{
use crate::window::{self, Window};

/// Display the provided mesh in a window that processes input
pub fn display(mesh: Mesh<Point<3>>, invert_zoom: bool) -> Result<(), Error> {
pub fn display(model: Model, invert_zoom: bool) -> Result<(), Error> {
let event_loop = EventLoop::new();
let window = Window::new(&event_loop)?;
let mut viewer = block_on(Viewer::new(&window))?;

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

let mut held_mouse_button = None;
let mut new_size = None;
Expand Down
16 changes: 11 additions & 5 deletions crates/fj/src/handle_model.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
use std::ops::Deref;

use fj_core::algorithms::{approx::Tolerance, triangulate::Triangulate};
use fj_interop::model::Model;
use fj_math::Aabb;

use crate::Args;

Expand All @@ -12,22 +14,26 @@ use crate::Args;
///
/// This function is used by Fornjot's own testing infrastructure, but is useful
/// beyond that, when using Fornjot directly to define a model.
pub fn handle_model<Model>(
model: impl Deref<Target = Model>,
pub fn handle_model<M>(
model: impl Deref<Target = M>,
tolerance: impl Into<Tolerance>,
) -> Result
where
for<'r> (&'r Model, Tolerance): Triangulate,
for<'r> (&'r M, Tolerance): Triangulate,
{
let mesh = (model.deref(), tolerance.into()).triangulate();

let args = Args::parse();
if let Some(path) = args.export {
crate::export::export(&mesh, &path)?;
} else {
crate::window::display(mesh, false)?;
return Ok(());
}

let aabb = Aabb::<3>::from_points(mesh.vertices());
let model = Model { mesh, aabb };

crate::window::display(model, false)?;

Ok(())
}

Expand Down

0 comments on commit dbfdc1a

Please sign in to comment.