1- import math
2- from pathlib import Path
3-
1+ from compas .geometry import Sphere
42from compas .datastructures import Mesh
5- from compas .geometry import Rotation
6- from compas .geometry import Scale
73from compas .geometry import Translation
8- from compas .geometry import Vector
9- from compas .geometry import scale_vector
104from compas .geometry import transform_points_numpy
115from compas_viewer import Viewer
126
137from compas_cgal .meshing import mesh_remesh , mesh_dual
14- from compas_cgal import _types_std # noqa: F401
158
169def main ():
17- """Remesh a bunny mesh that is loaded from .ply file."""
18-
19- FILE = Path (__file__ ).parent .parent .parent / "data" / "Bunny.ply"
20-
21- #bunny = Mesh.from_ply(FILE)
22- bunny = Mesh .from_meshgrid (1 ,10 ,1 ,10 )
23- bunny .quads_to_triangles ()
24- bunny .remove_unused_vertices ()
25-
26- centroid = bunny .vertex_point (0 )
27-
28- vector = scale_vector (centroid , - 1 )
10+ """Remesh a mesh."""
2911
30- T = Translation .from_vector (vector )
31- S = Scale .from_factors ([100 , 100 , 100 ])
32- R = Rotation .from_axis_and_angle (Vector (1 , 0 , 0 ), math .radians (90 ))
12+ mesh = Mesh .from_shape (Sphere (1 ))
13+ mesh .quads_to_triangles ()
3314
34- # bunny.transform(R * S * T)
35- V0 , F0 = bunny .to_vertices_and_faces ()
36- V1 = transform_points_numpy (V0 , R * S * T )
37-
38-
39- edge_length = 0.3
15+ edge_length = 0.5
4016 iterations = 10
41- x_translation = 0.0
42- V1 , F1 = mesh_remesh ((V0 , F0 ), edge_length , iterations )
17+ x_translation = 2
18+
19+ # Remesh
20+ V1 , F1 = mesh_remesh (mesh .to_vertices_and_faces (), edge_length , iterations )
4321 V1 = transform_points_numpy (V1 , Translation .from_vector ([x_translation , 0 , 0 ]))
44- mesh = Mesh .from_vertices_and_faces (V1 , F1 )
22+ remeshed = Mesh .from_vertices_and_faces (V1 , F1 )
4523
46-
24+ # Dual
4725 V2 , F2 = mesh_dual ((V1 , F1 ), 2.14 , True )
4826 V2 = transform_points_numpy (V2 , Translation .from_vector ([x_translation , 0 , 0 ]))
4927 dual = Mesh .from_vertices_and_faces (V2 , F2 )
5028
51- return bunny , mesh , dual
29+ return mesh , remeshed , dual
5230
5331
54- bunny , mesh , dual = main ()
32+ mesh , remeshed , dual = main ()
5533
5634
5735# ==============================================================================
@@ -63,8 +41,8 @@ def main():
6341viewer .renderer .camera .target = [0 , 0 , 0 ]
6442viewer .renderer .camera .position = [0 , - 0.25 , 0.10 ]
6543
66- # viewer.scene.add(bunny, show_points=False)
6744viewer .scene .add (mesh , show_points = False )
45+ viewer .scene .add (remeshed , show_points = False )
6846viewer .scene .add (dual , show_points = True )
6947
7048viewer .show ()
0 commit comments