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

Update to latest version of 3mf-rs #1595

Merged
merged 1 commit into from
Feb 17, 2023
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
16 changes: 14 additions & 2 deletions Cargo.lock

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

2 changes: 1 addition & 1 deletion crates/fj-export/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,5 @@ categories.workspace = true
fj-interop.workspace = true
fj-math.workspace = true
thiserror = "1.0.35"
threemf = "0.3.1"
threemf = "0.4.0"
stl = "0.2.1"
29 changes: 18 additions & 11 deletions crates/fj-export/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,26 +43,33 @@ pub fn export(mesh: &Mesh<Point<3>>, path: &Path) -> Result<(), Error> {
}

fn export_3mf(mesh: &Mesh<Point<3>>, path: &Path) -> Result<(), Error> {
let vertices = mesh.vertices().map(Into::into).collect();
let vertices = mesh
.vertices()
.map(|point| threemf::model::Vertex {
x: point.x.into_f64(),
y: point.y.into_f64(),
z: point.z.into_f64(),
})
.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,
]
.map(|triangle| threemf::model::Triangle {
v1: triangle[0] as usize,
v2: triangle[1] as usize,
v3: triangle[2] as usize,
})
.collect();

let mesh = threemf::TriangleMesh {
vertices,
triangles,
let mesh = threemf::Mesh {
vertices: threemf::model::Vertices { vertex: vertices },
triangles: threemf::model::Triangles {
triangle: triangles,
},
};

threemf::write(path, &mesh)?;
threemf::write(path, mesh)?;

Ok(())
}
Expand Down