mirror of
https://github.com/hannobraun/Fornjot
synced 2025-05-05 18:38:28 +00:00
Move export
to dedicated module
This commit is contained in:
parent
a5f2d71995
commit
02348ebe9e
28
experiments/2024-10-30/src/export.rs
Normal file
28
experiments/2024-10-30/src/export.rs
Normal 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(())
|
||||
}
|
@ -1,4 +1,5 @@
|
||||
mod model;
|
||||
mod export;
|
||||
|
||||
fn main() -> anyhow::Result<()> {
|
||||
model::model()?;
|
||||
|
@ -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(())
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user