Daankular commited on
Commit
0a1745e
·
1 Parent(s): 0998a0d

Replace pymeshlab with trimesh in inference_triposg.py (no py3.13 wheels)

Browse files

pymeshlab has no Python 3.13 wheels. It's only used for simplify_mesh()
which does QEM decimation + vertex merging. Replace with trimesh's
simplify_quadric_decimation() (backed by fast-simplification package).
Patch applied at runtime after triposg clone, guarded by pymeshlab_replaced_v1 tag.

Files changed (2) hide show
  1. app.py +48 -0
  2. requirements.txt +1 -0
app.py CHANGED
@@ -469,6 +469,54 @@ def load_triposg():
469
  _iu_path.write_text(_iu_text)
470
  print("[load_triposg] Patched inference_utils.py: diso optional + queries dtype cast")
471
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
472
  weights_path = snapshot_download("VAST-AI/TripoSG")
473
 
474
  from triposg.pipelines.pipeline_triposg import TripoSGPipeline
 
469
  _iu_path.write_text(_iu_text)
470
  print("[load_triposg] Patched inference_utils.py: diso optional + queries dtype cast")
471
 
472
+ # Patch inference_triposg.py: replace pymeshlab (no py3.13 wheels) with trimesh.
473
+ # pymeshlab is only used for simplify_mesh() — QEM decimation + vertex merging.
474
+ # trimesh.simplify_quadric_decimation() is a direct equivalent (needs fast-simplification).
475
+ _it_path = triposg_src / "scripts" / "inference_triposg.py"
476
+ if _it_path.exists():
477
+ _it_text = _it_path.read_text()
478
+ if "pymeshlab_replaced_v1" not in _it_text:
479
+ # Remove the pymeshlab import
480
+ _it_text = _it_text.replace("import pymeshlab\n", "")
481
+ # Replace the three pymeshlab helper functions + simplify_mesh with trimesh version
482
+ _old_simplify = (
483
+ "def mesh_to_pymesh(vertices, faces):\n"
484
+ " mesh = pymeshlab.Mesh(vertex_matrix=vertices, face_matrix=faces)\n"
485
+ " ms = pymeshlab.MeshSet()\n"
486
+ " ms.add_mesh(mesh)\n"
487
+ " return ms\n"
488
+ "\n"
489
+ "\n"
490
+ "def pymesh_to_trimesh(mesh):\n"
491
+ " verts = mesh.vertex_matrix()\n"
492
+ " faces = mesh.face_matrix()\n"
493
+ " return trimesh.Trimesh(vertices=verts, faces=faces)\n"
494
+ "\n"
495
+ "\n"
496
+ "def simplify_mesh(mesh: trimesh.Trimesh, n_faces):\n"
497
+ " if mesh.faces.shape[0] > n_faces:\n"
498
+ " ms = mesh_to_pymesh(mesh.vertices, mesh.faces)\n"
499
+ " ms.meshing_merge_close_vertices()\n"
500
+ " ms.meshing_decimation_quadric_edge_collapse(targetfacenum = n_faces)\n"
501
+ " return pymesh_to_trimesh(ms.current_mesh())\n"
502
+ " else:\n"
503
+ " return mesh\n"
504
+ )
505
+ _new_simplify = (
506
+ "# pymeshlab_replaced_v1: replaced with trimesh (no py3.13 wheels for pymeshlab)\n"
507
+ "def simplify_mesh(mesh: trimesh.Trimesh, n_faces):\n"
508
+ " if mesh.faces.shape[0] > n_faces:\n"
509
+ " mesh = trimesh.Trimesh(vertices=mesh.vertices, faces=mesh.faces, process=True)\n"
510
+ " mesh = mesh.simplify_quadric_decimation(n_faces)\n"
511
+ " return mesh\n"
512
+ )
513
+ if _old_simplify in _it_text:
514
+ _it_text = _it_text.replace(_old_simplify, _new_simplify)
515
+ _it_path.write_text(_it_text)
516
+ print("[load_triposg] Patched inference_triposg.py: pymeshlab → trimesh simplify")
517
+ else:
518
+ print("[load_triposg] WARNING: could not patch inference_triposg.py (pattern not found)")
519
+
520
  weights_path = snapshot_download("VAST-AI/TripoSG")
521
 
522
  from triposg.pipelines.pipeline_triposg import TripoSGPipeline
requirements.txt CHANGED
@@ -28,6 +28,7 @@ xformers
28
 
29
  # 3D / Mesh
30
  trimesh
 
31
  # open3d: no Python 3.13 wheels — not used in this Space
32
  # pymeshlab: no Python 3.13 wheels — not used in this Space
33
  pygltflib
 
28
 
29
  # 3D / Mesh
30
  trimesh
31
+ fast-simplification
32
  # open3d: no Python 3.13 wheels — not used in this Space
33
  # pymeshlab: no Python 3.13 wheels — not used in this Space
34
  pygltflib