~siretart/ubuntu/utopic/blender/libav10

1.3.4 by Kevin Roy
Import upstream version 2.57.2-svn36339
1
# add_mesh_gear.py (c) 2009, 2010 Michel J. Anders (varkenvarken)
2
#
3
# ***** BEGIN GPL LICENSE BLOCK *****
4
#
5
#
6
# This program is free software; you can redistribute it and/or
7
# modify it under the terms of the GNU General Public License
8
# as published by the Free Software Foundation; either version 2
9
# of the License, or (at your option) any later version.
10
#
11
# This program is distributed in the hope that it will be useful,
12
# but WITHOUT ANY WARRANTY; without even the implied warranty of
13
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.	See the
14
# GNU General Public License for more details.
15
#
16
# You should have received a copy of the GNU General Public License
17
# along with this program; if not, write to the Free Software Foundation,
18
# Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19
#
20
# ***** END GPL LICENCE BLOCK *****
1.3.7 by Kevin Roy
Import upstream version 2.61
21
'''
1.3.4 by Kevin Roy
Import upstream version 2.57.2-svn36339
22
bl_info = {
23
    "name": "Gears",
24
    "author": "Michel J. Anders (varkenvarken)",
25
    "version": (2, 4, 2),
1.3.11 by Matteo F. Vescovi
Import upstream version 2.65a+svn53743
26
    "blender": (2, 57, 0),
1.3.4 by Kevin Roy
Import upstream version 2.57.2-svn36339
27
    "location": "View3D > Add > Mesh > Gears ",
28
    "description": "Adds a mesh Gear to the Add Mesh menu",
29
    "warning": "",
30
    "wiki_url": "http://wiki.blender.org/index.php/Extensions:2.5/Py/"\
31
        "Scripts/Add_Mesh/Add_Gear",
32
    "tracker_url": "https://projects.blender.org/tracker/index.php?"\
33
        "func=detail&aid=21732",
34
    "category": "Add Mesh"}
1.3.7 by Kevin Roy
Import upstream version 2.61
35
'''
1.3.4 by Kevin Roy
Import upstream version 2.57.2-svn36339
36
37
import bpy
38
from math import *
39
from bpy.props import *
40
41
# Create a new mesh (object) from verts/edges/faces.
42
# verts/edges/faces ... List of vertices/edges/faces for the
43
#                       new mesh (as used in from_pydata).
44
# name ... Name of the new mesh (& object).
45
def create_mesh_object(context, verts, edges, faces, name):
46
    # Create new mesh
47
    mesh = bpy.data.meshes.new(name)
48
49
    # Make a mesh from a list of verts/edges/faces.
50
    mesh.from_pydata(verts, edges, faces)
51
52
    # Update mesh geometry after adding stuff.
53
    mesh.update()
54
1.3.5 by Kevin Roy
Import upstream version 2.58-svn37702
55
    from bpy_extras import object_utils
56
    return object_utils.object_data_add(context, mesh, operator=None)
1.3.4 by Kevin Roy
Import upstream version 2.57.2-svn36339
57
58
59
# A very simple "bridge" tool.
60
# Connects two equally long vertex rows with faces.
61
# Returns a list of the new faces (list of  lists)
62
#
63
# vertIdx1 ... First vertex list (list of vertex indices).
64
# vertIdx2 ... Second vertex list (list of vertex indices).
65
# closed ... Creates a loop (first & last are closed).
66
# flipped ... Invert the normal of the face(s).
67
#
68
# Note: You can set vertIdx1 to a single vertex index to create
69
#       a fan/star of faces.
70
# Note: If both vertex idx list are the same length they have
71
#       to have at least 2 vertices.
72
def createFaces(vertIdx1, vertIdx2, closed=False, flipped=False):
73
    faces = []
74
75
    if not vertIdx1 or not vertIdx2:
76
        return None
77
78
    if len(vertIdx1) < 2 and len(vertIdx2) < 2:
79
        return None
80
81
    fan = False
82
    if (len(vertIdx1) != len(vertIdx2)):
83
        if (len(vertIdx1) == 1 and len(vertIdx2) > 1):
84
            fan = True
85
        else:
86
            return None
87
88
    total = len(vertIdx2)
89
90
    if closed:
91
        # Bridge the start with the end.
92
        if flipped:
93
            face = [
94
                vertIdx1[0],
95
                vertIdx2[0],
96
                vertIdx2[total - 1]]
97
            if not fan:
98
                face.append(vertIdx1[total - 1])
99
            faces.append(face)
100
101
        else:
102
            face = [vertIdx2[0], vertIdx1[0]]
103
            if not fan:
104
                face.append(vertIdx1[total - 1])
105
            face.append(vertIdx2[total - 1])
106
            faces.append(face)
107
108
    # Bridge the rest of the faces.
109
    for num in range(total - 1):
110
        if flipped:
111
            if fan:
112
                face = [vertIdx2[num], vertIdx1[0], vertIdx2[num + 1]]
113
            else:
114
                face = [vertIdx2[num], vertIdx1[num],
115
                    vertIdx1[num + 1], vertIdx2[num + 1]]
116
            faces.append(face)
117
        else:
118
            if fan:
119
                face = [vertIdx1[0], vertIdx2[num], vertIdx2[num + 1]]
120
            else:
121
                face = [vertIdx1[num], vertIdx2[num],
122
                    vertIdx2[num + 1], vertIdx1[num + 1]]
123
            faces.append(face)
124
125
    return faces
126
127
128
# Calculate the vertex coordinates for a single
129
# section of a gear tooth.
130
# Returns 4 lists of vertex coords (list of tuples):
131
#  *-*---*---*	(1.) verts_inner_base
132
#  | |   |   |
133
#  *-*---*---*	(2.) verts_outer_base
134
#    |   |   |
135
#    *---*---*	(3.) verts_middle_tooth
136
#     \  |  /
137
#      *-*-*	(4.) verts_tip_tooth
138
#
139
# a
140
# t
141
# d
142
# radius
143
# Ad
144
# De
145
# base
146
# p_angle
147
# rack
148
# crown
149
def add_tooth(a, t, d, radius, Ad, De, base, p_angle, rack=0, crown=0.0):
150
    A = [a, a + t / 4, a + t / 2, a + 3 * t / 4]
151
    C = [cos(i) for i in A]
152
    S = [sin(i) for i in A]
153
154
    Ra = radius + Ad
155
    Rd = radius - De
156
    Rb = Rd - base
157
158
    # Pressure angle calc
159
    O = Ad * tan(p_angle)
160
    p_angle = atan(O / Ra)
161
162
    if radius < 0:
163
        p_angle = -p_angle
164
165
    if rack:
166
        S = [sin(t / 4) * I for I in range(-2, 3)]
167
        Sp = [0, sin(-t / 4 + p_angle), 0, sin(t / 4 - p_angle)]
168
169
        verts_inner_base = [(Rb, radius * S[I], d) for I in range(4)]
170
        verts_outer_base = [(Rd, radius * S[I], d) for I in range(4)]
171
        verts_middle_tooth = [(radius, radius * S[I], d) for I in range(1, 4)]
172
        verts_tip_tooth = [(Ra, radius * Sp[I], d) for I in range(1, 4)]
173
174
    else:
175
        Cp = [
176
            0,
177
            cos(a + t / 4 + p_angle),
178
            cos(a + t / 2),
179
            cos(a + 3 * t / 4 - p_angle)]
180
        Sp = [0,
181
            sin(a + t / 4 + p_angle),
182
            sin(a + t / 2),
183
            sin(a + 3 * t / 4 - p_angle)]
184
185
        verts_inner_base = [(Rb * C[I], Rb * S[I], d)
186
            for I in range(4)]
187
        verts_outer_base = [(Rd * C[I], Rd * S[I], d)
188
            for I in range(4)]
189
        verts_middle_tooth = [(radius * C[I], radius * S[I], d + crown / 3)
190
            for I in range(1, 4)]
191
        verts_tip_tooth = [(Ra * Cp[I], Ra * Sp[I], d + crown)
192
            for I in range(1, 4)]
193
194
    return (verts_inner_base, verts_outer_base,
195
        verts_middle_tooth, verts_tip_tooth)
196
197
198
# EXPERIMENTAL Calculate the vertex coordinates for a single
199
# section of a gearspoke.
200
# Returns them as a list of tuples.
201
#
202
# a
203
# t
204
# d
205
# radius
206
# De
207
# base
208
# s
209
# w
210
# l
211
# gap
212
# width
213
#
214
# @todo Finish this.
215
def add_spoke(a, t, d, radius, De, base, s, w, l, gap=0, width=19):
216
    Rd = radius - De
217
    Rb = Rd - base
1.3.6 by Kevin Roy
Import upstream version 2.59
218
    # Rl = Rb  # UNUSED
1.3.4 by Kevin Roy
Import upstream version 2.57.2-svn36339
219
220
    verts = []
221
    edgefaces = []
222
    edgefaces2 = []
223
    sf = []
224
225
    if not gap:
226
        for N in range(width, 1, -2):
227
            edgefaces.append(len(verts))
228
            ts = t / 4
229
            tm = a + 2 * ts
230
            te = asin(w / Rb)
231
            td = te - ts
232
            t4 = ts + td * (width - N) / (width - 3.0)
233
            A = [tm + (i - int(N / 2)) * t4 for i in range(N)]
234
            C = [cos(i) for i in A]
235
            S = [sin(i) for i in A]
236
237
            verts.extend((Rb * I, Rb * J, d) for (I, J) in zip(C, S))
238
            edgefaces2.append(len(verts) - 1)
239
240
            Rb = Rb - s
241
242
        n = 0
243
        for N in range(width, 3, -2):
244
            sf.extend([(i + n, i + 1 + n, i + 2 + n, i + N + n)
245
                for i in range(0, N - 1, 2)])
246
            sf.extend([(i + 2 + n, i + N + n, i + N + 1 + n, i + N + 2 + n)
247
                for i in range(0, N - 3, 2)])
248
249
            n = n + N
250
251
    return verts, edgefaces, edgefaces2, sf
252
253
254
# Create gear geometry.
255
# Returns:
256
# * A list of vertices (list of tuples)
257
# * A list of faces (list of lists)
258
# * A list (group) of vertices of the tip (list of vertex indices).
259
# * A list (group) of vertices of the valley (list of vertex indices).
260
#
261
# teethNum ... Number of teeth on the gear.
262
# radius ... Radius of the gear, negative for crown gear
263
# Ad ... Addendum, extent of tooth above radius.
264
# De ... Dedendum, extent of tooth below radius.
265
# base ... Base, extent of gear below radius.
266
# p_angle ... Pressure angle. Skewness of tooth tip. (radiant)
267
# width ... Width, thickness of gear.
268
# skew ... Skew of teeth. (radiant)
269
# conangle ... Conical angle of gear. (radiant)
270
# rack
271
# crown ... Inward pointing extend of crown teeth.
272
#
273
# inner radius = radius - (De + base)
274
def add_gear(teethNum, radius, Ad, De, base, p_angle,
275
    width=1, skew=0, conangle=0, rack=0, crown=0.0):
276
277
    if teethNum < 2:
278
        return None, None, None, None
279
280
    t = 2 * pi / teethNum
281
282
    if rack:
283
        teethNum = 1
284
1.3.12 by Matteo F. Vescovi
Import upstream version 2.66
285
    print(radius, width, conangle)
1.3.4 by Kevin Roy
Import upstream version 2.57.2-svn36339
286
    scale = (radius - 2 * width * tan(conangle)) / radius
287
288
    verts = []
289
    faces = []
290
    vgroup_top = []  # Vertex group of top/tip? vertices.
291
    vgroup_valley = []  # Vertex group of valley vertices
292
293
    verts_bridge_prev = []
294
    for toothCnt in range(teethNum):
295
        a = toothCnt * t
296
297
        verts_bridge_start = []
298
        verts_bridge_end = []
299
300
        verts_outside_top = []
301
        verts_outside_bottom = []
302
        for (s, d, c, top) \
303
            in [(0, -width, 1, True), \
304
            (skew, width, scale, False)]:
305
306
            verts1, verts2, verts3, verts4 = add_tooth(a + s, t, d,
307
                radius * c, Ad * c, De * c, base * c, p_angle,
308
                rack, crown)
309
310
            vertsIdx1 = list(range(len(verts), len(verts) + len(verts1)))
311
            verts.extend(verts1)
312
            vertsIdx2 = list(range(len(verts), len(verts) + len(verts2)))
313
            verts.extend(verts2)
314
            vertsIdx3 = list(range(len(verts), len(verts) + len(verts3)))
315
            verts.extend(verts3)
316
            vertsIdx4 = list(range(len(verts), len(verts) + len(verts4)))
317
            verts.extend(verts4)
318
319
            verts_outside = []
320
            verts_outside.extend(vertsIdx2[:2])
321
            verts_outside.append(vertsIdx3[0])
322
            verts_outside.extend(vertsIdx4)
323
            verts_outside.append(vertsIdx3[-1])
324
            verts_outside.append(vertsIdx2[-1])
325
326
            if top:
327
                #verts_inside_top = vertsIdx1
328
                verts_outside_top = verts_outside
329
330
                verts_bridge_start.append(vertsIdx1[0])
331
                verts_bridge_start.append(vertsIdx2[0])
332
                verts_bridge_end.append(vertsIdx1[-1])
333
                verts_bridge_end.append(vertsIdx2[-1])
334
335
            else:
336
                #verts_inside_bottom = vertsIdx1
337
                verts_outside_bottom = verts_outside
338
339
                verts_bridge_start.append(vertsIdx2[0])
340
                verts_bridge_start.append(vertsIdx1[0])
341
                verts_bridge_end.append(vertsIdx2[-1])
342
                verts_bridge_end.append(vertsIdx1[-1])
343
344
            # Valley = first 2 vertices of outer base:
345
            vgroup_valley.extend(vertsIdx2[:1])
346
            # Top/tip vertices:
347
            vgroup_top.extend(vertsIdx4)
348
349
            faces_tooth_middle_top = createFaces(vertsIdx2[1:], vertsIdx3,
350
                flipped=top)
351
            faces_tooth_outer_top = createFaces(vertsIdx3, vertsIdx4,
352
                flipped=top)
353
354
            faces_base_top = createFaces(vertsIdx1, vertsIdx2, flipped=top)
355
            faces.extend(faces_base_top)
356
357
            faces.extend(faces_tooth_middle_top)
358
            faces.extend(faces_tooth_outer_top)
359
360
        #faces_inside = createFaces(verts_inside_top, verts_inside_bottom)
361
        #faces.extend(faces_inside)
362
363
        faces_outside = createFaces(verts_outside_top, verts_outside_bottom,
364
            flipped=True)
365
        faces.extend(faces_outside)
366
367
        if toothCnt == 0:
368
            verts_bridge_first = verts_bridge_start
369
370
        # Bridge one tooth to the next
371
        if verts_bridge_prev:
372
            faces_bridge = createFaces(verts_bridge_prev, verts_bridge_start)
373
                            #, closed=True (for "inside" faces)
374
            faces.extend(faces_bridge)
375
376
        # Remember "end" vertices for next tooth.
377
        verts_bridge_prev = verts_bridge_end
378
379
    # Bridge the first to the last tooth.
380
    faces_bridge_f_l = createFaces(verts_bridge_prev, verts_bridge_first)
381
                        #, closed=True (for "inside" faces)
382
    faces.extend(faces_bridge_f_l)
383
384
    return verts, faces, vgroup_top, vgroup_valley
385
386
387
# Create spokes geometry.
388
# Returns:
389
# * A list of vertices (list of tuples)
390
# * A list of faces (list of lists)
391
#
392
# teethNum ... Number of teeth on the gear.
393
# radius ... Radius of the gear, negative for crown gear
394
# De ... Dedendum, extent of tooth below radius.
395
# base ... Base, extent of gear below radius.
396
# width ... Width, thickness of gear.
397
# conangle ... Conical angle of gear. (radiant)
398
# rack
399
# spoke
400
# spbevel
401
# spwidth
402
# splength
403
# spresol
404
#
405
# @todo Finish this
406
# @todo Create a function that takes a "Gear" and creates a
407
#       matching "Gear Spokes" object.
408
def add_spokes(teethNum, radius, De, base, width=1, conangle=0, rack=0,
409
    spoke=3, spbevel=0.1, spwidth=0.2, splength=1.0, spresol=9):
410
411
    if teethNum < 2:
412
        return None, None, None, None
413
414
    if spoke < 2:
415
        return None, None, None, None
416
417
    t = 2 * pi / teethNum
418
419
    if rack:
420
        teethNum = 1
421
422
    scale = (radius - 2 * width * tan(conangle)) / radius
423
424
    verts = []
425
    faces = []
426
427
    c = scale   # debug
428
429
    fl = len(verts)
430
    for toothCnt in range(teethNum):
431
        a = toothCnt * t
432
        s = 0       # For test
433
434
        if toothCnt % spoke == 0:
435
            for d in (-width, width):
436
                sv, edgefaces, edgefaces2, sf = add_spoke(a + s, t, d,
437
                    radius * c, De * c, base * c,
438
                    spbevel, spwidth, splength, 0, spresol)
439
                verts.extend(sv)
440
                faces.extend([j + fl for j in i] for i in sf)
441
                fl += len(sv)
442
443
            d1 = fl - len(sv)
444
            d2 = fl - 2 * len(sv)
445
446
            faces.extend([(i + d2, j + d2, j + d1, i + d1)
447
                for (i, j) in zip(edgefaces[:-1], edgefaces[1:])])
448
            faces.extend([(i + d2, j + d2, j + d1, i + d1)
449
                for (i, j) in zip(edgefaces2[:-1], edgefaces2[1:])])
450
451
        else:
452
            for d in (-width, width):
453
                sv, edgefaces, edgefaces2, sf = add_spoke(a + s, t, d,
454
                    radius * c, De * c, base * c,
455
                    spbevel, spwidth, splength, 1, spresol)
456
457
                verts.extend(sv)
458
                fl += len(sv)
459
460
            d1 = fl - len(sv)
461
            d2 = fl - 2 * len(sv)
462
463
            faces.extend([[i + d2, i + 1 + d2, i + 1 + d1, i + d1]
464
                for (i) in range(0, 3)])
465
            faces.extend([[i + d2, i + 1 + d2, i + 1 + d1, i + d1]
466
                for (i) in range(5, 8)])
467
468
    return verts, faces
469
470
471
# Create worm geometry.
472
# Returns:
473
# * A list of vertices
474
# * A list of faces
475
# * A list (group) of vertices of the tip
476
# * A list (group) of vertices of the valley
477
#
478
# teethNum ... Number of teeth on the worm
479
# radius ... Radius of the gear, negative for crown gear
480
# Ad ... Addendum, extent of tooth above radius.
481
# De ... Dedendum, extent of tooth below radius.
482
# p_angle ... Pressure angle. Skewness of tooth tip. (radiant)
483
# width ... Width, thickness of gear.
484
# crown ... Inward pointing extend of crown teeth.
485
#
486
# @todo: Fix teethNum. Some numbers are not possible yet.
487
# @todo: Create start & end geoemtry (closing faces)
488
def add_worm(teethNum, rowNum, radius, Ad, De, p_angle,
489
    width=1, skew=radians(11.25), crown=0.0):
490
491
    worm = teethNum
492
    teethNum = 24
493
494
    t = 2 * pi / teethNum
495
496
    verts = []
497
    faces = []
498
    vgroup_top = []  # Vertex group of top/tip? vertices.
499
    vgroup_valley = []  # Vertex group of valley vertices
500
501
    #width = width / 2.0
502
503
    edgeloop_prev = []
504
    for Row in range(rowNum):
505
        edgeloop = []
506
507
        for toothCnt in range(teethNum):
508
            a = toothCnt * t
509
510
            s = Row * skew
511
            d = Row * width
512
            c = 1
513
514
            isTooth = False
515
            if toothCnt % (teethNum / worm) != 0:
516
                # Flat
517
                verts1, verts2, verts3, verts4 = add_tooth(a + s, t, d,
518
                    radius - De, 0.0, 0.0, 0, p_angle)
519
520
                # Ignore other verts than the "other base".
521
                verts1 = verts3 = verts4 = []
522
523
            else:
524
                # Tooth
525
                isTooth = True
526
                verts1, verts2, verts3, verts4 = add_tooth(a + s, t, d,
527
                    radius * c, Ad * c, De * c, 0 * c, p_angle, 0, crown)
528
529
                # Remove various unneeded verts (if we are "inside" the tooth)
530
                del(verts2[2])  # Central vertex in the base of the tooth.
531
                del(verts3[1])  # Central vertex in the middle of the tooth.
532
533
            vertsIdx2 = list(range(len(verts), len(verts) + len(verts2)))
534
            verts.extend(verts2)
535
            vertsIdx3 = list(range(len(verts), len(verts) + len(verts3)))
536
            verts.extend(verts3)
537
            vertsIdx4 = list(range(len(verts), len(verts) + len(verts4)))
538
            verts.extend(verts4)
539
540
            if isTooth:
541
                verts_current = []
542
                verts_current.extend(vertsIdx2[:2])
543
                verts_current.append(vertsIdx3[0])
544
                verts_current.extend(vertsIdx4)
545
                verts_current.append(vertsIdx3[-1])
546
                verts_current.append(vertsIdx2[-1])
547
548
                # Valley = first 2 vertices of outer base:
549
                vgroup_valley.extend(vertsIdx2[:1])
550
                # Top/tip vertices:
551
                vgroup_top.extend(vertsIdx4)
552
553
            else:
554
                # Flat
555
                verts_current = vertsIdx2
556
557
                # Valley - all of them.
558
                vgroup_valley.extend(vertsIdx2)
559
560
            edgeloop.extend(verts_current)
561
562
        # Create faces between rings/rows.
563
        if edgeloop_prev:
564
            faces_row = createFaces(edgeloop, edgeloop_prev, closed=True)
565
            faces.extend(faces_row)
566
567
        # Remember last ring/row of vertices for next ring/row iteration.
568
        edgeloop_prev = edgeloop
569
570
    return verts, faces, vgroup_top, vgroup_valley
571
572
573
class AddGear(bpy.types.Operator):
1.3.11 by Matteo F. Vescovi
Import upstream version 2.65a+svn53743
574
    """Add a gear mesh"""
1.3.4 by Kevin Roy
Import upstream version 2.57.2-svn36339
575
    bl_idname = "mesh.primitive_gear"
576
    bl_label = "Add Gear"
1.3.8 by Matteo F. Vescovi
Import upstream version 2.62
577
    bl_options = {'REGISTER', 'UNDO', 'PRESET'}
1.3.4 by Kevin Roy
Import upstream version 2.57.2-svn36339
578
579
    number_of_teeth = IntProperty(name="Number of Teeth",
580
        description="Number of teeth on the gear",
581
        min=2,
582
        max=265,
583
        default=12)
584
    radius = FloatProperty(name="Radius",
585
        description="Radius of the gear, negative for crown gear",
586
        min=-100.0,
587
        max=100.0,
1.3.12 by Matteo F. Vescovi
Import upstream version 2.66
588
        unit='LENGTH',
1.3.4 by Kevin Roy
Import upstream version 2.57.2-svn36339
589
        default=1.0)
590
    addendum = FloatProperty(name="Addendum",
591
        description="Addendum, extent of tooth above radius",
592
        min=0.01,
593
        max=100.0,
1.3.12 by Matteo F. Vescovi
Import upstream version 2.66
594
        unit='LENGTH',
1.3.4 by Kevin Roy
Import upstream version 2.57.2-svn36339
595
        default=0.1)
596
    dedendum = FloatProperty(name="Dedendum",
597
        description="Dedendum, extent of tooth below radius",
598
        min=0.0,
599
        max=100.0,
1.3.12 by Matteo F. Vescovi
Import upstream version 2.66
600
        unit='LENGTH',
1.3.4 by Kevin Roy
Import upstream version 2.57.2-svn36339
601
        default=0.1)
602
    angle = FloatProperty(name="Pressure Angle",
1.3.12 by Matteo F. Vescovi
Import upstream version 2.66
603
        description="Pressure angle, skewness of tooth tip",
1.3.4 by Kevin Roy
Import upstream version 2.57.2-svn36339
604
        min=0.0,
1.3.12 by Matteo F. Vescovi
Import upstream version 2.66
605
        max=radians(45.0),
606
        unit='ROTATION',
1.3.4 by Kevin Roy
Import upstream version 2.57.2-svn36339
607
        default=20.0)
608
    base = FloatProperty(name="Base",
609
        description="Base, extent of gear below radius",
610
        min=0.0,
611
        max=100.0,
1.3.12 by Matteo F. Vescovi
Import upstream version 2.66
612
        unit='LENGTH',
1.3.4 by Kevin Roy
Import upstream version 2.57.2-svn36339
613
        default=0.2)
614
    width = FloatProperty(name="Width",
615
        description="Width, thickness of gear",
616
        min=0.05,
617
        max=100.0,
1.3.12 by Matteo F. Vescovi
Import upstream version 2.66
618
        unit='LENGTH',
1.3.4 by Kevin Roy
Import upstream version 2.57.2-svn36339
619
        default=0.2)
620
    skew = FloatProperty(name="Skewness",
1.3.12 by Matteo F. Vescovi
Import upstream version 2.66
621
        description="Skew of teeth",
622
        min=radians(-90.0),
623
        max=radians(90.0),
624
        unit='ROTATION',
1.3.4 by Kevin Roy
Import upstream version 2.57.2-svn36339
625
        default=0.0)
626
    conangle = FloatProperty(name="Conical angle",
1.3.12 by Matteo F. Vescovi
Import upstream version 2.66
627
        description="Conical angle of gear",
1.3.4 by Kevin Roy
Import upstream version 2.57.2-svn36339
628
        min=0.0,
1.3.12 by Matteo F. Vescovi
Import upstream version 2.66
629
        max=radians(90.0),
630
        unit='ROTATION',
1.3.4 by Kevin Roy
Import upstream version 2.57.2-svn36339
631
        default=0.0)
632
    crown = FloatProperty(name="Crown",
633
        description="Inward pointing extend of crown teeth",
634
        min=0.0,
635
        max=100.0,
1.3.12 by Matteo F. Vescovi
Import upstream version 2.66
636
        unit='LENGTH',
1.3.4 by Kevin Roy
Import upstream version 2.57.2-svn36339
637
        default=0.0)
638
639
    def draw(self, context):
640
        layout = self.layout
1.3.7 by Kevin Roy
Import upstream version 2.61
641
        
1.3.4 by Kevin Roy
Import upstream version 2.57.2-svn36339
642
        box = layout.box()
643
        box.prop(self, 'number_of_teeth')
1.3.7 by Kevin Roy
Import upstream version 2.61
644
        
1.3.4 by Kevin Roy
Import upstream version 2.57.2-svn36339
645
        box = layout.box()
646
        box.prop(self, 'radius')
647
        box.prop(self, 'width')
648
        box.prop(self, 'base')
1.3.7 by Kevin Roy
Import upstream version 2.61
649
        
1.3.4 by Kevin Roy
Import upstream version 2.57.2-svn36339
650
        box = layout.box()
651
        box.prop(self, 'dedendum')
652
        box.prop(self, 'addendum')
1.3.7 by Kevin Roy
Import upstream version 2.61
653
        
1.3.4 by Kevin Roy
Import upstream version 2.57.2-svn36339
654
        box = layout.box()
655
        box.prop(self, 'angle')
656
        box.prop(self, 'skew')
657
        box.prop(self, 'conangle')
658
        box.prop(self, 'crown')
659
660
661
    def execute(self, context):
662
        verts, faces, verts_tip, verts_valley = add_gear(
663
            self.number_of_teeth,
664
            self.radius,
665
            self.addendum,
666
            self.dedendum,
667
            self.base,
1.3.12 by Matteo F. Vescovi
Import upstream version 2.66
668
            self.angle,
1.3.4 by Kevin Roy
Import upstream version 2.57.2-svn36339
669
            width=self.width,
1.3.12 by Matteo F. Vescovi
Import upstream version 2.66
670
            skew=self.skew,
671
            conangle=self.conangle,
1.3.4 by Kevin Roy
Import upstream version 2.57.2-svn36339
672
            crown=self.crown)
673
674
        # Actually create the mesh object from this geometry data.
675
        base = create_mesh_object(context, verts, [], faces, "Gear")
676
        obj = base.object
677
1.5.4 by Matteo F. Vescovi
Import upstream version 2.69
678
        # XXX, supporting adding in editmode is move involved
679
        if obj.mode != 'EDIT':
680
            # Create vertex groups from stored vertices.
681
            tipGroup = obj.vertex_groups.new('Tips')
682
            tipGroup.add(verts_tip, 1.0, 'ADD')
1.3.4 by Kevin Roy
Import upstream version 2.57.2-svn36339
683
1.5.4 by Matteo F. Vescovi
Import upstream version 2.69
684
            valleyGroup = obj.vertex_groups.new('Valleys')
685
            valleyGroup.add(verts_valley, 1.0, 'ADD')
1.3.4 by Kevin Roy
Import upstream version 2.57.2-svn36339
686
687
        return {'FINISHED'}
688
689
690
class AddWormGear(bpy.types.Operator):
1.3.11 by Matteo F. Vescovi
Import upstream version 2.65a+svn53743
691
    """Add a worm gear mesh"""
1.3.4 by Kevin Roy
Import upstream version 2.57.2-svn36339
692
    bl_idname = "mesh.primitive_worm_gear"
693
    bl_label = "Add Worm Gear"
1.3.8 by Matteo F. Vescovi
Import upstream version 2.62
694
    bl_options = {'REGISTER', 'UNDO', 'PRESET'}
1.3.4 by Kevin Roy
Import upstream version 2.57.2-svn36339
695
696
    number_of_teeth = IntProperty(name="Number of Teeth",
697
        description="Number of teeth on the gear",
698
        min=2,
699
        max=265,
700
        default=12)
701
    number_of_rows = IntProperty(name="Number of Rows",
702
        description="Number of rows on the worm gear",
703
        min=2,
704
        max=265,
705
        default=32)
706
    radius = FloatProperty(name="Radius",
707
        description="Radius of the gear, negative for crown gear",
708
        min=-100.0,
709
        max=100.0,
1.3.12 by Matteo F. Vescovi
Import upstream version 2.66
710
        unit='LENGTH',
1.3.4 by Kevin Roy
Import upstream version 2.57.2-svn36339
711
        default=1.0)
712
    addendum = FloatProperty(name="Addendum",
713
        description="Addendum, extent of tooth above radius",
714
        min=0.01,
715
        max=100.0,
1.3.12 by Matteo F. Vescovi
Import upstream version 2.66
716
        unit='LENGTH',
1.3.4 by Kevin Roy
Import upstream version 2.57.2-svn36339
717
        default=0.1)
718
    dedendum = FloatProperty(name="Dedendum",
719
        description="Dedendum, extent of tooth below radius",
720
        min=0.0,
721
        max=100.0,
1.3.12 by Matteo F. Vescovi
Import upstream version 2.66
722
        unit='LENGTH',
1.3.4 by Kevin Roy
Import upstream version 2.57.2-svn36339
723
        default=0.1)
724
    angle = FloatProperty(name="Pressure Angle",
1.3.12 by Matteo F. Vescovi
Import upstream version 2.66
725
        description="Pressure angle, skewness of tooth tip",
1.3.4 by Kevin Roy
Import upstream version 2.57.2-svn36339
726
        min=0.0,
1.3.12 by Matteo F. Vescovi
Import upstream version 2.66
727
        max=radians(45.0),
728
        default=radians(20.0),
729
        unit='ROTATION')
1.3.4 by Kevin Roy
Import upstream version 2.57.2-svn36339
730
    row_height = FloatProperty(name="Row Height",
731
        description="Height of each Row",
732
        min=0.05,
733
        max=100.0,
1.3.12 by Matteo F. Vescovi
Import upstream version 2.66
734
        unit='LENGTH',
1.3.4 by Kevin Roy
Import upstream version 2.57.2-svn36339
735
        default=0.2)
736
    skew = FloatProperty(name="Skewness per Row",
1.3.12 by Matteo F. Vescovi
Import upstream version 2.66
737
        description="Skew of each row",
738
        min=radians(-90.0),
739
        max=radians(90.0),
740
        default=radians(11.25),
741
        unit='ROTATION')
1.3.4 by Kevin Roy
Import upstream version 2.57.2-svn36339
742
    crown = FloatProperty(name="Crown",
743
        description="Inward pointing extend of crown teeth",
744
        min=0.0,
745
        max=100.0,
1.3.12 by Matteo F. Vescovi
Import upstream version 2.66
746
        unit='LENGTH',
1.3.4 by Kevin Roy
Import upstream version 2.57.2-svn36339
747
        default=0.0)
748
749
    def draw(self, context):
750
        layout = self.layout
751
        box = layout.box()
752
        box.prop(self, 'number_of_teeth')
753
        box.prop(self, 'number_of_rows')
754
        box.prop(self, 'radius')
755
        box.prop(self, 'row_height')
756
        box = layout.box()
757
        box.prop(self, 'addendum')
758
        box.prop(self, 'dedendum')
759
        box = layout.box()
760
        box.prop(self, 'angle')
761
        box.prop(self, 'skew')
762
        box.prop(self, 'crown')
763
764
    def execute(self, context):
765
766
        verts, faces, verts_tip, verts_valley = add_worm(
767
            self.number_of_teeth,
768
            self.number_of_rows,
769
            self.radius,
770
            self.addendum,
771
            self.dedendum,
1.3.12 by Matteo F. Vescovi
Import upstream version 2.66
772
            self.angle,
1.3.4 by Kevin Roy
Import upstream version 2.57.2-svn36339
773
            width=self.row_height,
1.3.12 by Matteo F. Vescovi
Import upstream version 2.66
774
            skew=self.skew,
1.3.4 by Kevin Roy
Import upstream version 2.57.2-svn36339
775
            crown=self.crown)
776
777
        # Actually create the mesh object from this geometry data.
778
        base = create_mesh_object(context, verts, [], faces, "Worm Gear")
779
        obj = base.object
780
1.5.4 by Matteo F. Vescovi
Import upstream version 2.69
781
        # XXX, supporting adding in editmode is move involved
782
        if obj.mode != 'EDIT':
783
            # Create vertex groups from stored vertices.
784
            tipGroup = obj.vertex_groups.new('Tips')
785
            tipGroup.add(verts_tip, 1.0, 'ADD')
1.3.4 by Kevin Roy
Import upstream version 2.57.2-svn36339
786
1.5.4 by Matteo F. Vescovi
Import upstream version 2.69
787
            valleyGroup = obj.vertex_groups.new('Valleys')
788
            valleyGroup.add(verts_valley, 1.0, 'ADD')
1.3.4 by Kevin Roy
Import upstream version 2.57.2-svn36339
789
790
        return {'FINISHED'}