Spaces:
Paused
Paused
Download utils.py from efecelik/image-to-3d: direct link, hf CLI and curl.
- Browser
- Download file 753 Bytes
-
https://huggingface.co/spaces/efecelik/image-to-3d/resolve/main/utils.py
- Command line
-
hf download hf://spaces/efecelik/image-to-3d/utils.py
-
curl -L -o utils.py https://huggingface.co/spaces/efecelik/image-to-3d/resolve/main/utils.py
753 Bytes
| import pymeshlab | |
| import trimesh | |
| import open3d as o3d | |
| def mesh_to_pymesh(vertices, faces): | |
| mesh = pymeshlab.Mesh(vertex_matrix=vertices, face_matrix=faces) | |
| ms = pymeshlab.MeshSet() | |
| ms.add_mesh(mesh) | |
| return ms | |
| def pymesh_to_trimesh(mesh): | |
| verts = mesh.vertex_matrix()#.tolist() | |
| faces = mesh.face_matrix()#.tolist() | |
| return trimesh.Trimesh(vertices=verts, faces=faces) #, vID, fID | |
| def simplify_mesh(mesh: trimesh.Trimesh, n_faces): | |
| if mesh.faces.shape[0] > n_faces: | |
| ms = mesh_to_pymesh(mesh.vertices, mesh.faces) | |
| ms.meshing_merge_close_vertices() | |
| ms.meshing_decimation_quadric_edge_collapse(targetfacenum = n_faces) | |
| return pymesh_to_trimesh(ms.current_mesh()) | |
| else: | |
| return mesh |