Skip to content

Commit 0380cf5

Browse files
ADD custom joints.
1 parent f11e1de commit 0380cf5

File tree

9 files changed

+174
-128
lines changed

9 files changed

+174
-128
lines changed

src/rhino/raw/commands/w_raw_axis.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
from System.Drawing import Color
99

1010

11-
1211
def callback(selection: dict[str, any], name: str):
1312
if not selection["elements"]:
1413
return
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
#! python3
2+
# venv: timber_connections
3+
4+
import Rhino
5+
from wood_rui import process_input
6+
from wood_rui import add_sub_layer
7+
from wood_rui import Element
8+
from System.Drawing import Color
9+
from compas_wood.binding import wood_globals
10+
11+
def duplicate(data : list[Rhino.Geometry.Polyline]):
12+
duplicated_data = []
13+
for d in data:
14+
if d.Count == 2:
15+
duplicated_data.append(d)
16+
duplicated_data.append(d)
17+
else:
18+
duplicated_data.append(d)
19+
20+
return(duplicated_data)
21+
22+
23+
24+
def callback(selection: dict[str, any], name: str):
25+
26+
for key, item in selection.items():
27+
28+
key_to_attr = {
29+
"ss_e_ip_positive": "custom_joints_ss_e_ip_male",
30+
"ss_e_ip_negative": "custom_joints_ss_e_ip_female",
31+
"ss_e_op_positive": "custom_joints_ss_e_op_male",
32+
"ss_e_op_negative": "custom_joints_ss_e_op_female",
33+
"ts_e_p_positive": "custom_joints_ts_e_p_male",
34+
"ts_e_p_negative": "custom_joints_ts_e_p_female",
35+
"cr_c_ip_positive": "custom_joints_cr_c_ip_male",
36+
"cr_c_ip_negative": "custom_joints_cr_c_ip_female",
37+
"tt_e_p_positive": "custom_joints_tt_e_p_male",
38+
"tt_e_p_negative": "custom_joints_tt_e_p_female",
39+
"ss_e_r_positive": "custom_joints_ss_e_r_male",
40+
"ss_e_r_negative": "custom_joints_ss_e_r_female",
41+
"b_positive": "custom_joints_b_male",
42+
"b_negative": "custom_joints_b_female",
43+
}
44+
45+
for key, item in selection.items():
46+
if key in key_to_attr:
47+
attr_name = key_to_attr[key]
48+
duplicated_item = duplicate(item)
49+
setattr(wood_globals, attr_name, duplicated_item)
50+
print(f"{attr_name}: {duplicated_item}")
51+
52+
return
53+
54+
55+
if __name__ == "__main__":
56+
selection_types: dict[str, tuple] = {
57+
"ss_e_ip_positive": ([], list[Rhino.Geometry.Polyline]),
58+
"ss_e_ip_negative": ([], list[Rhino.Geometry.Polyline]),
59+
"ss_e_op_positive": ([], list[Rhino.Geometry.Polyline]),
60+
"ss_e_op_negative": ([], list[Rhino.Geometry.Polyline]),
61+
"ts_e_p_positive": ([], list[Rhino.Geometry.Polyline]),
62+
"ts_e_p_negative": ([], list[Rhino.Geometry.Polyline]),
63+
"cr_c_ip_positive": ([], list[Rhino.Geometry.Polyline]),
64+
"cr_c_ip_negative": ([], list[Rhino.Geometry.Polyline]),
65+
"tt_e_p_positive": ([], list[Rhino.Geometry.Polyline]),
66+
"tt_e_p_negative": ([], list[Rhino.Geometry.Polyline]),
67+
"ss_e_r_positive": ([], list[Rhino.Geometry.Polyline]),
68+
"ss_e_r_negative": ([], list[Rhino.Geometry.Polyline]),
69+
"b_positive": ([], list[Rhino.Geometry.Polyline]),
70+
"b_negative": ([], list[Rhino.Geometry.Polyline]),
71+
}
72+
73+
process_input(selection_types, callback)

src/rhino/raw/commands/w_raw_features.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ def callback(selection: dict[str, any], name: str):
3535

3636
return
3737

38+
3839
if __name__ == "__main__":
3940
selection_types: dict[str, tuple] = {
4041
"element": ([], list[Element]),
Lines changed: 79 additions & 107 deletions
Original file line numberDiff line numberDiff line change
@@ -1,127 +1,99 @@
11
#! python3
22
# venv: timber_connections
33

4-
# TODO:
5-
6-
# Parallel Features
7-
# Check Compas_wood project considering changes to compas_rui
8-
9-
# Publish raw to YAK
10-
# Publish wood_nano, wood_rui to PyPi
11-
# Publish compas_wood to YAK
12-
13-
# Custom Joints
14-
# Check How to input varying axis
15-
16-
17-
import Rhino
18-
from wood_rui import process_input
19-
from wood_rui import Element
20-
from wood_rui import add_sub_layer
21-
from System.Drawing import Color
22-
23-
#! python3
24-
# venv: timber_connections
25-
264
import Rhino
275
from wood_rui import process_input
286
from wood_rui import Element
297
from wood_rui import add_sub_layer
308
from System.Drawing import Color
319

32-
33-
34-
def closest_curves(
35-
curves: list[Rhino.Geometry.NurbsCurve],
36-
radii : list[float],
37-
distance : float,
38-
display_closest_line_segments : bool
39-
) -> None:
40-
41-
42-
###############################################################################
43-
# Run the closest point search
44-
###############################################################################
45-
bboxes = []
46-
for idx, c in enumerate(curves):
47-
bbox : Rhino.Geometry.BoundingBox = c.GetBoundingBox(True)
48-
bbox.Inflate(radii[idx] + 0.02)
49-
bboxes.append(bbox)
50-
51-
52-
# create a tree
53-
rtree = Rhino.Geometry.RTree()
54-
55-
# fill the tree
56-
for idx, bbox in enumerate(bboxes):
57-
rtree.Insert(bbox, idx)
58-
59-
# call_backs of rtree
60-
def search_callback(sender, rtree_event_args):
61-
data_by_reference.append(rtree_event_args.Id)
62-
63-
neighbours : list[list[int, int]] = []
64-
65-
# perform search
66-
for i in range(len(bboxes)):
67-
data_by_reference = []
68-
if rtree.Search(
69-
bboxes[i], search_callback, data_by_reference
70-
):
71-
for j in data_by_reference:
72-
if j < i:
73-
continue
74-
result, p0, p1 = curves[i].ClosestPoints(curves[j])
75-
76-
if(distance < p0.DistanceTo(p1)):
77-
neighbours.append([i, j])
78-
if display_closest_line_segments:
79-
line = Rhino.Geometry.Line(p0, p1)
80-
Rhino.RhinoDoc.ActiveDoc.Objects.AddLine(line)
81-
82-
83-
print(neighbours)
84-
85-
###############################################################################
86-
# Output
87-
###############################################################################
88-
return
89-
90-
91-
9210
def callback(selection: dict[str, any], name: str):
11+
9312
if not selection["elements"]:
9413
return
95-
96-
# Extract axes and radii
97-
curves = []
98-
radii = []
99-
for idx, element in enumerate(selection["elements"]):
100-
curves.append(element.axes[0].ToNurbsCurve())
101-
radii.append(max(element.radii[0]))
102-
103-
# Run closest curve search
104-
closest_curves(curves, radii, 25)
105-
106-
10714

108-
109-
110-
# add_sub_layer(
111-
# element.geometry_plane[0],
112-
# "axes",
113-
# axes_curves,
114-
# [Color.FromArgb(255, 30, 144, 255)],
115-
# idx == 0,
116-
# True,
117-
# )
15+
# Run closest curve search
16+
neighbours, planes, lines = Element.closest_axis(
17+
selection["elements"],
18+
selection["distance"],
19+
selection["display_plane"],
20+
selection["display_line"],
21+
)
22+
23+
####################################################################################################
24+
# Collect Neighbour Information
25+
####################################################################################################
26+
neighbours_for_user_data = {}
27+
features = {}
28+
29+
# Explicit loop for initialization
30+
for idx in range(len(selection["elements"])):
31+
neighbours_for_user_data[idx] = []
32+
features[idx] = []
33+
34+
# Populate neighbour relationships
35+
for pair in neighbours:
36+
a, b = pair # Explicit unpacking for clarity
37+
neighbours_for_user_data[a].append(b)
38+
neighbours_for_user_data[b].append(a)
39+
40+
# Assign indices and sorted neighbours
41+
for idx, element in enumerate(selection["elements"]):
42+
element.index = idx
43+
element.neighbours = sorted(neighbours_for_user_data[idx])
44+
45+
####################################################################################################
46+
# Collect breps into the features dictionary
47+
####################################################################################################
48+
for pair, target_plane in zip(neighbours, planes):
49+
element_pair = [selection["elements"][pair[0]], selection["elements"][pair[1]]]
50+
breps_pair = [selection["features_positive"], selection["features_negative"]]
51+
52+
T = Rhino.Geometry.Transform.PlaneToPlane(
53+
Rhino.Geometry.Plane.WorldXY, target_plane
54+
)
55+
56+
for element, breps in zip(element_pair, breps_pair):
57+
breps_copies = []
58+
for brep in breps:
59+
breps_copies.append(brep.DuplicateBrep())
60+
breps_copies[-1].Transform(T)
61+
features[element.index].extend(breps_copies)
62+
63+
####################################################################################################
64+
# Assign features to the elements
65+
####################################################################################################
66+
for idx, element in enumerate(selection["elements"]):
67+
new_features = (
68+
features[element.index]
69+
if selection["replace_or_extend_features"]
70+
else features[element.index] + element.features
71+
)
72+
73+
# Display must be in this position, because setter of features transforms BReps
74+
if selection["display_features"]:
75+
add_sub_layer(
76+
element.geometry_plane[0],
77+
"features",
78+
new_features,
79+
[Color.FromArgb(0, 0, 255)],
80+
idx == 0,
81+
True,
82+
)
83+
84+
element.features = new_features
11885

11986

12087
if __name__ == "__main__":
12188
selection_types: dict[str, tuple] = {
12289
"elements": ([], list[Element]),
123-
"features": ([], list[Rhino.Geometry.Brep]),
90+
"features_positive": ([], list[Rhino.Geometry.Brep]),
91+
"features_negative": ([], list[Rhino.Geometry.Brep]),
92+
"distance": (150, float),
93+
"display_plane": (False, bool),
94+
"display_line": (False, bool),
95+
"display_features": (False, bool),
96+
"replace_or_extend_features": (True, bool),
12497
}
12598

126-
process_input(selection_types, callback)
127-
99+
process_input(selection_types, callback, hide_input=False)

src/rhino/raw/commands/w_raw_find_volumes.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -225,15 +225,15 @@ def from_point3(point3):
225225

226226
if __name__ == "__main__":
227227
selection_types: dict[str, tuple] = {
228-
"elements": ([], List[Element]),
228+
"elements": ([], list[Element]),
229229
"allowed_types_per_polyline": (
230230
[-1],
231-
List[int],
231+
list[int],
232232
), # Default value for types (list of ints)
233233
"min_distance": (100, float), # Default value for min distance (float)
234234
"volume_length": (500, float), # Default value for volume length (float)
235235
"cross_or_side_to_end": (
236-
0.91,
236+
0.75,
237237
float,
238238
), # Default value for cross or side to end (float)
239239
"find_insertion": (

src/rhino/raw/commands/w_raw_shape.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ def callback(selection: dict[str, any], name: str):
1717

1818
for idx, element in enumerate(selection["elements"]):
1919
element.shape = selection["shape"][idx % num_shapes] # Cycle through shapes
20-
20+
2121
return
2222

2323

src/rhino/raw/commands/w_raw_skeleton.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111

1212

1313
def callback(selection: dict[str, any], name: str):
14-
1514
# Just axis without radii
1615
if not selection["simplify"]:
1716
for mesh in selection["meshes"]:
@@ -20,15 +19,14 @@ def callback(selection: dict[str, any], name: str):
2019
Rhino.RhinoDoc.ActiveDoc.Objects.AddPolyline(polyline)
2120
return
2221

23-
# Try to simplify an axis
22+
# Try to simplify an axis
2423

2524
polylines = []
2625
distances = []
2726
meshes = []
2827
transforms = []
2928

3029
for mesh in selection["meshes"]:
31-
3230
polyline = None
3331
polylines = []
3432

@@ -60,11 +58,9 @@ def callback(selection: dict[str, any], name: str):
6058

6159

6260
if __name__ == "__main__":
63-
64-
6561
input_dict = {
6662
"meshes": ([], list[Rhino.Geometry.Mesh]),
67-
"simplify" : (False, bool),
63+
"simplify": (False, bool),
6864
"divisions": (10, int),
6965
"nearest_neighbors": (10, int),
7066
"extend_end": (True, bool),

src/rhino/raw/commands/w_raw_solver.py

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -190,14 +190,6 @@ def callback(selection: dict[str, any], name: str):
190190
ir_joint_volume_extension = wood_rui_globals.joint_volume_extension
191191
iw_joint_volume_extension = to_double1(ir_joint_volume_extension)
192192

193-
######################################################################
194-
# input_custom_joints
195-
######################################################################
196-
197-
######################################################################
198-
# input_custom_joints_types
199-
######################################################################
200-
201193
######################################################################
202194
# output
203195
######################################################################
@@ -244,15 +236,19 @@ def callback(selection: dict[str, any], name: str):
244236
polyline1 = polylines[j + 1]
245237
fab_type = types[int(j * 0.5)]
246238

247-
if fab_type != "drill" and wood_rui_globals.dowel_radius > 0.01:
239+
print(polyline0.Count)
240+
print(polyline1.Count)
241+
print(fab_type)
242+
243+
if fab_type != "drill" and polyline0.Count != 2:
248244
brep = Element.loft_polylines_with_holes(
249245
[polyline0.ToNurbsCurve()],
250246
[polyline1.ToNurbsCurve()],
251247
System.Drawing.Color.Red,
252248
)
253249
# Rhino.RhinoDoc.ActiveDoc.Objects.AddBrep(brep)
254250
grouped_breps[index_to_group[count][0]].append(brep)
255-
else:
251+
elif wood_rui_globals.dowel_radius > 0.01:
256252
plane = Rhino.Geometry.Plane(
257253
polyline0[0], polyline0.SegmentAt(0).Direction
258254
)

0 commit comments

Comments
 (0)