Skip to content

Commit 5757bd0

Browse files
WIP Rhino user interface without joinery.
1 parent f0f725f commit 5757bd0

17 files changed

+1125
-504
lines changed

docs/examples/binding_read_xml_polylines_and_properties.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,9 @@
2222
input_adjacency,
2323
) = read_xml_polylines_and_properties(foldername, filename)
2424

25-
print("vectors_lists:", vectors_lists)
25+
26+
# print("polylines:", polylines)
27+
print("input_three_valence_element_indices_and_instruction:", input_three_valence_element_indices_and_instruction)
2628
print(filename)
2729

2830
try:

src/rhino/plugin/commands/w_element_axis.py

Lines changed: 23 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -2,54 +2,35 @@
22
# venv: timber_connections
33

44
import Rhino
5+
import Rhino.Input
6+
import Rhino.DocObjects
7+
from typing import *
8+
from wood_rui import wood_rui_globals, generalized_input_method, Element, add_sub_layer
59
import System
610

7-
from wood_rui import (
8-
select_and_find_valid_groups, polyline_obj_to_plane, generalized_input_method, add_sub_layer
9-
)
11+
def my_callback(input_dict, dataset_name):
1012

11-
def string_to_xyz(s):
12-
nums = list(map(float, s.split(',')))
13-
points = [Rhino.Geometry.Point3d(nums[i], nums[i+1], nums[i+2]) for i in range(0, len(nums), 3)]
14-
return points
13+
if not input_dict["elements"]:
14+
return
15+
16+
elements : list[Element] = input_dict["elements"]
1517

16-
def get_features(geometry_planes):
17-
18-
for geometry_plane in geometry_planes:
19-
20-
# Collect information from user strings
21-
string_dictionary = geometry_plane[0].Attributes.GetUserStrings()
22-
T = Rhino.Geometry.Transform.PlaneToPlane(Rhino.Geometry.Plane.WorldXY, polyline_obj_to_plane(geometry_plane[1]))
23-
24-
for key in string_dictionary:
25-
26-
if "axis" in key:
27-
# Get axis and plane
28-
value = string_dictionary[key] # GetValues returns a list of values for the key
29-
points = string_to_xyz(value)
30-
axis = Rhino.Geometry.Polyline(points).ToNurbsCurve()
31-
axis.Transform(T)
32-
add_sub_layer(geometry_plane[0], "axis", [axis], [System.Drawing.Color.FromArgb(0,0,255)], False)
33-
34-
35-
# Redraw the document to reflect changes
36-
Rhino.RhinoDoc.ActiveDoc.Views.Redraw()
37-
38-
def remove_features():
39-
pass
40-
41-
def add_features():
42-
pass
43-
44-
def update_features():
45-
pass
18+
for idx, element in enumerate(elements):
19+
axes = element.axes
20+
axes_curves = []
21+
for axis in axes:
22+
axes_curves.append(axis.ToNurbsCurve())
23+
add_sub_layer(element.geometry_plane[0], "axes", axes_curves, [System.Drawing.Color.Red], idx==0)
24+
4625

4726
if __name__ == "__main__":
48-
geometry_planes = select_and_find_valid_groups("Elements")
49-
50-
51-
5227

53-
get_features(geometry_planes)
28+
dataset_name = "beam"
29+
wood_rui_globals.init_data(dataset_name)
5430

31+
input_dict = {
32+
"elements" : ([], List[Element]),
33+
}
5534

35+
# Call the generalized input method with the dataset name and input dictionary
36+
generalized_input_method(dataset_name, input_dict, my_callback, False, True)
Lines changed: 164 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,164 @@
1+
#! python3
2+
# venv: timber_connections
3+
4+
import Rhino
5+
import Rhino.Input
6+
import Rhino.DocObjects
7+
from typing import *
8+
from wood_rui import wood_rui_globals, generalized_input_method, Element, add_sub_layer
9+
import System
10+
11+
def my_callback(input_dict, dataset_name):
12+
13+
if not input_dict["elements"]:
14+
return
15+
16+
elements : list[Element] = input_dict["elements"]
17+
18+
for idx, element in enumerate(elements):
19+
element.boolean_difference()
20+
# add_sub_layer(element.geometry_plane[0], "plane", plane_axes, [System.Drawing.Color.Red, System.Drawing.Color.Green, System.Drawing.Color.Blue], idx==0)
21+
22+
23+
if __name__ == "__main__":
24+
25+
dataset_name = "beam"
26+
wood_rui_globals.init_data(dataset_name)
27+
28+
input_dict = {
29+
"elements" : ([], List[Element]),
30+
}
31+
32+
# Call the generalized input method with the dataset name and input dictionary
33+
generalized_input_method(dataset_name, input_dict, my_callback, False, True)
34+
35+
# import Rhino
36+
# import System
37+
38+
# from wood_rui import (
39+
# select_and_find_valid_groups, polyline_obj_to_plane
40+
# )
41+
42+
43+
# def prepare_for_boolean_difference(geometry_planes):
44+
# shapes = []
45+
# cuts = []
46+
47+
# for geometry_plane in geometry_planes:
48+
# obj = geometry_plane[0]
49+
# geometry = obj.Geometry
50+
# string_dictionary = obj.Attributes.GetUserStrings()
51+
52+
# T = Rhino.Geometry.Transform.PlaneToPlane(Rhino.Geometry.Plane.WorldXY, polyline_obj_to_plane(geometry_plane[1]))
53+
# shapes.append(geometry)
54+
55+
# # Determine type-specific processing
56+
# obj_type = type(geometry)
57+
# valid_types = {
58+
# Rhino.Geometry.Brep: Rhino.DocObjects.ObjectType.Brep,
59+
# Rhino.Geometry.Mesh: Rhino.DocObjects.ObjectType.Mesh
60+
# }
61+
62+
# if obj_type in valid_types:
63+
# cut_list = []
64+
# expected_type = valid_types[obj_type]
65+
66+
# for key in string_dictionary:
67+
# value = string_dictionary[key]
68+
# if "feature" in key:
69+
# feature_geometry = Rhino.Geometry.GeometryBase.FromJSON(value)
70+
# feature_geometry.Transform(T)
71+
# if feature_geometry.ObjectType == expected_type:
72+
# cut_list.append(feature_geometry)
73+
74+
# cuts.append(cut_list)
75+
76+
# # Redraw the document to reflect changes
77+
# Rhino.RhinoDoc.ActiveDoc.Views.Redraw()
78+
79+
# return shapes, cuts
80+
81+
# def clean_brep(brep : Rhino.Geometry.Brep):
82+
# copy = brep.DuplicateBrep()
83+
# copy.Faces.SplitKinkyFaces()
84+
# if Rhino.Geometry.BrepSolidOrientation.Inward == copy.SolidOrientation:
85+
# copy.Flip()
86+
# return copy
87+
88+
# def clean_mesh(mesh : Rhino.Geometry.Mesh):
89+
# copy = mesh.DuplicateMesh()
90+
# copy.Compact();
91+
# copy.Vertices.CombineIdentical(True, True);
92+
# copy.Vertices.CullUnused();
93+
# copy.UnifyNormals();
94+
# copy.Weld(3.14159265358979);
95+
# copy.FaceNormals.ComputeFaceNormals();
96+
# copy.Normals.ComputeNormals();
97+
# if (copy.SolidOrientation() == -1):
98+
# copy.Flip(True, True, True);
99+
# return copy
100+
101+
# def brep_boolean_difference(shape : Rhino.Geometry.Brep, cutters : list[Rhino.Geometry.Brep]):
102+
103+
# for i in range(len(shapes)):
104+
105+
# shape_cleaned = clean_brep(shape)
106+
107+
# for brep in cutters:
108+
# cutter_cleaned = clean_brep(brep)
109+
# out_breps = Rhino.Geometry.Brep.CreateBooleanDifference(shape_cleaned, cutter_cleaned, Rhino.RhinoDoc.ActiveDoc.ModelAbsoluteTolerance)
110+
111+
# volume = 0
112+
113+
# if out_breps:
114+
# for o in out_breps:
115+
# o_cleaned = clean_brep(o)
116+
# current_volume = Rhino.Geometry.VolumeMassProperties.Compute(o_cleaned, True, False, False, False).Volume;
117+
# if current_volume > volume:
118+
# volume = current_volume
119+
# shape_cleaned = o_cleaned
120+
121+
# return shape_cleaned
122+
123+
# def mesh_boolean_difference(shape : Rhino.Geometry.Mesh, cutters : list[Rhino.Geometry.Mesh]):
124+
# print(shape, cutters)
125+
# for i in range(len(shapes)):
126+
127+
# shape_cleaned = clean_mesh(shape)
128+
129+
# for mesh in cutters:
130+
131+
# cutter_cleaned = clean_mesh(mesh)
132+
# out_meshes = Rhino.Geometry.Mesh.CreateBooleanDifference([shape_cleaned], [cutter_cleaned])
133+
134+
# volume = 0
135+
136+
# if out_meshes:
137+
# for o in out_meshes:
138+
# o_cleaned = clean_mesh(o)
139+
# current_volume = Rhino.Geometry.VolumeMassProperties.Compute(o_cleaned, True, False, False, False).Volume;
140+
# if current_volume > volume:
141+
# volume = current_volume
142+
# shape_cleaned = o_cleaned
143+
144+
# return shape_cleaned
145+
146+
# def boolean_difference(shapes : list[Rhino.Geometry.GeometryBase], cuts : list[list[Rhino.Geometry.GeometryBase]]):
147+
148+
# for i in range(len(shapes)):
149+
# if isinstance(shapes[i], Rhino.Geometry.Brep):
150+
# shapes[i] = brep_boolean_difference(shapes[i], cuts[i])
151+
# Rhino.RhinoDoc.ActiveDoc.Objects.AddBrep(shapes[i])
152+
# elif isinstance(shapes[i], Rhino.Geometry.Mesh):
153+
# shapes[i] = mesh_boolean_difference(shapes[i], cuts[i])
154+
# Rhino.RhinoDoc.ActiveDoc.Objects.AddMesh(shapes[i])
155+
156+
157+
158+
159+
# if __name__ == "__main__":
160+
# geometry_planes = select_and_find_valid_groups("Elements")
161+
# shapes, cuts = prepare_for_boolean_difference(geometry_planes)
162+
# boolean_difference(shapes, cuts)
163+
164+

src/rhino/plugin/commands/w_element_boolean_difference.py

Lines changed: 0 additions & 136 deletions
This file was deleted.

0 commit comments

Comments
 (0)