MCPcopy
hub / github.com/lightningpixel/modly / optimize_mesh

Function optimize_mesh

api/routers/optimize.py:66–87  ·  view source on GitHub ↗
(body: OptimizeRequest)

Source from the content-addressed store, hash-verified

64
65@router.post("/mesh")
66def optimize_mesh(body: OptimizeRequest):
67 _require_pymeshlab()
68 target_faces = max(100, min(500_000, body.target_faces))
69
70 input_path = _resolve_input_path(body.path)
71
72 tmp_dir = tempfile.mkdtemp()
73 try:
74 result = _decimate(str(input_path), target_faces, tmp_dir)
75 finally:
76 shutil.rmtree(tmp_dir, ignore_errors=True)
77
78 stem = input_path.stem
79 output_name = f"{stem}_opt{target_faces}.glb"
80 output_dir = input_path.parent if str(input_path).startswith(str(WORKSPACE_DIR.resolve())) else WORKSPACE_DIR / "Workflows"
81 output_dir.mkdir(parents=True, exist_ok=True)
82 output_path = output_dir / output_name
83 result.export(str(output_path))
84
85 face_count = len(result.faces)
86 rel = output_path.relative_to(WORKSPACE_DIR).as_posix()
87 return {"url": f"/workspace/{rel}", "face_count": face_count}
88
89
90def _has_texture(geom: trimesh.Trimesh) -> bool:

Callers

nothing calls this directly

Calls 3

_require_pymeshlabFunction · 0.85
_resolve_input_pathFunction · 0.85
_decimateFunction · 0.85

Tested by

no test coverage detected