forked from nortikin/sverchok
-
Notifications
You must be signed in to change notification settings - Fork 0
/
node_Cylinder.py
157 lines (126 loc) · 6.05 KB
/
node_Cylinder.py
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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
import bpy
from node_s import *
from util import *
from math import sin, cos
class CylinderNode(Node, SverchCustomTreeNode):
''' Cylinder '''
bl_idname = 'CylinderNode'
bl_label = 'Cylinder'
bl_icon = 'OUTLINER_OB_EMPTY'
radTop_ = bpy.props.FloatProperty(name = 'radTop_', description='Radius Top', default=1.0, options={'ANIMATABLE'}, update=updateNode)
radBot_ = bpy.props.FloatProperty(name = 'radBot_', description='Radius Bottom', default=1.0, options={'ANIMATABLE'}, update=updateNode)
vert_ = bpy.props.IntProperty(name = 'vert_', description='Vertices', default=32, min=3, options={'ANIMATABLE'}, update=updateNode)
height_ = bpy.props.FloatProperty(name = 'height_', description='Height', default=2.0, options={'ANIMATABLE'}, update=updateNode)
subd_ = bpy.props.IntProperty(name = 'subd_', description='Subdivisions', default=0, min=0,options={'ANIMATABLE'}, update=updateNode)
cap_ = bpy.props.BoolProperty(name = 'cap_', description='Caps', default=True, options={'ANIMATABLE'}, update=updateNode)
Separate = bpy.props.BoolProperty(name = 'Separate', description='Separate UV coords', default=True, update=updateNode)
def init(self, context):
self.inputs.new('StringsSocket', "RadTop", "RadTop")
self.inputs.new('StringsSocket', "RadBot", "RadBot")
self.inputs.new('StringsSocket', "Vertices", "Vertices")
self.inputs.new('StringsSocket', "Height", "Height")
self.inputs.new('StringsSocket', "Subdivisions", "Subdivisions")
self.outputs.new('VerticesSocket', "Vertices", "Vertices")
self.outputs.new('StringsSocket', "Edges", "Edges")
self.outputs.new('StringsSocket', "Polygons", "Polygons")
def draw_buttons(self, context, layout):
row = layout.row(align=True)
row.prop(self, "Separate", text="Separate")
row.prop(self, "cap_", text="Caps")
layout.prop(self, "radTop_", text="Radius Top")
layout.prop(self, "radBot_", text="Radius Bottom")
layout.prop(self, "vert_", text="Nº Vert")
layout.prop(self, "height_", text="Height")
layout.prop(self, "subd_", text="Subdivisions")
def update(self):
# inputs
if 'RadTop' in self.inputs and self.inputs['RadTop'].links:
RadiusTop = float(SvGetSocketAnyType(self,self.inputs['RadTop'])[0][0])
else:
RadiusTop = self.radTop_
if 'RadBot' in self.inputs and self.inputs['RadBot'].links:
RadiusBot = float(SvGetSocketAnyType(self,self.inputs['RadBot'])[0][0])
else:
RadiusBot = self.radBot_
if 'Vertices' in self.inputs and self.inputs['Vertices'].links:
Vertices = int(SvGetSocketAnyType(self,self.inputs['Vertices'])[0][0])
if Vertices < 3:
Vertices = 3
else:
Vertices = self.vert_
if 'Height' in self.inputs and self.inputs['Height'].links:
Height = float(SvGetSocketAnyType(self,self.inputs['Height'])[0][0])
else:
Height = self.height_
if 'Subdivisions' in self.inputs and self.inputs['Subdivisions'].links:
Subd = int(SvGetSocketAnyType(self,self.inputs['Subdivisions'])[0][0])
if Subd < 0:
Subd = 0
else:
Subd = self.subd_
theta = 360/Vertices
heightSubd = Height/(Subd+1)
listVertX = []
listVertY = []
listVertZ = []
for i in range(Subd+2):
radius = RadiusBot - ((RadiusBot-RadiusTop)/(Subd+1))*i
for j in range(Vertices):
listVertX.append(radius*cos(radians(theta*j)))
listVertY.append(radius*sin(radians(theta*j)))
listVertZ.append(heightSubd*i)
# outputs
if 'Vertices' in self.outputs and self.outputs['Vertices'].links:
X = listVertX
Y = listVertY
Z = listVertZ
max_num = max(len(X), len(Y), len(Z))
fullList(X,max_num)
fullList(Y,max_num)
fullList(Z,max_num)
points = list(sv_zip(X,Y,Z))
if self.Separate:
out=[]
for y in range(Vertices):
out_=[]
for x in range(Subd+2):
out_.append(points[Subd+2*y+x])
out.append(out_)
SvSetSocketAnyType(self, 'Vertices',[out])
else:
SvSetSocketAnyType(self, 'Vertices',[points])
if 'Edges' in self.outputs and self.outputs['Edges'].links:
listEdg = []
for i in range(Subd+2):
for j in range(Vertices-1):
listEdg.append([j+Vertices*i, j+1+Vertices*i])
listEdg.append([Vertices-1+Vertices*i, 0+Vertices*i])
for i in range(Subd+1):
for j in range(Vertices):
listEdg.append([j+Vertices*i, j+Vertices+Vertices*i])
edg = list(listEdg)
SvSetSocketAnyType(self, 'Edges',[edg])
if 'Polygons' in self.outputs and self.outputs['Polygons'].links:
listPlg = []
for i in range(Subd+1):
for j in range(Vertices-1):
listPlg.append([j+Vertices*i, j+1+Vertices*i, j+1+Vertices*i+Vertices, j+Vertices*i+Vertices])
listPlg.append([Vertices-1+Vertices*i, 0+Vertices*i, 0+Vertices*i+Vertices, Vertices-1+Vertices*i+Vertices])
if self.cap_ == 1:
capBot = []
capTop = []
for i in range(Vertices):
capBot.append(i)
capTop.append(Vertices*(Subd+1)+i)
capBot.reverse()
listPlg.append(capBot)
listPlg.append(capTop)
SvSetSocketAnyType(self, 'Polygons',[listPlg])
def update_socket(self, context):
self.update()
def register():
bpy.utils.register_class(CylinderNode)
def unregister():
bpy.utils.unregister_class(CylinderNode)
if __name__ == "__main__":
register()