forked from blender/blender-addons
-
Notifications
You must be signed in to change notification settings - Fork 0
/
achm_window_maker.py
2285 lines (2096 loc) · 121 KB
/
achm_window_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
# SPDX-License-Identifier: GPL-2.0-or-later
# ----------------------------------------------------------
# Author: Antonio Vazquez (antonioya)
#
# ----------------------------------------------------------
# noinspection PyUnresolvedReferences
import bpy
from math import pi, radians
from bpy.types import Operator, PropertyGroup, Object, Panel
from bpy.props import StringProperty, FloatProperty, BoolProperty, IntProperty, FloatVectorProperty, \
CollectionProperty, EnumProperty
from .achm_tools import *
# ------------------------------------------------------------------
# Define operator class to create object
# ------------------------------------------------------------------
class ARCHIMESH_OT_Windows(Operator):
bl_idname = "mesh.archimesh_window"
bl_label = "Rail Windows"
bl_description = "Rail Windows Generator"
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("WindowFrane")
mainobject = bpy.data.objects.new("WindowFrame", mainmesh)
mainobject.location = bpy.context.scene.cursor.location
bpy.context.collection.objects.link(mainobject)
mainobject.WindowObjectGenerator.add()
# we shape the main object and create other objects as children
shape_mesh_and_create_children(mainobject, mainmesh)
# 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
ploc = myparent.location
if myparent is not None:
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_and_create_children(o, tmp_mesh, True)
o.data = tmp_mesh
# 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_and_create_children(mainobject, tmp_mesh, update=False):
mp = mainobject.WindowObjectGenerator[0]
# Create only mesh, because the object is created before
if mp.opentype == "1":
generate_rail_window(mainobject, mp, tmp_mesh)
else:
generate_leaf_window(mainobject, mp, tmp_mesh)
remove_doubles(mainobject)
set_normals(mainobject)
# saves OpenGL data
if mp.blind is True:
plus = mp.blind_height
else:
plus = 0
mp.glpoint_a = (-mp.width / 2, 0, 0)
mp.glpoint_b = (-mp.width / 2, 0, mp.height + plus)
mp.glpoint_c = (mp.width / 2, 0, mp.height + plus)
# Lock
mainobject.lock_location = (True, True, True)
mainobject.lock_rotation = (True, True, True)
# -------------------------
# 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 = "Window_Group"
parentobject(myempty, mainobject)
mainobject["archimesh.hole_enable"] = True
# Rotate Empty
myempty.rotation_euler.z = radians(mp.r)
# Create control box to open wall holes
gap = 0.002
y = 0
z = 0
if mp.blind is True:
y = mp.blind_rail
if mp.blind is True and mp.blind_box is True:
z = mp.blind_height
myctrl = create_control_box("CTRL_Hole",
mp.width - gap,
mp.depth * 3, # + y,
mp.height + z - gap)
# 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.depth * 3 / 2
myctrl.location.z = 0
myctrl.display_type = 'BOUNDS'
myctrl.hide_viewport = False
myctrl.hide_render = True
if bpy.context.scene.render.engine in {'CYCLES', 'BLENDER_EEVEE'}:
myctrl.visible_camera = False
myctrl.visible_diffuse = False
myctrl.visible_glossy = False
myctrl.visible_transmission = False
myctrl.visible_shadow = False
mat = create_transparent_material("hidden_material", False)
set_material(myctrl, mat)
# deactivate others
for o in bpy.data.objects:
if o.select_get() is True and o.name != mainobject.name:
o.select_set(False)
return
# ------------------------------------------------------------------
# Define property group class to create or modify
# ------------------------------------------------------------------
class ObjectProperties(PropertyGroup):
width: FloatProperty(
name='Width',
min=0.20, max=50,
default=1.20, precision=3,
description='window width',
update=update_object,
)
depth: FloatProperty(
name='Depth',
min=0.07, max=1,
default=0.10, precision=3,
description='window depth',
update=update_object,
)
height: FloatProperty(
name='Height',
min=0.20, max=50,
default=1, precision=3,
description='window height',
update=update_object,
)
r: FloatProperty(
name='Rotation', min=0, max=360, default=0, precision=1,
description='Window rotation',
update=update_object,
)
external: BoolProperty(
name="External frame",
description="Create an external front frame",
default=True,
update=update_object,
)
frame: FloatProperty(
name='External Frame',
min=0.001, max=1,
default=0.01, precision=3,
description='External Frame size',
update=update_object,
)
frame_L: FloatProperty(
name='Frame',
min=0.02, max=1,
default=0.06, precision=3,
description='Frame size',
update=update_object,
)
wf: FloatProperty(
name='WinFrame',
min=0.001, max=1,
default=0.05, precision=3,
description='Window Frame size',
update=update_object,
)
leafratio: FloatProperty(
name='Leaf ratio',
min=0.001, max=0.999,
default=0.50,
precision=3,
description='Leaf thickness ratio',
update=update_object,
)
opentype: EnumProperty(
items=(
('1', "Rail window", ""),
('2', "Two leaf", ""),
('3', "Right leaf", ""),
('4', "Left leaf", "")),
name="Type",
description="Defines type of window",
update=update_object,
)
handle: BoolProperty(
name="Create handles",
description="Create default handle to the leaf",
default=True,
update=update_object,
)
sill: BoolProperty(
name="Sill",
description="Add sill to window",
default=True,
update=update_object,
)
sill_thickness: FloatProperty(
name='Thickness',
min=0, max=50,
default=0.01, precision=3,
description='Sill thickness',
update=update_object,
)
sill_back: FloatProperty(
name='Back',
min=0, max=10,
default=0.0, precision=3,
description='Extrusion in back side',
update=update_object,
)
sill_front: FloatProperty(
name='Front',
min=0, max=10,
default=0.12, precision=3,
description='Extrusion in front side',
update=update_object,
)
blind: BoolProperty(
name="Blind",
description="Create an external blind",
default=False,
update=update_object,
)
blind_box: BoolProperty(
name="Blind box", description="Create a box over frame for blind",
default=True,
update=update_object,
)
blind_height: FloatProperty(
name='Height',
min=0.001, max=10,
default=0.12, precision=3,
description='Blind box height',
update=update_object,
)
blind_back: FloatProperty(
name='Back',
min=0.001, max=10,
default=0.002, precision=3,
description='Extrusion in back side',
update=update_object,
)
blind_rail: FloatProperty(
name='Separation',
min=0.001, max=10,
default=0.10, precision=3,
description='Separation from frame',
update=update_object,
)
blind_ratio: IntProperty(
name='Extend',
min=0, max=100,
default=20,
description='% of extension (100 full extend)',
update=update_object,
)
# Materials
crt_mat: BoolProperty(
name="Create default Cycles materials",
description="Create default materials for Cycles render",
default=True,
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),
)
# Register
bpy.utils.register_class(ObjectProperties)
Object.WindowObjectGenerator = CollectionProperty(type=ObjectProperties)
# ------------------------------------------------------------------
# Define panel class to modify object
# ------------------------------------------------------------------
class ARCHIMESH_PT_WindowObjectgenerator(Panel):
bl_idname = "OBJECT_PT_window_generator"
bl_label = "Window Rail"
bl_space_type = 'VIEW_3D'
bl_region_type = 'UI'
bl_category = 'Create'
# -----------------------------------------------------
# Verify if visible
# -----------------------------------------------------
@classmethod
def poll(cls, context):
o = context.object
if o is None:
return False
if 'WindowObjectGenerator' not in o:
return False
else:
return True
# -----------------------------------------------------
# Draw (create UI interface)
# -----------------------------------------------------
def draw(self, context):
o = context.object
# noinspection PyBroadException
try:
if 'WindowObjectGenerator' 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.WindowObjectGenerator[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, 'opentype')
row = box.row()
row.label(text="Window size")
row = box.row()
row.prop(myobjdat, 'width')
row.prop(myobjdat, 'depth')
row.prop(myobjdat, 'height')
row = box.row()
row.prop(myobjdat, 'wf')
row = box.row()
row.prop(myobjdat, 'r')
row = box.row()
row.prop(myobjdat, 'external')
row.prop(myobjdat, 'handle')
if myobjdat.external:
row.prop(myobjdat, 'frame')
if myobjdat.opentype != "1":
row = box.row()
row.prop(myobjdat, 'frame_L')
row.prop(myobjdat, 'leafratio', slider=True)
box = layout.box()
row = box.row()
row.prop(myobjdat, 'sill')
if myobjdat.sill:
row = box.row()
row.prop(myobjdat, 'sill_thickness')
row.prop(myobjdat, 'sill_back')
row.prop(myobjdat, 'sill_front')
box = layout.box()
row = box.row()
row.prop(myobjdat, 'blind')
if myobjdat.blind:
row = box.row()
row.prop(myobjdat, 'blind_rail')
row.prop(myobjdat, 'blind_ratio', slider=True)
row = box.row()
row.prop(myobjdat, 'blind_box')
if myobjdat.blind_box:
row.prop(myobjdat, 'blind_height')
row.prop(myobjdat, 'blind_back')
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')
# ------------------------------------------------------------------------------
# Generate rail windows
# ------------------------------------------------------------------------------
def generate_rail_window(myframe, mp, mymesh):
myloc = bpy.context.scene.cursor.location
alummat = None
if mp.crt_mat and bpy.context.scene.render.engine in {'CYCLES', 'BLENDER_EEVEE'}:
alummat = create_diffuse_material("Window_material", False, 0.8, 0.8, 0.8, 0.6, 0.6, 0.6, 0.15)
# Frame
win_size, p1, p2 = create_rail_window_frame(myframe, mymesh,
mp.width, mp.depth, mp.height,
mp.frame,
mp.crt_mat, alummat, mp.external,
mp.blind and mp.blind_box,
mp.blind_height,
mp.blind_back,
mp.blind_rail)
remove_doubles(myframe)
set_normals(myframe)
# Window L
width = (mp.width / 2) + 0.01
mywin_l = create_rail_window_leaf("Window.L", "L",
width, win_size, mp.height - 0.05,
mp.wf,
myloc.x, myloc.y, myloc.z,
mp.crt_mat, alummat, mp.handle)
remove_doubles(mywin_l)
set_normals(mywin_l)
mywin_l.parent = myframe
mywin_l.location.x = (-mp.width / 2) + 0.01
mywin_l.location.y = p1 - 0.001
mywin_l.location.z = 0.025
# Window R
mywin_r = create_rail_window_leaf("Window.R", "R",
width, win_size, mp.height - 0.05,
mp.wf,
myloc.x, myloc.y, myloc.z,
mp.crt_mat, alummat, mp.handle)
remove_doubles(mywin_r)
set_normals(mywin_r)
mywin_r.parent = myframe
mywin_r.location.x = (mp.width / 2) - 0.01
mywin_r.location.y = p2 - 0.001
mywin_r.location.z = 0.025
# Sill
if mp.sill:
mysill = create_sill("Windows_Sill", mp.width,
mp.depth + mp.sill_back + mp.sill_front,
mp.sill_thickness, mp.crt_mat)
mysill.parent = myframe
mysill.location.x = 0
mysill.location.y = -mp.depth - mp.sill_back
mysill.location.z = 0
# Blind
if mp.blind:
myblindrail = create_blind_rail("Blind_rails", mp.width, mp.height,
myloc.x, myloc.y, myloc.z,
mp.crt_mat, alummat, mp.blind_rail)
set_normals(myblindrail)
myblindrail.parent = myframe
myblindrail.location.x = 0
myblindrail.location.y = 0
myblindrail.location.z = 0
# Lock
myblindrail.lock_location = (True, True, True)
myblindrail.lock_rotation = (True, True, True)
myblind = create_blind("Blind", mp.width - 0.006, mp.height,
myloc.x, myloc.y, myloc.z,
mp.crt_mat, mp.blind_ratio)
set_normals(myblind)
myblind.parent = myframe
myblind.location.x = 0
myblind.location.y = mp.blind_rail - 0.014
myblind.location.z = mp.height - 0.098
# Lock
myblind.lock_location = (True, True, True)
myblind.lock_rotation = (True, True, True)
# ------------------------------------------------------------------------------
# Generate leaf windows
# ------------------------------------------------------------------------------
def generate_leaf_window(myframe, mp, mymesh):
myloc = bpy.context.scene.cursor.location
alummat = None
if mp.crt_mat and bpy.context.scene.render.engine in {'CYCLES', 'BLENDER_EEVEE'}:
alummat = create_diffuse_material("Window_material", False, 0.8, 0.8, 0.8, 0.6, 0.6, 0.6, 0.15)
# Frame
win_size = create_leaf_window_frame(myframe, mymesh,
mp.width, mp.depth, mp.height,
mp.frame, mp.frame_L, mp.leafratio,
mp.crt_mat, alummat, mp.external,
mp.blind and mp.blind_box, mp.blind_height, mp.blind_back,
mp.blind_rail)
remove_doubles(myframe)
set_normals(myframe)
stepsize = 0.01
# -----------------------------
# Window L
# -----------------------------
if mp.opentype == "2" or mp.opentype == "4":
handle = mp.handle
if mp.opentype == "2":
width = ((mp.width - (mp.frame_L * 2) + stepsize) / 2) + 0.004
handle = False # two windows only one handle
else:
width = mp.width - (mp.frame_L * 2) + stepsize + 0.008
mywin_l = create_leaf_window_leaf("Window.L", "L",
width, win_size, mp.height - (mp.frame_L * 2) + (stepsize * 2) - 0.004,
mp.wf,
myloc.x, myloc.y, myloc.z,
mp.crt_mat, alummat, handle)
remove_doubles(mywin_l)
set_normals(mywin_l)
mywin_l.parent = myframe
mywin_l.location.x = -mp.width / 2 + mp.frame_L - stepsize + 0.001
mywin_l.location.y = -mp.depth
mywin_l.location.z = mp.frame_L - (stepsize / 2) - 0.003
# -----------------------------
# Window R
# -----------------------------
if mp.opentype == "2" or mp.opentype == "3":
if mp.opentype == "2":
width = ((mp.width - (mp.frame_L * 2) + stepsize) / 2) + 0.003
else:
width = mp.width - (mp.frame_L * 2) + stepsize + 0.008
mywin_r = create_leaf_window_leaf("Window.R", "R",
width, win_size, mp.height - (mp.frame_L * 2) + (stepsize * 2) - 0.004,
mp.wf,
myloc.x, myloc.y, myloc.z,
mp.crt_mat, alummat, mp.handle)
remove_doubles(mywin_r)
set_normals(mywin_r)
mywin_r.parent = myframe
mywin_r.location.x = mp.width / 2 - mp.frame_L + stepsize - 0.001
mywin_r.location.y = -mp.depth
mywin_r.location.z = mp.frame_L - (stepsize / 2) - 0.003
# Sill
if mp.sill:
mysill = create_sill("Windows_Sill", mp.width,
mp.depth + mp.sill_back + mp.sill_front,
mp.sill_thickness, mp.crt_mat)
mysill.parent = myframe
mysill.location.x = 0
mysill.location.y = -mp.depth - mp.sill_back
mysill.location.z = 0
# Blind
if mp.blind:
myblindrail = create_blind_rail("Blind_rails", mp.width, mp.height,
myloc.x, myloc.y, myloc.z,
mp.crt_mat, alummat, mp.blind_rail)
myblindrail.parent = myframe
myblindrail.location.x = 0
myblindrail.location.y = 0
myblindrail.location.z = 0
# Lock
myblindrail.lock_location = (True, True, True)
myblindrail.lock_rotation = (True, True, True)
myblind = create_blind("Blind", mp.width - 0.006, mp.height,
myloc.x, myloc.y, myloc.z,
mp.crt_mat, mp.blind_ratio)
myblind.parent = myframe
myblind.location.x = 0
myblind.location.y = mp.blind_rail - 0.014
myblind.location.z = mp.height - 0.098
# Lock
myblind.lock_location = (True, True, True)
myblind.lock_rotation = (True, True, True)
# deactivate others
for o in bpy.data.objects:
if o.select_get() is True:
o.select_set(False)
myframe.select_set(True)
bpy.context.view_layer.objects.active = myframe
return myframe
# ------------------------------------------------------------------------------
# Create windows frame
#
# sX: Size in X axis
# sY: Size in Y axis
# sZ: Size in Z axis
# frame: size of external frame
# mat: Flag for creating materials
# matdata: Aluminum material
# external: create external frame flag
# blind: blind flag
# blind_height: height of blind box
# blind_back: front extension
# blind_rail: distance of the rail
# ------------------------------------------------------------------------------
def create_rail_window_frame(mywindow, mymesh, sx, sy, sz, frame, mat, matdata, external,
blind, blind_height, blind_back, blind_rail):
myvertex = []
myfaces = []
v = 0
# ===========================================================================
# Horizontal pieces
# ===========================================================================
m = 0.02 # gap in front
gap = 0.001 # gap between leafs
rail = 0.007 # rail width
thick = 0.002 # aluminum thickness
w = (sy - m - gap - thick - thick - thick) / 2 # width of each leaf
p = (w - rail) / 2 # space of each side
side = 0.02 # vertical
for z in (0, sz):
for x in (-sx / 2, sx / 2):
myvertex.extend([(x, 0, z), (x, 0, z + side),
(x, -m - p, z + side),
(x, -m - p, z + (side * 2)), # rail 1
(x, -m - p - rail, z + (side * 2)),
(x, -m - p - rail, z + side),
(x, -m - p - rail - thick - p - gap - p, z + side),
(x, -m - p - rail - thick - p - gap - p, z + (side * 2)), # rail 2
(x, -m - p - rail - thick - p - gap - p - rail, z + (side * 2)),
(x, -m - p - rail - thick - p - gap - p - rail, z + side),
(x, -m - p - rail - thick - p - gap - p - rail - p - thick, z + side)])
# Faces
myfaces.extend([(v + 12, v + 1, v + 0, v + 11), (v + 13, v + 2, v + 1, v + 12), (v + 14, v + 3, v + 2, v + 13),
(v + 15, v + 4, v + 3, v + 14), (v + 16, v + 5, v + 4, v + 15), (v + 17, v + 6, v + 5, v + 16),
(v + 18, v + 7, v + 6, v + 17), (v + 19, v + 8, v + 7, v + 18), (v + 20, v + 9, v + 8, v + 19),
(v + 20, v + 21, v + 10, v + 9)])
side *= -1 # reveser direction
v = len(myvertex)
# ===========================================================================
# Vertical pieces
# ===========================================================================
y = 0
sideb = 0.03
sides = 0.02
thickb = 0.002 # aluminum thickness
win_size = p + rail + p
p1 = y - m - thick
p2 = y - m - thick - gap - p - rail - p - thick
# Left
for x in (-sx / 2, sx / 2):
for z in (0, sz):
myvertex.extend([(x, y, z),
(x + thickb, y, z),
(x + thickb, y - m, z),
(x + thickb + sides, y - m, z),
(x + thickb + sides, y - m - thick, z),
(x + thickb, y - m - thick, z),
(x + thickb, y - m - thick - gap - p - rail - p, z),
(x + thickb + sides, y - m - thick - gap - p - rail - p, z),
(x + thickb + sides, y - m - thick - gap - p - rail - p - thick, z),
(x + thickb, y - m - thick - gap - p - rail - p - thick, z),
(x + thickb, y - m - thick - gap - p - rail - p - thick - p - rail - p, z),
(x + thickb + sideb, y - m - thick - gap - p - rail - p - thick - p - rail - p, z),
(x + thickb + sideb, y - m - thick - gap - p - rail - p - thick - p - rail - p - thick, z),
(x, y - m - thick - gap - p - rail - p - thick - p - rail - p - thick, z)])
# Faces
myfaces.extend([(v + 13, v + 27, v + 14, v + 0), (v + 13, v + 12, v + 26, v + 27),
(v + 11, v + 10, v + 24, v + 25),
(v + 6, v + 5, v + 19, v + 20), (v + 10, v + 9, v + 23, v + 24),
(v + 25, v + 24, v + 27, v + 26), (v + 24, v + 23, v + 15, v + 16),
(v + 22, v + 21, v + 20, v + 23),
(v + 17, v + 16, v + 19, v + 18), (v + 9, v + 8, v + 22, v + 23),
(v + 7, v + 6, v + 20, v + 21), (v + 3, v + 2, v + 16, v + 17),
(v + 5, v + 4, v + 18, v + 19),
(v + 4, v + 3, v + 17, v + 18), (v + 7, v + 8, v + 9, v + 6),
(v + 3, v + 4, v + 5, v + 2), (v + 11, v + 12, v + 13, v + 10),
(v + 6, v + 5, v + 9, v + 10),
(v + 1, v + 0, v + 14, v + 15),
(v + 19, v + 16, v + 15, v + 14, v + 27, v + 24, v + 23, v + 20),
(v + 8, v + 7, v + 21, v + 22), (v + 12, v + 11, v + 25, v + 26),
(v + 2, v + 1, v + 15, v + 16),
(v + 5, v + 6, v + 9, v + 10, v + 13, v + 0, v + 1, v + 2)])
v = len(myvertex)
# reverse
thickb *= -1
sideb *= -1
sides *= -1
# ===========================================================================
# Front covers
# ===========================================================================
x = sx - 0.005 - (sideb * 2) # sideB + small gap
y = y - m - thick - gap - p - rail - p - thick - p - rail - p
z = sideb
# Bottom
myvertex.extend([(-x / 2, y - thick, 0.0),
(-x / 2, y, 0.0),
(x / 2, y, 0.0),
(x / 2, y - thick, 0.0),
(-x / 2, y - thick, z),
(-x / 2, y, z),
(x / 2, y, z),
(x / 2, y - thick, z)])
myfaces.extend([(v + 0, v + 1, v + 2, v + 3), (v + 0, v + 1, v + 5, v + 4), (v + 1, v + 2, v + 6, v + 5),
(v + 2, v + 6, v + 7, v + 3), (v + 5, v + 6, v + 7, v + 4), (v + 0, v + 4, v + 7, v + 3)])
v = len(myvertex)
# Top
myvertex.extend([(-x / 2, y - thick, sz - sideb),
(-x / 2, y, sz - sideb),
(x / 2, y, sz - sideb),
(x / 2, y - thick, sz - sideb),
(-x / 2, y - thick, sz - sideb + z),
(-x / 2, y, sz - sideb + z),
(x / 2, y, sz - sideb + z),
(x / 2, y - thick, sz - sideb + z)])
myfaces.extend([(v + 0, v + 1, v + 2, v + 3), (v + 0, v + 1, v + 5, v + 4), (v + 1, v + 2, v + 6, v + 5),
(v + 2, v + 6, v + 7, v + 3), (v + 5, v + 6, v + 7, v + 4), (v + 0, v + 4, v + 7, v + 3)])
v = len(myvertex)
# ===========================================================================
# External front covers
# ===========================================================================
if external:
x = sx
gap = -0.001
sidem = frame
box = 0
if blind:
box = blind_height
myvertex.extend([((-x / 2) - sidem, y - thick, sz + sidem + box),
((x / 2) + sidem, y - thick, sz + sidem + box),
((-x / 2) - sidem, y - thick, -sidem),
((x / 2) + sidem, y - thick, -sidem),
((-x / 2) - gap, y - thick, sz + gap + box),
((x / 2) + gap, y - thick, sz + gap + box),
((-x / 2) - gap, y - thick, -gap),
((x / 2) + gap, y - thick, -gap)])
myvertex.extend([((-x / 2) - sidem, y - thick * 2, sz + sidem + box),
((x / 2) + sidem, y - thick * 2, sz + sidem + box),
((-x / 2) - sidem, y - thick * 2, -sidem),
((x / 2) + sidem, y - thick * 2, -sidem),
((-x / 2) - gap, y - thick * 2, sz + gap + box),
((x / 2) + gap, y - thick * 2, sz + gap + box),
((-x / 2) - gap, y - thick * 2, -gap),
((x / 2) + gap, y - thick * 2, -gap)])
myfaces.extend([(v + 3, v + 1, v + 9, v + 11), (v + 9, v + 8, v + 0, v + 1),
(v + 1, v + 5, v + 4, v + 0),
(v + 3, v + 7, v + 5, v + 1),
(v + 7, v + 3, v + 2, v + 6),
(v + 0, v + 4, v + 6, v + 2),
(v + 9, v + 13, v + 12, v + 8), (v + 11, v + 15, v + 13, v + 9),
(v + 15, v + 11, v + 10, v + 14),
(v + 8, v + 12, v + 14, v + 10),
(v + 11, v + 3, v + 2, v + 10),
(v + 2, v + 10, v + 8, v + 0), (v + 14, v + 12, v + 4, v + 6),
(v + 7, v + 6, v + 14, v + 15),
(v + 5, v + 13, v + 12, v + 4),
(v + 15, v + 7, v + 5, v + 13)])
mymesh.from_pydata(myvertex, [], myfaces)
mymesh.update(calc_edges=True)
if mat and bpy.context.scene.render.engine in {'CYCLES', 'BLENDER_EEVEE'}:
set_material(mywindow, matdata)
# --------------
# Blind Box
# --------------
if blind:
mybox = create_blind_box("Blind_box", sx, sy + blind_back + blind_rail, blind_height)
set_normals(mybox)
mybox.parent = mywindow
mybox.location.x = 0
mybox.location.y = -blind_back - sy
mybox.location.z = sz
if mat and bpy.context.scene.render.engine in {'CYCLES', 'BLENDER_EEVEE'}:
set_material(mybox, matdata)
# Lock
mybox.lock_location = (True, True, True)
mybox.lock_rotation = (True, True, True)
return win_size, p1, p2
# ------------------------------------------------------------------------------
# Create leafs windows frame
#
# sX: Size in X axis
# sY: Size in Y axis
# sZ: Size in Z axis
# frame: size of external frame
# frame_L: size of main frame
# leafratio: ratio of leaf depth
# mat: Flag for creating materials
# matdata: Aluminum material
# external: create external frame flag
# blind: blind flag
# blind_height: height of blind box
# blind_back: front extension
# blind_rail: distance of the rail
# ------------------------------------------------------------------------------
def create_leaf_window_frame(mywindow, mymesh, sx, sy, sz, frame, frame_l, leafratio, mat, matdata, external,
blind, blind_height, blind_back, blind_rail):
myvertex = []
myfaces = []
# ===========================================================================
# Main frame_L
# ===========================================================================
x = sx / 2
z = sz
y = sy * leafratio
gap = 0.01
size = sy - y - 0.001 # thickness of the leaf
myvertex.extend([(-x, 0, 0),
(-x, 0, z),
(x, 0, z),
(x, 0, 0),
(-x + frame_l, 0, frame_l),
(-x + frame_l, 0, z - frame_l),
(x - frame_l, 0, z - frame_l),
(x - frame_l, 0, frame_l),
(-x + frame_l, -y, frame_l),
(-x + frame_l, -y, z - frame_l),
(x - frame_l, -y, z - frame_l),
(x - frame_l, -y, frame_l),
(-x + frame_l - gap, -y, frame_l - gap),
(-x + frame_l - gap, -y, z - frame_l + gap),
(x - frame_l + gap, -y, z - frame_l + gap),
(x - frame_l + gap, -y, frame_l - gap),
(-x + frame_l - gap, -sy, frame_l - gap),
(-x + frame_l - gap, -sy, z - frame_l + gap),
(x - frame_l + gap, -sy, z - frame_l + gap),
(x - frame_l + gap, -sy, frame_l - gap),
(-x, -sy, 0),
(-x, -sy, z),
(x, -sy, z),
(x, -sy, 0)])
# Faces
myfaces.extend([(1, 5, 4, 0), (21, 1, 0, 20), (17, 21, 20, 16), (16, 12, 13, 17), (12, 8, 9, 13),
(5, 9, 8, 4), (3, 7, 6, 2), (23, 3, 2, 22), (19, 23, 22, 18), (15, 19, 18, 14),
(11, 15, 14, 10), (6, 7, 11, 10), (0, 3, 23, 20), (21, 22, 2, 1), (17, 13, 14, 18),
(21, 17, 18, 22), (13, 9, 10, 14), (8, 11, 7, 4), (8, 12, 15, 11), (4, 7, 3, 0),
(12, 16, 19, 15), (16, 20, 23, 19), (9, 5, 6, 10), (1, 2, 6, 5)])
v = len(myvertex)
# ===========================================================================
# External front covers
# ===========================================================================
if external:
thick = 0.002 # aluminum thickness
x = sx
gap = -0.001
sidem = frame
box = 0
if blind:
box = blind_height
myvertex.extend([((-x / 2) - sidem, -sy, sz + sidem + box),
((x / 2) + sidem, -sy, sz + sidem + box),
((-x / 2) - sidem, -sy, -sidem),
((x / 2) + sidem, -sy, -sidem),
((-x / 2) - gap, -sy, sz + gap + box),
((x / 2) + gap, -sy, sz + gap + box),
((-x / 2) - gap, -sy, -gap),
((x / 2) + gap, -sy, -gap)])
myvertex.extend([((-x / 2) - sidem, -sy - thick, sz + sidem + box),
((x / 2) + sidem, -sy - thick, sz + sidem + box),
((-x / 2) - sidem, -sy - thick, -sidem),
((x / 2) + sidem, -sy - thick, -sidem),
((-x / 2) - gap, -sy - thick, sz + gap + box),
((x / 2) + gap, -sy - thick, sz + gap + box),
((-x / 2) - gap, -sy - thick, -gap),