Re-use fj-export

This commit is contained in:
Hanno Braun 2025-03-21 23:19:54 +01:00
parent bc451bb6a0
commit d77b84a8f5
2 changed files with 1 additions and 50 deletions

View File

@ -1,48 +0,0 @@
use std::{collections::BTreeMap, fs::File, path::Path};
use fj_interop::TriMesh;
pub fn export(
tri_mesh: &TriMesh,
path: impl AsRef<Path>,
) -> anyhow::Result<()> {
let mut indices_by_vertex = BTreeMap::new();
let mut points = Vec::new();
let mut triangles = Vec::new();
for triangle in tri_mesh.external_triangles() {
let triangle = triangle.points.map(|point| {
*indices_by_vertex.entry(point).or_insert_with(|| {
let index = points.len();
points.push(point);
index
})
});
triangles.push(triangle);
}
let mesh = threemf::Mesh {
vertices: threemf::model::Vertices {
vertex: points
.into_iter()
.map(|point| {
point.coords.components.map(|coord| coord.into_f64())
})
.map(|[x, y, z]| threemf::model::Vertex { x, y, z })
.collect(),
},
triangles: threemf::model::Triangles {
triangle: triangles
.into_iter()
.map(|[v1, v2, v3]| threemf::model::Triangle { v1, v2, v3 })
.collect(),
},
};
let output = File::create(path)?;
threemf::write(output, mesh)?;
Ok(())
}

View File

@ -1,7 +1,6 @@
#![allow(clippy::module_inception)]
mod app;
mod export;
mod extra;
mod geometry;
mod handle;
@ -14,7 +13,7 @@ mod topology;
fn main() -> anyhow::Result<()> {
let tri_mesh = model::model();
export::export(&tri_mesh, "output.3mf")?;
fj_export::export(&tri_mesh, "output.3mf")?;
app::run(tri_mesh)?;
Ok(())