Understanding the Problem: Mesh Deformation During Stitching

When working with 3D CAD models or surface scans in Python, you often need to join multiple disconnected surface meshes that have gaps between them. Standard global reconstruction tools like Screened Poisson Surface Reconstruction (available in PyMeshLab and CloudCompare) or Constructive Solid Geometry (CSG) Booleans (in Trimesh) often produce unsatisfactory results in this context.

Global Poisson reconstruction recalculates the entire surface mesh based on point normals. When applied to sharp or smooth geometric primitives like cylinders, it frequently introduces unwanted artifacts, such as wavy surfaces, rounded edges, or localized distortion. On the other hand, CSG boolean union operations require watertight, manifold closed volumes to compute intersections properly; when applied to open surfaces with gaps, they either fail or produce corrupt topology.

To join open meshes cleanly without deforming the source geometry, you must use localized boundary stitching—connecting only the open boundary loops across gaps while leaving the existing mesh vertices and faces intact.

Why Global Reconstruction Methods Fail

  • Screened Poisson Reconstruction: Solves a global spatial linear system over the whole bounding box. It smoothly interpolates across all points, which causes flat planes or perfect cylinders to bend, wave, or warp.
  • Boolean Unions: Rely on clear inside/outside volume definitions. Open surface patches lack defined volumetric interiors, leading to ray-casting errors and missing faces.

The Solution: Local Boundary Bridging and Vertex Snapping

The optimal strategy involves three targeted steps:

  1. Identify boundary loops: Locate the open boundary edges (edges belonging to only one polygon face) for each mesh part.
  2. Bridge or snap boundary edges: Either generate new triangular face strips between the nearest boundary loops or snap close boundary vertices within a defined distance tolerance.
  3. Concatenate topology without re-triangulation: Combine the original meshes and the newly created bridging faces into a single consolidated mesh object.

Python Solution Using Trimesh and PyVista

Below is a clean, robust Python solution using trimesh to identify open boundaries and bridge them, along with pyvista for visualization.