Welcome to mirror list, hosted at ThFree Co, Russian Federation.

achm_column_maker.py « archimesh - git.blender.org/blender-addons.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: ac7ca2e68adb26f397ce6fd50e617c0c14d02fd5 (plain)
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
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
# ##### BEGIN GPL LICENSE BLOCK #####
#
#  This program is free software; you can redistribute it and/or
#  modify it under the terms of the GNU General Public License
#  as published by the Free Software Foundation; either version 2
#  of the License, or (at your option) any later version.
#
#  This program is distributed in the hope that it will be useful,
#  but WITHOUT ANY WARRANTY; without even the implied warranty of
#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#  GNU General Public License for more details.
#
#  You should have received a copy of the GNU General Public License
#  along with this program; if not, write to the Free Software Foundation,
#  Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#
# ##### END GPL LICENSE BLOCK #####

# <pep8 compliant>

# ----------------------------------------------------------
# Automatic generation of columns
# Author: Antonio Vazquez (antonioya)
#
# ----------------------------------------------------------
# noinspection PyUnresolvedReferences
import bpy
from math import cos, sin, radians, atan, sqrt
from bpy.props import BoolProperty, IntProperty, FloatProperty, FloatVectorProperty
from .achm_tools import *


# ------------------------------------------------------------------
# Define UI class
# Columns
# ------------------------------------------------------------------
class ARCHIMESH_OT_Column(bpy.types.Operator):
    bl_idname = "mesh.archimesh_column"
    bl_label = "Column"
    bl_description = "Columns Generator"
    bl_category = 'View'
    bl_options = {'REGISTER', 'UNDO'}

    # Define properties
    model: bpy.props.EnumProperty(
            name="Model",
            items=(
                ('1', "Circular", ""),
                ('2', "Rectangular", ""),
                ),
            description="Type of column",
            )
    keep_size: BoolProperty(
            name="Keep radius equal",
            description="Keep all radius (top, mid and bottom) to the same size",
            default=True,
            )

    rad_top: FloatProperty(
            name='Top radius',
            min=0.001, max=10, default=0.15, precision=3,
            description='Radius of the column in the top',
            )
    rad_mid: FloatProperty(
            name='Middle radius',
            min=0.001, max=10, default=0.15, precision=3,
            description='Radius of the column in the middle',
            )
    shift: FloatProperty(
            name='',
            min=-1, max=1, default=0, precision=3,
            description='Middle displacement',
            )

    rad_bottom: FloatProperty(
            name='Bottom radius',
            min=0.001, max=10, default=0.15, precision=3,
            description='Radius of the column in the bottom',
            )

    col_height: FloatProperty(
            name='Total height',
            min=0.001, max=10, default=2.4, precision=3,
            description='Total height of column, including bases and tops',
            )
    col_sx: FloatProperty(
            name='X size',
            min=0.001, max=10, default=0.30, precision=3,
            description='Column size for x axis',
            )
    col_sy: FloatProperty(
            name='Y size',
            min=0.001, max=10, default=0.30, precision=3,
            description='Column size for y axis',
            )

    cir_base: BoolProperty(
            name="Include circular base",
            description="Include a base with circular form",
            default=False,
            )
    cir_base_r: FloatProperty(
            name='Radio',
            min=0.001, max=10, default=0.08, precision=3,
            description='Rise up radio of base',
            )
    cir_base_z: FloatProperty(
            name='Height',
            min=0.001, max=10, default=0.05, precision=3,
            description='Size for z axis',
            )

    cir_top: BoolProperty(
            name="Include circular top",
            description="Include a top with circular form",
            default=False,
            )
    cir_top_r: FloatProperty(
            name='Radio',
            min=0.001, max=10, default=0.08, precision=3,
            description='Rise up radio of top',
            )
    cir_top_z: FloatProperty(
            name='Height',
            min=0.001, max=10, default=0.05, precision=3,
            description='Size for z axis',
            )

    box_base: BoolProperty(
            name="Include rectangular base",
            description="Include a base with rectangular form",
            default=True,
            )
    box_base_x: FloatProperty(
            name='X size',
            min=0.001, max=10, default=0.40, precision=3,
            description='Size for x axis',
            )
    box_base_y: FloatProperty(
            name='Y size',
            min=0.001, max=10, default=0.40, precision=3,
            description='Size for y axis',
            )
    box_base_z: FloatProperty(
            name='Height',
            min=0.001, max=10, default=0.05, precision=3,
            description='Size for z axis',
            )

    box_top: BoolProperty(
            name="Include rectangular top",
            description="Include a top with rectangular form",
            default=True,
            )
    box_top_x: FloatProperty(
            name='X size',
            min=0.001, max=10, default=0.40, precision=3,
            description='Size for x axis',
            )
    box_top_y: FloatProperty(
            name='Y size',
            min=0.001, max=10, default=0.40, precision=3,
            description='Size for y axis',
            )
    box_top_z: FloatProperty(
            name='Height',
            min=0.001, max=10, default=0.05, precision=3,
            description='Size for z axis',
            )

    arc_top: BoolProperty(
            name="Create top arch",
            description="Include an arch in the top of the column",
            default=False,
            )
    arc_radio: FloatProperty(
            name='Arc Radio',
            min=0.001, max=10, default=1, precision=1,
            description='Radio of the arch',
            )
    arc_width: FloatProperty(
            name='Thickness',
            min=0.01, max=10, default=0.15, precision=2,
            description='Thickness of the arch wall',
            )
    arc_gap: FloatProperty(
            name='Arc gap',
            min=0.01, max=10, default=0.25, precision=2,
            description='Size of the gap in the arch sides',
            )

    crt_mat: BoolProperty(
            name="Create default Cycles materials",
            description="Create default materials for Cycles render",
            default=True,
            )
    crt_array: BoolProperty(
            name="Create array of elements",
            description="Create a modifier array for all elemnst",
            default=False,
            )
    array_num_x: IntProperty(
            name='Count X',
            min=0, max=100, default=3,
            description='Number of elements in array',
            )
    array_space_x: FloatProperty(
            name='Distance X',
            min=0.000, max=10, default=1, precision=3,
            description='Distance between elements (only arc disabled)',
            )
    array_num_y: IntProperty(
            name='Count Y',
            min=0, max=100, default=0,
            description='Number of elements in array',
            )
    array_space_y: FloatProperty(
            name='Distance Y',
            min=0.000, max=10, default=1, precision=3,
            description='Distance between elements (only arc disabled)',
            )
    array_space_z: FloatProperty(
            name='Distance Z',
            min=-10, max=10, default=0, precision=3,
            description='Combined X/Z distance between elements (only arc disabled)',
            )
    ramp: BoolProperty(
            name="Deform",
            description="Deform top base with Z displacement", default=True,
            )
    array_space_factor: FloatProperty(
            name='Move Y center',
            min=0.00, max=1, default=0.0, precision=3,
            description='Move the center of the arch in Y axis. (0 centered)',
            )

    # -----------------------------------------------------
    # Draw (create UI interface)
    # -----------------------------------------------------
    # noinspection PyUnusedLocal
    def draw(self, context):
        layout = self.layout
        space = bpy.context.space_data
        if not space.local_view:
            # Imperial units warning
            if bpy.context.scene.unit_settings.system == "IMPERIAL":
                row = layout.row()
                row.label(text="Warning: Imperial units not supported", icon='COLOR_RED')
            box = layout.box()
            box.prop(self, 'model')
            # Circular
            if self.model == "1":
                box.prop(self, 'keep_size')
                box.prop(self, 'rad_top')
                if self.keep_size is False:
                    row = box.row()
                    row.prop(self, 'rad_mid')
                    row.prop(self, 'shift')
                    box.prop(self, 'rad_bottom')

            # Rectangular
            if self.model == "2":
                box.prop(self, 'col_sx')
                box.prop(self, 'col_sy')

            box.prop(self, 'col_height')

            box = layout.box()
            box.prop(self, 'box_base')
            if self.box_base is True:
                row = box.row()
                row.prop(self, 'box_base_x')
                row.prop(self, 'box_base_y')
                row.prop(self, 'box_base_z')

            box = layout.box()
            box.prop(self, 'box_top')
            if self.box_top is True:
                row = box.row()
                row.prop(self, 'box_top_x')
                row.prop(self, 'box_top_y')
                row.prop(self, 'box_top_z')

            box = layout.box()
            box.prop(self, 'cir_base')
            if self.cir_base is True:
                row = box.row()
                row.prop(self, 'cir_base_r')
                row.prop(self, 'cir_base_z')

            box = layout.box()
            box.prop(self, 'cir_top')
            if self.cir_top is True:
                row = box.row()
                row.prop(self, 'cir_top_r')
                row.prop(self, 'cir_top_z')

            box = layout.box()
            box.prop(self, 'arc_top')
            if self.arc_top is True:
                row = box.row()
                row.prop(self, 'arc_radio')
                row.prop(self, 'arc_width')
                row = box.row()
                row.prop(self, 'arc_gap')
                row.prop(self, 'array_space_factor')

            box = layout.box()
            box.prop(self, 'crt_array')
            if self.crt_array is True:
                row = box.row()
                row.prop(self, 'array_num_x')
                row.prop(self, 'array_num_y')
                if self.arc_top is True:
                    box.label(text="Use arch radio and thickness to set distances")

                if self.arc_top is False:
                    row = box.row()
                    row.prop(self, 'array_space_x')
                    row.prop(self, 'array_space_y')
                    row = box.row()
                    row.prop(self, 'array_space_z')
                    row.prop(self, 'ramp')

            box = layout.box()
            if not context.scene.render.engine in {'CYCLES', 'BLENDER_EEVEE'}:
                box.enabled = False
            box.prop(self, 'crt_mat')
        else:
            row = layout.row()
            row.label(text="Warning: Operator does not work in local view mode", icon='ERROR')

    # -----------------------------------------------------
    # Execute
    # -----------------------------------------------------
    # noinspection PyUnusedLocal
    def execute(self, context):
        if bpy.context.mode == "OBJECT":
            create_column_mesh(self)
            return {'FINISHED'}
        else:
            self.report({'WARNING'}, "Archimesh: Option only valid in Object mode")
            return {'CANCELLED'}


# ------------------------------------------------------------------------------
# Generate mesh data
# All custom values are passed using self container (self.myvariable)
# ------------------------------------------------------------------------------
def create_column_mesh(self):
    myarc = None
    cir_top = None
    cir_bottom = None
    box_top = None
    box_bottom = None
    mycolumn = None
    # deactivate others
    for o in bpy.data.objects:
        if o.select_get() is True:
            o.select_set(False)

    bpy.ops.object.select_all(action='DESELECT')

    radio_top = self.rad_top
    if self.keep_size is True:
        radio_mid = radio_top
        radio_bottom = radio_top
    else:
        radio_mid = self.rad_mid
        radio_bottom = self.rad_bottom

    # Calculate height
    height = self.col_height
    if self.box_base:
        height = height - self.box_base_z
    if self.box_top:
        height = height - self.box_top_z

    # ------------------------
    # Create circular column
    # ------------------------
    if self.model == "1":
        bpy.ops.object.select_all(action='DESELECT')
        mycolumn = create_circular_column(self, "Column", radio_top, radio_mid, radio_bottom, height)
        mycolumn.select_set(True)
        bpy.context.view_layer.objects.active = mycolumn
        # Subsurf
        set_smooth(mycolumn)
        set_modifier_subsurf(mycolumn)
    # ------------------------
    # Create rectangular column
    # ------------------------
    if self.model == "2":
        mycolumn = create_rectangular_base(self, "Column", self.col_sx, self.col_sy, height)
        bpy.ops.object.select_all(action='DESELECT')
        mycolumn.select_set(True)
        bpy.context.view_layer.objects.active = mycolumn
        set_normals(mycolumn)
    # ------------------------
    # Circular base
    # ------------------------
    if self.cir_base is True:
        cir_bottom = create_torus("Column_cir_bottom", radio_bottom, self.cir_base_r, self.cir_base_z)
        bpy.ops.object.select_all(action='DESELECT')
        cir_bottom.select_set(True)
        bpy.context.view_layer.objects.active = cir_bottom
        set_modifier_subsurf(cir_bottom)
        set_smooth(cir_bottom)
        cir_bottom.location.x = 0.0
        cir_bottom.location.y = 0.0
        cir_bottom.location.z = self.cir_base_z / 2
        cir_bottom.parent = mycolumn

    # ------------------------
    # Rectangular base
    # ------------------------
    if self.box_base is True:
        box_bottom = create_rectangular_base(self, "Column_box_bottom", self.box_base_x, self.box_base_y,
                                             self.box_base_z)
        bpy.ops.object.select_all(action='DESELECT')
        box_bottom.select_set(True)
        bpy.context.view_layer.objects.active = box_bottom
        box_bottom.parent = mycolumn
        set_normals(box_bottom)
        box_bottom.location.x = 0.0
        box_bottom.location.y = 0.0
        box_bottom.location.z = - self.box_base_z
        # move column
        mycolumn.location.z += self.box_base_z

    # ------------------------
    # Circular top
    # ------------------------
    if self.cir_top is True:
        cir_top = create_torus("Column_cir_top", radio_top, self.cir_top_r, self.cir_top_z)
        bpy.ops.object.select_all(action='DESELECT')
        cir_top.select_set(True)
        bpy.context.view_layer.objects.active = cir_top
        set_modifier_subsurf(cir_top)
        set_smooth(cir_top)
        cir_top.parent = mycolumn
        cir_top.location.x = 0.0
        cir_top.location.y = 0.0
        cir_top.location.z = height - self.cir_top_z / 2

    # ------------------------
    # Rectangular top
    # ------------------------
    if self.box_top is True:
        box_top = create_rectangular_base(self, "Column_box_top", self.box_top_x, self.box_top_y,
                                          self.box_top_z, self.ramp)
        bpy.ops.object.select_all(action='DESELECT')
        box_top.select_set(True)
        bpy.context.view_layer.objects.active = box_top
        set_normals(box_top)
        box_top.parent = mycolumn
        box_top.location.x = 0.0
        box_top.location.y = 0.0
        box_top.location.z = height

    # ------------------------
    # Create arc
    # ------------------------
    if self.arc_top:
        myarc = create_arc("Column_arch", self.arc_radio, self.arc_gap, self.arc_width,
                           self.array_space_factor)
        myarc.parent = mycolumn
        bpy.ops.object.select_all(action='DESELECT')
        myarc.select_set(True)
        bpy.context.view_layer.objects.active = myarc
        set_normals(myarc)
        set_modifier_mirror(myarc, "X")
        myarc.location.x = self.arc_radio + self.arc_gap
        myarc.location.y = 0.0
        if self.box_top is True:
            myarc.location.z = height + self.box_top_z
        else:
            myarc.location.z = height
    # ------------------------
    # Create Array X
    # ------------------------
    if self.array_num_x > 0:
        if self.arc_top:
            distance = ((self.arc_radio + self.arc_gap) * 2)
            zmove = 0
        else:
            distance = self.array_space_x
            zmove = self.array_space_z

        if self.crt_array:
            set_modifier_array(mycolumn, "X", 0, self.array_num_x, True, distance, zmove)

            if self.box_base is True:
                set_modifier_array(box_bottom, "X", 0, self.array_num_x, True, distance, zmove)
            if self.box_top is True:
                set_modifier_array(box_top, "X", 0, self.array_num_x, True, distance, zmove)

            if self.cir_base is True:
                set_modifier_array(cir_bottom, "X", 0, self.array_num_x, True, distance, zmove)
            if self.cir_top is True:
                set_modifier_array(cir_top, "X", 0, self.array_num_x, True, distance, zmove)

            if self.arc_top:
                if self.array_num_x > 1:
                    set_modifier_array(myarc, "X", 1, self.array_num_x - 1)  # one arc minus
    # ------------------------
    # Create Array Y
    # ------------------------
    if self.array_num_y > 0:
        if self.arc_top:
            distance = self.arc_width
        else:
            distance = self.array_space_y

        if self.crt_array:
            set_modifier_array(mycolumn, "Y", 0, self.array_num_y, True, distance)

            if self.box_base is True:
                set_modifier_array(box_bottom, "Y", 0, self.array_num_y, True, distance)
            if self.box_top is True:
                set_modifier_array(box_top, "Y", 0, self.array_num_y, True, distance)

            if self.cir_base is True:
                set_modifier_array(cir_bottom, "Y", 0, self.array_num_y, True, distance)
            if self.cir_top is True:
                set_modifier_array(cir_top, "Y", 0, self.array_num_y, True, distance)

            if self.arc_top:
                if self.array_num_y > 1:
                    set_modifier_array(myarc, "Y", 1, self.array_num_y - 1)  # one less

    # ------------------------
    # Create materials
    # ------------------------
    if self.crt_mat and bpy.context.scene.render.engine in {'CYCLES', 'BLENDER_EEVEE'}:
        # Column material
        mat = create_diffuse_material("Column_material", False, 0.748, 0.734, 0.392, 0.573, 0.581, 0.318)
        set_material(mycolumn, mat)

        if self.box_base is True or self.box_top is True:
            mat = create_diffuse_material("Column_rect", False, 0.56, 0.56, 0.56, 0.56, 0.56, 0.56)
        if self.box_base is True:
            set_material(box_bottom, mat)
        if self.box_top is True:
            set_material(box_top, mat)

        if self.cir_base is True or self.cir_top is True:
            mat = create_diffuse_material("Column_cir", False, 0.65, 0.65, 0.65, 0.65, 0.65, 0.65)
        if self.cir_base is True:
            set_material(cir_bottom, mat)
        if self.cir_top is True:
            set_material(cir_top, mat)

        if self.arc_top:
            mat = create_diffuse_material("Column_arch", False, 0.8, 0.8, 0.8)
            set_material(myarc, mat)

    bpy.ops.object.select_all(action='DESELECT')
    mycolumn.select_set(True)
    bpy.context.view_layer.objects.active = mycolumn

    return


# ------------------------------------------------------------------------------
# Create Column
# ------------------------------------------------------------------------------
def create_circular_column(self, objname, radio_top, radio_mid, radio_bottom, height):
    myvertex = []
    myfaces = []
    pies = [0, 30, 60, 90, 120, 150, 180, 210, 240, 270, 300, 330]  # circle

    # Add bottom circle
    for pie in pies:
        x = cos(radians(pie)) * radio_bottom
        y = sin(radians(pie)) * radio_bottom
        mypoint = [(x, y, 0.0)]
        myvertex.extend(mypoint)
    # Add middle circle
    for pie in pies:
        x = cos(radians(pie)) * radio_mid
        y = sin(radians(pie)) * radio_mid
        mypoint = [(x, y, (height / 2) + ((height / 2) * self.shift))]
        myvertex.extend(mypoint)
    # Add top circle
    for pie in pies:
        x = cos(radians(pie)) * radio_top
        y = sin(radians(pie)) * radio_top
        mypoint = [(x, y, height)]
        myvertex.extend(mypoint)
    # -------------------------------------
    # Faces
    # -------------------------------------
    t = 1
    for n in range(0, len(pies) * 2):
        t += 1
        if t > len(pies):
            t = 1
            myface = [(n, n - len(pies) + 1, n + 1, n + len(pies))]
            myfaces.extend(myface)
        else:
            myface = [(n, n + 1, n + len(pies) + 1, n + len(pies))]
            myfaces.extend(myface)

    mesh = bpy.data.meshes.new(objname)
    myobject = bpy.data.objects.new(objname, mesh)

    myobject.location = bpy.context.scene.cursor.location
    bpy.context.collection.objects.link(myobject)

    mesh.from_pydata(myvertex, [], myfaces)
    mesh.update(calc_edges=True)

    return myobject


# ------------------------------------------------------------------------------
# Create Torus
# ------------------------------------------------------------------------------
def create_torus(objname, radio_inside, radio_outside, height):
    myvertex = []
    myfaces = []
    pies = [0, 30, 60, 90, 120, 150, 180, 210, 240, 270, 300, 330]  # circle
    segments = [80, 60, 30, 0, 330, 300, 280]  # section

    radio_mid = radio_outside + radio_inside - (height / 2)
    # Add internal circles Top
    for pie in pies:
        x = cos(radians(pie)) * radio_inside
        y = sin(radians(pie)) * radio_inside
        mypoint = [(x, y, height / 2)]
        myvertex.extend(mypoint)
    # Add external circles Top
    for pie in pies:
        x = cos(radians(pie)) * radio_mid
        y = sin(radians(pie)) * radio_mid
        mypoint = [(x, y, height / 2)]
        myvertex.extend(mypoint)
    # Add Intermediate lines
    for segment in segments:
        for pie in pies:
            radio_externo = radio_mid + (height * cos(radians(segment)))
            x = cos(radians(pie)) * radio_externo
            y = sin(radians(pie)) * radio_externo
            z = sin(radians(segment)) * (height / 2)

            mypoint = [(x, y, z)]
            myvertex.extend(mypoint)

    # Add internal circles Bottom
    for pie in pies:
        x = cos(radians(pie)) * radio_inside
        y = sin(radians(pie)) * radio_inside
        mypoint = [(x, y, height / 2 * -1)]
        myvertex.extend(mypoint)
    # Add external circles bottom
    for pie in pies:
        x = cos(radians(pie)) * radio_mid
        y = sin(radians(pie)) * radio_mid
        mypoint = [(x, y, height / 2 * -1)]
        myvertex.extend(mypoint)

    # -------------------------------------
    # Faces
    # -------------------------------------
    t = 1
    for n in range(0, len(pies) * len(segments) + (len(pies) * 2)):
        t += 1
        if t > len(pies):
            t = 1
            myface = [(n, n - len(pies) + 1, n + 1, n + len(pies))]
            myfaces.extend(myface)
        else:
            myface = [(n, n + 1, n + len(pies) + 1, n + len(pies))]
            myfaces.extend(myface)

    mesh = bpy.data.meshes.new(objname)
    myobject = bpy.data.objects.new(objname, mesh)

    myobject.location = bpy.context.scene.cursor.location
    bpy.context.collection.objects.link(myobject)

    mesh.from_pydata(myvertex, [], myfaces)
    mesh.update(calc_edges=True)

    return myobject


# ------------------------------------------------------------------------------
# Create rectangular base
# ------------------------------------------------------------------------------
def create_rectangular_base(self, objname, x, y, z, ramp=False):
    elements = self.array_num_x - 1
    height = self.array_space_z * elements
    width = self.array_space_x * elements
    if width > 0:
        angle = atan(height / width)
    else:
        angle = 0

    radio = sqrt((x * x) + (self.array_space_z * self.array_space_z))
    disp = radio * sin(angle)

    if ramp is False or self.arc_top:
        addz1 = 0
        addz2 = 0
    else:
        if self.array_space_z >= 0:
            addz1 = 0
            addz2 = disp
        else:
            addz1 = disp * -1
            addz2 = 0

    myvertex = [(-x / 2, -y / 2, 0.0),
                (-x / 2, y / 2, 0.0),
                (x / 2, y / 2, 0.0),
                (x / 2, -y / 2, 0.0),
                (-x / 2, -y / 2, z + addz1),
                (-x / 2, y / 2, z + addz1),
                (x / 2, y / 2, z + addz2),
                (x / 2, -y / 2, z + addz2)]

    myfaces = [(0, 1, 2, 3), (0, 1, 5, 4), (1, 2, 6, 5), (2, 6, 7, 3), (5, 6, 7, 4), (0, 4, 7, 3)]

    mesh = bpy.data.meshes.new(objname)
    myobject = bpy.data.objects.new(objname, mesh)

    myobject.location = bpy.context.scene.cursor.location
    bpy.context.collection.objects.link(myobject)

    mesh.from_pydata(myvertex, [], myfaces)
    mesh.update(calc_edges=True)

    return myobject


# ------------------------------------------------------------------------------
# Create arc
# ------------------------------------------------------------------------------
def create_arc(objname, radio, gap, thickness, center):
    myvertex = []

    half = (thickness / 2)
    move = half * center

    listdata = [half + move, -half + move]
    for pos_y in listdata:
        # --------------------------------
        # First vertices
        # --------------------------------
        myvertex.extend([(-radio - gap, pos_y, radio + radio / 10)])
        # Flat cuts
        angle = 13 * (180 / 16)
        for i in range(1, 4):
            z = sin(radians(angle)) * radio
            mypoint = [(-radio - gap, pos_y, z)]
            myvertex.extend(mypoint)
            angle += 180 / 16

        myvertex.extend([(-radio - gap, pos_y, 0.0)])
        # --------------------------------
        # Arc points
        # --------------------------------
        angle = 180
        for i in range(0, 9):
            x = cos(radians(angle)) * radio
            z = sin(radians(angle)) * radio
            mypoint = [(x, pos_y, z)]
            myvertex.extend(mypoint)

            angle -= 180 / 16
        # --------------------------------
        # vertical cut points
        # --------------------------------
        angle = 8 * (180 / 16)
        for i in range(1, 5):
            x = cos(radians(angle)) * radio
            mypoint = [(x, pos_y, radio + radio / 10)]
            myvertex.extend(mypoint)

            angle += 180 / 16

    myfaces = [(23, 24, 21, 22), (24, 25, 20, 21), (25, 26, 19, 20), (27, 18, 19, 26), (18, 27, 28, 35),
               (28, 29, 34, 35), (29, 30, 33, 34), (30, 31, 32, 33), (12, 13, 31, 30), (29, 11, 12, 30),
               (11, 29, 28, 10), (10, 28, 27, 9), (9, 27, 26, 8), (25, 7, 8, 26), (24, 6, 7, 25),
               (23, 5, 6, 24), (22, 4, 5, 23), (5, 4, 3, 6), (6, 3, 2, 7), (7, 2, 1, 8),
               (8, 1, 0, 9), (9, 0, 17, 10), (10, 17, 16, 11), (11, 16, 15, 12), (14, 13, 12, 15),
               (21, 3, 4, 22), (20, 2, 3, 21), (19, 1, 2, 20), (1, 19, 18, 0), (0, 18, 35, 17),
               (17, 35, 34, 16), (33, 15, 16, 34), (32, 14, 15, 33)]

    mesh = bpy.data.meshes.new(objname)
    myobject = bpy.data.objects.new(objname, mesh)

    myobject.location = bpy.context.scene.cursor.location
    bpy.context.collection.objects.link(myobject)

    mesh.from_pydata(myvertex, [], myfaces)
    mesh.update(calc_edges=True)

    return myobject