mirror of
https://github.com/hannobraun/Fornjot
synced 2025-01-31 04:15:54 +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 args;
|
||||||
mod camera;
|
mod camera;
|
||||||
mod config;
|
mod config;
|
||||||
|
mod export;
|
||||||
mod graphics;
|
mod graphics;
|
||||||
mod input;
|
mod input;
|
||||||
mod window;
|
mod window;
|
||||||
@ -24,6 +25,7 @@ use crate::{
|
|||||||
args::Args,
|
args::Args,
|
||||||
camera::Camera,
|
camera::Camera,
|
||||||
config::Config,
|
config::Config,
|
||||||
|
export::export,
|
||||||
graphics::{DrawConfig, Renderer},
|
graphics::{DrawConfig, Renderer},
|
||||||
window::Window,
|
window::Window,
|
||||||
};
|
};
|
||||||
@ -65,27 +67,7 @@ fn main() -> anyhow::Result<()> {
|
|||||||
let shape = model.load_once(¶meters)?;
|
let shape = model.load_once(¶meters)?;
|
||||||
let shape = shape_processor.process(&shape);
|
let shape = shape_processor.process(&shape);
|
||||||
|
|
||||||
let vertices =
|
export(&shape.mesh, &path)?;
|
||||||
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)?;
|
|
||||||
|
|
||||||
return Ok(());
|
return Ok(());
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user