-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathsimplify.py
More file actions
29 lines (21 loc) · 892 Bytes
/
simplify.py
File metadata and controls
29 lines (21 loc) · 892 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
import torch
import trimesh
import cumesh
import utils
if __name__ == "__main__":
mesh = trimesh.load('remeshed_256.obj', force="mesh")
# mesh = utils.get_bunny()
# mesh.export("original.ply")
vertices = torch.from_numpy(mesh.vertices).float()
faces = torch.from_numpy(mesh.faces).int()
print(f"Original mesh: {vertices.shape[0]} vertices, {faces.shape[0]} faces")
vertices = vertices.cuda()
faces = faces.cuda()
target_faces = 10000
mesh = cumesh.CuMesh()
mesh.init(vertices, faces)
mesh.simplify(target_faces, verbose=True)
new_vertices, new_faces = mesh.read()
print(f"Simplified mesh: {new_vertices.shape[0]} vertices, {new_faces.shape[0]} faces")
new_mesh = trimesh.Trimesh(vertices=new_vertices.cpu().numpy(), faces=new_faces.cpu().numpy(), process=False)
new_mesh.export("simplified.obj",file_type="obj")