forked from blender/blender-addons
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathachm_door_maker.py
2391 lines (2258 loc) · 167 KB
/
achm_door_maker.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
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
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
# ##### 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>
# ----------------------------------------------------------
# Author: Antonio Vazquez (antonioya)
#
# ----------------------------------------------------------
# noinspection PyUnresolvedReferences
import bpy
import math
# noinspection PyUnresolvedReferences
from bpy.types import Operator, PropertyGroup, Object, Panel
from bpy.props import FloatProperty, BoolProperty, EnumProperty, FloatVectorProperty, CollectionProperty
from .achm_tools import *
# ------------------------------------------------------------------
# Define operator class to create object
# ------------------------------------------------------------------
class ARCHIMESH_OT_Door(Operator):
bl_idname = "mesh.archimesh_door"
bl_label = "Door"
bl_description = "Door"
bl_category = 'View'
bl_options = {'REGISTER', 'UNDO'}
# -----------------------------------------------------
# Draw (create UI interface)
# -----------------------------------------------------
# noinspection PyUnusedLocal
def draw(self, context):
layout = self.layout
row = layout.row()
row.label(text="Use Properties panel (N) to define parms", icon='INFO')
# -----------------------------------------------------
# Execute
# -----------------------------------------------------
def execute(self, context):
if bpy.context.mode == "OBJECT":
create_object(self, context)
return {'FINISHED'}
else:
self.report({'WARNING'}, "Archimesh: Option only valid in Object mode")
return {'CANCELLED'}
# ------------------------------------------------------------------------------
#
# Create main object. The other objects will be children of this.
#
# ------------------------------------------------------------------------------
# noinspection PyUnusedLocal
def create_object(self, context):
# deselect all objects
for o in bpy.data.objects:
o.select_set(False)
# we create main object and mesh
mainmesh = bpy.data.meshes.new("DoorFrane")
mainobject = bpy.data.objects.new("DoorFrame", mainmesh)
mainobject.location = bpy.context.scene.cursor_location
bpy.context.collection.objects.link(mainobject)
mainobject.DoorObjectGenerator.add()
# we shape the main object and create other objects as children
shape_mesh(mainobject, mainmesh)
shape_children(mainobject)
# we select, and activate, main object
mainobject.select_set(True)
bpy.context.view_layer.objects.active = mainobject
# ------------------------------------------------------------------------------
#
# Update main mesh and children objects
#
# ------------------------------------------------------------------------------
# noinspection PyUnusedLocal
def update_object(self, context):
# When we update, the active object is the main object
o = bpy.context.active_object
oldmesh = o.data
oldname = o.data.name
# Now we deselect that object to not delete it.
o.select_set(False)
# and we create a new mesh
tmp_mesh = bpy.data.meshes.new("temp")
# deselect all objects
for obj in bpy.data.objects:
obj.select_set(False)
# ---------------------------------
# Clear Parent objects (autohole)
# ---------------------------------
myparent = o.parent
if myparent is not None:
ploc = myparent.location
o.parent = None
o.location = ploc
# remove_children(parent)
for child in myparent.children:
# noinspection PyBroadException
try:
# clear child data
child.hide_viewport = False # must be visible to avoid bug
child.hide_render = False # must be visible to avoid bug
old = child.data
child.select_set(True)
bpy.ops.object.delete()
bpy.data.meshes.remove(old)
except:
dummy = -1
myparent.select_set(True)
bpy.ops.object.delete()
# -----------------------
# remove all children
# -----------------------
# first granchild
for child in o.children:
remove_children(child)
# now children of main object
remove_children(o)
# Finally we create all that again (except main object),
shape_mesh(o, tmp_mesh, True)
o.data = tmp_mesh
shape_children(o, True)
# Remove data (mesh of active object),
bpy.data.meshes.remove(oldmesh)
tmp_mesh.name = oldname
# and select, and activate, the main object
o.select_set(True)
bpy.context.view_layer.objects.active = o
# ------------------------------------------------------------------------------
# Generate all objects
# For main, it only shapes mesh and creates modifiers (the modifier, only the first time).
# And, for the others, it creates object and mesh.
# ------------------------------------------------------------------------------
# noinspection PyUnusedLocal
def shape_mesh(mainobject, tmp_mesh, update=False):
mp = mainobject.DoorObjectGenerator[0]
# Create only mesh, because the object is created before
create_doorframe(mp, tmp_mesh)
remove_doubles(mainobject)
set_normals(mainobject)
# saves OpenGL data
mp.glpoint_a = (-mp.frame_width / 2, 0, 0)
mp.glpoint_b = (-mp.frame_width / 2, 0, mp.frame_height)
mp.glpoint_c = (mp.frame_width / 2, 0, mp.frame_height)
mp.glpoint_d = (-mp.frame_width / 2 + mp.frame_size, 0, mp.frame_height - mp.frame_size - 0.01)
mp.glpoint_e = (mp.frame_width / 2 - mp.frame_size, 0, mp.frame_height - mp.frame_size - 0.01)
# Lock
mainobject.lock_location = (True, True, True)
mainobject.lock_rotation = (True, True, True)
return
# ------------------------------------------------------------------------------
# Generate all Children
#
# ------------------------------------------------------------------------------
# noinspection PyUnusedLocal
def shape_children(mainobject, update=False):
mp = mainobject.DoorObjectGenerator[0]
if mp.openside != "3":
make_one_door(mp, mainobject, mp.frame_width, mp.openside)
else:
w = mp.frame_width
widthl = (w * mp.factor)
widthr = w - widthl
# left door
mydoor = make_one_door(mp, mainobject, widthl + mp.frame_size, "2")
mydoor.location.x = -mp.frame_width / 2 + mp.frame_size
# right door (pending width)
mydoor = make_one_door(mp, mainobject, widthr + mp.frame_size, "1")
mydoor.location.x = mp.frame_width / 2 - mp.frame_size
if mp.crt_mat and bpy.context.scene.render.engine in {'CYCLES', 'BLENDER_EEVEE'}:
mat = create_diffuse_material("Door_material", False, 0.8, 0.8, 0.8)
set_material(mainobject, mat)
# -------------------------
# Create empty and parent
# -------------------------
bpy.ops.object.empty_add(type='PLAIN_AXES')
myempty = bpy.data.objects[bpy.context.active_object.name]
myempty.location = mainobject.location
myempty.name = "Door_Group"
parentobject(myempty, mainobject)
mainobject["archimesh.hole_enable"] = True
# Rotate Empty
myempty.rotation_euler.z = math.radians(mp.r)
# Create control box to open wall holes
gap = 0.002
myctrl = create_control_box("CTRL_Hole",
mp.frame_width, mp.frame_thick * 3, mp.frame_height)
# Add custom property to detect Controller
myctrl["archimesh.ctrl_hole"] = True
set_normals(myctrl)
myctrl.parent = myempty
myctrl.location.x = 0
myctrl.location.y = -((mp.frame_thick * 3) / 2)
myctrl.location.z = -gap
myctrl.display_type = 'BOUNDS'
myctrl.hide_viewport = False
myctrl.hide_render = True
if bpy.context.scene.render.engine in {'CYCLES', 'BLENDER_EEVEE'}:
myctrl.cycles_visibility.camera = False
myctrl.cycles_visibility.diffuse = False
myctrl.cycles_visibility.glossy = False
myctrl.cycles_visibility.transmission = False
myctrl.cycles_visibility.scatter = False
myctrl.cycles_visibility.shadow = False
# Create control box for baseboard
myctrlbase = create_control_box("CTRL_Baseboard",
mp.frame_width, 0.40, 0.40,
False)
# Add custom property to detect Controller
myctrlbase["archimesh.ctrl_base"] = True
set_normals(myctrlbase)
myctrlbase.parent = myempty
myctrlbase.location.x = 0
myctrlbase.location.y = -0.15 - (mp.frame_thick / 3)
myctrlbase.location.z = -0.10
myctrlbase.display_type = 'BOUNDS'
myctrlbase.hide_viewport = False
myctrlbase.hide_render = True
if bpy.context.scene.render.engine in {'CYCLES', 'BLENDER_EEVEE'}:
myctrlbase.cycles_visibility.camera = False
myctrlbase.cycles_visibility.diffuse = False
myctrlbase.cycles_visibility.glossy = False
myctrlbase.cycles_visibility.transmission = False
myctrlbase.cycles_visibility.scatter = False
myctrlbase.cycles_visibility.shadow = False
mat = create_transparent_material("hidden_material", False)
set_material(myctrl, mat)
set_material(myctrlbase, mat)
# deactivate others
for o in bpy.data.objects:
if o.select_get() is True and o.name != mainobject.name:
o.select_set(False)
# ------------------------------------------------------------------
# Define property group class to create or modify
# ------------------------------------------------------------------
class ObjectProperties(PropertyGroup):
frame_width: FloatProperty(
name='Frame width',
min=0.25, max=10,
default=1, precision=2,
description='Doorframe width', update=update_object,
)
frame_height: FloatProperty(
name='Frame height',
min=0.25, max=10,
default=2.1, precision=2,
description='Doorframe height', update=update_object,
)
frame_thick: FloatProperty(
name='Frame thickness',
min=0.05, max=0.50,
default=0.08, precision=2,
description='Doorframe thickness', update=update_object,
)
frame_size: FloatProperty(
name='Frame size',
min=0.05, max=0.25,
default=0.08, precision=2,
description='Doorframe size', update=update_object,
)
crt_mat: BoolProperty(
name="Create default Cycles materials",
description="Create default materials for Cycles render",
default=True,
update=update_object,
)
factor: FloatProperty(
name='',
min=0.2, max=1,
default=0.5, precision=3, description='Door ratio',
update=update_object,
)
r: FloatProperty(
name='Rotation', min=0, max=360,
default=0, precision=1,
description='Door rotation', update=update_object,
)
openside: EnumProperty(
name="Open side",
items=(
('1', "Right open", ""),
('2', "Left open", ""),
('3', "Both sides", ""),
),
description="Defines the direction for opening the door",
update=update_object,
)
model: EnumProperty(
name="Model",
items=(
('1', "Model 01", ""),
('2', "Model 02", ""),
('3', "Model 03", ""),
('4', "Model 04", ""),
('5', "Model 05", "Glass"),
('6', "Model 06", "Glass"),
),
description="Door model",
update=update_object,
)
handle: EnumProperty(
name="Handle",
items=(
('1', "Handle 01", ""),
('2', "Handle 02", ""),
('3', "Handle 03", ""),
('4', "Handle 04", ""),
('0', "None", ""),
),
description="Handle model",
update=update_object,
)
# opengl internal data
glpoint_a: FloatVectorProperty(
name="glpointa",
description="Hidden property for opengl",
default=(0, 0, 0),
)
glpoint_b: FloatVectorProperty(
name="glpointb",
description="Hidden property for opengl",
default=(0, 0, 0),
)
glpoint_c: FloatVectorProperty(
name="glpointc",
description="Hidden property for opengl",
default=(0, 0, 0),
)
glpoint_d: FloatVectorProperty(
name="glpointc",
description="Hidden property for opengl",
default=(0, 0, 0),
)
glpoint_e: FloatVectorProperty(
name="glpointc",
description="Hidden property for opengl",
default=(0, 0, 0),
)
# Register
bpy.utils.register_class(ObjectProperties)
Object.DoorObjectGenerator= CollectionProperty(type=ObjectProperties)
# ------------------------------------------------------------------
# Define panel class to modify object
# ------------------------------------------------------------------
class ARCHIMESH_PT_DoorObjectgenerator(Panel):
bl_idname = "OBJECT_PT_door_generator"
bl_label = "Door"
bl_space_type = 'VIEW_3D'
bl_region_type = 'UI'
bl_category = 'View'
# -----------------------------------------------------
# Verify if visible
# -----------------------------------------------------
@classmethod
def poll(cls, context):
o = context.object
if o is None:
return False
if 'DoorObjectGenerator' not in o:
return False
else:
return True
# -----------------------------------------------------
# Draw (create UI interface)
# -----------------------------------------------------
def draw(self, context):
o = context.object
# noinspection PyBroadException
try:
if 'DoorObjectGenerator' not in o:
return
except:
return
layout = self.layout
if bpy.context.mode == 'EDIT_MESH':
layout.label(text='Warning: Operator does not work in edit mode.', icon='ERROR')
else:
myobjdat = o.DoorObjectGenerator[0]
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()
row = box.row()
row.prop(myobjdat, 'frame_width')
row.prop(myobjdat, 'frame_height')
row = box.row()
row.prop(myobjdat, 'frame_thick')
row.prop(myobjdat, 'frame_size')
row = box.row()
row.prop(myobjdat, 'r')
box = layout.box()
row = box.row()
row.prop(myobjdat, 'openside')
if myobjdat.openside == "3":
row.prop(myobjdat, "factor")
layout.prop(myobjdat, 'model')
layout.prop(myobjdat, 'handle')
box = layout.box()
if not context.scene.render.engine in {'CYCLES', 'BLENDER_EEVEE'}:
box.enabled = False
box.prop(myobjdat, 'crt_mat')
else:
row = layout.row()
row.label(text="Warning: Operator does not work in local view mode", icon='ERROR')
# ------------------------------------------------------------------------------
# Create Doorframe
# ------------------------------------------------------------------------------
def create_doorframe(mp, mymesh):
tf = mp.frame_thick / 3
sf = mp.frame_size
wf = (mp.frame_width / 2) - sf
hf = mp.frame_height - sf
gap = 0.02
deep = mp.frame_thick * 0.50
verts = [(-wf - sf, -tf, 0),
(-wf - sf, tf * 2, 0),
(-wf, tf * 2, 0),
(-wf - sf, -tf, hf + sf),
(-wf - sf, tf * 2, hf + sf),
(wf + sf, tf * 2, hf + sf),
(wf + sf, -tf, hf + sf),
(wf, -tf, hf),
(-wf, tf * 2, hf),
(wf, -tf, 0),
(wf + sf, -tf, 0),
(wf + sf, tf * 2, 0),
(wf, -tf + deep, hf),
(-wf, -tf + deep, hf),
(-wf, -tf + deep, 0),
(-wf + gap, -tf + deep, hf),
(-wf + gap, -tf + deep, 0),
(-wf + gap, tf * 2, hf),
(-wf + gap, tf * 2, 0),
(wf, -tf + deep, 0),
(-wf, -tf, hf),
(-wf, -tf, 0),
(wf, tf * 2, hf),
(wf, tf * 2, 0),
(wf - gap, tf * 2, 0),
(wf - gap, -tf + deep, 0),
(wf - gap, tf * 2, hf),
(wf - gap, -tf + deep, hf - gap),
(wf - gap, -tf + deep, hf),
(-wf + gap, tf * 2, hf - gap),
(-wf + gap, -tf + deep, hf - gap),
(wf - gap, tf * 2, hf - gap)]
faces = [(3, 4, 1, 0), (7, 12, 19, 9), (4, 3, 6, 5), (10, 11, 5, 6), (13, 20, 21, 14), (17, 15, 16, 18),
(11, 23, 22, 5),
(20, 13, 12, 7), (20, 3, 0, 21), (9, 10, 6, 7), (13, 14, 16, 15), (4, 8, 2, 1), (29, 30, 27, 31),
(7, 6, 3, 20),
(8, 4, 5, 22), (14, 2, 18, 16), (17, 18, 2, 8), (28, 25, 19, 12), (28, 26, 24, 25), (25, 24, 23, 19),
(22, 23, 24, 26),
(29, 31, 26, 17), (15, 28, 27, 30), (8, 22, 26)]
mymesh.from_pydata(verts, [], faces)
mymesh.update(calc_edges=True)
return
# ------------------------------------------------------------------------------
# Make one door
#
# ------------------------------------------------------------------------------
def make_one_door(self, myframe, width, openside):
mydoor = create_door_data(self, myframe, width, openside)
handle1 = None
handle2 = None
if self.handle != "0":
handle1 = create_handle(self, mydoor, "Front", width, openside)
handle1.select_set(True)
bpy.context.view_layer.objects.active = handle1
set_smooth(handle1)
set_modifier_subsurf(handle1)
handle2 = create_handle(self, mydoor, "Back", width, openside)
set_smooth(handle2)
set_modifier_subsurf(handle2)
# Create materials
if self.crt_mat and bpy.context.scene.render.engine in {'CYCLES', 'BLENDER_EEVEE'}:
# Door material
mat = create_diffuse_material("Door_material", False, 0.8, 0.8, 0.8)
set_material(mydoor, mat)
# Handle material
if self.handle != "0":
mat = create_glossy_material("Handle_material", False, 0.733, 0.779, 0.8)
set_material(handle1, mat)
set_material(handle2, mat)
if self.model == "5" or self.model == "6":
mat = create_glass_material("DoorGlass_material", False)
mydoor.data.materials.append(mat)
if self.model == "5":
select_faces(mydoor, 20, True)
select_faces(mydoor, 41, False)
if self.model == "6":
select_faces(mydoor, 37, True)
select_faces(mydoor, 76, False)
set_material_faces(mydoor, 1)
set_normals(mydoor)
return mydoor
# ------------------------------------------------------------------------------
# Create Door
# All custom values are passed using self container (self.myvariable)
# ------------------------------------------------------------------------------
def create_door_data(self, myframe, width, openside):
# Retry mesh data
if self.model == "1":
mydata = door_model_01(self.frame_size, width, self.frame_height, self.frame_thick, openside)
elif self.model == "2":
mydata = door_model_02(self.frame_size, width, self.frame_height, self.frame_thick, openside)
elif self.model == "3":
mydata = door_model_03(self.frame_size, width, self.frame_height, self.frame_thick, openside)
elif self.model == "4":
mydata = door_model_04(self.frame_size, width, self.frame_height, self.frame_thick, openside)
elif self.model == "5":
mydata = door_model_04(self.frame_size, width, self.frame_height, self.frame_thick,
openside) # uses the same mesh
elif self.model == "6":
mydata = door_model_02(self.frame_size, width, self.frame_height, self.frame_thick,
openside) # uses the same mesh
else:
mydata = door_model_01(self.frame_size, width, self.frame_height, self.frame_thick, openside) # default model
# move data
verts = mydata[0]
faces = mydata[1]
wf = mydata[2]
deep = mydata[3]
side = mydata[4]
mymesh = bpy.data.meshes.new("Door")
myobject = bpy.data.objects.new("Door", mymesh)
myobject.location = bpy.context.scene.cursor_location
bpy.context.collection.objects.link(myobject)
mymesh.from_pydata(verts, [], faces)
mymesh.update(calc_edges=True)
# Translate to doorframe and parent
myobject.parent = myframe
myobject.lock_rotation = (True, True, False)
myobject.lock_location = (True, True, True)
myobject.location.x = ((wf / 2) * side)
myobject.location.y = -(deep * 0.65)
myobject.location.z = self.frame_height / 2
return myobject
# ------------------------------------------------------------------------------
# Create Handles
# All custom values are passed using self container (self.myvariable)
# ------------------------------------------------------------------------------
def create_handle(self, mydoor, pos, frame_width, openside):
# Retry mesh data
if self.handle == "1":
mydata = handle_model_01()
elif self.handle == "2":
mydata = handle_model_02()
elif self.handle == "3":
mydata = handle_model_03()
elif self.handle == "4":
mydata = handle_model_04()
else:
mydata = handle_model_01() # default model
# move data
verts = mydata[0]
faces = mydata[1]
gap = 0.002
sf = self.frame_size
wf = frame_width - (sf * 2) - (gap * 2)
deep = (self.frame_thick * 0.50) - (gap * 3)
# Open to right or left
if openside == "1":
side = -1
else:
side = 1
mymesh = bpy.data.meshes.new("Handle_" + pos)
myobject = bpy.data.objects.new("Handle_" + pos, mymesh)
myobject.location = bpy.context.scene.cursor_location
bpy.context.collection.objects.link(myobject)
mymesh.from_pydata(verts, [], faces)
mymesh.update(calc_edges=True)
# Rotate if pos is front
xrot = 0.0
yrot = 0.0
if self.handle == "1":
if openside != "1":
yrot = math.pi
else:
yrot = 0.0
if pos == "Front":
xrot = math.pi
myobject.rotation_euler = (xrot, yrot, 0.0) # radians PI=180
# Translate to door and parent (depend of model of door)
if self.model == "1":
myobject.location.x = (wf * side) + (0.072 * side * -1)
if pos == "Front":
myobject.location.y = deep - 0.005
else:
myobject.location.y = 0.005
if self.model == "2" or self.model == "6":
myobject.location.x = (wf * side) + (0.060 * side * -1)
if pos == "Front":
myobject.location.y = deep - 0.011
else:
myobject.location.y = 0.00665
if self.model == "3":
myobject.location.x = (wf * side) + (0.060 * side * -1)
if pos == "Front":
myobject.location.y = deep - 0.011
else:
myobject.location.y = 0.00665
if self.model == "4" or self.model == "5":
myobject.location.x = (wf * side) + (0.060 * side * -1)
if pos == "Front":
myobject.location.y = deep - 0.011
else:
myobject.location.y = 0.00665
myobject.location.z = 0
myobject.parent = mydoor
myobject.lock_rotation = (True, False, True)
return myobject
# ----------------------------------------------
# Door model 01
# ----------------------------------------------
def door_model_01(frame_size, frame_width, frame_height, frame_thick, openside):
# ------------------------------------
# Mesh data
# ------------------------------------
gap = 0.002
sf = frame_size
wf = frame_width - (sf * 2) - (gap * 2)
hf = (frame_height / 2) - (gap * 2)
deep = (frame_thick * 0.50) - (gap * 3)
# Open to right or left
if openside == "1":
side = 1
minx = wf * -1
maxx = 0.0
else:
side = -1
minx = 0.0
maxx = wf
miny = 0.0 # locked
maxy = deep
minz = -hf
maxz = hf - sf - gap
# Vertex
myvertex = [(minx, miny, minz),
(minx, maxy, minz),
(maxx, maxy, minz),
(maxx, miny, minz),
(minx, miny, maxz),
(minx, maxy, maxz),
(maxx, maxy, maxz),
(maxx, miny, maxz)]
# Faces
myfaces = [(4, 5, 1, 0), (5, 6, 2, 1), (6, 7, 3, 2), (7, 4, 0, 3), (0, 1, 2, 3),
(7, 6, 5, 4)]
return myvertex, myfaces, wf, deep, side
# ----------------------------------------------
# Door model 02
# ----------------------------------------------
def door_model_02(frame_size, frame_width, frame_height, frame_thick, openside):
gap = 0.002
sf = frame_size
wf = frame_width - (sf * 2) - (gap * 2)
hf = (frame_height / 2) - (gap * 2)
deep = (frame_thick * 0.50)
# ------------------------------------
# Mesh data
# ------------------------------------
# Open to right or left
if openside == "1":
side = 1
minx = wf * -1
maxx = 0.0
else:
side = -1
minx = 0.0
maxx = wf
maxy = deep
minz = -hf
maxz = hf - sf - gap
# Vertex
myvertex = [(minx, -1.57160684466362e-08, minz + 2.384185791015625e-06),
(maxx, -1.5599653124809265e-08, minz),
(minx, -1.5599653124809265e-08, maxz),
(minx, -1.5599653124809265e-08, maxz - 0.12999999523162842),
(minx, -1.57160684466362e-08, minz + 0.2500007152557373),
(maxx, -1.5599653124809265e-08, minz + 0.25000011920928955),
(maxx, -1.5599653124809265e-08, maxz),
(maxx, -1.5599653124809265e-08, maxz - 0.12999999523162842),
(maxx - 0.11609852313995361, -1.5599653124809265e-08, maxz),
(maxx - 0.12357193231582642, -1.5599653124809265e-08, minz),
(maxx - 0.11658430099487305, -1.5599653124809265e-08, maxz - 0.12999999523162842),
(maxx - 0.12263774871826172, -1.5599653124809265e-08, minz + 0.25000011920928955),
(minx, -1.57160684466362e-08, minz + 0.8700000941753387),
(maxx, -1.5599653124809265e-08, minz + 0.8700000941753387),
(maxx - 0.12076938152313232, -1.5599653124809265e-08, minz + 0.7500001192092896),
(minx + 0.11735659837722778, -1.57160684466362e-08, minz + 0.25000011920928955),
(minx + 0.12341010570526123, -1.5599653124809265e-08, maxz - 0.12999999523162842),
(minx + 0.11642247438430786, -1.57160684466362e-08, minz),
(minx + 0.11967337131500244, -1.57160684466362e-08, minz + 0.8700000941753387),
(minx, -1.57160684466362e-08, minz + 0.7500001192092896),
(maxx - 0.12032097578048706, -1.5599653124809265e-08, minz + 0.8700000941753387),
(minx + 0.12389582395553589, -1.5599653124809265e-08, maxz),
(maxx, -1.5599653124809265e-08, minz + 0.7500001192092896),
(minx + 0.11922496557235718, -1.57160684466362e-08, minz + 0.7500001192092896),
(minx + 0.11922496557235718, -0.010000014677643776, minz + 0.7500001192092896),
(minx + 0.12341010570526123, -0.010000014677643776, maxz - 0.12999999523162842),
(maxx - 0.12032097578048706, -0.010000014677643776, minz + 0.8700000941753387),
(minx + 0.11735659837722778, -0.010000014677643776, minz + 0.25000011920928955),
(maxx - 0.11658430099487305, -0.010000014677643776, maxz - 0.12999999523162842),
(maxx - 0.12263774871826172, -0.010000014677643776, minz + 0.25000011920928955),
(minx + 0.11967337131500244, -0.010000014677643776, minz + 0.8700000941753387),
(maxx - 0.12076938152313232, -0.010000014677643776, minz + 0.7500001192092896),
(minx + 0.13388586044311523, -0.010000014677643776, minz + 0.7375001013278961),
(minx + 0.1321108341217041, -0.010000014677643776, minz + 0.2625001072883606),
(maxx - 0.1372986137866974, -0.010000014677643776, minz + 0.2625001072883606),
(maxx - 0.13552364706993103, -0.010000014677643776, minz + 0.7375001013278961),
(minx + 0.13802427053451538, -0.010000014677643776, maxz - 0.14747536182403564),
(maxx - 0.13493508100509644, -0.010000014677643776, minz + 0.8866067305207253),
(maxx - 0.13138526678085327, -0.010000014677643776, maxz - 0.14747536182403564),
(minx + 0.13447439670562744, -0.010000014677643776, minz + 0.8866067305207253),
(minx + 0.13388586044311523, -0.008776669390499592, minz + 0.7375001013278961),
(minx + 0.1321108341217041, -0.008776669390499592, minz + 0.2625001072883606),
(maxx - 0.1372986137866974, -0.008776669390499592, minz + 0.2625001072883606),
(maxx - 0.13552364706993103, -0.008776669390499592, minz + 0.7375001013278961),
(minx + 0.13802427053451538, -0.008776669390499592, maxz - 0.14747536182403564),
(maxx - 0.13493508100509644, -0.008776669390499592, minz + 0.8866067305207253),
(maxx - 0.13138526678085327, -0.008776669390499592, maxz - 0.14747536182403564),
(minx + 0.13447439670562744, -0.008776669390499592, minz + 0.8866067305207253),
(minx, maxy - 0.009999999776482582, minz + 2.384185791015625e-06),
(maxx, maxy - 0.009999999776482582, minz),
(minx, maxy - 0.009999999776482582, maxz),
(minx, maxy - 0.009999999776482582, maxz - 0.12999999523162842),
(minx, maxy - 0.009999999776482582, minz + 0.2500007152557373),
(maxx, maxy - 0.009999999776482582, minz + 0.25000011920928955),
(maxx, maxy - 0.009999999776482582, maxz),
(maxx, maxy - 0.009999999776482582, maxz - 0.12999999523162842),
(maxx - 0.11609852313995361, maxy - 0.009999999776482582, maxz),
(maxx - 0.12357193231582642, maxy - 0.009999999776482582, minz),
(maxx - 0.11658430099487305, maxy - 0.009999999776482582, maxz - 0.12999999523162842),
(maxx - 0.12263774871826172, maxy - 0.009999999776482582, minz + 0.25000011920928955),
(minx, maxy - 0.009999999776482582, minz + 0.8700000941753387),
(maxx, maxy - 0.009999999776482582, minz + 0.8700000941753387),
(maxx - 0.12076938152313232, maxy - 0.009999999776482582, minz + 0.7500001192092896),
(minx + 0.11735659837722778, maxy - 0.009999999776482582, minz + 0.25000011920928955),
(minx + 0.12341010570526123, maxy - 0.009999999776482582, maxz - 0.12999999523162842),
(minx + 0.11642247438430786, maxy - 0.009999999776482582, minz),
(minx + 0.11967337131500244, maxy - 0.009999999776482582, minz + 0.8700000941753387),
(minx, maxy - 0.009999999776482582, minz + 0.7500001192092896),
(maxx - 0.12032097578048706, maxy - 0.009999999776482582, minz + 0.8700000941753387),
(minx + 0.12389582395553589, maxy - 0.009999999776482582, maxz),
(maxx, maxy - 0.009999999776482582, minz + 0.7500001192092896),
(minx + 0.11922496557235718, maxy - 0.009999999776482582, minz + 0.7500001192092896),
(minx + 0.11922496557235718, maxy, minz + 0.7500001192092896),
(minx + 0.12341010570526123, maxy, maxz - 0.12999999523162842),
(maxx - 0.12032097578048706, maxy, minz + 0.8700000941753387),
(minx + 0.11735659837722778, maxy, minz + 0.25000011920928955),
(maxx - 0.11658430099487305, maxy, maxz - 0.12999999523162842),
(maxx - 0.12263774871826172, maxy, minz + 0.25000011920928955),
(minx + 0.11967337131500244, maxy, minz + 0.8700000941753387),
(maxx - 0.12076938152313232, maxy, minz + 0.7500001192092896),
(minx + 0.13388586044311523, maxy, minz + 0.7375001013278961),
(minx + 0.1321108341217041, maxy, minz + 0.2625001072883606),
(maxx - 0.1372986137866974, maxy, minz + 0.2625001072883606),
(maxx - 0.13552364706993103, maxy, minz + 0.7375001013278961),
(minx + 0.13802427053451538, maxy, maxz - 0.14747536182403564),
(maxx - 0.13493508100509644, maxy, minz + 0.8866067305207253),
(maxx - 0.13138526678085327, maxy, maxz - 0.14747536182403564),
(minx + 0.13447439670562744, maxy, minz + 0.8866067305207253),
(minx + 0.13388586044311523, maxy - 0.0012233443558216095, minz + 0.7375001013278961),
(minx + 0.1321108341217041, maxy - 0.0012233443558216095, minz + 0.2625001072883606),
(maxx - 0.1372986137866974, maxy - 0.0012233443558216095, minz + 0.2625001072883606),
(maxx - 0.13552364706993103, maxy - 0.0012233443558216095, minz + 0.7375001013278961),
(minx + 0.13802427053451538, maxy - 0.0012233443558216095, maxz - 0.14747536182403564),
(maxx - 0.13493508100509644, maxy - 0.0012233443558216095, minz + 0.8866067305207253),
(maxx - 0.13138526678085327, maxy - 0.0012233443558216095, maxz - 0.14747536182403564),
(minx + 0.13447439670562744, maxy - 0.0012233443558216095, minz + 0.8866067305207253)]
# Faces
myfaces = [(15, 4, 0, 17), (21, 2, 3, 16), (23, 19, 4, 15), (6, 8, 10, 7), (8, 21, 16, 10),
(16, 3, 12, 18), (11, 15, 17, 9), (20, 18, 23, 14), (18, 12, 19, 23), (5, 11, 9, 1),
(22, 14, 11, 5), (7, 10, 20, 13), (13, 20, 14, 22), (20, 10, 28, 26), (10, 16, 25, 28),
(16, 18, 30, 25), (18, 20, 26, 30), (15, 11, 29, 27), (14, 23, 24, 31), (23, 15, 27, 24),
(11, 14, 31, 29), (31, 24, 32, 35), (24, 27, 33, 32), (27, 29, 34, 33), (29, 31, 35, 34),
(26, 28, 38, 37), (30, 26, 37, 39), (28, 25, 36, 38), (25, 30, 39, 36), (33, 34, 42, 41),
(36, 39, 47, 44), (34, 35, 43, 42), (37, 38, 46, 45), (32, 33, 41, 40), (38, 36, 44, 46),
(35, 32, 40, 43), (39, 37, 45, 47), (18, 20, 10, 16), (14, 23, 15, 11), (63, 52, 48, 65),
(69, 50, 51, 64), (71, 67, 52, 63), (54, 56, 58, 55), (56, 69, 64, 58), (64, 51, 60, 66),
(59, 63, 65, 57), (68, 66, 71, 62), (66, 60, 67, 71), (53, 59, 57, 49), (70, 62, 59, 53),
(55, 58, 68, 61), (61, 68, 62, 70), (68, 58, 76, 74), (58, 64, 73, 76), (64, 66, 78, 73),
(66, 68, 74, 78), (63, 59, 77, 75), (62, 71, 72, 79), (71, 63, 75, 72), (59, 62, 79, 77),
(79, 72, 80, 83), (72, 75, 81, 80), (75, 77, 82, 81), (77, 79, 83, 82), (74, 76, 86, 85),
(78, 74, 85, 87), (76, 73, 84, 86), (73, 78, 87, 84), (81, 82, 90, 89), (84, 87, 95, 92),
(82, 83, 91, 90), (85, 86, 94, 93), (80, 81, 89, 88), (86, 84, 92, 94), (83, 80, 88, 91),
(87, 85, 93, 95), (66, 68, 58, 64), (62, 71, 63, 59), (50, 2, 21, 69), (8, 56, 69, 21),
(6, 54, 56, 8), (54, 6, 7, 55), (55, 7, 13, 61), (61, 13, 22, 70), (5, 53, 70, 22),
(1, 49, 53, 5), (49, 1, 9, 57), (57, 9, 17, 65), (0, 48, 65, 17), (48, 0, 4, 52),
(52, 4, 19, 67), (12, 60, 67, 19), (3, 51, 60, 12), (2, 50, 51, 3)]
return myvertex, myfaces, wf, deep, side
# ----------------------------------------------
# Door model 03
# ----------------------------------------------
def door_model_03(frame_size, frame_width, frame_height, frame_thick, openside):
gap = 0.002
sf = frame_size
wf = frame_width - (sf * 2) - (gap * 2)
hf = (frame_height / 2) - (gap * 2)
deep = (frame_thick * 0.50)
# ------------------------------------
# Mesh data
# ------------------------------------
# Open to right or left
if openside == "1":
side = 1
minx = wf * -1
maxx = 0.0
else:
side = -1
minx = 0.0
maxx = wf
miny = 0.0 # Locked
maxy = deep
minz = -hf
maxz = hf - sf - gap
# Vertex
myvertex = [(minx, -1.5599653124809265e-08, maxz),
(maxx, -1.5599653124809265e-08, maxz),
(minx, maxy, maxz),
(maxx, maxy, maxz),
(maxx - 0.10429960489273071, -1.5832483768463135e-08, maxz),
(minx + 0.10429966449737549, -1.5832483768463135e-08, maxz),
(minx + 0.10429966449737549, maxy, maxz),
(minx, -1.5628756955266e-08, maxz - 0.5012519359588623),
(maxx, -1.5599653124809265e-08, maxz - 0.5012525320053101),
(minx, maxy, maxz - 0.5012519359588623),
(maxx, maxy, maxz - 0.5012525320053101),
(maxx - 0.10429960489273071, -1.5832483768463135e-08, maxz - 0.501252293586731),
(minx + 0.10429966449737549, -1.5832483768463135e-08, maxz - 0.5012521147727966),
(minx + 0.10429966449737549, maxy, maxz - 0.5012521147727966),
(maxx - 0.10429960489273071, maxy, maxz - 0.501252293586731),
(minx + 0.11909735202789307, -1.5832483768463135e-08, maxz),
(maxx - 0.11909729242324829, -1.5832483768463135e-08, maxz),
(minx + 0.11909735202789307, maxy, maxz),
(minx + 0.11909735202789307, -1.5832483768463135e-08, maxz - 0.5012521743774414),
(maxx - 0.11909729242324829, -1.5832483768463135e-08, maxz - 0.5012522339820862),
(minx, -1.5629622041046787e-08, maxz - 0.516154021024704),
(maxx, -1.5599653124809265e-08, maxz - 0.5161546468734741),
(minx, maxy, maxz - 0.516154021024704),
(maxx, maxy, maxz - 0.5161546468734741),
(maxx - 0.10429960489273071, -1.5832483768463135e-08, maxz - 0.516154408454895),
(minx + 0.10429966449737549, -1.5832483768463135e-08, maxz - 0.5161541998386383),
(maxx - 0.10429960489273071, maxy, maxz - 0.516154408454895),
(maxx - 0.11909729242324829, -1.5832483768463135e-08, maxz - 0.5161543190479279),
(minx + 0.11909735202789307, -1.5832483768463135e-08, maxz - 0.5161542594432831),
(minx + 0.11909735202789307, maxy, maxz - 0.5161542594432831),
(maxx - 0.10429960489273071, miny + 0.009999999776482582, maxz),
(minx + 0.10429966449737549, miny + 0.009999999776482582, maxz),
(maxx - 0.10429960489273071, miny + 0.009999999776482582, maxz - 0.501252293586731),
(minx + 0.10429966449737549, miny + 0.009999999776482582, maxz - 0.5012521147727966),
(minx + 0.11909735202789307, miny + 0.009999999776482582, maxz),
(maxx - 0.11909729242324829, miny + 0.009999999776482582, maxz),
(minx + 0.11909735202789307, miny + 0.009999999776482582, maxz - 0.5012521743774414),
(maxx - 0.11909729242324829, miny + 0.009999999776482582, maxz - 0.5012522339820862),
(maxx - 0.10429960489273071, miny + 0.009999999776482582, maxz - 0.516154408454895),
(minx + 0.10429966449737549, miny + 0.009999999776482582, maxz - 0.5161541998386383),
(maxx - 0.11909729242324829, miny + 0.009999999776482582, maxz - 0.5161543190479279),
(minx + 0.11909735202789307, miny + 0.009999999776482582, maxz - 0.5161542594432831),
(maxx - 0.11909729242324829, -1.5832483768463135e-08, maxz - 0.992994874715805),
(minx + 0.11909735202789307, -1.5832483768463135e-08, maxz - 0.9929947257041931),
(minx + 0.11909735202789307, maxy, maxz - 0.9929947257041931),
(maxx - 0.11909738183021545, maxy, maxz - 0.992994874715805),
(minx, -1.565730833874568e-08, maxz - 0.9929942488670349),
(maxx, -1.5599653124809265e-08, maxz - 0.9929954260587692),
(minx, maxy, maxz - 0.9929942488670349),
(maxx, maxy, maxz - 0.9929954260587692),
(maxx - 0.10429960489273071, -1.5832483768463135e-08, maxz - 0.9929950088262558),
(minx + 0.10429966449737549, -1.5832483768463135e-08, maxz - 0.9929945915937424),
(maxx - 0.10429960489273071, maxy, maxz - 0.9929950088262558),
(maxx - 0.10429960489273071, miny + 0.009999999776482582, maxz - 0.9929950088262558),
(minx + 0.10429966449737549, miny + 0.009999999776482582, maxz - 0.9929945915937424),
(maxx - 0.11909729242324829, miny + 0.009999999776482582, maxz - 0.992994874715805),
(minx + 0.11909735202789307, miny + 0.009999999776482582, maxz - 0.9929947257041931),
(maxx - 0.11909729242324829, maxy - 0.0004077646881341934, maxz - 0.992994874715805),
(maxx - 0.10429960489273071, maxy - 0.0004077646881341934, maxz - 0.9929950088262558),
(maxx - 0.10429960489273071, maxy, maxz),
(maxx - 0.11909729242324829, maxy, maxz),
(maxx - 0.11909738183021545, maxy, maxz - 0.5012522339820862),
(minx + 0.11909735202789307, maxy, maxz - 0.5012521743774414),
(minx + 0.10429966449737549, maxy, maxz - 0.5161541998386383),
(maxx - 0.11909738183021545, maxy, maxz - 0.5161543190479279),
(minx + 0.10429966449737549, maxy, maxz - 0.9929945915937424),
(maxx - 0.10429960489273071, maxy - 0.008999999612569809, maxz),