mirror of
https://github.com/hannobraun/Fornjot
synced 2025-09-18 15:18:10 +00:00
Make fj_export::export
more flexible
This commit is contained in:
parent
341b561e5d
commit
8540ed7d74
@ -16,7 +16,7 @@ use std::{
|
|||||||
|
|
||||||
use thiserror::Error;
|
use thiserror::Error;
|
||||||
|
|
||||||
use fj_interop::{MeshTriangle, TriMesh, vertices_to_indexed_vertices};
|
use fj_interop::{MeshTriangle, vertices_to_indexed_vertices};
|
||||||
use fj_math::Triangle;
|
use fj_math::Triangle;
|
||||||
|
|
||||||
/// # Export the provided mesh to the file at the given path
|
/// # Export the provided mesh to the file at the given path
|
||||||
@ -26,19 +26,22 @@ use fj_math::Triangle;
|
|||||||
///
|
///
|
||||||
/// Currently 3MF & STL file types are supported. The case insensitive file
|
/// Currently 3MF & STL file types are supported. The case insensitive file
|
||||||
/// extension of the provided path is used to switch between supported types.
|
/// extension of the provided path is used to switch between supported types.
|
||||||
pub fn export(tri_mesh: &TriMesh, path: impl AsRef<Path>) -> Result<(), Error> {
|
pub fn export<'r>(
|
||||||
|
triangles: impl IntoIterator<Item = &'r MeshTriangle>,
|
||||||
|
path: impl AsRef<Path>,
|
||||||
|
) -> Result<(), Error> {
|
||||||
match path.as_ref().extension() {
|
match path.as_ref().extension() {
|
||||||
Some(extension) if extension.eq_ignore_ascii_case("3MF") => {
|
Some(extension) if extension.eq_ignore_ascii_case("3MF") => {
|
||||||
let mut file = File::create(path)?;
|
let mut file = File::create(path)?;
|
||||||
export_3mf(tri_mesh.triangles.iter(), &mut file)
|
export_3mf(triangles, &mut file)
|
||||||
}
|
}
|
||||||
Some(extension) if extension.eq_ignore_ascii_case("STL") => {
|
Some(extension) if extension.eq_ignore_ascii_case("STL") => {
|
||||||
let mut file = File::create(path)?;
|
let mut file = File::create(path)?;
|
||||||
export_stl(tri_mesh.triangles.iter(), &mut file)
|
export_stl(triangles, &mut file)
|
||||||
}
|
}
|
||||||
Some(extension) if extension.eq_ignore_ascii_case("OBJ") => {
|
Some(extension) if extension.eq_ignore_ascii_case("OBJ") => {
|
||||||
let mut file = File::create(path)?;
|
let mut file = File::create(path)?;
|
||||||
export_obj(tri_mesh.triangles.iter(), &mut file)
|
export_obj(triangles, &mut file)
|
||||||
}
|
}
|
||||||
Some(extension) => Err(Error::InvalidExtension(
|
Some(extension) => Err(Error::InvalidExtension(
|
||||||
extension.to_string_lossy().into_owned(),
|
extension.to_string_lossy().into_owned(),
|
||||||
|
@ -84,7 +84,7 @@ impl Instance {
|
|||||||
let tri_mesh = (model, tolerance).triangulate(&mut self.core);
|
let tri_mesh = (model, tolerance).triangulate(&mut self.core);
|
||||||
|
|
||||||
if let Some(path) = args.export {
|
if let Some(path) = args.export {
|
||||||
export::export(&tri_mesh, &path)?;
|
export::export(tri_mesh.triangles.iter(), &path)?;
|
||||||
return Ok(());
|
return Ok(());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user