Meshes returned by the marching cubes implementations are usually not clean: Rvcg::vcgIsosurface() returns duplicated vertices along with a large number of degenerate (zero area) faces which overlap the real faces, and misc3d::contour3d() returns completely unwelded meshes, i.e., one vertex per triangle corner. Both waste memory and render badly when lighting is enabled: the degenerate faces get invalid normals and fight for the same depth values as the real faces, which makes the surface look patched, grooved and partly black instead of smoothly shaded. This function welds vertices which are at (numerically) identical positions, removes the faces which use the same vertex more than once, and recomputes the normals.
Arguments
- mesh
a
mesh3dinstance, e.g., as returned byRvcg::vcgIsosurface(),misc3d::contour3d()orshell.extract.mesh.- drop_degenerate
logical, whether to remove the degenerate faces, i.e., the faces which have at least two coincident corners and thus zero area. Defaults to
TRUE.- add_normals
logical, whether to compute per-vertex normals for the result. Defaults to
TRUE.- tolerance
numerical scalar, the distance (in the units of the mesh coordinates, typically mm) below which two vertices are considered identical. Defaults to
1e-6.