Crate remesh

Crate remesh 

Source
Expand description

§remesh

A type-agnostic isotropic remeshing library for triangle meshes.

remesh provides 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 f32 and f64 scalar 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_default_collapse_multiplier()?
    .run()?;

§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:

use remesh::prelude::*;
// 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 or any other type that implements `From<[S; 3]>` and `Into<[S; 3]>`
#[derive(Copy, Clone)]
struct MyVec3 { x: f32, y: f32, z: f32 }
impl From<[f32; 3]> for MyVec3 { /* ... */ }
impl Into<[f32; 3]> for MyVec3 { /* ... */ }

let vertices: Vec<MyVec3> = vec![/* ... */];
let (out_vertices, out_indices):(Vec<MyVec3>,Vec<usize>) = IsotropicRemesh::<f32, _>::new(&vertices, &indices)?.run()?;

Modules§

prelude