-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathexample_mapping_patterns.py
More file actions
59 lines (41 loc) · 2.31 KB
/
example_mapping_patterns.py
File metadata and controls
59 lines (41 loc) · 2.31 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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
from pathlib import Path
from compas.colors import Color
from compas.geometry import Point
from compas.datastructures import Mesh
from compas_viewer import Viewer
from compas_viewer.config import Config
from compas_libigl.mapping import map_pattern_to_mesh
# ==============================================================================
# Input geometry: 3D Mesh
# ==============================================================================
mesh = Mesh.from_obj(Path(__file__).parent.parent.parent / "data" / "minimal_surface.obj")
for vertex in mesh.vertices():
x, y, z = mesh.vertex_attributes(vertex, "xyz") # type: ignore
mesh.vertex_attributes(vertex, "xyz", [x, -z, y])
# ==============================================================================
# Get Lowest and Highest points
# ==============================================================================
aabb = mesh.aabb()
fixed_vertices = []
for vertex in mesh.vertices():
x, y, z = mesh.vertex_attributes(vertex, "xyz") # type: ignore
if abs(z - aabb.zmin) < 1e-3 or abs(z - aabb.zmax) < 1e-3:
fixed_vertices.append(vertex)
# ==============================================================================
# Mapping: 3D Mesh, 2D Pattern, UV
# ==============================================================================
mesh_mapped0 = map_pattern_to_mesh("ZigZag", mesh, clip_boundaries=True, tolerance=1e-6, pattern_u=16, pattern_v=16, simplify_borders=True, fixed_vertices=fixed_vertices)
mesh_mapped1 = map_pattern_to_mesh("ZigZag", mesh, clip_boundaries=True, tolerance=1e-6, pattern_u=16, pattern_v=16, simplify_borders=False)
# ==============================================================================
# Viewer
# ==============================================================================
config = Config()
config.camera.target = [0, 0, 0]
config.camera.position = [0.75, 0, 0.75]
viewer = Viewer(config=config)
viewer.scene.add(mesh, name="mesh", show_faces=False, linecolor=Color.grey(), opacity=0.2)
viewer.scene.add(mesh_mapped0, name="mesh_mapped0", facecolor=Color.red(), show_points=True)
# viewer.scene.add(mesh_mapped1, name="mesh_mapped1", facecolor=Color.blue(), show_points=True, show_faces=False)
for p in fixed_vertices:
viewer.scene.add(mesh.vertex_point(p), pointcolor=Color.red(), pointsize=10)
viewer.show()