Expand description
§remesh
A type-agnostic isotropic remeshing library for triangle meshes.
remesh provides high-quality mesh refinement with a flexible, builder-style API that works
seamlessly with any vertex type—whether you’re using glam, nalgebra, cgmath
or your own custom types.
§Features
- Type-agnostic: Works with any vertex format convertible to/from
[S; 3] - Flexible configuration: Tri-state parameters (explicit value, default, or disabled)
- High precision: Supports both
f32andf64scalar types:S - Ergonomic API: Builder pattern with sensible defaults
§Quick Start
use remesh::prelude::*;
let vertices = vec![
[0.0, 0.0, 0.0],
[0.0, 0.0, 1.0],
[0.0, 0.5, 0.0],
[1.0, 0.0, 0.0],
[0.5, 0.0, 0.5],
];
let indices = vec![0, 1, 2, 1, 4, 2, 2, 3, 0, 1, 0, 4, 2, 4, 3, 0, 3, 4];
// Remesh with a target edge length of 0.7
let (result_vertices, result_indices) = IsotropicRemesh::<f64, _>::new(&vertices, &indices)?
.with_iterations(10)?
.with_target_edge_length(0.7)?
.with_collapse_multiplier(true)?
.run()?;§Configuration Options
Most configuration methods accepts flexible input:
- Explicit value: Enable the feature with a specific parameter (e.g.,
with_collapse_multiplier(0.8)) - Default value: Pass
trueto use a sensible default (e.g.,with_collapse_multiplier(true)) - Disabled: Pass
falseorNoneto disable the feature (e.g.,with_split_multiplier(false))
§Available Operations
- Edge splitting: Subdivide long edges (controlled by
target_edge_length*split_multiplier) - Edge collapsing: Merge short edges (controlled by
target_edge_length*collapse_multiplier) - Edge flipping: Improve triangle quality (via
flip_edges) - Vertex smoothing: Smooth vertex positions (via
smooth_weight)
§Working with Different Math Libraries
The library internally uses glam for computations but preserves your original vertex type in the results:
ⓘ
// Works with glam
let verts: Vec<glam::Vec3> = vec![/* ... */];
let (out_verts, indices) = IsotropicRemesh::<f32, _>::new(&verts, &indices)?.run()?;
// Works with nalgebra
let verts: Vec<nalgebra::Vector3<f64>> = vec![/* ... */];
let (out_verts, indices) = IsotropicRemesh::<f64, _>::new(&verts, &indices)?.run()?;
// Works with custom types
#[derive(Copy, Clone)]
struct MyVec3 { x: f32, y: f32, z: f32 }
impl From<[f32; 3]> for MyVec3 { /* ... */ }
impl Into<[f32; 3]> for MyVec3 { /* ... */ }
let verts: Vec<MyVec3> = vec![/* ... */];
let (out_verts, indices) = IsotropicRemesh::<f32, _>::new(&verts, &indices)?.run()?;