-
Notifications
You must be signed in to change notification settings - Fork 22
/
W_Cone.py
257 lines (218 loc) · 6.62 KB
/
W_Cone.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
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
# __________________________________/
# __Author:_________Vit_Prochazka___/
# __Created:________16.07.2019______/
# __Version:________1.0_____________/
# __________________________________/
# imports
import bpy
from bpy.props import (
FloatProperty,
IntProperty,
BoolProperty,
PointerProperty
)
from bpy_extras import object_utils
from mathutils import Vector, Quaternion
from math import pi as PI
from .genFunctions import (
circleVerts as circ_V,
moveVerts as move_V,
fanClose,
bridgeLoops,
create_mesh_object
)
# generate geometry
def geoGen_WCone (
radius_main,
radius_top,
height,
seg_perimeter,
seg_height,
seg_radius,
centered,
smoothed):
# Prepare empty lists
verts = []
edges = []
faces = []
loops = []
# Set minimums
if seg_perimeter < 3:
seg_perimeter = 3
if seg_height < 1:
seg_height = 1
if seg_radius < 1:
seg_radius = 1
# Add top and bottom center vertices
verts.append(Vector((0, 0, 0)))
verts.append(Vector((0, 0, height)))
if radius_top == 0 and radius_main == 0:
edges.append((0, 1))
return verts, edges, faces
# Create base segmentation loops
if radius_main > 0:
if seg_radius > 1:
step = radius_main / seg_radius
for i in range(1, seg_radius):
newVerts, loop = circ_V(i * step, seg_perimeter, len(verts))
verts.extend(newVerts)
loops.append(loop)
# Create the base corner circle
newVerts, loop = circ_V(radius_main, seg_perimeter, len(verts))
verts.extend(newVerts)
loops.append(loop)
# Create the side segmentation loops
if seg_height > 1:
heightStep = height / seg_height
radiusStep = (radius_top - radius_main) / seg_height
for i in range(1, seg_height):
newRadius = radius_main + (i * radiusStep)
newVerts, loop = circ_V(newRadius, seg_perimeter, len(verts))
move_V(newVerts, Vector((0, 0, heightStep * i)))
verts.extend(newVerts)
loops.append(loop)
# Create top corner circle
if radius_top > 0:
newVerts, loop = circ_V(radius_top, seg_perimeter, len(verts))
move_V(newVerts, Vector((0, 0, height)))
verts.extend(newVerts)
loops.append(loop)
# Create the top segmentation loops
if seg_radius > 1:
step = radius_top / seg_radius
for i in range(1, seg_radius):
newRadius = radius_top - (i * step)
newVerts, loop = circ_V(newRadius, seg_perimeter, len(verts))
move_V(newVerts, Vector((0, 0, height)))
verts.extend(newVerts)
loops.append(loop)
# Close caps
faces.extend(fanClose(loops[0], 0, closed = True, flipped = True))
faces.extend(fanClose(loops[-1], 1))
# Bridge all loops
for i in range(1, len(loops)):
faces.extend(bridgeLoops(loops[i - 1], loops[i], True))
if centered:
move_V(verts, Vector((0, 0, -height / 2)))
return verts, edges, faces
def update_WCone (wData):
return geoGen_WCone (
radius_main = wData.rad_1,
radius_top = wData.rad_2,
height = wData.siz_z,
seg_perimeter = wData.seg_1,
seg_height = wData.seg_2,
seg_radius = wData.seg_3,
centered = wData.cent,
smoothed = wData.smo
)
# add object W_Plane
class Make_WCone(bpy.types.Operator):
"""Create primitive wCone"""
bl_idname = "mesh.make_wcone"
bl_label = "wCone"
bl_options = {'UNDO', 'REGISTER'}
radius_top: FloatProperty(
name = "Radius top",
description = "Top Radius",
default = 0.0,
min = 0.0,
soft_min = 0.0,
step = 1,
precision = 2,
unit = "LENGTH"
)
radius_main: FloatProperty(
name = "Radius bottom",
description = "Bottom Radius",
default = 1.0,
min = 0.0,
soft_min = 0.0,
step = 1,
precision = 2,
unit = "LENGTH"
)
height: FloatProperty(
name = "Height",
description = "Height of the cone",
default = 2.0,
min = 0.0,
soft_min = 0.0,
step = 1,
precision = 2,
unit = "LENGTH"
)
seg_perimeter: IntProperty(
name = "Perim Segments",
description = "Subdivision on perimeter",
default = 24,
min = 3,
soft_min = 3,
step = 1,
subtype = 'NONE'
)
seg_height: IntProperty(
name = "Height Segments",
description = "Subdivision of the height",
default = 1,
min = 1,
soft_min = 1,
step = 1,
subtype = 'NONE'
)
seg_radius: IntProperty(
name = "Radius Segments",
description = "Subdivision of the radius",
default = 1,
min = 1,
soft_min = 1,
step = 1,
subtype = 'NONE'
)
centered: BoolProperty(
name = "Centered",
description = "Set origin of the cone",
default = False
)
def execute(self, context):
mesh = bpy.data.meshes.new("wCone")
wD = mesh.wData
wD.rad_1 = self.radius_main
wD.rad_2 = self.radius_top
wD.siz_z = self.height
wD.seg_1 = self.seg_perimeter
wD.seg_2 = self.seg_height
wD.seg_3 = self.seg_radius
wD.cent = self.centered
wD.smo = True
wD.wType = 'WCONE'
mesh.from_pydata(*update_WCone(wD))
mesh.update()
object_utils.object_data_add(context, mesh, operator=None)
bpy.ops.object.shade_smooth()
context.object.data.use_auto_smooth = True
context.object.data.auto_smooth_angle = 1.0
return {'FINISHED'}
# create UI panel
def draw_WCone_panel(self, context):
lay_out = self.layout
lay_out.use_property_split = True
WData = context.object.data.wData
lay_out.label(text="Type: wCone", icon='MESH_CONE')
col = lay_out.column(align=True)
col.prop(WData, "rad_2", text="Radius Top")
col.prop(WData, "rad_1", text="Radius Main")
col.prop(WData, "siz_z", text="Height")
col = lay_out.column(align=True)
col.prop(WData, "seg_1", text="Segmentation Main")
col.prop(WData, "seg_2", text="Vertical")
col.prop(WData, "seg_3", text="Caps")
lay_out.prop(WData, "cent", text="Centered")
lay_out.prop(WData, "smo", text="Smooth Shading")
lay_out.prop(WData, "anim", text="Animated")
# register
def reg_wCone():
bpy.utils.register_class(Make_WCone)
# unregister
def unreg_wCone():
bpy.utils.unregister_class(Make_WCone)