Crate dedup_mesh

Source
Expand description

§dedup_mesh

A library for de-duplicating 3D mesh vertices using spatial hashing and precision-aware clustering.

This crate is designed for robustness, speed, and precision, with strong support for configurable behavior through type-level polymorphism.

§Compile-Time Specialization

All major configuration points—such as threading strategy, topology type, pruning behavior, and tolerance handling—are controlled via type parameters, not runtime enums.

This design enables the compiler to optimize each code path statically, resulting in:

  • No runtime branching overhead
  • Inlining of behavior-specific logic

Note: If you use multiple distinct configurations (e.g., Triangulated and Edges), each one will be compiled separately. This increases code size slightly but ensures each variant is optimized independently.

§Flexible Vector Support

Input and output vertex types are fully generic:

  • Any type that implements Into<[T; 3]> + Clone + Sync can be used as input
  • Any type that implements From<[T; 3]> + Into<[T; 3]> + Clone + Sync can be used as output

This means you can directly pass in or receive vertices using types from libraries like glam, nalgebra, cgmath or your own custom structs

§Example

use dedup_mesh::prelude::*;

let (vertices, indices) = dedup::<f32, usize, glam::Vec3, MultiThreaded, Triangulated>(
    &input_vertices,
    &input_indices,
    0.001,
    PruneUnused,
    PruneDegenerate,
    CheckTolerance,
)?;

§Features

  • Spatial hashing with automatic precision scaling
  • Exact or relaxed tolerance policies
  • Support for point clouds, edge meshes, and triangles
  • Single-threaded and multithreaded execution
  • Zero-cost abstraction: unused features are fully optimized out

§MSRV

Minimum Supported Rust Version: 1.85.1 (requires Rust 2024 edition)

§Crate Status

  • #![no_std]: Not yet supported
  • Parallelism via rayon

Re-exports§

pub use PruneDegenerateEnum::KeepDegenerate;
pub use PruneDegenerateEnum::PruneDegenerate;
pub use PruneUnusedEnum::KeepUnused;
pub use PruneUnusedEnum::PruneUnused;
pub use ToleranceEnum::CheckTolerance;
pub use ToleranceEnum::RelaxTolerance;

Modules§

prelude

Structs§

Auto
Automatically selects the best threading policy at runtime.
CheckFinite
Tells the algorithm to perform value test of each vertex scalar.
DeDupError
The error type thrown when an error is detected, typically when a NaN or infinite vertex value is detected.
Edges
Interpret the index buffer as a list of vertex pairs representing edges.
MultiThreaded
Executes the de-duplication algorithm using all available CPU cores.
PointCloud
Interpret the index buffer as a flat list of point indices.
SingleThreaded
Use this policy to run the de-duplication in a single thread.
SkipCheckFinite
Tells the algorithm to skip value test of each vertex scalar.
Triangulated
Interpret the index buffer as a list of triangles (groups of 3 indices).

Enums§

PruneDegenerateEnum
Defines how to handle degenerate mesh elements such as zero-area triangles or zero-length edges.
PruneUnusedEnum
Specifies how to handle vertices that are not referenced by any input indices.
ToleranceEnum
Defines how to treat the user provided tolerance. See CheckTolerance & RelaxTolerance

Traits§

CheckFinitePolicy
Choose between checking/no checking scalars for finite values by CheckFinite or SkipCheckFinite. CheckFinite is required when using MultiThreaded
IndexType
Only usize, u32, and u16 are possible as index types.
Scalar
The scalar type used by the vertices, f32 or f64.
ThreadingPolicy
Threading policy for vertex de-duplication.
TopologyPolicy
Specify how input indices are interpreted (e.g., as Edges, PointCloud or Triangulated).

Functions§

dedup
Performs de-duplication of 3D vertices in a mesh using spatial hashing.
dedup_exact
Performs bitwise-exact de-duplication of vertices.
dedup_exact_from_iter
Performs bitwise-exact de-duplication of vertices.