mirror of
https://github.com/hannobraun/Fornjot
synced 2025-01-30 20:05:55 +00:00
Extract export code to dedicated module
This commit is contained in:
parent
3918896cd8
commit
5f2ef72e71
31
fj-app/src/export.rs
Normal file
31
fj-app/src/export.rs
Normal 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;
|
@ -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(());
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user