staswrs commited on
Commit
d22bdf6
·
1 Parent(s): 5572b0e

clean scene 9

Browse files
Files changed (2) hide show
  1. app.py +10 -5
  2. inference_triposg.py +15 -4
app.py CHANGED
@@ -80,15 +80,20 @@ def generate(image_path, face_number=50000, guidance_scale=5.0, num_steps=25):
80
  faces=int(face_number),
81
  )
82
 
83
- if mesh is None:
84
- raise ValueError("Mesh generation returned None")
 
 
 
 
 
 
 
85
 
86
- # Очистка визуала, метаданных и имени
87
- mesh.visual = None
88
  mesh.metadata.clear()
89
  mesh.name = "geometry_0"
90
 
91
- # Экспорт в GLB без scene/world
92
  glb_data = export_glb(mesh)
93
  with open(output_path, "wb") as f:
94
  f.write(glb_data)
 
80
  faces=int(face_number),
81
  )
82
 
83
+ if mesh is None or mesh.vertices.shape[0] == 0 or mesh.faces.shape[0] == 0:
84
+ raise ValueError("Mesh generation returned an empty mesh")
85
+
86
+ # Безопасная очистка визуала
87
+ if hasattr(mesh, "visual") and mesh.visual is not None:
88
+ try:
89
+ mesh.visual = None
90
+ except Exception:
91
+ print("[WARN] Failed to clear visual, skipping")
92
 
 
 
93
  mesh.metadata.clear()
94
  mesh.name = "geometry_0"
95
 
96
+ # Экспорт .glb
97
  glb_data = export_glb(mesh)
98
  with open(output_path, "wb") as f:
99
  f.write(glb_data)
inference_triposg.py CHANGED
@@ -89,14 +89,25 @@ def pymesh_to_trimesh(mesh):
89
  faces = mesh.face_matrix()#.tolist()
90
  return trimesh.Trimesh(vertices=verts, faces=faces) #, vID, fID
91
 
 
 
 
 
 
 
 
 
 
92
  def simplify_mesh(mesh: trimesh.Trimesh, n_faces):
93
  if mesh.faces.shape[0] > n_faces:
94
  ms = mesh_to_pymesh(mesh.vertices, mesh.faces)
95
  ms.meshing_merge_close_vertices()
96
- ms.meshing_decimation_quadric_edge_collapse(targetfacenum = n_faces)
97
- return pymesh_to_trimesh(ms.current_mesh())
98
- else:
99
- return mesh
 
 
100
 
101
  if __name__ == "__main__":
102
  device = "cuda"
 
89
  faces = mesh.face_matrix()#.tolist()
90
  return trimesh.Trimesh(vertices=verts, faces=faces) #, vID, fID
91
 
92
+ # def simplify_mesh(mesh: trimesh.Trimesh, n_faces):
93
+ # if mesh.faces.shape[0] > n_faces:
94
+ # ms = mesh_to_pymesh(mesh.vertices, mesh.faces)
95
+ # ms.meshing_merge_close_vertices()
96
+ # ms.meshing_decimation_quadric_edge_collapse(targetfacenum = n_faces)
97
+ # return pymesh_to_trimesh(ms.current_mesh())
98
+ # else:
99
+ # return mesh
100
+
101
  def simplify_mesh(mesh: trimesh.Trimesh, n_faces):
102
  if mesh.faces.shape[0] > n_faces:
103
  ms = mesh_to_pymesh(mesh.vertices, mesh.faces)
104
  ms.meshing_merge_close_vertices()
105
+ ms.meshing_decimation_quadric_edge_collapse(targetfacenum=n_faces)
106
+ simplified = ms.current_mesh()
107
+ if simplified is None or simplified.face_number() == 0:
108
+ return None
109
+ return pymesh_to_trimesh(simplified)
110
+ return mesh
111
 
112
  if __name__ == "__main__":
113
  device = "cuda"