Skip to content
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
11 changes: 1 addition & 10 deletions examples/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,7 @@ use std::{env, path::PathBuf, time::Instant};
use miniacd::{
Config,
io::{self, load_obj},
mesh::Mesh,
ops::{self},
};
use rayon::iter::{IntoParallelRefIterator, ParallelIterator};

fn main() {
let args: Vec<String> = env::args().collect();
Expand All @@ -31,11 +28,5 @@ fn main() {
let tf = Instant::now();
println!("main:\t{:.2}s", (tf - t0).as_secs_f64());

// PARALLEL: compute the output convex hulls in parallel.
let convex_meshes: Vec<Mesh> = components
.par_iter()
.map(|c| ops::convex_hull(&c.mesh))
.collect();

io::write_meshes_to_obj(&output_path, &convex_meshes).unwrap();
io::write_meshes_to_obj(&output_path, &components).unwrap();
}
17 changes: 7 additions & 10 deletions python/miniacd/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ def main(

# Run the miniacd algorithm.
mesh = miniacd.Mesh(input_mesh.vertices, input_mesh.faces)
parts = miniacd.run(
hulls = miniacd.run(
mesh,
threshold=threshold,
mcts_depth=mcts_depth,
Expand All @@ -98,24 +98,21 @@ def main(
print=True,
)

# Convexify the output slices.
parts = [part.convex_hull() for part in parts]

# Build Trimesh objects from the miniacd meshes.
output_parts = [
output_hulls = [
trimesh.Trimesh(
part.vertices(), part.faces(), vertex_colors=random_rgb(), process=False
hull.vertices(), hull.faces(), vertex_colors=random_rgb(), process=False
)
for part in parts
for hull in hulls
]

# Output a single file of multiple objects or multiple files.
output_path = Path(output_path)
if output_split:
for i, part in enumerate(output_parts):
part.export(output_path.with_stem(output_path.stem + f"_{i}"))
for i, hull in enumerate(output_hulls):
hull.export(output_path.with_stem(output_path.stem + f"_{i}"))
else:
trimesh.Scene(output_parts).export(output_path)
trimesh.Scene(output_hulls).export(output_path)


if __name__ == "__main__":
Expand Down
6 changes: 3 additions & 3 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ fn run_inner(input: Part, config: &Config, progress: &ProgressBar, prev_cost: f6
components
}

pub fn run(input: Mesh, config: &Config) -> Vec<Part> {
pub fn run(input: Mesh, config: &Config) -> Vec<Mesh> {
let progress_bar = ProgressBar::new(1)
.with_message("Slicing parts...")
.with_style(
Expand Down Expand Up @@ -127,7 +127,7 @@ pub fn run(input: Mesh, config: &Config) -> Vec<Part> {
// Unapply the transform so the outputs part positions match the input.
output_parts
.into_iter()
.map(|p| Part::from_mesh(Arc::unwrap_or_clone(p.mesh).transform(&normalization_tfm_inv)))
.filter(|p| !p.mesh.is_empty())
.map(|p| Arc::unwrap_or_clone(p.convex_hull).transform(&normalization_tfm_inv))
.filter(|m| !m.is_empty())
.collect()
}
7 changes: 1 addition & 6 deletions src/py.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
#[pyo3::pymodule(name = "miniacd")]
mod pyminiacd {
use std::sync::Arc;

use nalgebra::Point3;
use pyo3::prelude::*;

Expand Down Expand Up @@ -66,9 +64,6 @@ mod pyminiacd {
};

let components = crate::run(mesh.0.clone(), &config);
components
.into_iter()
.map(|c| PyMesh(Arc::unwrap_or_clone(c.mesh)))
.collect()
components.into_iter().map(PyMesh).collect()
}
}
Loading