mirror of
https://github.com/hannobraun/Fornjot
synced 2025-01-30 11:55:57 +00:00
Merge pull request #472 from hannobraun/export
Extract `fj-export` from `fj-app`
This commit is contained in:
commit
aafe282902
15
Cargo.lock
generated
15
Cargo.lock
generated
@ -698,6 +698,7 @@ dependencies = [
|
|||||||
"clap",
|
"clap",
|
||||||
"figment",
|
"figment",
|
||||||
"fj",
|
"fj",
|
||||||
|
"fj-export",
|
||||||
"fj-host",
|
"fj-host",
|
||||||
"fj-interop",
|
"fj-interop",
|
||||||
"fj-kernel",
|
"fj-kernel",
|
||||||
@ -708,7 +709,6 @@ dependencies = [
|
|||||||
"parry3d-f64",
|
"parry3d-f64",
|
||||||
"serde",
|
"serde",
|
||||||
"thiserror",
|
"thiserror",
|
||||||
"threemf",
|
|
||||||
"tracing",
|
"tracing",
|
||||||
"tracing-subscriber",
|
"tracing-subscriber",
|
||||||
"wgpu",
|
"wgpu",
|
||||||
@ -716,6 +716,15 @@ dependencies = [
|
|||||||
"winit",
|
"winit",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "fj-export"
|
||||||
|
version = "0.5.0"
|
||||||
|
dependencies = [
|
||||||
|
"fj-interop",
|
||||||
|
"fj-math",
|
||||||
|
"threemf",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "fj-host"
|
name = "fj-host"
|
||||||
version = "0.5.0"
|
version = "0.5.0"
|
||||||
@ -2543,9 +2552,9 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "threemf"
|
name = "threemf"
|
||||||
version = "0.2.0"
|
version = "0.3.0"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "c0c98800ca8044fa88359515e47c1e2a432dd463b7cfb0764307d5e643e6cc93"
|
checksum = "02a12818d477c54ac38deb1bd8e222036385b594c020f02097914b6ac81cfff3"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"thiserror",
|
"thiserror",
|
||||||
"zip",
|
"zip",
|
||||||
|
@ -18,7 +18,6 @@ futures = "0.3.21"
|
|||||||
nalgebra = "0.30.0"
|
nalgebra = "0.30.0"
|
||||||
parry3d-f64 = "0.8.0"
|
parry3d-f64 = "0.8.0"
|
||||||
thiserror = "1.0.30"
|
thiserror = "1.0.30"
|
||||||
threemf = "0.2.0"
|
|
||||||
tracing = "0.1.33"
|
tracing = "0.1.33"
|
||||||
wgpu = "0.12.0"
|
wgpu = "0.12.0"
|
||||||
wgpu_glyph = "0.16.0"
|
wgpu_glyph = "0.16.0"
|
||||||
@ -36,6 +35,10 @@ features = ["env", "toml"]
|
|||||||
version = "0.5.0"
|
version = "0.5.0"
|
||||||
path = "../fj"
|
path = "../fj"
|
||||||
|
|
||||||
|
[dependencies.fj-export]
|
||||||
|
version = "0.5.0"
|
||||||
|
path = "../fj-export"
|
||||||
|
|
||||||
[dependencies.fj-host]
|
[dependencies.fj-host]
|
||||||
version = "0.5.0"
|
version = "0.5.0"
|
||||||
path = "../fj-host"
|
path = "../fj-host"
|
||||||
|
@ -9,6 +9,7 @@ use std::path::PathBuf;
|
|||||||
use std::time::Instant;
|
use std::time::Instant;
|
||||||
|
|
||||||
use anyhow::anyhow;
|
use anyhow::anyhow;
|
||||||
|
use fj_export::export;
|
||||||
use fj_host::{Model, Parameters};
|
use fj_host::{Model, Parameters};
|
||||||
use fj_operations::shape_processor::ShapeProcessor;
|
use fj_operations::shape_processor::ShapeProcessor;
|
||||||
use futures::executor::block_on;
|
use futures::executor::block_on;
|
||||||
@ -65,27 +66,7 @@ fn main() -> anyhow::Result<()> {
|
|||||||
let shape = model.load_once(¶meters)?;
|
let shape = model.load_once(¶meters)?;
|
||||||
let shape = shape_processor.process(&shape);
|
let shape = shape_processor.process(&shape);
|
||||||
|
|
||||||
let vertices =
|
export(&shape.mesh, &path)?;
|
||||||
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)?;
|
|
||||||
|
|
||||||
return Ok(());
|
return Ok(());
|
||||||
}
|
}
|
||||||
|
23
fj-export/Cargo.toml
Normal file
23
fj-export/Cargo.toml
Normal file
@ -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
fj-export/src/lib.rs
Normal file
39
fj-export/src/lib.rs
Normal file
@ -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;
|
Loading…
Reference in New Issue
Block a user