MCPcopy Create free account
hub / github.com/PyMesh/PyMesh / fix_mesh

Function fix_mesh

scripts/fix_mesh.py:14–49  ·  view source on GitHub ↗
(mesh, detail="normal")

Source from the content-addressed store, hash-verified

12
13
14def fix_mesh(mesh, detail="normal"):
15 bbox_min, bbox_max = mesh.bbox
16 diag_len = norm(bbox_max - bbox_min)
17 if detail == "normal":
18 target_len = diag_len * 5e-3
19 elif detail == "high":
20 target_len = diag_len * 2.5e-3
21 elif detail == "low":
22 target_len = diag_len * 1e-2
23 print("Target resolution: {} mm".format(target_len))
24
25 count = 0
26 mesh, __ = pymesh.remove_degenerated_triangles(mesh, 100)
27 mesh, __ = pymesh.split_long_edges(mesh, target_len)
28 num_vertices = mesh.num_vertices
29 while True:
30 mesh, __ = pymesh.collapse_short_edges(mesh, 1e-6)
31 mesh, __ = pymesh.collapse_short_edges(mesh, target_len,
32 preserve_feature=True)
33 mesh, __ = pymesh.remove_obtuse_triangles(mesh, 150.0, 100)
34 if mesh.num_vertices == num_vertices:
35 break
36
37 num_vertices = mesh.num_vertices
38 print("#v: {}".format(num_vertices))
39 count += 1
40 if count > 10: break
41
42 mesh = pymesh.resolve_self_intersection(mesh)
43 mesh, __ = pymesh.remove_duplicated_faces(mesh)
44 mesh = pymesh.compute_outer_hull(mesh)
45 mesh, __ = pymesh.remove_duplicated_faces(mesh)
46 mesh, __ = pymesh.remove_obtuse_triangles(mesh, 179.0, 5)
47 mesh, __ = pymesh.remove_isolated_vertices(mesh)
48
49 return mesh
50
51
52def old_fix_mesh(vertices, faces, detail="normal"):

Callers 1

mainFunction · 0.85

Calls 3

split_long_edgesMethod · 0.80

Tested by

no test coverage detected