-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPt 7: Smooth Ribbon Generation with Material Frames and Lofting in RhinoCommon
113 lines (50 loc) · 2.08 KB
/
Pt 7: Smooth Ribbon Generation with Material Frames and Lofting in RhinoCommon
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
import Rhino.Geometry as rg
import ghpythonlib.treehelpers as th
num_branches = edges.BranchCount
num_sampling_segments = 100
ribbons = []
for i in range(num_branches):
#iterate through all the branches
edge_branch = edges.Branch(i)
#join curves
curves = rg.Curve.JoinCurves(edge_branch)
ribbons_per_family = []
num_ribbons = len(curves)
for j in range(num_ribbons):
#extract the polyline curve and converte it into a polyline
pl = curves[j].ToPolyline()
#creatre a smooth version of the polyline
crv = rg.Curve.CreateInterpolatedCurve(pl,3)
# Smooth version. Extract different points and eval normals and tangencies
t_params = crv.DivideByCount(num_sampling_segments, True)
#create a list with the material frames
cs_list = []
frame_list = []
for t in t_params:
#create a test point
p = crv.PointAt(t)
#extract mesh point
mp_pt = m.ClosestMeshPoint(p,0.0)
#compute a normal
p_normal = m.NormalAt(mp_pt)
#extract the tangent
p_tangent = crv.TangentAt(t)
# Compute the cross product
p_cross = rg.Vector3d.CrossProduct(p_normal, p_tangent)
# Matrial Plane/Frame
mat_frame = rg.Plane(p, p_cross, p_normal)
#saving it into an empty list
frame_list.append(mat_frame)
# Create a rectangular section
x_dom = rg.Interval(-0.5*width,0.5*width)
y_dom = rg.Interval(-0.5*height,0.5*height)
rec = rg.Rectangle3d(mat_frame, x_dom, y_dom).ToNurbsCurve()
#Store the values
cs_list.append(rec)
brep_list = rg.Brep.CreateFromLoft(cs_list, rg.Point3d.Unset, rg.Point3d.Unset, rg.LoftType.Normal, True)
for brep in brep_list:
ribbons_per_family.append(brep)
ribbons.append(ribbons_per_family)
ribbons_tree = th.list_to_tree(ribbons)
#OUTPUT
Ribbons = ribbons_tree