Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extract fj-export from fj-app #472

Merged
merged 4 commits into from
Apr 13, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 12 additions & 3 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 4 additions & 1 deletion fj-app/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ futures = "0.3.21"
nalgebra = "0.30.0"
parry3d-f64 = "0.8.0"
thiserror = "1.0.30"
threemf = "0.2.0"
tracing = "0.1.33"
wgpu = "0.12.0"
wgpu_glyph = "0.16.0"
Expand All @@ -36,6 +35,10 @@ features = ["env", "toml"]
version = "0.5.0"
path = "../fj"

[dependencies.fj-export]
version = "0.5.0"
path = "../fj-export"

[dependencies.fj-host]
version = "0.5.0"
path = "../fj-host"
Expand Down
23 changes: 2 additions & 21 deletions fj-app/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ use std::path::PathBuf;
use std::time::Instant;

use anyhow::anyhow;
use fj_export::export;
use fj_host::{Model, Parameters};
use fj_operations::shape_processor::ShapeProcessor;
use futures::executor::block_on;
Expand Down Expand Up @@ -65,27 +66,7 @@ fn main() -> anyhow::Result<()> {
let shape = model.load_once(&parameters)?;
let shape = shape_processor.process(&shape);

let vertices =
shape.mesh.vertices().map(|vertex| vertex.into()).collect();

let indices: Vec<_> = shape.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)?;
export(&shape.mesh, &path)?;

return Ok(());
}
Expand Down
23 changes: 23 additions & 0 deletions fj-export/Cargo.toml
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"
39 changes: 39 additions & 0 deletions fj-export/src/lib.rs
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;