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.
JavaScript 3d-generationai-agentsanimationavatardigital-humangenerative-aiglbgltfimage-to-3dllmmcpmcp-servermodel-context-protocolsolanatext-to-3dthreejsweb-componentswebglwebxrx402
fix(remesh): fall back to QuadriFlow's default solver when min-cost flow aborts
nirholas739edab5be5c
diff --git a/workers/remesh/main.py b/workers/remesh/main.pyindex f26e54ca3..fda030e66 100644--- a/workers/remesh/main.py+++ b/workers/remesh/main.py@@ -283,13 +283,28 @@ def _parse_obj(path: Path):return np.asarray(verts, dtype=np.float64), faces+# QuadriFlow solver ladder, best topology first. `-mcf` (minimum-cost flow)+# gives the cleanest loops and the fewest singularities, but its index-map solve+# is fragile on meshes with open boundaries, which is most rigged character+# exports: on CesiumMan it aborts outright with "wrong init", and on denser+# inputs it is what ran past the timeout on 2026-08-06. Dropping to QuadriFlow's+# default solver still produces a genuine quad remesh with a real quad_ratio, so+# the caller gets what it asked for. Falling back to triangle soup never happens.+QUADRIFLOW_ATTEMPTS = (+ ("-mcf", "-sharp"),+ ("-sharp",),+ (),+)+QUADRIFLOW_BUDGET_S = 600.0++def _quad_remesh(mesh, target_faces: int):"""Run QuadriFlow to produce quad-dominant topology.Returns (verts, polys, quad_ratio) where polys is a list of 0-based index- lists (length 3 or 4). Raises with an actionable message if the binary or- the run fails — we never silently fall back to triangle soup for a quad- request, which would mislead the caller."""+ lists (length 3 or 4). Walks QUADRIFLOW_ATTEMPTS until one succeeds, sharing+ a single wall-clock budget across them. Raises with an actionable message if+ the binary is missing or every solver fails."""binary = shutil.which(QUADRIFLOW_BIN) or QUADRIFLOW_BINif shutil.which(QUADRIFLOW_BIN) is None and not os.path.isfile(binary):raise RuntimeError(@@ -299,27 +314,50 @@ def _quad_remesh(mesh, target_faces: int):with tempfile.TemporaryDirectory() as tmp:src = Path(tmp) / "in.obj"- dst = Path(tmp) / "out.obj"_write_obj_geometry(mesh, src)- cmd = [- binary,- "-i", str(src),- "-o", str(dst),- "-f", str(max(1000, int(target_faces))),- "-mcf", # minimum-cost-flow solver: fewer singularities, cleaner loops- "-sharp", # preserve sharp feature edges- ]- try:- proc = subprocess.run(- cmd, capture_output=True, text=True, timeout=600, check=False,- )- except subprocess.TimeoutExpired as exc:- raise RuntimeError("quad remesh timed out after 600s") from exc+ deadline = time.monotonic() + QUADRIFLOW_BUDGET_S+ last_error = "quad remesh produced no attempts"+ dst = None++ for attempt, flags in enumerate(QUADRIFLOW_ATTEMPTS):+ remaining = deadline - time.monotonic()+ if remaining <= 0:+ last_error = (+ f"quad remesh ran out of its {int(QUADRIFLOW_BUDGET_S)}s budget; "+ f"last solver said: {last_error}"+ )+ break++ candidate = Path(tmp) / f"out{attempt}.obj"+ cmd = [+ binary,+ "-i", str(src),+ "-o", str(candidate),+ "-f", str(max(1000, int(target_faces))),+ *flags,+ ]+ try:+ proc = subprocess.run(+ cmd, capture_output=True, text=True, timeout=remaining, check=False,+ )+ except subprocess.TimeoutExpired:+ last_error = f"solver {flags or ('default',)} timed out"+ log.warning("quad remesh: %s, trying the next solver", last_error)+ continue++ if proc.returncode == 0 and candidate.exists():+ dst = candidate+ if attempt:+ log.info("quad remesh: solver %s succeeded after a fallback", flags or ("default",))+ break- if proc.returncode != 0 or not dst.exists():tail = (proc.stderr or proc.stdout or "").strip().splitlines()[-5:]- raise RuntimeError("quad remesh failed: " + " | ".join(tail))+ last_error = f"solver {flags or ('default',)} failed: " + " | ".join(tail)+ log.warning("quad remesh: %s", last_error)++ if dst is None:+ raise RuntimeError("quad remesh failed: " + last_error)verts, polys = _parse_obj(dst)diff --git a/workers/remesh/test_remesh.py b/workers/remesh/test_remesh.pyindex e8ac5321d..d1d753efa 100644--- a/workers/remesh/test_remesh.py+++ b/workers/remesh/test_remesh.py@@ -394,6 +394,35 @@ if shutil.which(remesh.QUADRIFLOW_BIN) or os.path.isfile(remesh.QUADRIFLOW_BIN):)qtri = remesh._triangulate_polys(qverts, qpolys)check("quad output triangulates for glb", len(qtri.faces) > 0)++ # An open-boundary mesh is where QuadriFlow's minimum-cost-flow solver aborts+ # ("wrong init"), so this is the case the solver ladder exists for: a mesh+ # with a hole must still come back quad-dominant, via a later rung.+ open_sphere = sphere(3)+ keep = np.asarray(open_sphere.vertices)[open_sphere.faces].mean(axis=1)[:, 1] < 0.85+ open_sphere.update_faces(keep)+ open_sphere.remove_unreferenced_vertices()+ check(+ "open-boundary fixture really has a boundary",+ len(trimesh.grouping.group_rows(open_sphere.edges_sorted, require_count=1)) > 0,+ )+ overts, opolys, oratio = remesh._quad_remesh(open_sphere, 1000)+ check(+ "quad remesh survives an open boundary",+ len(opolys) > 0 and oratio > 0.5,+ f"{len(opolys)} polys, quad_ratio={oratio}",+ )+ check(+ "open-boundary quad indices stay in range",+ max(max(p) for p in opolys) < len(overts),+ )++ check(+ "the solver ladder starts with minimum-cost flow and ends bare",+ remesh.QUADRIFLOW_ATTEMPTS[0] == ("-mcf", "-sharp")+ and remesh.QUADRIFLOW_ATTEMPTS[-1] == (),+ str(remesh.QUADRIFLOW_ATTEMPTS),+ )else:skip("quad remesh", f"quadriflow binary not found ({remesh.QUADRIFLOW_BIN})")