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

Expect Model in fj_window::display #1865

Merged
merged 4 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
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