|
1 | | -from itertools import filterfalse |
2 | 1 | from pathlib import Path |
3 | 2 |
|
4 | 3 | from compas.colors import Color |
5 | 4 | from compas.datastructures import Mesh |
6 | 5 | from compas_viewer import Viewer |
7 | 6 | from compas_viewer.config import Config |
8 | | -from tessagon.adaptors.list_adaptor import ListAdaptor |
9 | | -from tessagon.types.brick_tessagon import BrickTessagon |
10 | | -from tessagon.types.dissected_hex_quad_tessagon import DissectedHexQuadTessagon |
11 | | -from tessagon.types.dissected_hex_tri_tessagon import DissectedHexTriTessagon |
12 | | -from tessagon.types.dissected_square_tessagon import DissectedSquareTessagon |
13 | | -from tessagon.types.dissected_triangle_tessagon import DissectedTriangleTessagon |
14 | | -from tessagon.types.dodeca_tessagon import DodecaTessagon |
15 | | -from tessagon.types.floret_tessagon import FloretTessagon |
16 | | -from tessagon.types.hex_big_tri_tessagon import HexBigTriTessagon |
17 | | -from tessagon.types.hex_tessagon import HexTessagon |
18 | | -from tessagon.types.hex_tri_tessagon import HexTriTessagon |
19 | | -from tessagon.types.octo_tessagon import OctoTessagon |
20 | | -from tessagon.types.pythagorean_tessagon import PythagoreanTessagon |
21 | | -from tessagon.types.rhombus_tessagon import RhombusTessagon |
22 | | -from tessagon.types.square_tessagon import SquareTessagon |
23 | | -from tessagon.types.square_tri_tessagon import SquareTriTessagon |
24 | | -from tessagon.types.tri_tessagon import TriTessagon |
25 | | -from tessagon.types.weave_tessagon import WeaveTessagon |
26 | | -from tessagon.types.zig_zag_tessagon import ZigZagTessagon |
27 | 7 |
|
28 | | -from compas_libigl.mapping import map_mesh |
29 | | -from compas_libigl.parametrisation import trimesh_lsc_mapping |
30 | | - |
31 | | -TESSAGON_TYPES = { |
32 | | - 1: ("Hex", HexTessagon), |
33 | | - 2: ("Tri", TriTessagon), |
34 | | - 3: ("Octo", OctoTessagon), |
35 | | - 4: ("Square", SquareTessagon), |
36 | | - 5: ("Rhombus", RhombusTessagon), |
37 | | - 6: ("HexTri", HexTriTessagon), |
38 | | - 7: ("DissectedSquare", DissectedSquareTessagon), |
39 | | - 8: ("DissectedTriangle", DissectedTriangleTessagon), |
40 | | - 9: ("DissectedHexQuad", DissectedHexQuadTessagon), |
41 | | - 10: ("DissectedHexTri", DissectedHexTriTessagon), |
42 | | - 11: ("Floret", FloretTessagon), |
43 | | - 12: ("Pythagorean", PythagoreanTessagon), |
44 | | - 13: ("Brick", BrickTessagon), |
45 | | - 14: ("Weave", WeaveTessagon), |
46 | | - 15: ("ZigZag", ZigZagTessagon), |
47 | | - 16: ("HexBigTri", HexBigTriTessagon), |
48 | | - 17: ("Dodeca", DodecaTessagon), |
49 | | - 18: ("SquareTri", SquareTriTessagon), |
50 | | -} |
51 | | - |
52 | | -# Pattern selection - change this value to use a different pattern |
53 | | - |
54 | | -PATTERN_TYPE = 15 |
| 8 | +from compas_libigl.mapping import map_pattern_to_mesh |
55 | 9 |
|
56 | 10 | # ============================================================================== |
57 | 11 | # Input geometry: 3D Mesh |
|
63 | 17 | x, y, z = mesh.vertex_attributes(vertex, "xyz") # type: ignore |
64 | 18 | mesh.vertex_attributes(vertex, "xyz", [x, -z, y]) |
65 | 19 |
|
66 | | -mesh.translate([2, 2, 0.5]) |
67 | | - |
68 | | -v, f = mesh.to_vertices_and_faces() |
69 | | - |
70 | | -# ============================================================================== |
71 | | -# Input geometry: 2D Pattern creation using Tessagon library, can be other mesh. |
72 | | -# ============================================================================== |
73 | | - |
74 | | -options = { |
75 | | - "function": lambda u, v: [u * 1, v * 1, 0], |
76 | | - "u_range": [-0.25, 1.25], |
77 | | - "v_range": [-0.25, 1.25], |
78 | | - "u_num": 20, |
79 | | - "v_num": 20, |
80 | | - "u_cyclic": False, |
81 | | - "v_cyclic": False, |
82 | | - "adaptor_class": ListAdaptor, |
83 | | -} |
84 | | - |
85 | | -# Get pattern name and class based on selected pattern type |
86 | | -pattern_name, pattern_class = TESSAGON_TYPES[PATTERN_TYPE] |
87 | | - |
88 | | -# Create the selected tessagon pattern |
89 | | -tessagon = pattern_class(**options) |
90 | | -tessagon_mesh = tessagon.create_mesh() |
91 | | -pv = tessagon_mesh["vert_list"] |
92 | | -pf = tessagon_mesh["face_list"] |
93 | | - |
94 | 20 | # ============================================================================== |
95 | 21 | # Mapping: 3D Mesh, 2D Pattern, UV |
96 | 22 | # ============================================================================== |
97 | | - |
98 | | -mv, mf = map_mesh((v, f), (pv, pf), clip_boundaries=True, tolerance=1e-6) |
99 | | -mesh_mapped = Mesh.from_vertices_and_faces(mv, mf) |
100 | | - |
101 | | -print(len(mv)) |
| 23 | +mesh_mapped = map_pattern_to_mesh("ZigZag", mesh, clip_boundaries=True, tolerance=1e-6, pattern_u=10, pattern_v=10) |
102 | 24 |
|
103 | 25 | # ============================================================================== |
104 | 26 | # Viewer |
105 | 27 | # ============================================================================== |
106 | 28 |
|
107 | 29 | config = Config() |
108 | | -config.camera.target = [2, 2, 0.25] |
109 | | -config.camera.position = [5, 2, 1.5] |
| 30 | +config.camera.target = [0, 0, 0] |
| 31 | +config.camera.position = [0.75, 0, 0.75] |
110 | 32 |
|
111 | 33 | viewer = Viewer(config=config) |
112 | 34 |
|
113 | 35 | viewer.scene.add(mesh, name="mesh", show_faces=False, linecolor=Color.grey(), opacity=0.2) |
114 | | -viewer.scene.add(Mesh.from_vertices_and_faces(pv, pf), name="pattern2d") |
115 | 36 | viewer.scene.add(mesh_mapped, name="mesh_mapped", facecolor=Color.red()) |
116 | 37 |
|
117 | | -# To see where the pattern is mapped: |
118 | | -uv = trimesh_lsc_mapping((v, f)) |
119 | | -mesh_flattened = mesh.copy() |
120 | | -for i in range(mesh.number_of_vertices()): |
121 | | - mesh_flattened.vertex_attributes(i, "xyz", [uv[i][0], uv[i][1], 0]) |
122 | | -viewer.scene.add(mesh_flattened, name="mesh_flattened", show_lines=False, opacity=0.5) |
123 | 38 |
|
124 | 39 | viewer.show() |
0 commit comments