Extract export code to dedicated module

This commit is contained in:
Hanno Braun 2022-04-13 13:36:29 +02:00
parent 3918896cd8
commit 5f2ef72e71
2 changed files with 34 additions and 21 deletions

31
fj-app/src/export.rs Normal file
View File

@ -0,0 +1,31 @@
use std::path::Path;
use fj_interop::mesh::Mesh;
use fj_math::Point;
pub fn export(mesh: &Mesh<Point<3>>, 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;

View File

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