From 3918896cd8f12d479122f7f69686ab8d122e5b87 Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Wed, 13 Apr 2022 13:28:36 +0200 Subject: [PATCH 1/4] Upgrade to latest `threemf` --- Cargo.lock | 4 ++-- fj-app/Cargo.toml | 2 +- fj-app/src/main.rs | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 5be43a446..bfb551ed5 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2543,9 +2543,9 @@ dependencies = [ [[package]] name = "threemf" -version = "0.2.0" +version = "0.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c0c98800ca8044fa88359515e47c1e2a432dd463b7cfb0764307d5e643e6cc93" +checksum = "02a12818d477c54ac38deb1bd8e222036385b594c020f02097914b6ac81cfff3" dependencies = [ "thiserror", "zip", diff --git a/fj-app/Cargo.toml b/fj-app/Cargo.toml index f90fbfaf3..ec642080e 100644 --- a/fj-app/Cargo.toml +++ b/fj-app/Cargo.toml @@ -18,7 +18,7 @@ futures = "0.3.21" nalgebra = "0.30.0" parry3d-f64 = "0.8.0" thiserror = "1.0.30" -threemf = "0.2.0" +threemf = "0.3.0" tracing = "0.1.33" wgpu = "0.12.0" wgpu_glyph = "0.16.0" diff --git a/fj-app/src/main.rs b/fj-app/src/main.rs index 43b3953d7..9631ebfb3 100644 --- a/fj-app/src/main.rs +++ b/fj-app/src/main.rs @@ -85,7 +85,7 @@ fn main() -> anyhow::Result<()> { triangles, }; - threemf::write(path, &mesh)?; + threemf::write(&path, &mesh)?; return Ok(()); } From 5f2ef72e71fa4a3b47f9388d19f465db1735d9b2 Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Wed, 13 Apr 2022 13:36:29 +0200 Subject: [PATCH 2/4] Extract export code to dedicated module --- fj-app/src/export.rs | 31 +++++++++++++++++++++++++++++++ fj-app/src/main.rs | 24 +++--------------------- 2 files changed, 34 insertions(+), 21 deletions(-) create mode 100644 fj-app/src/export.rs diff --git a/fj-app/src/export.rs b/fj-app/src/export.rs new file mode 100644 index 000000000..cb0a9cf44 --- /dev/null +++ b/fj-app/src/export.rs @@ -0,0 +1,31 @@ +use std::path::Path; + +use fj_interop::mesh::Mesh; +use fj_math::Point; + +pub fn export(mesh: &Mesh>, 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; diff --git a/fj-app/src/main.rs b/fj-app/src/main.rs index 9631ebfb3..f0f236bd1 100644 --- a/fj-app/src/main.rs +++ b/fj-app/src/main.rs @@ -1,6 +1,7 @@ mod args; mod camera; mod config; +mod export; mod graphics; mod input; mod window; @@ -24,6 +25,7 @@ use crate::{ args::Args, camera::Camera, config::Config, + export::export, graphics::{DrawConfig, Renderer}, window::Window, }; @@ -65,27 +67,7 @@ fn main() -> anyhow::Result<()> { let shape = model.load_once(¶meters)?; 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(()); } From d96b3ef29df9b3df770026c220849725215ab5d2 Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Wed, 13 Apr 2022 13:44:59 +0200 Subject: [PATCH 3/4] Extract `fj-export` from `fj-app` --- Cargo.lock | 11 +++++++++- fj-app/Cargo.toml | 5 ++++- fj-app/src/main.rs | 3 +-- fj-export/Cargo.toml | 23 ++++++++++++++++++++ fj-app/src/export.rs => fj-export/src/lib.rs | 0 5 files changed, 38 insertions(+), 4 deletions(-) create mode 100644 fj-export/Cargo.toml rename fj-app/src/export.rs => fj-export/src/lib.rs (100%) diff --git a/Cargo.lock b/Cargo.lock index bfb551ed5..e5611164b 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -698,6 +698,7 @@ dependencies = [ "clap", "figment", "fj", + "fj-export", "fj-host", "fj-interop", "fj-kernel", @@ -708,7 +709,6 @@ dependencies = [ "parry3d-f64", "serde", "thiserror", - "threemf", "tracing", "tracing-subscriber", "wgpu", @@ -716,6 +716,15 @@ dependencies = [ "winit", ] +[[package]] +name = "fj-export" +version = "0.5.0" +dependencies = [ + "fj-interop", + "fj-math", + "threemf", +] + [[package]] name = "fj-host" version = "0.5.0" diff --git a/fj-app/Cargo.toml b/fj-app/Cargo.toml index ec642080e..63ad7538c 100644 --- a/fj-app/Cargo.toml +++ b/fj-app/Cargo.toml @@ -18,7 +18,6 @@ futures = "0.3.21" nalgebra = "0.30.0" parry3d-f64 = "0.8.0" thiserror = "1.0.30" -threemf = "0.3.0" tracing = "0.1.33" wgpu = "0.12.0" wgpu_glyph = "0.16.0" @@ -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" diff --git a/fj-app/src/main.rs b/fj-app/src/main.rs index f0f236bd1..9e770c87e 100644 --- a/fj-app/src/main.rs +++ b/fj-app/src/main.rs @@ -1,7 +1,6 @@ mod args; mod camera; mod config; -mod export; mod graphics; mod input; mod window; @@ -10,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; @@ -25,7 +25,6 @@ use crate::{ args::Args, camera::Camera, config::Config, - export::export, graphics::{DrawConfig, Renderer}, window::Window, }; diff --git a/fj-export/Cargo.toml b/fj-export/Cargo.toml new file mode 100644 index 000000000..5086dcba6 --- /dev/null +++ b/fj-export/Cargo.toml @@ -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" diff --git a/fj-app/src/export.rs b/fj-export/src/lib.rs similarity index 100% rename from fj-app/src/export.rs rename to fj-export/src/lib.rs From 61a11550b2c1ea6b8eec939effc793ae25bb6f33 Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Wed, 13 Apr 2022 13:48:21 +0200 Subject: [PATCH 4/4] Document `fj-export` --- fj-export/src/lib.rs | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/fj-export/src/lib.rs b/fj-export/src/lib.rs index cb0a9cf44..635802f8c 100644 --- a/fj-export/src/lib.rs +++ b/fj-export/src/lib.rs @@ -1,8 +1,16 @@ +//! 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>, path: &Path) -> Result<(), Error> { let vertices = mesh.vertices().map(|vertex| vertex.into()).collect();