This repository has been archived by the owner on Apr 19, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaframe.py
1724 lines (1606 loc) · 72.8 KB
/
aframe.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
from math import radians, sin, cos, asin, degrees, pi, sqrt, pow, fabs, atan2
def parse_dxf(dxf_f, material_gallery):
output = {}
layer_color = {}
flag = False
x = 0
value = 'dummy'
while value !='ENTITIES':
key = dxf_f.readline().strip()
value = dxf_f.readline().strip()
if value == 'AcDbLayerTableRecord':#dict of layer names and colors
key = dxf_f.readline().strip()
layer_name = dxf_f.readline().strip()
key = dxf_f.readline().strip()
value = dxf_f.readline().strip()
key = dxf_f.readline().strip()
layer_color[layer_name] = cad2hex(dxf_f.readline().strip())
elif value=='EOF' or key=='':#security to avoid loops if file is corrupted
return output
while value !='ENDSEC':
key = dxf_f.readline().strip()
value = dxf_f.readline().strip()
if value=='EOF' or key=='':#security to avoid loops if file is corrupted
return output
if flag == 'face':#stores values for 3D faces
if key == '8':#layer name
data[key] = value
elif key == '10' or key == '11' or key == '12' or key == '13':#X position
data[key] = float(value)
elif key == '20' or key == '21' or key == '22' or key == '23':#mirror Y position
data[key] = -float(value)
elif key == '30' or key == '31' or key == '32' or key == '33':#Z position
data[key] = float(value)
elif flag == 'block':#stores values for blocks
if key == '2':#block name
data[key] = value
if key == '8':#layer name
data[key] = value
data['layer'] = value#sometimes key 8 is replaced, so I need the original layer value
elif key == '10' or key == '30':#X Z position
data[key] = float(value)
elif key == '20':#Y position, mirrored
data[key] = -float(value)
elif key == '50':#Z rotation
data[key] = float(value)
elif key == '41' or key == '42' or key == '43':#scale values
data[key] = float(value)
elif key == '210':#X of OCS unitary vector
Az_1 = float(value)
P_x = data['10']
elif key == '220':#Y of OCS unitary vector
Az_2 = float(value)
P_y = -data['20']#reset original value
elif key == '230':#Z of OCS unitary vector
Az_3 = float(value)
P_z = data['30']
#arbitrary axis algorithm
#see if OCS z vector is close to world Z axis
if fabs(Az_1) < (1/64) and fabs(Az_2) < (1/64):
W = ('Y', 0, 1, 0)
else:
W = ('Z', 0, 0, 1)
#cross product for OCS x arbitrary vector, normalized
Ax_1 = W[2]*Az_3-W[3]*Az_2
Ax_2 = W[3]*Az_1-W[1]*Az_3
Ax_3 = W[1]*Az_2-W[2]*Az_1
Norm = sqrt(pow(Ax_1, 2)+pow(Ax_2, 2)+pow(Ax_3, 2))
Ax_1 = Ax_1/Norm
Ax_2 = Ax_2/Norm
Ax_3 = Ax_3/Norm
#cross product for OCS y arbitrary vector, normalized
Ay_1 = Az_2*Ax_3-Az_3*Ax_2
Ay_2 = Az_3*Ax_1-Az_1*Ax_3
Ay_3 = Az_1*Ax_2-Az_2*Ax_1
Norm = sqrt(pow(Ay_1, 2)+pow(Ay_2, 2)+pow(Ay_3, 2))
Ay_1 = Ay_1/Norm
Ay_2 = Ay_2/Norm
Ay_3 = Ay_3/Norm
#insertion world coordinates from OCS
data['10'] = P_x*Ax_1+P_y*Ay_1+P_z*Az_1
data['20'] = P_x*Ax_2+P_y*Ay_2+P_z*Az_2
data['30'] = P_x*Ax_3+P_y*Ay_3+P_z*Az_3
#OCS X vector translated into WCS
Ax_1 = ((P_x+cos(radians(data['50'])))*Ax_1+(P_y+sin(radians(data['50'])))*Ay_1+P_z*Az_1)-data['10']
Ax_2 = ((P_x+cos(radians(data['50'])))*Ax_2+(P_y+sin(radians(data['50'])))*Ay_2+P_z*Az_2)-data['20']
Ax_3 = ((P_x+cos(radians(data['50'])))*Ax_3+(P_y+sin(radians(data['50'])))*Ay_3+P_z*Az_3)-data['30']
#cross product for OCS y vector, normalized
Ay_1 = Az_2*Ax_3-Az_3*Ax_2
Ay_2 = Az_3*Ax_1-Az_1*Ax_3
Ay_3 = Az_1*Ax_2-Az_2*Ax_1
Norm = sqrt(pow(Ay_1, 2)+pow(Ay_2, 2)+pow(Ay_3, 2))
Ay_1 = Ay_1/Norm
Ay_2 = Ay_2/Norm
Ay_3 = Ay_3/Norm
#A-Frame rotation order is Yaw(Z), Pitch(X) and Roll(Y)
#thanks for help Marilena Vendittelli and https://www.geometrictools.com/
if Ay_3<1:
if Ay_3>-1:
pitch = asin(Ay_3)
yaw = atan2(-Ay_1, Ay_2)
roll = atan2(-Ax_3, Az_3)
else:
pitch = -pi/2
yaw = -atan2(Az_1, Ax_1)
roll = 0
else:
pitch = pi/2
yaw = atan2(Az_1, Ax_1)
roll = 0
#Y position, mirrored
data['20'] = -data['20']
#rotations from radians to degrees
data['210'] = degrees(pitch)
data['50'] = degrees(yaw)
data['220'] = -degrees(roll)
elif flag == 'attrib':#stores values for attributes within block
if key == '1':#attribute value
attr_value = value
elif key == '2':#attribute key
data[value] = attr_value
flag = 'block'#restore block modality
if key == '0':
invisible = False#by default layer is visible
if flag == 'face':#close 3D face
data['2'] = '3dface'
#is material set in model?
try:
material = material_gallery.get(layer = data['8'])
data['color'] = material.color
invisible = material.invisible#layer visibility
except:
data['color'] = layer_color[data['8']]
data['8'] = 'default'
if invisible:
flag = False
else:
data['num'] = x
output[x] = data
if data['12']!=data['13'] or data['22']!=data['23'] or data['32']!=data['33']:
data2 = data.copy()
data2['11'] = data['12']
data2['21'] = data['22']
data2['31'] = data['32']
data2['12'] = data['13']
data2['22'] = data['23']
data2['32'] = data['33']
x += 1
data2['num'] = x
output[x] = data2
flag = False
elif value == 'ATTRIB':#start attribute within block
attr_value = ''
flag = 'attrib'
elif flag == 'block':#close block
#material images are patterns? is material set in model?
try:
material = material_gallery.get(layer = data['8'])
data['color'] = material.color
invisible = material.invisible#layer visibility
if material.pattern:# == True
data['repeat']=True
except:
data['color'] = layer_color[data['8']]
data['8'] = 'default'
if invisible:
flag = False
else:
data['num'] = x
output[x] = data
flag = False
if value == '3DFACE':#start 3D face
data = {}#default values
flag = 'face'
x += 1
elif value == 'INSERT':#start block
data = {'41': 1, '42': 1, '43': 1, '50': 0, '210': 0, '220': 0, '230': 1,'repeat': False, 'type': '','animation': False}#default values
flag = 'block'
x += 1
return output
def make_html(page_obj, collection, partitions, finishings, csv_f):
output = {}
for x, data in collection.items():
if data['2'] == '3dface':
output[x] = make_triangle(page_obj, x, data)
if data['2'] == '6planes':#left for legacy
output[x] = make_box(page_obj, x, data)
elif data['2'] == 'box' or data['2'] == 'a-box':
output[x] = make_box(page_obj, x, data)
elif data['2'] == 'cylinder' or data['2'] == 'a-cylinder':
output[x] = make_cylinder(page_obj, x, data)
elif data['2'] == 'a-curvedimage':
output[x] = make_curvedimage(x, data)
elif data['2'] == 'cone' or data['2'] == 'a-cone':
output[x] = make_cone(page_obj, x, data)
elif data['2'] == 'sphere' or data['2'] == 'a-sphere':
output[x] = make_sphere(page_obj, x, data)
elif data['2'] == 'circle' or data['2'] == 'a-circle':
output[x] = make_circle(page_obj, x, data)
elif data['2'] == 'plane' or data['2'] == 'a-plane' or data['2'] == 'look-at':
output[x] = make_plane(page_obj, x, data)
elif data['2'] == 'floor':#left for legacy
data['210'] = data['210'] - 90
output[x] = make_plane(page_obj, x, data)
elif data['2'] == 'ceiling':#left for legacy
data['210'] = data['210'] + 90
output[x] = make_plane(page_obj, x, data)
elif data['2'] == 'light' or data['2'] == 'a-light':
output[x] = make_light(page_obj, x, data)
elif data['2'] == 'a-text':
output[x] = make_text(x, data)
elif data['2'] == 'a-link':
output[x] = make_link(page_obj, x, data)
elif data['2'] == 'a-door':
door = AOpening(page_obj, data, partitions, finishings, csv_f)
if door.type_obj:
door.has_type()#changes colors and writes to csv
else:
door.no_type()#writes to csv
if door.finish_obj:
door.has_finishing()#changes colors again
if door.d['alert'] == 'None':
output[x] = door.write_html()
else:#by now useless, if is always true
pass #output[x] = door.write_html_alert()
elif data['2'] == 'a-furniture':
furn = AFurniture(page_obj, data, finishings)
if furn.finish_obj:
furn.has_finishing()#changes colors
output[x] = furn.write_html()
elif data['2'] == 'a-wall' or data['2'] == 'a-slab' or data['2'] == 'a-openwall':
part = APartition(page_obj, data, partitions, finishings, csv_f)
if part.type_obj:
part.calc_weight()
else:
part.no_weight()
#here we could add the has_finishing, as in AOpening
if part.d['alert'] == 'None':
output[x] = part.write_html()
else:
output[x] = part.write_html_alert()
return output
def reference_openings(collection):
collection2 = collection.copy()
for x, data in collection.items():
if data['2'] == 'a-door':
collection[x] = data
for x2, data2 in collection2.items():
if data2['2'] == 'a-wall':
if data['210']==0 and data['220']==0 and data2['210']==0 and data2['220']==0:
data2 = door_straight_case(x, data, data2)
else:
data2 = door_tilted_case(x, data, data2)
collection[x2] = data2
return collection
def reference_animations(collection):#TODO
collection2 = collection.copy()
for x, data in collection.items():
if data['2'] == 'a-animation':
collection[x] = data
for x2, data2 in collection2.items():
if data2['2'] != '3dface' or data2['2'] != 'a-wall' or data2['2'] != 'a-openwall' or data2['2'] != 'a-door':
if data['10']==data2['10'] and data['20']==data2['20'] and data['30']==data2['30']:
data2['animation'] = True
data2['ATTRIBUTE'] = data['ATTRIBUTE']
data2['FROM'] = data['FROM']
data2['TO'] = data['TO']
data2['BEGIN'] = data['BEGIN']
data2['DIRECTION'] = data['DIRECTION']
data2['REPEAT'] = data['REPEAT']
data2['DURATION'] = data['DURATION']
collection[x2] = data2
return collection
def door_straight_case(x, data, data2):
if data['30']==data2['30'] and data['43']>0 and data2['43']>0:
rotd = round(data['50'], 0)
rotw = round(data2['50'], 0)
if rotd==rotw-180 or rotd-180==rotw:
backwards = -1
else:
backwards = 1
if rotd == rotw or backwards == -1:
#translation
xt = data['10']-data2['10']
zt = data['20']-data2['20']
#rotation
alfa = radians(data2['50'])
xd = round(xt*cos(alfa)-zt*sin(alfa), 4)
zd = round(xt*sin(alfa)+zt*cos(alfa), 4)
xde = xd + round(data['41'], 4)*backwards
zde = zd + round(data['42'], 4)
#wall bounding box
if data2['41'] > 0:
xmaxw = round(data2['41'], 4)
xminw = 0
else:
xmaxw = 0
xminw = round(data2['41'], 4)
if data2['42'] > 0:
zmaxw = 0
zminw = -round(data2['42'], 4)
else:
zmaxw = -round(data2['42'], 4)
zminw = 0
#door bounding box
if xde > xd:
xmaxd = xde
xmind = xd
else:
xmaxd = xd
xmind = xde
if zde > zd:
zmaxd = zde * ( - backwards)
zmind = zd * ( - backwards)
else:
zmaxd = zd * ( - backwards)
zmind = zde * ( - backwards)
#door inclusion
if xmaxw >= xmaxd and xminw <= xmind and zmaxw >= zmaxd and zminw <= zmind:
data2['door'] = x
data2['2'] = 'a-openwall'
if data['43']>data2['43']:
data2['door_height'] = data2['43']
else:
data2['door_height'] = data['43']
if data2['41']>0:
data2['door_off_1'] = xmind
data2['door_off_2'] = xmaxd
else:
data2['door_off_1'] = xmaxd - xmaxw
data2['door_off_2'] = xmind - xmaxw
return data2
#TODO
def door_tilted_case(x, data, data2):
#d210 = round(data['210']*fabs(data['41'])/data['41'], 4)
#d220 = round(data['220']*fabs(data['42'])/data['42'], 4)
#d50 = round(data['50']*fabs(data['43'])/data['43'], 4)
#w210 = round(data2['210']*fabs(data2['41'])/data2['41'], 4)
#w220 = round(data2['220']*fabs(data2['42'])/data2['42'], 4)
#w50 = round(data2['50']*fabs(data2['43'])/data2['43'], 4)
return data2
#returns repeat image values
def is_repeat(repeat, rx, ry):
if repeat:
output = f'; repeat:{fabs(rx)} {fabs(ry)}'
return output
else:
return ';'
#returns positive/negative scaling
def unit(nounit):
unit = fabs(nounit)/nounit
return unit
def make_box(page_obj, x, data):
outstr = f'<a-entity id="box-{x}-ent" \n'
if page_obj.shadows:
outstr += 'shadow="receive: true; cast: true" \n'
outstr += f'position="{data["10"]} {data["30"]} {data["20"]}" \n'
outstr += f'rotation="{data["210"]} {data["50"]} {data["220"]}">\n'
outstr += f'<a-box id="box-{x}" \n'
outstr += f'position="{data["41"]/2} {data["43"]/2} {-data["42"]/2}" \n'
outstr += f'scale="{fabs(data["41"])} {fabs(data["43"])} {fabs(data["42"])}" \n'
outstr += 'geometry="'
try:
if data['segments-depth']!='1':
outstr += f'segments-depth: {data["segments-depth"]};'
if data['segments-height']!='1':
outstr += f'segments-height: {data["segments-height"]};'
if data['segments-width']!='1':
outstr += f'segments-width: {data["segments-width"]};'
outstr += '" \n'
except KeyError:
outstr += '" \n'
outstr += f'material="src: #image-{data["8"]}; color: {data["color"]}'
outstr += is_repeat(data["repeat"], data["41"], data["43"])
outstr += '">\n'
if data['animation']:
outstr += is_animation(data)
outstr += '</a-box>\n</a-entity>\n'
return outstr
def is_animation(data):
outstr = f'<a-animation attribute="{data["ATTRIBUTE"]}"\n'
outstr += f'from="{data["FROM"]}"\n'
outstr += f'to="{data["TO"]}"\n'
outstr += f'begin="{data["BEGIN"]}"\n'
outstr += f'direction="{data["DIRECTION"]}"\n'
outstr += f'repeat="{data["REPEAT"]}"\n'
outstr += f'duration="{data["DURATION"]}"\n'
outstr += '></a-animation>\n'
return outstr
def make_cone(page_obj, x, data):
outstr = f'<a-entity id="cone-{x}-ent" \n'
if page_obj.shadows:
outstr += 'shadow="receive: true; cast: true" \n'
outstr += f'position="{data["10"]} {data["30"]} {data["20"]}" \n'
outstr += f'rotation="{data["210"]} {data["50"]} {data["220"]}">\n'
outstr += f'<a-cone id="cone-{x}" \n'
outstr += f'position="0 {data["43"]/2} 0" \n'
if float(data['43']) < 0:
outstr += 'rotation="180 0 0">\n'
outstr += f'scale="{fabs(data["41"])} {fabs(data["43"])} {fabs(data["42"])}" \n'
outstr += 'geometry="'
try:
if data['open-ended']!='false':
outstr += 'open-ended: true;'
if data['radius-top']!='0':
outstr += f'radius-top: {data["radius-top"]};'
if data['segments-height']!='18':
outstr += f'segments-height: {data["segments-height"]};'
if data['segments-radial']!='36':
outstr += f'segments-radial: {data["segments-radial"]};'
if data['theta-length']!='360':
outstr += f'theta-length: {data["theta-length"]};'
if data['theta-start']!='0':
outstr += f'theta-start: {data["theta-start"]};'
outstr += '" \n'
except KeyError:
outstr += '" \n'
outstr += f'material="src: #image-{data["8"]}; color: {data["color"]}'
outstr += is_repeat(data["repeat"], data["41"], data["43"])
outstr += '">\n'
if data['animation']:
outstr += is_animation(data)
outstr += '</a-cone>\n</a-entity>\n'
return outstr
def make_circle(page_obj, x, data):
outstr = f'<a-entity id="circle-{x}-ent" \n'
if page_obj.shadows:
outstr += 'shadow="receive: true; cast: true" \n'
outstr += f'position="{data["10"]} {data["30"]} {data["20"]}" \n'
outstr += f'rotation="{data["210"]} {data["50"]} {data["220"]}">\n'
outstr += f'<a-circle id="circle-{x}" \n'
if data['2'] == 'circle':
outstr += f'rotation="-90 0 0"\n'
outstr += f'radius="{fabs(data["41"])}" \n'
outstr += 'geometry="'
try:
if data['segments']!='32':
outstr += f'segments: {data["segments"]};'
if data['theta-length']!='360':
outstr += f'theta-length: {data["theta-length"]};'
if data['theta-start']!='0':
outstr += f'theta-start: {data["theta-start"]};'
outstr += '" \n'
except KeyError:
outstr += '" \n'
outstr += f'material="src: #image-{data["8"]}; color: {data["color"]}'
outstr += is_repeat(data["repeat"], data["41"], data["43"])
outstr += '">\n'
if data['animation']:
outstr += is_animation(data)
outstr += '</a-circle>\n</a-entity>\n'
return outstr
def make_cylinder(page_obj, x, data):
outstr = f'<a-entity id="cylinder-{x}-ent" \n'
if page_obj.shadows:
outstr += 'shadow="receive: true; cast: true" \n'
outstr += f'position="{data["10"]} {data["30"]} {data["20"]}" \n'
outstr += f'rotation="{data["210"]} {data["50"]} {data["220"]}">\n'
outstr += f'<a-cylinder id="cylinder-{x}" \n'
outstr += f'position="0 {data["43"]/2} 0" \n'
if float(data['43']) < 0:
outstr += 'rotation="180 0 0">\n'
outstr += f'scale="{fabs(data["41"])} {fabs(data["43"])} {fabs(data["42"])}" \n'
outstr += 'geometry="'
try:
if data['open-ended']!='false':
outstr += 'open-ended: true;'
if data['radius-top']!='0':
outstr += f'radius-top: {data["radius-top"]};'
if data['segments-height']!='18':
outstr += f'segments-height: {data["segments-height"]};'
if data['segments-radial']!='36':
outstr += f'segments-radial: {data["segments-radial"]};'
if data['theta-length']!='360':
outstr += f'theta-length: {data["theta-length"]};'
if data['theta-start']!='0':
outstr += f'theta-start: {data["theta-start"]};'
outstr += '" \n'
except KeyError:
outstr += '" \n'
outstr += f'material="src: #image-{data["8"]}; color: {data["color"]}'
outstr += is_repeat(data["repeat"], data["41"], data["43"])
outstr += '">\n'
if data['animation']:
outstr += is_animation(data)
outstr += '</a-cylinder>\n</a-entity>\n'
return outstr
def make_curvedimage(x, data):
outstr = f'<a-entity id="curvedimage-{x}-ent" \n'
outstr += 'shadow="receive: false; cast: false" \n'
outstr += f'position="{data["10"]} {data["30"]} {data["20"]}" \n'
outstr += f'rotation="{data["210"]} {data["50"]} {data["220"]}">\n'
outstr += f'<a-curvedimage id="curvedimage-{x}" \n'
outstr += f'position="0 {data["43"]/2} 0" \n'
if float(data['43']) < 0:
outstr += 'rotation="180 0 0">\n'
outstr += f'scale="{fabs(data["41"])} {fabs(data["43"])} {fabs(data["42"])}" \n'
try:
if data['theta-length']!='270':
outstr += f'theta-length="{data["theta-length"]}" '
if data['theta-start']!='0':
outstr += f'theta-start="{data["theta-start"]}" '
except KeyError:
pass
outstr += f'src="#image-{data["8"]}">\n'
if data['animation']:
outstr += is_animation(data)
outstr += '</a-curvedimage>\n</a-entity>\n'
return outstr
def make_sphere(page_obj, x, data):
outstr = f'<a-entity id="sphere-{x}-ent" \n'
if page_obj.shadows:
outstr += 'shadow="receive: true; cast: true" \n'
outstr += f'position="{data["10"]} {data["30"]} {data["20"]}" \n'
outstr += f'rotation="{data["210"]} {data["50"]} {data["220"]}">\n'
outstr += f'<a-sphere id="sphere-{x}" \n'
outstr += f'position="0 {data["43"]} 0" \n'
if float(data['43']) < 0:
outstr += 'rotation="180 0 0">\n'
outstr += f'scale="{fabs(data["41"])} {fabs(data["43"])} {fabs(data["42"])}" \n'
outstr += 'geometry="'
try:
if data['phi-length']!='360':
outstr += f'phi-length: {data["phi-length"]};'
if data['phi-start']!='0':
outstr += f'phi-start: {data["phi-start"]};'
if data['segments-height']!='18':
outstr += f'segments-height: {data["segments-height"]};'
if data['segments-width']!='36':
outstr += f'segments-width: {data["segments-width"]};'
if data['theta-length']!='180':
outstr += f'theta-length: {data["theta-length"]};'
if data['theta-start']!='0':
outstr += f'theta-start: {data["theta-start"]};'
outstr += '" \n'
except KeyError:
outstr += '" \n'
outstr += f'material="src: #image-{data["8"]}; color: {data["color"]}'
outstr += is_repeat(data["repeat"], data["41"], data["43"])
outstr += '">\n'
if data['animation']:
outstr += is_animation(data)
outstr += '</a-sphere>\n</a-entity>\n'
return outstr
def make_plane(page_obj, x, data):
outstr = f'<a-entity id="plane-{x}-ent" \n'
if page_obj.shadows:
outstr += 'shadow="receive: true; cast: true" \n'
outstr += f'position="{data["10"]} {data["30"]} {data["20"]}" \n'
outstr += f'rotation="{data["210"]} {data["50"]} {data["220"]}">\n'
outstr += f'<a-plane id="plane-{x}" \n'
if data['2'] == 'look-at':#if it's a look at, it is centered and looks at the camera foot
outstr += f'position="0 {data["43"]/2} 0" \n'
outstr += 'look-at="#camera-foot" \n'
elif data['2'] == 'ceiling':#if it's a ceiling, correct position
outstr += f'position="{data["41"]/2} {-data["43"]/2} 0" \n'
else:#insertion is at corner
outstr += f'position="{data["41"]/2} {data["43"]/2} 0" \n'
outstr += f'width="{fabs(data["41"])}" height="{fabs(data["43"])}" \n'
outstr += 'geometry="'
try:
if data['segments-height']!='1':
outstr += f'segments-height: {data["segments-height"]};'
if data['segments-width']!='1':
outstr += f'segments-width: {data["segments-width"]};'
outstr += '" \n'
except KeyError:
outstr += '" \n'
outstr += f'material="src: #image-{data["8"]}; color: {data["color"]}'
outstr += is_repeat(data["repeat"], data["41"], data["43"])
outstr += '">\n'
if data['animation']:
outstr += is_animation(data)
outstr += '</a-plane>\n</a-entity>\n'
return outstr
def make_text(x, data):
outstr = f'<a-entity id="text-{x}" \n'
outstr += f'position="{data["10"]} {data["30"]} {data["20"]}" \n'
outstr += f'rotation="{data["210"]} {data["50"]} {data["220"]}"\n'
outstr += f'text="width: {data["41"]}; align: {data["align"]}; color: {data["color"]}; '
outstr += f'value: {data["text"]}; wrap-count: {data["wrap-count"]}; '
outstr += '">\n'
if data['animation']:
outstr += is_animation(data)
outstr += '</a-entity>\n'
return outstr
def make_link(page_obj, x, data):
outstr = f'<a-link id="link-{x}" \n'
outstr += f'position="{data["10"]} {data["30"]} {data["20"]}" \n'
outstr += f'rotation="{data["210"]} {data["50"]} {data["220"]}"\n'
outstr += f'scale="{data["41"]} {data["43"]} {data["42"]}"\n'
if data['tree'] == 'parent':
target = page_obj.get_parent()
elif data['tree'] == 'child':
target = page_obj.get_first_child()
elif data['tree'] == 'previous' or data['tree'] == 'prev':
target = page_obj.get_prev_sibling()
else:#we default to next sibling
target = page_obj.get_next_sibling()
try:
if target:
outstr += f'href="{target.url}"\n'
outstr += f'title="{data["title"]}" color="{data["color"]}" on="click"\n'
eq_image = target.specific.equirectangular_image
if eq_image:
outstr += f'image="{eq_image.file.url}"'
else:
outstr += 'image="#default-sky"'
outstr += '>\n'
if data['animation']:
outstr += is_animation(data)
outstr += '</a-link>\n'
return outstr
else:
return ''
except:
return ''
def make_triangle(page_obj, x, data):
outstr = f'<a-triangle id="triangle-{x}" \n'
if page_obj.shadows:
outstr += 'shadow="receive: true; cast: true" \n'
outstr += f'geometry="vertexA:{data["10"]} {data["30"]} {data["20"]}; \n'
outstr += f'vertexB:{data["11"]} {data["31"]} {data["21"]}; \n'
outstr += f'vertexC:{data["12"]} {data["32"]} {data["22"]}" \n'
outstr += f'material="src: #image-{data["8"]}; color: {data["color"]}; '
if page_obj.double_face:
outstr += 'side: double; '
outstr += '">\n</a-triangle> \n'
return outstr
def make_light(page_obj, x, data):
outstr = f'<a-entity id="light-{x}" \n'
outstr += f'position="{data["10"]} {data["30"]} {data["20"]}" \n'
outstr += f'rotation="{data["210"]} {data["50"]} {data["220"]}"\n'
try:
if data['type'] == 'ambient':
outstr += f'light="type: ambient; color: {data["color"]}; intensity: {data["intensity"]}; '
outstr += '">\n'
elif data['type'] == 'point':
outstr += f'light="type: point; color: {data["color"]}; intensity: {data["intensity"]}; '
outstr += f'decay: {data["decay"]}; distance: {data["distance"]}; '
if page_obj.shadows:
outstr += 'castShadow: true; '
outstr += '"> \n'
elif data['type'] == 'spot':
outstr += f'light="type: spot; color: {data["color"]}; intensity: {data["intensity"]}; '
outstr += f'decay: {data["decay"]}; distance: {data["distance"]}; '
outstr += f'angle: {data["angle"]}; penumbra: {data["penumbra"]}; '
if page_obj.shadows:
outstr += 'castShadow: true; '
outstr += f'target: #light-{x}-target;"> \n'
outstr += f'<a-entity id="light-{x}-target" position="0 -1 0"> </a-entity> \n'
else:#defaults to directional
outstr += f'light="type: directional; color: {data["color"]}; intensity: {data["intensity"]}; '
if page_obj.shadows:
outstr += 'castShadow: true; '
outstr += f'shadowCameraBottom: {-5*fabs(data["42"])}; \n'
outstr += f'shadowCameraLeft: {-5*fabs(data["41"])}; \n'
outstr += f'shadowCameraTop: {5*fabs(data["42"])}; \n'
outstr += f'shadowCameraRight: {5*fabs(data["41"])}; \n'
outstr += f'target: #light-{x}-target;"> \n'
outstr += f'<a-entity id="light-{x}-target" position="0 -1 0"> </a-entity> \n'
except KeyError:#default if no light type is set
outstr += 'light="type: point; intensity: 0.75; distance: 50; decay: 2; '
if page_obj.shadows:
outstr += 'castShadow: true;'
outstr += '">\n'
if data['animation']:
outstr += is_animation(data)
outstr += '</a-entity>\n'#close light entity
return outstr
class APartition(object):
def __init__(self, page_obj, data, types, finishings, csv_f):
self.d = data#is it possible to use the self.__dict__=data construct? it would be much cleaner
self.page_obj = page_obj.specific
self.d['alert'] = 'None'
self.type_obj = False
if self.d['type']:
try:
self.type_obj = types.get(title = self.d['type'])
except:
pass
self.finishings = finishings
self.csv_f = csv_f
def calc_weight(self):
part_weight = 0
unit_weight = 0
zero_weight = 0
part_thickness = 0
fixed_thickness = True
for part_layer in self.type_obj.part_layers.all():
part_layer_thickness = fabs(float(part_layer.thickness))
part_layer_weight = fabs(float(part_layer.weight))
if part_layer_thickness == 0:
fixed_thickness = False
zero_weight = part_layer_weight
part_thickness += part_layer_thickness
unit_weight += part_layer_thickness/100 * part_layer_weight
unit_weight += (fabs(self.d['42']) - part_thickness/100) * zero_weight#add eventual zero thickness layer
part_weight = unit_weight * fabs(self.d['41']) * fabs(self.d['43'])#actual part size
if self.d['2'] == 'a-openwall':
part_weight = part_weight - (unit_weight * fabs(self.d['door_off_2']-self.d['door_off_1']) * fabs(self.d['door_height']))#remove door
if part_thickness and fixed_thickness and fabs(self.d['42']) != part_thickness/100:
self.d['alert'] = 'Different than Partition Type'
elif fabs(self.d['42']) < part_thickness/100:
self.d['alert'] = 'Partition too thin'
else:
if self.type_obj.image:
self.d['8'] = 'partition-' + self.type_obj.title
self.d['repeat'] = self.type_obj.pattern
if self.type_obj.color:
self.d['color'] = self.type_obj.color
#writing to csv file
self.csv_f.write(f'{self.d["num"]},{self.d["layer"]},{self.d["2"]},-,-,{self.type_obj.title},{self.d["10"]},{-self.d["20"]},{self.d["30"]},')
self.csv_f.write(f'{self.d["210"]},{-self.d["220"]},{self.d["50"]},{self.d["41"]},{self.d["42"]},{self.d["43"]},{part_weight},{self.d["alert"]} \n')
return
def no_weight(self):
#writing to csv file
self.csv_f.write(f'{self.d["num"]},{self.d["layer"]},{self.d["2"]},-,-,None,{self.d["10"]},{-self.d["20"]},{self.d["30"]},')
self.csv_f.write(f'{self.d["210"]},{-self.d["220"]},{self.d["50"]},{self.d["41"]},{self.d["42"]},{self.d["43"]},0,{self.d["alert"]} \n')
return
def write_html(self):
#start entity
outstr = f'<a-entity id="{self.d["2"]}-{self.d["num"]}" \n'
if self.page_obj.shadows:
outstr += 'shadow="receive: true; cast: true" \n'
outstr += f'position="{self.d["10"]} {self.d["30"]} {self.d["20"]}" \n'
outstr += f'rotation="{self.d["210"]} {self.d["50"]} {self.d["220"]}">\n'
#slab handle is on top
if self.d['2'] == 'a-slab':
y = self.d['43']
else:
y = 0
#top surface
if self.d['2'] == 'a-slab':
self.d['side'] = 'floor'
else:
self.d['side'] = 'top'
self.d['sub_side'] = self.d['side']
self.d['width'] = fabs(self.d['41'])
self.d['height'] = fabs(self.d['42'])
outstr += f'<a-entity id="{self.d["2"]}-{self.d["num"]}-{self.d["side"]}-ent" \n'
outstr += f'position="{self.d["41"]/2} {self.d["43"]-y} 0" \n'
if self.d['43'] > 0:
outstr += 'rotation="-90 0 0"> \n'
else:
outstr += 'rotation="-90 180 0"> \n'
outstr += self.part_simple_finishing()
outstr += '</a-entity> \n'
#bottom surface, a-openwall has left and right bottoms
if self.d['2'] == 'a-wall' or self.d['2'] == 'a-slab':
if self.d['2'] == 'a-slab':
self.d['side'] = 'ceiling'
else:
self.d['side'] = 'bottom'
self.d['sub_side'] = self.d['side']
self.d['width'] = fabs(self.d['41'])
self.d['height'] = fabs(self.d['42'])
outstr += f'<a-entity id="{self.d["2"]}-{self.d["num"]}-{self.d["side"]}-ent" \n'
outstr += f'position="{self.d["41"]/2} {-y} 0" \n'
if self.d['43'] > 0:
outstr += 'rotation="90 180 0"> \n'
else:
outstr += 'rotation="90 0 0"> \n'
outstr += self.part_simple_finishing()
outstr += '</a-entity> \n'
#inside surface, a-openwall has left, right and top insides
if self.d['2'] == 'a-wall' or self.d['2'] == 'a-slab':
if self.d['2'] == 'a-slab':
self.d['side'] = 'front'
else:
self.d['side'] = 'in'
self.d['sub_side'] = self.d['side']
self.d['width'] = fabs(self.d['41'])
self.d['height'] = fabs(self.d['43'])
outstr += f'<a-entity id="{self.d["2"]}-{self.d["num"]}-{self.d["side"]}-ent" \n'
outstr += f'position="{self.d["41"]/2} {-y} 0" \n'
if self.d['42'] < 0:
outstr += 'rotation="0 180 0"> \n'
else:
outstr += '> \n'
if self.d['2'] == 'a-slab':
outstr += self.part_simple_finishing()
else:
outstr += self.part_striped_finishing()
outstr += '</a-entity> \n'
#outside surface, a-openwall has left, right and top outsides
if self.d['2'] == 'a-wall' or self.d['2'] == 'a-slab':
if self.d['2'] == 'a-slab':
self.d['side'] = 'back'
else:
self.d['side'] = 'out'
self.d['sub_side'] = self.d['side']
self.d['width'] = fabs(self.d['41'])
self.d['height'] = fabs(self.d['43'])
outstr += f'<a-entity id="{self.d["2"]}-{self.d["num"]}-{self.d["side"]}-ent" \n'
outstr += f'position="{self.d["41"]/2} {-y} {-self.d["42"]}" \n'
if self.d['42'] > 0:
outstr += 'rotation="0 180 0"> \n'
else:
outstr += '> \n'
if self.d['2'] == 'a-slab':
outstr += self.part_simple_finishing()
else:
outstr += self.part_striped_finishing()
outstr += '</a-entity> \n'
#left surface
self.d['side'] = 'left'
self.d['sub_side'] = 'left'
self.d['width'] = fabs(self.d['42'])
self.d['height'] = fabs(self.d['43'])
outstr += f'<a-entity id="{self.d["2"]}-{self.d["num"]}-{self.d["side"]}-ent" \n'
outstr += f'position="0 {-y} {-self.d["42"]/2}" \n'
if self.d['41'] > 0:
outstr += 'rotation="0 -90 0"> \n'
else:
outstr += 'rotation="0 90 0"> \n'
if self.d['2'] == 'a-slab':
outstr += self.part_simple_finishing()
else:
outstr += self.part_striped_finishing()
outstr += '</a-entity> \n'
#right surface
self.d['side'] = 'right'
self.d['sub_side'] = 'right'
self.d['width'] = fabs(self.d['42'])
self.d['height'] = fabs(self.d['43'])
outstr += f'<a-entity id="{self.d["2"]}-{self.d["num"]}-{self.d["side"]}-ent" \n'
outstr += f'position="{self.d["41"]} {-y} {-self.d["42"]/2}" \n'
if self.d['41'] < 0:
outstr += 'rotation="0 -90 0"> \n'
else:
outstr += 'rotation="0 90 0"> \n'
if self.d['2'] == 'a-slab':
outstr += self.part_simple_finishing()
else:
outstr += self.part_striped_finishing()
outstr += '</a-entity> \n'
if self.d['2'] == 'a-openwall':
#bottom left surface
self.d['side'] = 'bottom'
self.d['sub_side'] = 'bottom-left'
self.d['width'] = fabs(self.d['door_off_1'])
self.d['height'] = fabs(self.d['42'])
outstr += f'<a-entity id="{self.d["2"]}-{self.d["num"]}-{self.d["sub_side"]}-ent" \n'
outstr += f'position="{self.d["door_off_1"]/2} 0 0" \n'
if self.d['43'] > 0:
outstr += 'rotation="90 180 0"> \n'
else:
outstr += 'rotation="90 0 0"> \n'
outstr += self.part_simple_finishing()
outstr += '</a-entity> \n'
#bottom right surface
self.d['side'] = 'bottom'
self.d['sub_side'] = 'bottom-right'
self.d['width'] = fabs(self.d['41']-self.d['door_off_2'])
self.d['height'] = fabs(self.d['42'])
outstr += f'<a-entity id="{self.d["2"]}-{self.d["num"]}-{self.d["sub_side"]}-ent" \n'
outstr += f'position="{self.d["width"]/2+self.d["door_off_2"]} 0 0" \n'
if self.d['43'] > 0:
outstr += 'rotation="90 180 0"> \n'
else:
outstr += 'rotation="90 0 0"> \n'
outstr += self.part_simple_finishing()
outstr += '</a-entity> \n'
#inside left surface
self.d['side'] = 'in'
self.d['sub_side'] = 'in-left'
self.d['width'] = fabs(self.d['door_off_1'])
self.d['height'] = fabs(self.d['door_height'])
outstr += f'<a-entity id="{self.d["2"]}-{self.d["num"]}-{self.d["sub_side"]}-ent" \n'
outstr += f'position="{self.d["door_off_1"]/2} 0 0" \n'
if self.d['42'] < 0:
outstr += 'rotation="0 180 0"> \n'
else:
outstr += '> \n'
outstr += self.part_striped_finishing()
outstr += '</a-entity> \n'
#inside right surface
self.d['side'] = 'in'
self.d['sub_side'] = 'in-right'
self.d['width'] = fabs(self.d['41']-self.d['door_off_2'])
self.d['height'] = fabs(self.d['door_height'])
outstr += f'<a-entity id="{self.d["2"]}-{self.d["num"]}-{self.d["sub_side"]}-ent" \n'
outstr += f'position="{self.d["width"]/2+self.d["door_off_2"]} 0 0" \n'
if self.d['42'] < 0:
outstr += 'rotation="0 180 0"> \n'
else:
outstr += '> \n'
outstr += self.part_striped_finishing()
outstr += '</a-entity> \n'
#inside top surface
self.d['side'] = 'in'
self.d['sub_side'] = 'in-top'
self.d['width'] = fabs(self.d['41'])
self.d['height'] = fabs(self.d['43'])
outstr += f'<a-entity id="{self.d["2"]}-{self.d["num"]}-{self.d["sub_side"]}-ent" \n'
outstr += f'position="{self.d["width"]/2} {self.d["door_height"]} 0" \n'
if self.d['42'] < 0:
outstr += 'rotation="0 180 0"> \n'
else:
outstr += '> \n'
outstr += self.part_striped_finishing()
outstr += '</a-entity> \n'
#outside left surface
self.d['side'] = 'out'
self.d['sub_side'] = 'out-left'
self.d['width'] = fabs(self.d['door_off_1'])
self.d['height'] = fabs(self.d['door_height'])
outstr += f'<a-entity id="{self.d["2"]}-{self.d["num"]}-{self.d["sub_side"]}-ent" \n'
outstr += f'position="{self.d["door_off_1"]/2} 0 {-self.d["42"]}" \n'
if self.d['42'] > 0:
outstr += 'rotation="0 180 0"> \n'
else:
outstr += '> \n'