Move export to dedicated module

This commit is contained in:
Hanno Braun 2024-10-30 01:25:09 +01:00
parent a5f2d71995
commit 02348ebe9e
3 changed files with 30 additions and 28 deletions

View File

@ -0,0 +1,28 @@
use std::fs::File;
pub fn export(
vertices: impl IntoIterator<Item = [f64; 3]>,
triangles: impl IntoIterator<Item = [usize; 3]>,
) -> anyhow::Result<()> {
let vertices = vertices
.into_iter()
.map(|[x, y, z]| threemf::model::Vertex { x, y, z })
.collect();
let triangles = triangles
.into_iter()
.map(|[v1, v2, v3]| threemf::model::Triangle { v1, v2, v3 })
.collect();
let mesh = threemf::Mesh {
vertices: threemf::model::Vertices { vertex: vertices },
triangles: threemf::model::Triangles {
triangle: triangles,
},
};
let output = File::create("output.3mf")?;
threemf::write(output, mesh)?;
Ok(())
}

View File

@ -1,4 +1,5 @@
mod model;
mod export;
fn main() -> anyhow::Result<()> {
model::model()?;

View File

@ -1,4 +1,4 @@
use std::fs::File;
use crate::export::export;
pub fn model() -> anyhow::Result<()> {
let vertices = [
@ -31,30 +31,3 @@ pub fn model() -> anyhow::Result<()> {
Ok(())
}
fn export(
vertices: impl IntoIterator<Item = [f64; 3]>,
triangles: impl IntoIterator<Item = [usize; 3]>,
) -> anyhow::Result<()> {
let vertices = vertices
.into_iter()
.map(|[x, y, z]| threemf::model::Vertex { x, y, z })
.collect();
let triangles = triangles
.into_iter()
.map(|[v1, v2, v3]| threemf::model::Triangle { v1, v2, v3 })
.collect();
let mesh = threemf::Mesh {
vertices: threemf::model::Vertices { vertex: vertices },
triangles: threemf::model::Triangles {
triangle: triangles,
},
};
let output = File::create("output.3mf")?;
threemf::write(output, mesh)?;
Ok(())
}