Merge pull request #1865 from hannobraun/display

Expect `Model` in `fj_window::display`
This commit is contained in:
Hanno Braun 2023-06-06 13:32:05 +02:00 committed by GitHub
commit dbfdc1a3b2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 14 additions and 12 deletions

View File

@ -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,
@ -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;

View File

@ -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;
@ -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(())
}