From 5f2ef72e71fa4a3b47f9388d19f465db1735d9b2 Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Wed, 13 Apr 2022 13:36:29 +0200 Subject: [PATCH] Extract export code to dedicated module --- fj-app/src/export.rs | 31 +++++++++++++++++++++++++++++++ fj-app/src/main.rs | 24 +++--------------------- 2 files changed, 34 insertions(+), 21 deletions(-) create mode 100644 fj-app/src/export.rs diff --git a/fj-app/src/export.rs b/fj-app/src/export.rs new file mode 100644 index 000000000..cb0a9cf44 --- /dev/null +++ b/fj-app/src/export.rs @@ -0,0 +1,31 @@ +use std::path::Path; + +use fj_interop::mesh::Mesh; +use fj_math::Point; + +pub fn export(mesh: &Mesh>, path: &Path) -> Result<(), Error> { + let vertices = mesh.vertices().map(|vertex| vertex.into()).collect(); + + let indices: Vec<_> = mesh.indices().collect(); + let triangles = indices + .chunks(3) + .map(|triangle| { + [ + triangle[0] as usize, + triangle[1] as usize, + triangle[2] as usize, + ] + }) + .collect(); + + let mesh = threemf::TriangleMesh { + vertices, + triangles, + }; + + threemf::write(path, &mesh)?; + + Ok(()) +} + +pub use threemf::Error; diff --git a/fj-app/src/main.rs b/fj-app/src/main.rs index 9631ebfb3..f0f236bd1 100644 --- a/fj-app/src/main.rs +++ b/fj-app/src/main.rs @@ -1,6 +1,7 @@ mod args; mod camera; mod config; +mod export; mod graphics; mod input; mod window; @@ -24,6 +25,7 @@ use crate::{ args::Args, camera::Camera, config::Config, + export::export, graphics::{DrawConfig, Renderer}, window::Window, }; @@ -65,27 +67,7 @@ fn main() -> anyhow::Result<()> { let shape = model.load_once(¶meters)?; let shape = shape_processor.process(&shape); - let vertices = - shape.mesh.vertices().map(|vertex| vertex.into()).collect(); - - let indices: Vec<_> = shape.mesh.indices().collect(); - let triangles = indices - .chunks(3) - .map(|triangle| { - [ - triangle[0] as usize, - triangle[1] as usize, - triangle[2] as usize, - ] - }) - .collect(); - - let mesh = threemf::TriangleMesh { - vertices, - triangles, - }; - - threemf::write(&path, &mesh)?; + export(&shape.mesh, &path)?; return Ok(()); }