A simple Node.js tool for cleaning and repairing 3D mesh files (OBJ format) by removing degenerate faces, merging close vertices, and consolidating coplanar faces.
This tool is intended for use as a toy project and is not equipped to handle some important real-world cases. These include UV, vertex normals, watertight meshes or non-manifold edges.
Most of the code is based on some python scripts that were generated using AI and then adapted to typescript/nodejs.
- Remove Degenerated Faces: Eliminates faces with less than 3 edges or zero area
- Merge Close Vertices: Consolidates vertices that are within a specified distance threshold
- Merge Coplanar Faces: Combines adjacent faces that lie on the same plane
- Node.js 18+
- npm or yarn
npm installnpm run start input.obj [output.obj]npm test
npm run test:watch # Run tests in watch mode (Node test runner)Removes faces that have:
- Less than 3 vertices
- Zero or near-zero area (threshold: 1e-9)
Consolidates vertices that are within a specified distance threshold, reducing mesh complexity while maintaining visual quality.
Combines adjacent faces that lie on the same plane, reducing the total number of faces in the mesh.
- @thi.ng/geom-io-obj: OBJ file parsing and manipulation
- @thi.ng/vectors: Vector mathematics operations
- @thi.ng/object-utils: Utility functions for object manipulation
- tsx: TypeScript execution environment