Skip to main content

auto_repair

Function auto_repair 

Source
pub fn auto_repair(
    tx: &mut Transaction<'_>,
    options: &AutoRepairOptions,
) -> Result<AutoRepairReport>
Expand description

Repairs a mesh with the standard cleanup pipeline: weld() → remove_degenerate() → orient() → remove_small_components() → fill_holes(), all in tx, so committing it makes one undo step.

The order matters: welding stitches coincident vertices and can leave duplicate triangles for the next stage, orienting makes hole rims clean for filling, and small components go before filling so that their holes are not filled for nothing. Holes past max_edges are skipped and holes that cannot be filled are listed in FillReport; neither is an error.

On a mesh with UVs a seam stays a seam: the weld keeps its two sides apart, UV islands of one surface count as one component, and loops with a seam edge are skipped with SkipReason::UvSeam. New fill vertices interpolate their rim’s UVs.

use fast_mesh_ops::{AutoRepairOptions, auto_repair};
use fast_mesh_store::Mesh;

// Two triangles of a unit square, with the shared corners duplicated.
let positions = [
    0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 1.0, 1.0, 0.0, // first triangle
    0.0, 0.0, 0.0, 1.0, 1.0, 0.0, 0.0, 1.0, 0.0, // second triangle
];
let mut mesh = Mesh::from_buffers(&positions, &[0, 1, 2, 3, 4, 5]).unwrap();

let mut tx = mesh.begin_edit();
let report = auto_repair(&mut tx, &AutoRepairOptions::default()).unwrap();
tx.commit().unwrap();
assert_eq!(report.weld.merged_vertices, 2);

§Errors

OpsError::InvalidInput when weld_tolerance is negative, NaN or infinite; OpsError::Store when memory runs out. Earlier stages have written to tx by then: drop it, which rolls all of them back, instead of committing.