mirror of
https://github.com/hannobraun/Fornjot
synced 2025-05-08 03:48:27 +00:00
Re-use fj-export
This commit is contained in:
parent
bc451bb6a0
commit
d77b84a8f5
@ -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(())
|
|
||||||
}
|
|
@ -1,7 +1,6 @@
|
|||||||
#![allow(clippy::module_inception)]
|
#![allow(clippy::module_inception)]
|
||||||
|
|
||||||
mod app;
|
mod app;
|
||||||
mod export;
|
|
||||||
mod extra;
|
mod extra;
|
||||||
mod geometry;
|
mod geometry;
|
||||||
mod handle;
|
mod handle;
|
||||||
@ -14,7 +13,7 @@ mod topology;
|
|||||||
fn main() -> anyhow::Result<()> {
|
fn main() -> anyhow::Result<()> {
|
||||||
let tri_mesh = model::model();
|
let tri_mesh = model::model();
|
||||||
|
|
||||||
export::export(&tri_mesh, "output.3mf")?;
|
fj_export::export(&tri_mesh, "output.3mf")?;
|
||||||
app::run(tri_mesh)?;
|
app::run(tri_mesh)?;
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
|
Loading…
Reference in New Issue
Block a user