(body: OptimizeRequest)
| 64 | |
| 65 | @router.post("/mesh") |
| 66 | def 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 | |
| 90 | def _has_texture(geom: trimesh.Trimesh) -> bool: |
nothing calls this directly
no test coverage detected