-
-
Notifications
You must be signed in to change notification settings - Fork 119
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #472 from hannobraun/export
Extract `fj-export` from `fj-app`
- Loading branch information
Showing
5 changed files
with
80 additions
and
25 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
[package] | ||
name = "fj-export" | ||
version = "0.5.0" | ||
edition = "2021" | ||
|
||
description = "The world needs another CAD program." | ||
readme = "../README.md" | ||
repository = "https://github.com/hannobraun/fornjot" | ||
license = "0BSD" | ||
keywords = ["cad", "programmatic", "code-cad"] | ||
categories = ["encoding"] | ||
|
||
|
||
[dependencies] | ||
threemf = "0.3.0" | ||
|
||
[dependencies.fj-interop] | ||
version = "0.5.0" | ||
path = "../fj-interop" | ||
|
||
[dependencies.fj-math] | ||
version = "0.5.0" | ||
path = "../fj-math" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
//! Exporting Fornjot models to external files | ||
#![deny(missing_docs)] | ||
|
||
use std::path::Path; | ||
|
||
use fj_interop::mesh::Mesh; | ||
use fj_math::Point; | ||
|
||
/// Export the provided mesh to the file at the given path | ||
/// | ||
/// Currently only 3MF is supported as an export format. The file extension of | ||
/// the provided path is ignored. | ||
pub fn export(mesh: &Mesh<Point<3>>, path: &Path) -> Result<(), Error> { | ||
let vertices = mesh.vertices().map(|vertex| vertex.into()).collect(); | ||
|
||
let indices: Vec<_> = mesh.indices().collect(); | ||
let triangles = indices | ||
.chunks(3) | ||
.map(|triangle| { | ||
[ | ||
triangle[0] as usize, | ||
triangle[1] as usize, | ||
triangle[2] as usize, | ||
] | ||
}) | ||
.collect(); | ||
|
||
let mesh = threemf::TriangleMesh { | ||
vertices, | ||
triangles, | ||
}; | ||
|
||
threemf::write(path, &mesh)?; | ||
|
||
Ok(()) | ||
} | ||
|
||
pub use threemf::Error; |