Skip to content

Commit ffa1f85

Browse files
committed
pattern templates
1 parent fa3c8f2 commit ffa1f85

File tree

1 file changed

+48
-137
lines changed

1 file changed

+48
-137
lines changed

commands/RV_pattern.py

Lines changed: 48 additions & 137 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,18 @@
33
# r: compas_rv>=0.9.1
44

55
import rhinoscriptsyntax as rs # type: ignore
6-
from compas_skeleton.datastructures import Skeleton
7-
from compas_triangle.delaunay import conforming_delaunay_triangulation
8-
from compas_triangle.rhino import discretise_boundary
9-
from compas_triangle.rhino import discretise_constraints
10-
11-
import compas_rhino
12-
import compas_rhino.conversions
13-
import compas_rhino.objects
14-
from compas.geometry import NurbsCurve
15-
from compas.geometry import Point
16-
from compas_rv.datastructures import Pattern
6+
7+
from compas_rv.commands import make_pattern_from_meshgrid
8+
from compas_rv.commands import make_pattern_from_rhinolines
9+
from compas_rv.commands import make_pattern_from_rhinomesh
10+
from compas_rv.commands import make_pattern_from_rhinosurface
11+
from compas_rv.commands import make_pattern_from_skeleton
12+
from compas_rv.commands import make_pattern_from_triangulation
13+
from compas_rv.patterns.circular import create_circular_radial_pattern
14+
from compas_rv.patterns.circular import create_circular_radial_spaced_pattern
15+
from compas_rv.patterns.circular import create_circular_spiral_pattern
16+
from compas_rv.patterns.rectangular import create_cross_pattern
17+
from compas_rv.patterns.rectangular import create_fan_pattern
1718
from compas_rv.session import RVSession
1819

1920

@@ -47,151 +48,61 @@ def RunCommand():
4748
"MeshGrid",
4849
"Triangulation",
4950
"Skeleton",
51+
"Json",
52+
"Template",
5053
],
5154
)
5255

5356
if option == "RhinoLines":
54-
guids = compas_rhino.objects.select_lines("Select lines")
55-
if not guids:
56-
return
57-
58-
lines = compas_rhino.objects.get_line_coordinates(guids)
59-
if not lines:
60-
return
61-
62-
pattern = Pattern.from_lines(lines, delete_boundary_face=True)
63-
64-
rs.HideObjects(guids)
57+
pattern = make_pattern_from_rhinolines()
6558

6659
elif option == "RhinoMesh":
67-
guid = compas_rhino.objects.select_mesh("Select a mesh")
68-
if not guid:
69-
return
70-
71-
obj = compas_rhino.objects.find_object(guid)
72-
pattern = compas_rhino.conversions.mesh_to_compas(obj.Geometry, cls=Pattern)
73-
74-
rs.HideObject(guid)
60+
pattern = make_pattern_from_rhinomesh()
7561

7662
elif option == "RhinoSurface":
77-
guid = compas_rhino.objects.select_surface("Select a surface")
78-
if not guid:
79-
return
80-
81-
U = rs.GetInteger(message="U faces", number=16, minimum=2, maximum=64)
82-
if not U:
83-
return
84-
85-
V = rs.GetInteger(message="V faces", number=4, minimum=2, maximum=64)
86-
if not V:
87-
return
88-
89-
# ------------------------------------------------
90-
91-
obj = compas_rhino.objects.find_object(guid)
92-
brep = obj.Geometry
93-
surface = brep.Surfaces[0]
94-
95-
# ------------------------------------------------
96-
97-
pattern = compas_rhino.conversions.surface_to_compas_mesh(surface, nu=U, nv=V, weld=True, cls=Pattern)
98-
99-
rs.HideObject(guid)
63+
pattern = make_pattern_from_rhinosurface()
10064

10165
elif option == "MeshGrid":
102-
DX = rs.GetInteger(message="X Size", number=10)
103-
if not DX:
104-
return
105-
106-
DY = rs.GetInteger(message="Y Size", number=DX)
107-
if not DY:
108-
return
109-
110-
NX = rs.GetInteger(message="Number of faces in X", number=10)
111-
if not NX:
112-
return
113-
114-
NY = rs.GetInteger(message="Number of faces in Y", number=NX)
115-
if not NY:
116-
return
117-
118-
pattern = Pattern.from_meshgrid(dx=DX, nx=NX, dy=DY, ny=NY)
66+
pattern = make_pattern_from_meshgrid()
11967

12068
elif option == "Triangulation":
121-
boundary_guids = compas_rhino.objects.select_curves("Select outer boundary.")
122-
if not boundary_guids:
123-
return
124-
125-
rs.UnselectAllObjects()
126-
hole_guids = compas_rhino.objects.select_curves("Select inner boundaries.")
127-
128-
rs.UnselectAllObjects()
129-
segments_guids = compas_rhino.objects.select_curves("Select constraint curves.")
130-
131-
rs.UnselectAllObjects()
132-
133-
target_length = rs.GetReal("Specifiy target edge length.", 1.0)
134-
if not target_length:
135-
return
136-
137-
boundary = discretise_boundary(boundary_guids, target_length)
138-
holes = None
139-
segments = None
140-
curves = None
141-
142-
if hole_guids:
143-
holes = discretise_constraints(hole_guids, target_length)
144-
145-
if segments_guids:
146-
segments = discretise_constraints(segments_guids, target_length)
147-
curves: list[NurbsCurve] = [NurbsCurve.from_interpolation(segment) for segment in segments]
148-
149-
points, triangles = conforming_delaunay_triangulation(
150-
boundary,
151-
polylines=segments,
152-
polygons=holes,
153-
area=target_length**2 / 2,
154-
)
155-
pattern = Pattern.from_vertices_and_faces(points, triangles)
156-
157-
fixed = [vertex for boundary in pattern.vertices_on_boundaries() for vertex in boundary]
158-
if curves:
159-
for index, point in enumerate(points):
160-
for curve in curves:
161-
closest: Point = curve.closest_point(point)
162-
if closest.distance_to_point(point) < 0.1 * target_length:
163-
fixed.append(index)
164-
165-
pattern.smooth_area(fixed=fixed)
69+
pattern = make_pattern_from_triangulation()
16670

16771
elif option == "Skeleton":
168-
guids = compas_rhino.objects.select_lines("Select skeleton lines.")
169-
if not guids:
170-
return
72+
pattern = make_pattern_from_skeleton()
73+
74+
elif option == "Json":
75+
raise NotImplementedError
76+
77+
elif option == "Template":
78+
option2 = rs.GetString(
79+
message="Template Name",
80+
strings=[
81+
"Radial",
82+
"RadialSpaced",
83+
"Spiral",
84+
"Cross",
85+
"Fan",
86+
],
87+
)
17188

172-
rs.UnselectAllObjects()
89+
if option2 == "Radial":
90+
pattern = create_circular_radial_pattern()
17391

174-
width = rs.GetReal("Specifiy skeleton width.", 1.0)
175-
if not width:
176-
return
92+
elif option2 == "RadialSpaced":
93+
pattern = create_circular_radial_spaced_pattern()
17794

178-
angle = rs.GetReal("Specifiy skeleton leaf angle (degrees).", 30)
179-
if not angle:
180-
return
95+
elif option2 == "Spiral":
96+
pattern = create_circular_spiral_pattern()
18197

182-
density = rs.GetInteger("Specifiy skeleton density.", 2)
183-
if not density:
184-
return
98+
elif option2 == "Cross":
99+
pattern = create_cross_pattern()
185100

186-
objects = [compas_rhino.objects.find_object(guid) for guid in guids]
187-
curves = [obj.Geometry for obj in objects]
188-
lines = [compas_rhino.conversions.curve_to_compas_line(curve) for curve in curves]
101+
elif option2 == "Fan":
102+
pattern = create_fan_pattern()
189103

190-
skeleton = Skeleton(lines)
191-
skeleton.node_width = width
192-
skeleton.leaf_angle = angle
193-
skeleton.density = density
194-
pattern = skeleton.pattern.copy(cls=Pattern)
104+
else:
105+
raise NotImplementedError
195106

196107
else:
197108
return
@@ -200,7 +111,7 @@ def RunCommand():
200111
# Update scene
201112
# =============================================================================
202113

203-
session.scene.add(pattern, name=pattern.name)
114+
session.scene.add(pattern, name=pattern.name) # type: ignore
204115
session.scene.draw()
205116

206117
print("Pattern successfully created.")

0 commit comments

Comments
 (0)