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§
Structs§
- Auto
- Automatically selects the best threading policy at runtime.
- Check
Finite - Tells the algorithm to perform value test of each vertex scalar.
- DeDup
Error - 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.
- Multi
Threaded - Executes the de-duplication algorithm using all available CPU cores.
- Point
Cloud - Interpret the index buffer as a flat list of point indices.
- Single
Threaded - Use this policy to run the de-duplication in a single thread.
- Skip
Check Finite - 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§
- Prune
Degenerate Enum - Defines how to handle degenerate mesh elements such as zero-area triangles or zero-length edges.
- Prune
Unused Enum - Specifies how to handle vertices that are not referenced by any input indices.
- Tolerance
Enum - Defines how to treat the user provided tolerance.
See
CheckTolerance
&RelaxTolerance
Traits§
- Check
Finite Policy - Choose between checking/no checking scalars for finite values by
CheckFinite
orSkipCheckFinite
.CheckFinite
is required when usingMultiThreaded
- Index
Type - Only
usize
,u32
, andu16
are possible as index types. - Scalar
- The scalar type used by the vertices, f32 or f64.
- Threading
Policy - Threading policy for vertex de-duplication.
- Topology
Policy - Specify how input indices are interpreted (e.g., as
Edges
,PointCloud
orTriangulated
).
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.