Skip to content

Open-source platform for 3D AI agents. Turn text or a photo into a rigged, animated GLB avatar, give it an LLM brain, memory and a wallet, and embed it anywhere with one web component. Remote MCP server, x402 payments, Three.js, browser-native.

fix(remesh): strip the non-manifold edges QuadriFlow aborts on before the solve

nirholas8a17a7712438
diff --git a/workers/remesh/main.py b/workers/remesh/main.py
index fda030e66..9f5a77e6a 100644
--- a/workers/remesh/main.py
+++ b/workers/remesh/main.py
@@ -368,6 +368,41 @@ def _quad_remesh(mesh, target_faces: int):
return verts, polys, quad_ratio
+def _make_manifold(mesh):
+ """Strip the topology QuadriFlow refuses, returning the input unchanged if
+ the cleanup would leave nothing behind.
+
+ QuadriFlow's index-map solve aborts with "wrong init" on a mesh whose edges
+ are shared by more than two faces. Character exports hit that constantly:
+ they are assembled from overlapping parts, so body and clothing seams meet on
+ shared edges. `_repair_mesh` does not help here (trimesh has no non-manifold
+ edge removal); open3d does."""
+ import numpy as np
+ import open3d as o3d
+ import trimesh
+
+ o3d_mesh = o3d.geometry.TriangleMesh()
+ o3d_mesh.vertices = o3d.utility.Vector3dVector(
+ np.asarray(mesh.vertices, dtype=np.float64)
+ )
+ o3d_mesh.triangles = o3d.utility.Vector3iVector(
+ np.asarray(mesh.faces, dtype=np.int32)
+ )
+ o3d_mesh.remove_duplicated_vertices()
+ o3d_mesh.remove_duplicated_triangles()
+ o3d_mesh.remove_degenerate_triangles()
+ o3d_mesh.remove_non_manifold_edges()
+ o3d_mesh.remove_unreferenced_vertices()
+
+ faces = np.asarray(o3d_mesh.triangles)
+ if len(faces) == 0:
+ log.warning("manifold cleanup removed every face; using the source mesh")
+ return mesh
+ return trimesh.Trimesh(
+ vertices=np.asarray(o3d_mesh.vertices), faces=faces, process=False,
+ )
+
+
def _triangulate_polys(verts, polys):
"""Triangulate a mixed tri/quad polygon list into a Trimesh (for GLB export
and texture baking — glTF has no native quads)."""
@@ -762,6 +797,7 @@ def _process_quad(source, target_faces: int, output_format: str, tex_size: int,
# QuadriFlow wants a clean watertight-ish triangle mesh as input.
geom = source.copy()
_repair_mesh(geom)
+ geom = _make_manifold(geom)
verts, polys, quad_ratio = _quad_remesh(geom, target_faces)
tri_mesh = _triangulate_polys(verts, polys)
diff --git a/workers/remesh/test_remesh.py b/workers/remesh/test_remesh.py
index d1d753efa..bef6fef45 100644
--- a/workers/remesh/test_remesh.py
+++ b/workers/remesh/test_remesh.py
@@ -417,6 +417,35 @@ if shutil.which(remesh.QUADRIFLOW_BIN) or os.path.isfile(remesh.QUADRIFLOW_BIN):
max(max(p) for p in opolys) < len(overts),
)
+ # A bow-tie edge shared by three faces is exactly the topology QuadriFlow
+ # aborts on, and exactly what a character assembled from overlapping parts
+ # carries.
+ nonmanifold = trimesh.Trimesh(
+ vertices=np.array(
+ [[0.0, 0, 0], [1, 0, 0], [0.5, 1, 0], [0.5, -1, 0], [0.5, 0, 1]]
+ ),
+ faces=np.array([[0, 1, 2], [0, 1, 3], [0, 1, 4]]),
+ process=False,
+ )
+ cleaned = remesh._make_manifold(nonmanifold)
+ check(
+ "manifold cleanup drops the non-manifold edge",
+ len(cleaned.faces) < 3,
+ f"{len(cleaned.faces)} faces remain",
+ )
+ check(
+ "manifold cleanup keeps a sound mesh intact",
+ len(remesh._make_manifold(sphere(2)).faces) == len(sphere(2).faces),
+ )
+ check(
+ "manifold cleanup never returns an empty mesh",
+ len(remesh._make_manifold(
+ trimesh.Trimesh(
+ vertices=np.zeros((3, 3)), faces=np.array([[0, 1, 2]]), process=False
+ )
+ ).faces) > 0,
+ )
+
check(
"the solver ladder starts with minimum-cost flow and ends bare",
remesh.QUADRIFLOW_ATTEMPTS[0] == ("-mcf", "-sharp")