-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathremesh.py
More file actions
37 lines (30 loc) · 1.14 KB
/
remesh.py
File metadata and controls
37 lines (30 loc) · 1.14 KB
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
30
31
32
33
34
35
36
37
import torch
import trimesh
import cumesh
import utils
if __name__ == "__main__":
mesh = trimesh.load('HydraSparc3d.glb', 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()
aabb_max = vertices.max(dim=0)[0]
aabb_min = vertices.min(dim=0)[0]
center = (aabb_max + aabb_min) / 2
scale = (aabb_max - aabb_min).max().item()
print(f"Center: {center}, Scale: {scale}")
new_vertices, new_faces = cumesh.remeshing.remesh_narrow_band_dc(
vertices, faces,
center = center,
scale = 1.0,
resolution = 256,
band = 1,
project_back = 0.1,
verbose = True
)
print(f"Remeshed 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("remeshed_256.obj",file_type="obj")