|
1 | 1 | #! python3 |
2 | 2 | # venv: brg-csd |
3 | | -# r: compas_rv>=0.5.0 |
| 3 | +# r: compas_rv>=0.6.0 |
4 | 4 |
|
5 | 5 | import rhinoscriptsyntax as rs # type: ignore |
| 6 | +from compas_triangle.delaunay import conforming_delaunay_triangulation |
| 7 | +from compas_triangle.rhino import discretise_boundary |
| 8 | +from compas_triangle.rhino import discretise_constraints |
6 | 9 |
|
7 | 10 | import compas_rhino |
8 | 11 | import compas_rhino.conversions |
9 | 12 | import compas_rhino.objects |
| 13 | +from compas.geometry import NurbsCurve |
| 14 | +from compas.geometry import Point |
10 | 15 | from compas_rv.datastructures import Pattern |
11 | 16 | from compas_rv.session import RVSession |
12 | 17 |
|
@@ -102,6 +107,53 @@ def RunCommand(): |
102 | 107 | pattern = Pattern.from_meshgrid(dx=DX, nx=NX, dy=DY, ny=NY) |
103 | 108 |
|
104 | 109 | elif option == "Triangulation": |
| 110 | + boundary_guids = compas_rhino.objects.select_curves("Select outer boundary.") |
| 111 | + if not boundary_guids: |
| 112 | + return |
| 113 | + |
| 114 | + rs.UnselectAllObjects() |
| 115 | + hole_guids = compas_rhino.objects.select_curves("Select inner boundaries.") |
| 116 | + |
| 117 | + rs.UnselectAllObjects() |
| 118 | + segments_guids = compas_rhino.objects.select_curves("Select constraint curves.") |
| 119 | + |
| 120 | + rs.UnselectAllObjects() |
| 121 | + |
| 122 | + target_length = rs.GetReal("Specifiy target edge length.", 1.0) |
| 123 | + if not target_length: |
| 124 | + return |
| 125 | + |
| 126 | + boundary = discretise_boundary(boundary_guids, target_length) |
| 127 | + holes = None |
| 128 | + segments = None |
| 129 | + curves = None |
| 130 | + |
| 131 | + if hole_guids: |
| 132 | + holes = discretise_constraints(hole_guids, target_length) |
| 133 | + |
| 134 | + if segments_guids: |
| 135 | + segments = discretise_constraints(segments_guids, target_length) |
| 136 | + curves: list[NurbsCurve] = [NurbsCurve.from_interpolation(segment) for segment in segments] |
| 137 | + |
| 138 | + points, triangles = conforming_delaunay_triangulation( |
| 139 | + boundary, |
| 140 | + polylines=segments, |
| 141 | + polygons=holes, |
| 142 | + area=target_length**2 / 2, |
| 143 | + ) |
| 144 | + pattern = Pattern.from_vertices_and_faces(points, triangles) |
| 145 | + |
| 146 | + fixed = [vertex for boundary in pattern.vertices_on_boundaries() for vertex in boundary] |
| 147 | + if curves: |
| 148 | + for index, point in enumerate(points): |
| 149 | + for curve in curves: |
| 150 | + closest: Point = curve.closest_point(point) |
| 151 | + if closest.distance_to_point(point) < 0.1 * target_length: |
| 152 | + fixed.append(index) |
| 153 | + |
| 154 | + pattern.smooth_area(fixed=fixed) |
| 155 | + |
| 156 | + elif option == "Skeleton": |
105 | 157 | raise NotImplementedError |
106 | 158 |
|
107 | 159 | else: |
|
0 commit comments