-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathvi_display.py
3071 lines (2567 loc) · 142 KB
/
vi_display.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 #####
import bpy, blf, mathutils, datetime, os, inspect, gpu, bmesh
from gpu_extras.batch import batch_for_shader
from mathutils import Vector
from bpy_extras import view3d_utils
from .vi_func import ret_vp_loc, viewdesc, draw_index, draw_time, blf_props, retcols, retdp
from .vi_func import ret_res_vals, draw_index_distance, selobj, mp2im, move_obs
from .vi_func import logentry, move_to_coll, cmap, retvpvloc, objmode, skframe, clearscene
from .vi_func import solarPosition, solarRiseSet, create_coll, create_empty_coll, compass, joinobj, sunpath, sunpath1
from .livi_func import setscenelivivals, res_interpolate, res_direction
#from .auvi_func import setsceneauvivals
# from .livi_export import spfc
from .vi_dicts import res2unit, unit2res
from . import livi_export
from .vi_svg import vi_info
from math import pi, log10, atan2, sin, cos
from numpy import array, repeat, logspace, multiply, digitize, frombuffer, ubyte, float32, int8
from numpy import min as nmin
from numpy import max as nmax
from numpy import sum as nsum
from numpy import log10 as nlog10
from numpy import append as nappend
from xml.dom.minidom import parseString
# from bpy.app.handlers import persistent
from PySide6.QtGui import QImage, QPdfWriter, QPagedPaintDevice, QPainter, QPageSize
from PySide6.QtPrintSupport import QPrinter
from PySide6.QtSvg import QSvgRenderer
from PySide6.QtCore import QSizeF, QMarginsF
from PySide6.QtCore import QSize
from PySide6.QtWidgets import QApplication
try:
import matplotlib
matplotlib.use('qtagg', force=True)
import matplotlib.pyplot as plt
plt.ion()
plt.ioff()
import matplotlib.cm as mcm
import matplotlib.colors as mcolors
from matplotlib.patches import Rectangle
from matplotlib.collections import PatchCollection
mp = 1
except Exception as e:
print("No matplotlib: {}".format(e))
mp = 0
kfsa = array([0.02391, 0.02377, 0.02341, 0.02738, 0.02933, 0.03496, 0.04787, 0.05180, 0.13552])
kfact = array([0.9981, 0.9811, 0.9361, 0.8627, 0.7631, 0.6403, 0.4981, 0.3407, 0.1294])
def ret_dcoords(context):
return (context.area.regions[0].height + context.area.regions[1].height, context.area.regions[4].width, context.area.regions[-1].height)
def script_update(self, context):
print('script_update')
svp = context.scene.vi_params
if svp.vi_res_process == '2' and svp.script_file in bpy.data.texts:
script = bpy.data.texts[svp.script_file]
exec(script.as_string())
leg_update(self, context)
def col_update(self, context):
cmap(context.scene.vi_params)
def leg_update(self, context):
scene = context.scene
svp = scene.vi_params
params = 'liparams'
type_strings = ('LiVi Res', 'LiVi Calc')
disp_menu = svp.li_disp_menu
legmm = leg_min_max(svp)
frames = range(svp[params]['fs'], svp[params]['fe'] + 1)
obs = [o for o in scene.objects if o.vi_params.vi_type_string == type_strings[0]]
cobs = [o for o in scene.objects if o.vi_params.vi_type_string == type_strings[1]]
increment = 1/svp.vi_leg_levels
if svp.vi_leg_scale == '0':
bins = array([increment * i for i in range(1, svp.vi_leg_levels + 1)])
elif svp.vi_leg_scale == '1':
slices = logspace(0, 2, svp.vi_leg_levels + 1, True)
bins = array([(slices[i] - increment * (svp.vi_leg_levels - i))/100 for i in range(svp.vi_leg_levels + 1)])
bins = array([1 - log10(i)/log10(svp.vi_leg_levels + 1) for i in range(1, svp.vi_leg_levels + 2)][::-1])
bins = bins[1:-1]
for o in obs:
selobj(context.view_layer, o)
bm = bmesh.new()
bm.from_mesh(o.data)
cmap(self)
if svp.vi_disp_process == '2':
if o.name[:-3] in [cob.name for cob in cobs]:
cob = cobs[[cob.name for cob in cobs].index(o.name[:-3])]
res_interpolate(scene, context.evaluated_depsgraph_get(), cob, o, plt, svp[params]['offset'])
elif svp.vi_disp_process == '3':
if o.name[:-3] in [cob.name for cob in cobs]:
cob = cobs[[cob.name for cob in cobs].index(o.name[:-3])]
res_direction(scene, cob, o, svp[params]['offset'])
if len(o.material_slots) != svp.vi_leg_levels:
for matname in ['{}#{}'.format('vi-suite', i) for i in range(0, svp.vi_leg_levels)]:
if bpy.data.materials[matname] not in o.data.materials[:]:
bpy.ops.object.material_slot_add()
o.material_slots[-1].material = bpy.data.materials[matname]
while len(o.material_slots) > svp.vi_leg_levels:
bpy.ops.object.material_slot_remove()
for f, frame in enumerate(frames):
if disp_menu == 'aga1v':
res_name = 'aga{}v{}'.format(svp.vi_views, frame)
elif disp_menu == 'ago1v':
res_name = 'ago{}v{}'.format(svp.vi_views, frame)
elif disp_menu == 'rt':
res_name = f'{svp.au_sources}_rt{frame}'
elif disp_menu == 'vol':
res_name = f'{svp.au_sources}_vol{frame}'
elif disp_menu == 'sti':
res_name = f'{svp.au_sources}_sti{frame}'
else:
res_name = '{}{}'.format(disp_menu, frame)
if bm.faces.layers.float.get(res_name):
vires = bm.faces.layers.float[res_name]
ovals = array([f[vires] for f in bm.faces])
elif bm.verts.layers.float.get(res_name):
vires = bm.verts.layers.float[res_name]
ovals = array([sum([vert[vires] for vert in f.verts])/len(f.verts) for f in bm.faces])
ovals = array(ret_res_vals(svp, ovals))
if legmm[1] > legmm[0]:
vals = ovals - legmm[0]
vals = vals/(legmm[1] - legmm[0])
else:
vals = array([legmm[1] for f in bm.faces])
if svp.vi_res_process == '2' and svp.script_file:
nmatis = array(ovals).astype(int8)
else:
nmatis = digitize(vals, bins, right=False).clip(0, svp.vi_leg_levels - 1)
if len(frames) == 1:
o.data.polygons.foreach_set('material_index', nmatis)
o.data.update()
elif len(frames) > 1:
for fi, fc in enumerate(o.data.animation_data.action.fcurves):
fc.keyframe_points[f].co = frame, nmatis[fi]
else:
if len(o.material_slots) != svp.vi_leg_levels:
for matname in ['{}#{}'.format('vi-suite', i) for i in range(0, svp.vi_leg_levels)]:
if bpy.data.materials[matname] not in o.data.materials[:]:
bpy.ops.object.material_slot_add()
o.material_slots[-1].material = bpy.data.materials[matname]
while len(o.material_slots) > svp.vi_leg_levels:
bpy.ops.object.material_slot_remove()
for f, frame in enumerate(frames):
if disp_menu == 'aga1v':
res_name = 'aga{}v{}'.format(svp.vi_views, frame)
elif disp_menu == 'ago1v':
res_name = 'ago{}v{}'.format(svp.vi_views, frame)
elif disp_menu == 'rt':
res_name = f'{svp.au_sources}_rt{frame}'
elif disp_menu == 'vol':
res_name = f'{svp.au_sources}_vol{frame}'
elif disp_menu == 'sti':
res_name = f'{svp.au_sources}_sti{frame}'
else:
res_name = '{}{}'.format(disp_menu, frame)
if bm.faces.layers.float.get(res_name):
vires = bm.faces.layers.float[res_name]
ovals = array([f[vires] for f in bm.faces])
elif bm.verts.layers.float.get(res_name):
vires = bm.verts.layers.float[res_name]
ovals = array([sum([vert[vires] for vert in f.verts])/len(f.verts) for f in bm.faces])
ovals = array(ret_res_vals(svp, ovals))
if legmm[1] > legmm[0]:
vals = ovals - legmm[0]
vals = vals/(legmm[1] - legmm[0])
else:
vals = array([legmm[1] for f in bm.faces])
if svp.vi_res_process == '2' and svp.script_file:
nmatis = array(ovals).astype(int8)
else:
nmatis = digitize(vals, bins, right=False).clip(0, svp.vi_leg_levels - 1)
if len(frames) == 1:
o.data.polygons.foreach_set('material_index', nmatis)
o.data.update()
elif len(frames) > 1:
for fi, fc in enumerate(o.data.animation_data.action.fcurves):
fc.keyframe_points[f].co = frame, nmatis[fi]
bm.free()
try:
context.space_data.region_3d.view_location[2] += 0.0001
except Exception as e:
pass
def leg_min_max(svp):
try:
if svp.vi_res_process == '2' and 'resmod' in bpy.app.driver_namespace.keys():
return bpy.app.driver_namespace['resmod']([svp.vi_leg_min, svp.vi_leg_max])
elif svp.vi_res_process == '1' and svp.vi_res_mod:
return (eval('{}{}'.format(svp.vi_leg_min, svp.vi_res_mod)), eval('{}{}'.format(svp.vi_leg_max, svp.vi_res_mod)))
else:
return (svp.vi_leg_min, svp.vi_leg_max)
except Exception as e:
logentry('Error setting legend values: {}'.format(e))
return (svp.vi_leg_min, svp.vi_leg_max)
def e_update(self, context):
scene = context.scene
svp = scene.vi_params
maxo, mino = svp.vi_leg_max, svp.vi_leg_min
odiff = svp.vi_leg_max - svp.vi_leg_min
if context.active_object and context.active_object.mode == 'EDIT':
return
if odiff:
for frame in range(svp['liparams']['fs'], svp['liparams']['fe'] + 1):
if svp.li_disp_menu == 'aga1v':
res_name = 'aga{}v{}'.format(svp.vi_views, frame)
elif svp.li_disp_menu == 'ago1v':
res_name = 'ago{}v{}'.format(svp.vi_views, frame)
elif svp.li_disp_menu == 'rt':
res_name = f'{svp.au_sources}_rt{frame}'
elif svp.li_disp_menu == 'vol':
res_name = f'{svp.au_sources}_vol{frame}'
elif svp.li_disp_menu == 'sti':
res_name = f'{svp.au_sources}_sti{frame}'
else:
res_name = '{}{}'.format(svp.li_disp_menu, frame)
for o in [obj for obj in bpy.data.objects if obj.vi_params.vi_type_string == 'LiVi Res' and obj.data.shape_keys and str(frame) in [sk.name for sk in obj.data.shape_keys.key_blocks]]:
ovp = o.vi_params
bm = bmesh.new()
bm.from_mesh(o.data)
bm.transform(o.matrix_world)
skb = bm.verts.layers.shape['Basis']
skf = bm.verts.layers.shape[str(frame)]
if str(frame) in ovp['omax']:
if bm.faces.layers.float.get(res_name):
extrude = bm.faces.layers.int['extrude']
res = bm.faces.layers.float[res_name] # if context.scene['cp'] == '0' else bm.verts.layers.float['res{}'.format(frame)]
faces = [f for f in bm.faces if f[extrude]]
fnorms = array([f.normal.normalized() for f in faces]).T
fres = array([f[res] for f in faces])
extrudes = (0.1 * svp.vi_disp_3dlevel * (nlog10(maxo * (fres + 1 - mino)/odiff)) * fnorms).T if svp.vi_leg_scale == '1' else \
multiply(fnorms, svp.vi_disp_3dlevel * ((fres - mino)/odiff)).T
for f, face in enumerate(faces):
for v in face.verts:
v[skf] = v[skb] + mathutils.Vector(extrudes[f])
elif bm.verts.layers.float.get(res_name):
res = bm.verts.layers.float[res_name]
vnorms = array([v.normal.normalized() for v in bm.verts]).T
vres = array([v[res] for v in bm.verts])
extrudes = multiply(vnorms, svp.vi_disp_3dlevel * ((vres-mino)/odiff)).T if svp.vi_leg_scale == '0' else \
[0.1 * svp.vi_disp_3dlevel * (log10(maxo * (v[res] + 1 - mino)/odiff)) * v.normal.normalized() for v in bm.verts]
for v, vert in enumerate(bm.verts):
vert[skf] = vert[skb] + mathutils.Vector(extrudes[v])
bm.transform(o.matrix_world.inverted())
bm.to_mesh(o.data)
bm.free()
def t_update(self, context):
for o in [o for o in context.scene.objects if o.type == 'MESH' and 'lightarray' not in o.name and not o.hide_viewport and o.vi_params.vi_type_string == 'LiVi Res']:
o.show_transparent = 1
for mat in [bpy.data.materials['{}#{}'.format('vi-suite', index)] for index in range(context.scene.vi_params.vi_leg_levels)]:
mat.blend_method = 'BLEND'
mat.diffuse_color[3] = self.id_data.vi_params.vi_disp_trans
cmap(self)
def w_update(self, context):
o = context.active_object
if o and o.type == 'MESH':
(o.show_wire, o.show_all_edges) = (1, 1) if context.scene.vi_params.vi_disp_wire else (0, 0)
def livires_update(self, context):
setscenelivivals(context.scene)
for o in [o for o in bpy.data.objects if o.vi_params.vi_type_string == 'LiVi Res']:
o.vi_params.lividisplay(context.scene)
e_update(self, context)
def auvires_update(self, context):
setsceneauvivals(context.scene)
for o in [o for o in bpy.data.objects if o.vi_params.vi_type_string == 'AuVi Res']:
o.vi_params.lividisplay(context.scene)
e_update(self, context)
def rendview(i):
for scrn in bpy.data.screens:
for area in scrn.areas:
if area.type == 'VIEW_3D':
for space in area.spaces:
if space.type == 'VIEW_3D':
space.clip_start = 0.1
bpy.context.scene['cs'] = space.clip_start
def li_display(context, disp_op, simnode):
if not [o for o in bpy.data.objects if o.vi_params.vi_type_string == 'LiVi Calc']:
return 'CANCELLED'
scene, obreslist, obcalclist = context.scene, [], []
dp = context.evaluated_depsgraph_get()
svp = scene.vi_params
svp.li_disp_menu = unit2res[svp['liparams']['unit']]
setscenelivivals(scene)
(rcol, mtype) = ('hot', 'livi') if 'LiVi' in simnode.bl_label else ('grey', 'shad')
for geo in context.view_layer.objects:
context.view_layer.objects.active = geo
if getattr(geo, 'mode') != 'OBJECT':
bpy.ops.object.mode_set(mode='OBJECT')
bpy.ops.object.select_all(action='DESELECT')
if not bpy.app.handlers.frame_change_post:
bpy.app.handlers.frame_change_post.append(livi_export.cyfc1)
for o in context.view_layer.objects:
if o.type == "MESH" and o.vi_params.vi_type_string == 'LiVi Calc' and o.visible_get():
bpy.ops.object.select_all(action='DESELECT')
obcalclist.append(o)
scene.frame_set(svp['liparams']['fs'])
context.view_layer.objects.active = None
cmap(svp)
for i, o in enumerate(obcalclist):
ovp = o.vi_params
if svp.vi_disp_process == "2":
mesh = bpy.data.meshes.new(f'{o.name}_res')
ores = bpy.data.objects.new(f'{o.name}_res', mesh)
ores.name, ores.show_wire, ores.show_all_edges, ores.display_type, orvp, ores.vi_params.vi_type_string = o.name+"res", 1, 1, 'SOLID', ores.vi_params, 'LiVi Res'
move_to_coll(context, 'LiVi Results', ores)
context.view_layer.layer_collection.children['LiVi Results'].exclude = 0
context.view_layer.objects.active = ores
ores.visible_diffuse, ores.visible_glossy, ores.visible_transmission, ores.visible_volume_scatter, ores.visible_shadow = 0, 0, 0, 0, 0
ores.vi_params.vi_type_string == 'LiVi Res'
orvp['omax'], orvp['omin'], orvp['oave'] = ovp['omax'], ovp['omin'], ovp['oave']
selobj(context.view_layer, ores)
res_interpolate(scene, dp, o, ores, plt, simnode['goptions']['offset'])
ores.vi_params.lividisplay(scene)
elif svp.vi_disp_process == "3":
mesh = bpy.data.meshes.new(f'{o.name}_res')
ores = bpy.data.objects.new(f'{o.name}_res', mesh)
ores.name, ores.show_wire, ores.show_all_edges, ores.display_type, orvp, ores.vi_params.vi_type_string = o.name+"res", 1, 1, 'SOLID', ores.vi_params, 'LiVi Res'
move_to_coll(context, 'LiVi Results', ores)
context.view_layer.layer_collection.children['LiVi Results'].exclude = 0
selobj(context.view_layer, ores)
res_direction(scene, o, ores, simnode['goptions']['offset'])
orvp['omax'], orvp['oave'], orvp['omin'] = ovp['omax'], ovp['omin'], ovp['oave']
orvp.lividisplay(scene)
obreslist.append(ores)
else:
bm = bmesh.new()
bm.from_object(o, dp)
if svp['liparams']['cp'] == '0':
cindex = bm.faces.layers.int['cindex']
for f in [f for f in bm.faces if f[cindex] < 1]:
bm.faces.remove(f)
[bm.verts.remove(v) for v in bm.verts if not v.link_faces]
elif svp['liparams']['cp'] == '1':
cindex = bm.verts.layers.int['cindex']
for v in [v for v in bm.verts if v[cindex] < 1]:
bm.verts.remove(v)
for v in bm.verts:
v.select = True
while bm.verts.layers.shape:
bm.verts.layers.shape.remove(bm.verts.layers.shape[-1])
for v in bm.verts:
v_norm = mathutils.Vector((nsum([f.normal for f in v.link_faces], axis=0))).normalized()
v.co += mathutils.Vector([v_norm[i]/abs(o.scale[i]) for i in range(3)]) * simnode['goptions']['offset']
selobj(context.view_layer, o)
bpy.ops.object.duplicate()
for face in bm.faces:
face.select = True
if not context.active_object:
disp_op.report({'ERROR'}, "No display object. If in local view switch to global view and/or re-export the geometry")
return 'CANCELLED'
ores = context.active_object
ores.name, ores.show_wire, ores.show_all_edges, ores.display_type, orvp, ores.vi_params.vi_type_string = o.name+"res", 1, 1, 'SOLID', ores.vi_params, 'LiVi Res'
move_to_coll(context, 'LiVi Results', ores)
context.view_layer.layer_collection.children['LiVi Results'].exclude = 0
context.view_layer.objects.active = ores
while ores.material_slots:
bpy.ops.object.material_slot_remove()
while ores.data.shape_keys:
context.object.active_shape_key_index = 0
bpy.ops.object.shape_key_remove(all=True)
ores.visible_diffuse, ores.visible_glossy, ores.visible_transmission, ores.visible_volume_scatter, ores.visible_shadow = 0, 0, 0, 0, 0
obreslist.append(ores)
ores.vi_params.vi_type_string == 'LiVi Res'
orvp['omax'], orvp['omin'], orvp['oave'] = ovp['omax'], ovp['omin'], ovp['oave']
selobj(context.view_layer, ores)
for matname in ['{}#{}'.format('vi-suite', i) for i in range(svp.vi_leg_levels)]:
if bpy.data.materials[matname] not in ores.data.materials[:]:
bpy.ops.object.material_slot_add()
ores.material_slots[-1].material = bpy.data.materials[matname]
if svp.vi_disp_process == "1" and svp['liparams']['cp'] == '0':
bm.faces.layers.int.new('extrude')
extrude = bm.faces.layers.int['extrude']
for face in bmesh.ops.extrude_discrete_faces(bm, faces=bm.faces)['faces']:
face.select = True
face[extrude] = 1
bm.to_mesh(ores.data)
bm.free()
bpy.ops.object.shade_flat()
ores.vi_params.lividisplay(scene)
if svp.vi_disp_process == "1" and not ores.data.shape_keys:
selobj(context.view_layer, ores)
bpy.ops.object.shape_key_add(from_mix=False)
for frame in range(svp['liparams']['fs'], svp['liparams']['fe'] + 1):
bpy.ops.object.shape_key_add(from_mix=False)
ores.active_shape_key.name, ores.active_shape_key.value = str(frame), 1
skframe('', scene, obreslist, 'liparams')
bpy.ops.wm.save_mainfile(check_existing=False)
scene.frame_set(svp['liparams']['fs'])
rendview(1)
class linumdisplay():
def __init__(self, disp_op, context):
scene = context.scene
svp = scene.vi_params
self.fn = scene.frame_current - svp['liparams']['fs']
self.level = svp.vi_disp_3dlevel
self.disp_op = disp_op
svp.vi_display_rp = 0
self.fs = svp.vi_display_rp_fs
self.fontmult = 1
self.obreslist = [ob for ob in scene.objects if ob.vi_params.vi_type_string == 'LiVi Res']
if not svp.vi_display_sel_only:
self.obd = self.obreslist
else:
self.obd = [context.active_object] if context.active_object in self.obreslist else []
self.omws = [o.matrix_world for o in self.obd]
mid_x, mid_y, self.width, self.height = viewdesc(context)
self.view_location = retvpvloc(context)
objmode()
self.update(context)
def draw(self, context):
self.u = 0
scene = context.scene
svp = scene.vi_params
bcao = bpy.context.active_object
self.fontmult = 2 # if context.space_data.region_3d.is_perspective else 500
if not svp.get('viparams') or svp['viparams']['vidisp'] not in ('svf', 'li', 'ss', 'lcpanel', 'rt'):
svp.vi_display = 0
return
if scene.frame_current not in range(svp['liparams']['fs'], svp['liparams']['fe'] + 1):
self.disp_op.report({'INFO'}, "Outside result frame range")
return
if not svp.vi_display_rp or (bcao not in self.obreslist and svp.vi_display_sel_only) or (bcao and bcao.mode == 'EDIT'):
return
if (self.width, self.height) != viewdesc(context)[2:]:
mid_x, mid_y, self.width, self.height = viewdesc(context)
self.u = 1
if self.view_location != retvpvloc(context):
self.view_location = retvpvloc(context)
self.u = 1
if not svp.vi_display_sel_only:
obd = self.obreslist
else:
obd = [context.active_object] if context.active_object in self.obreslist else []
if self.obd != obd:
self.obd = obd
self.u = 1
if self.fn != scene.frame_current - svp['liparams']['fs']:
self.fn = scene.frame_current - svp['liparams']['fs']
self.u = 1
if self.level != svp.vi_disp_3dlevel:
self.level = svp.vi_disp_3dlevel
self.u = 1
blf_props(scene, self.width, self.height)
if self.u:
self.update(context)
else:
draw_index_distance(self.allpcs, self.allres, self.fontmult * svp.vi_display_rp_fs, svp.vi_display_rp_fc, svp.vi_display_rp_fsh, self.alldepths)
if svp.vi_display_rp_fs != self.fs:
self.fs = svp.vi_display_rp_fs
def update(self, context):
dp = context.evaluated_depsgraph_get()
scene = context.scene
vl = context.view_layer
svp = scene.vi_params
self.allpcs, self.alldepths, self.allres = array([]), array([]), array([])
for ob in self.obd:
if ob.data.get('shape_keys') and str(self.fn) in [sk.name for sk in ob.data.shape_keys.key_blocks] and ob.active_shape_key.name != str(self.fn):
ob.active_shape_key_index = [sk.name for sk in ob.data.shape_keys.key_blocks].index(str(self.fn))
for ob in self.obd:
res = array([])
bm = bmesh.new()
bm.from_object(ob, dp)
bm.transform(ob.matrix_world)
bm.normal_update()
if svp.li_disp_menu == 'aga1v':
var = 'aga{}v'.format(svp.vi_views)
elif svp.li_disp_menu == 'ago1v':
var = 'ago{}v'.format(svp.vi_views)
elif svp.li_disp_menu == 'rt':
var = f'{svp.au_sources}_rt'
elif svp.li_disp_menu == 'vol':
var = f'{svp.au_sources}_vol'
elif svp.li_disp_menu == 'sti':
var = f'{svp.au_sources}_sti'
else:
var = svp.li_disp_menu
if bm.faces.layers.float.get('{}{}'.format(var, scene.frame_current)):
geom = bm.faces
elif bm.verts.layers.float.get('{}{}'.format(var, scene.frame_current)):
geom = bm.verts
else:
self.disp_op.report({'ERROR'}, f"No result data on {ob.name}. Re-export LiVi Context and Geometry")
return 'CANCELLED'
geom = bm.faces if bm.faces.layers.float.get('{}{}'.format(var, scene.frame_current)) else bm.verts
geom.ensure_lookup_table()
livires = geom.layers.float['{}{}'.format(var, scene.frame_current)]
if bm.faces.layers.float.get('{}{}'.format(var, scene.frame_current)):
if svp.vi_disp_process == "1":
extrude = geom.layers.int['extrude']
faces = [f for f in geom if f.select and f[extrude]]
else:
faces = [f for f in geom if f.select]
distances = [(self.view_location - f.calc_center_median_weighted() + svp.vi_display_rp_off * f.normal.normalized()).length for f in faces]
if svp.vi_display_vis_only:
fcos = [f.calc_center_median_weighted() + svp.vi_display_rp_off * f.normal.normalized() for f in faces]
direcs = [self.view_location - f for f in fcos]
try:
(faces, distances) = map(list, zip(*[[f, distances[i]] for i, f in enumerate(faces) if not scene.ray_cast(vl.depsgraph, fcos[i], direcs[i], distance=distances[i])[0] and f.normal.dot(direcs[i]) > 0]))
except Exception as e:
(faces, distances) = ([], [])
if faces:
face2d = [view3d_utils.location_3d_to_region_2d(context.region, context.region_data, f.calc_center_median_weighted()) for f in faces]
try:
(faces, pcs, depths) = map(list, zip(*[[f, face2d[fi], distances[fi]] for fi, f in enumerate(faces) if
face2d[fi] and 0 < face2d[fi][0] < self.width and 0 < face2d[fi][1] < self.height]))
except Exception:
(faces, pcs, depths) = ([], [], [])
res = array([f[livires] for f in faces])
res = ret_res_vals(svp, res)
elif bm.verts.layers.float.get('{}{}'.format(var, scene.frame_current)):
verts = [v for v in geom if not v.hide and v.select and (context.space_data.region_3d.view_location -
self.view_location).dot(v.co + svp.vi_display_rp_off * v.normal.normalized() - self.view_location) /
((context.space_data.region_3d.view_location-self.view_location).length * (v.co + svp.vi_display_rp_off * v.normal.normalized() - self.view_location).length) > 0]
distances = [(self.view_location - v.co + svp.vi_display_rp_off * v.normal.normalized()).length for v in verts]
if svp.vi_display_vis_only:
vcos = [v.co + svp.vi_display_rp_off * v.normal.normalized() for v in verts]
direcs = [self.view_location - v for v in vcos]
try:
(verts, distances) = map(list, zip(*[[v, distances[i]] for i, v in enumerate(verts) if not scene.ray_cast(vl.depsgraph, vcos[i], direcs[i], distance=distances[i])[0]]))
except Exception:
(verts, distances) = ([], [])
if verts:
vert2d = [view3d_utils.location_3d_to_region_2d(context.region, context.region_data, v.co) for v in verts]
try:
(verts, pcs, depths) = map(list, zip(*[[v, vert2d[vi], distances[vi]] for vi, v in enumerate(verts) if
vert2d[vi] and 0 < vert2d[vi][0] < self.width and 0 < vert2d[vi][1] < self.height]))
except Exception:
(verts, pcs, depths) = ([], [], [])
res = array([v[livires] for v in verts])
res = ret_res_vals(svp, res)
bm.free()
if len(res):
self.allpcs = nappend(self.allpcs, array(pcs))
self.alldepths = nappend(self.alldepths, array(depths))
self.allres = nappend(self.allres, res)
if len(self.alldepths):
self.alldepths = self.alldepths/nmin(self.alldepths)
draw_index_distance(self.allpcs, self.allres, self.fontmult * svp.vi_display_rp_fs, svp.vi_display_rp_fc, svp.vi_display_rp_fsh, self.alldepths)
class Base_Display():
def __init__(self, ipos, width, height, xdiff, ydiff):
self.ispos = ipos
self.iepos = [ipos[0] + 40, ipos[1] + 40]
self.xdiff, self.ydiff = xdiff, ydiff
self.lspos = [ipos[0] - 5, ipos[1] - self.ydiff - 25]
self.lepos = [ipos[0] - 5 + self.xdiff, self.lspos[1] + self.ydiff]
self.resize, self.move, self.expand = 0, 0, 0
self.hl = [1, 1, 1, 1]
self.cao = None
class results_bar():
def __init__(self, images):
self.images = images
self.rh = 0
self.xpos = 0
self.shaders = [gpu.shader.from_builtin('UNIFORM_COLOR'), gpu.shader.from_builtin('UNIFORM_COLOR')]
self.f_indices = ((0, 1, 2), (2, 3, 0))
self.tex_coords = ((0, 0), (1, 0), (1, 1), (0, 1))
self.no = len(images)
self.yoffset = 10
self.size = 50
self.isize = self.size - 10
self.iyoffset = self.yoffset + (self.size - self.isize)/2
self.ixoffset = self.isize + 5
self.iyoffsetb = self.iyoffset + self.isize
self.ipos = []
for ii, im in enumerate(images):
if im not in bpy.data.images:
bpy.data.images.load(os.path.join(os.path.dirname(os.path.abspath(inspect.getfile(inspect.currentframe()))), 'Images', im))
self.shaders.append(gpu.shader.from_builtin('IMAGE'))
pos = self.ret_coords(self.xpos, self.rh, ii)
self.ipos.append(pos)
def ret_coords(self, xpos, rh, no):
return ((xpos + 5 + no * self.size, rh - self.iyoffsetb),
(xpos + self.ixoffset + no * self.size, rh - self.iyoffsetb),
(xpos + self.ixoffset + no * self.size, rh - self.iyoffset),
(xpos + 5 + no * self.size, rh - self.iyoffset))
def draw(self, xpos, rh):
if self.rh != rh or xpos != self.xpos - 10:
self.ipos = []
self.rh = rh
self.xpos = xpos
v_coords = ((self.xpos, rh - self.yoffset - self.size), (self.xpos + self.no * self.size, rh - self.yoffset - self.size),
(self.xpos + self.no * self.size, rh - self.yoffset), (self.xpos, rh - self.yoffset), (self.xpos, rh - self.yoffset - self.size))
self.batches = [batch_for_shader(self.shaders[1], 'TRIS', {"pos": v_coords}, indices=self.f_indices),
batch_for_shader(self.shaders[0], 'LINE_STRIP', {"pos": v_coords})]
for i in range(self.no):
pos = self.ret_coords(self.xpos, rh, i)
self.batches.append(batch_for_shader(self.shaders[i + 2], 'TRI_FAN', {"pos": pos, "texCoord": self.tex_coords}))
self.ipos.append(pos)
for si, s in enumerate(self.shaders):
s.bind()
if si == 0:
s.uniform_float("color", (1, 1, 1, 1))
self.batches[si].draw(s)
elif si == 1:
s.uniform_float("color", (0, 0, 0, 1))
self.batches[si].draw(s)
else:
im = bpy.data.images[self.images[si - 2]]
texture = gpu.texture.from_image(im)
if im.gl_load():
raise Exception()
s.uniform_sampler("image", texture)
#s.uniform_int("image", 0)
self.batches[si].draw(s)
class draw_bsdf(Base_Display):
def __init__(self, context, unit, pos, width, height, xdiff, ydiff):
Base_Display.__init__(self, pos, width, height, xdiff, ydiff)
self.plt = plt
self.pw, self.ph = 0.175 * xdiff, 0.35 * ydiff
self.type_select = 0
self.patch_hl = 0
self.scale_select = 'Log'
self.buttons = {}
self.num_disp = 0
self.leg_max, self.leg_min = 100, 0
self.base_unit = unit
self.font_id = blf.load(os.path.join(os.path.dirname(os.path.realpath(__file__)), 'Fonts', 'NotoSans-Regular.ttf'))
self.dpi = 157
self.v_coords = [(0, 0), (0, 1), (1, 1), (1, 0)]
self.f_indices = [(0, 1, 2), (2, 3, 0)]
self.segments = (1, 8, 16, 20, 24, 24, 24, 16, 12)
self.radii = (6.9, 20.6, 34.4, 48.2, 62, 75.8, 89.5, 103.3, 124)
self.f_colours = [(1, 1, 1, 1)] * (721 + 8 * 720)
self.imspos = (self.lspos[0], self.lspos[1])
self.image = 'bsdfplot.png'
self.isize = (self.xdiff, self.xdiff - 50)
self.iimage = 'bsdf_empty.png'
self.iisize = (250, 270)
self.type = context.active_object.active_material.vi_params['bsdf']['type']
if self.iimage not in [im.name for im in bpy.data.images]:
bpy.data.images.load(os.path.join(os.path.dirname(os.path.realpath(__file__)), 'Images', 'bsdf_empty.png'))
self.vi_coords = [(0.0, 0.0), (0.0, 1.0), (1.0, 1.0), (1.0, 0.0)]
self.tex_coords = ((0, 0), (0, 1), (1, 1), (1, 0))
self.sr = 0
self.cr = 0
self.sseg = 1
self.cseg = 0
self.srs = 1
self.crs = 0
self.create_batch('all')
self.get_data(context)
def get_data(self, context):
self.mat = context.active_object.active_material
bsdf = parseString(self.mat.vi_params['bsdf']['xml'])
self.radtype = [path.firstChild.data for path in bsdf.getElementsByTagName('Wavelength')]
self.rad_select = self.radtype[0]
self.dattype = [path.firstChild.data for path in bsdf.getElementsByTagName('WavelengthDataDirection')]
self.direc = self.dattype[0]
self.type_select = self.dattype[0].split()[0]
self.dir_select = self.dattype[0].split()[1]
self.uthetas = [float(path.firstChild.data) for path in bsdf.getElementsByTagName('UpperTheta')]
self.phis = [int(path.firstChild.data) for path in bsdf.getElementsByTagName('nPhis')]
if ',' in bsdf.getElementsByTagName('ScatteringData')[0].firstChild.data:
self.scatdat = [array([float(nv) for nv in path.firstChild.data.strip('\t').strip('\n').strip().split(',') if nv]) for path in bsdf.getElementsByTagName('ScatteringData')]
else:
self.scatdat = [array([float(nv) for nv in path.firstChild.data.strip('\t').strip('\n').strip(',').split(' ') if nv]) for path in bsdf.getElementsByTagName('ScatteringData')]
self.plot(context)
def plot(self, context):
scene = context.scene
svp = scene.vi_params
leg_min = svp.vi_bsdfleg_min if svp.vi_bsdfleg_scale == '0' or svp.vi_bsdfleg_min > 0 else svp.vi_bsdfleg_min + 0.01
self.col = svp.vi_leg_col
self.centre = (self.lspos[0] + 0.225 * self.xdiff, self.lspos[1] + 0.425 * self.ydiff)
self.plt.clf()
self.plt.close()
self.fig = self.plt.figure(figsize=(4, 3.5), dpi=100)
ax = self.plt.subplot(111, projection='polar')
ax.bar(0, 0)
self.plt.title('{} {}'.format(self.rad_select, svp.vi_bsdf_direc), size=9, y=1.025)
ax.axis([0, 2 * pi, 0, 1])
ax.spines['polar'].set_visible(False)
ax.xaxis.set_ticks([])
ax.yaxis.set_ticks([])
for dti, dt in enumerate(self.dattype):
if dt == svp.vi_bsdf_direc:
self.scat_select = dti
break
selectdat = self.scatdat[self.scat_select].reshape(145, 145) # if self.scale_select == 'Linear' else nlog10((self.scatdat[self.scat_select] + 1).reshape(145, 145))
widths = [0] + [self.uthetas[w]/90 for w in range(9)]
patches, p = [], 0
sa = repeat(kfsa, self.phis)
act = repeat(kfact, self.phis)
patchdat = selectdat[self.sseg - 1] * act * sa * 100
bg = self.plt.Rectangle((0, 0), 2 * pi, 1, color=mcm.get_cmap(svp.vi_leg_col)((0, 0.01)[svp.vi_bsdfleg_scale == '1']), zorder=0)
for ring in range(1, 10):
angdiv = pi/self.phis[ring - 1]
anglerange = range(self.phis[ring - 1], 0, -1) # if self.type_select == 'Transmission' else range(self.phis[ring - 1])
ri = widths[ring] - widths[ring-1]
for wedge in anglerange:
phi1, phi2 = wedge * 2 * angdiv - angdiv, (wedge + 1) * 2 * angdiv - angdiv
patches.append(Rectangle((phi1, widths[ring - 1]), phi2 - phi1, ri))
if self.num_disp:
y = 0 if ring == 1 else 0.5 * (widths[ring] + widths[ring-1])
self.plt.text(0.5 * (phi1 + phi2), y, ('{:.1f}', '{:.0f}')[patchdat[p] >= 10].format(patchdat[p]), ha="center",
va='center', family='sans-serif', size=self.num_disp)
p += 1
pc = PatchCollection(patches, norm=mcolors.LogNorm(vmin=leg_min, vmax=svp.vi_bsdfleg_max), cmap=self.col, linewidths=[0] + 144*[0.5],
edgecolors=('black',)) if svp.vi_bsdfleg_scale == '1' else PatchCollection(patches, cmap=self.col, linewidths=[0] + 144*[0.5], edgecolors=('black',))
pc.set_array(patchdat)
ax.add_collection(pc)
ax.add_artist(bg)
cb = self.plt.colorbar(pc, fraction=0.04, pad=0.02, format='%3g')
cb.set_label(label='Percentage of incoming flux (%)', size=9)
cb.ax.tick_params(labelsize=7)
pc.set_clim(vmin=leg_min + 0.01, vmax=svp.vi_bsdfleg_max)
self.plt.tight_layout()
self.save(scene)
def save(self, scene):
mp2im(self.fig, self.image)
def ret_coords(self):
if self.type == 'LBNL/Klems Full':
vl_coords, f_indices = [], []
v_coords = [(0, 0)]
if self.sseg == 1:
va_coords = [(0, 0)]
va_coords += [(self.radii[self.sr] * cos((x*0.5 - 360/(2 * self.segments[self.sr]))*pi/180),
self.radii[self.sr] * sin((x*0.5 - 360/(2 * self.segments[self.sr]))*pi/180)) for x in range(720)]
fa_indices = [(0, x + (1, -719)[x > 0 and not x % 720], x) for x in range(1, 720 + 1)]
else:
va_coords = [(-self.radii[self.sr - 1] * cos((x*0.5 - 360/(2 * self.segments[self.sr]))*pi/180),
self.radii[self.sr - 1] * sin((x*0.5 - 360/(2 * self.segments[self.sr]))*pi/180)) for x in range(int((self.srs - 1) * 720/self.segments[self.sr]),
int((self.srs) * 720/self.segments[self.sr]) + 1)]
va_coords += [(-self.radii[self.sr] * cos((x*0.5 - 360/(2 * self.segments[self.sr]))*pi/180),
self.radii[self.sr] * sin((x*0.5 - 360/(2 * self.segments[self.sr]))*pi/180)) for x in range(int((self.srs - 1) * 720/self.segments[self.sr]),
int((self.srs)*720/self.segments[self.sr]) + 1)]
fa_indices = [(x, x+1, int(x+720/self.segments[self.sr] + 1)) for x in range(int(720/self.segments[self.sr]))] + \
[(x-1, x, int(x-720/self.segments[self.sr] - 1)) for x in range(int(720/self.segments[self.sr] + 2), int(1440/self.segments[self.sr] + 2))]
fa_colours = [(1, 1, 0.0, 1) for _ in range(len(va_coords))]
for ri, radius in enumerate(self.radii):
if ri < 8:
for si, s in enumerate(range(self.segments[ri + 1])):
vl_coords += [(radius * cos((360/self.segments[ri + 1] * si + 360/(2 * self.segments[ri + 1])) * pi/180),
radius * sin((360/self.segments[ri + 1] * si + 360/(2 * self.segments[ri + 1])) * pi/180)),
(self.radii[ri + 1] * cos((360/self.segments[ri + 1] * si + 360/(2 * self.segments[ri + 1])) * pi/180),
self.radii[ri + 1] * sin((360/self.segments[ri + 1] * si + 360/(2 * self.segments[ri + 1])) * pi/180))]
vl_coords1 = [[radius * cos((x*0.5 - 360/(2 * self.segments[ri]))*pi/180), radius * sin((x*0.5 - 360/(2 * self.segments[ri]))*pi/180)] for x in range(720)]
vl_coords2 = [[radius * cos(((x*0.5 + 0.5) - 360/(2 * self.segments[ri]))*pi/180), radius * sin(((x*0.5 + 0.5) - 360/(2 * self.segments[ri]))*pi/180)] for x in range(720)]
vl_coordstot = list(zip(vl_coords1, vl_coords2))
vl_coords += [item for sublist in vl_coordstot for item in sublist]
v_coords += vl_coords1
f_indices = [(0, x + (1, -719)[x > 0 and not x % 720], x) for x in range(1, 720*9 + 1)][::-1]
return (vl_coords, v_coords, f_indices, va_coords, fa_colours, fa_indices)
def create_batch(self, sel):
line_shader = gpu.types.GPUShaderCreateInfo()
line_shader.push_constant('MAT4', 'ModelViewProjectionMatrix')
line_shader.push_constant('VEC2', 'spos')
line_shader.push_constant('FLOAT', 'zpos')
line_shader.push_constant('VEC2', 'size')
line_shader.push_constant('VEC4', 'colour')
line_shader.vertex_in(0, 'VEC2', 'position')
line_shader.fragment_out(0, 'VEC4', 'FragColour')
line_shader.vertex_source(
'''
void main()
{
float xpos = spos[0] + position[0] * size[0];
float ypos = spos[1] + position[1] * size[1];
gl_Position = ModelViewProjectionMatrix * vec4(int(xpos), int(ypos), zpos, 1.0f);
vec4 pp = gl_Position;
}
'''
)
line_shader.fragment_source(
'''
void main()
{
FragColour = colour;
}
'''
)
arc_shader = gpu.types.GPUShaderCreateInfo()
arc_shader.push_constant('MAT4', 'ModelViewProjectionMatrix')
arc_shader.push_constant('VEC2', 'spos')
arc_shader.push_constant('VEC2', 'size')
arc_shader.push_constant('FLOAT', 'zpos')
arc_shader.vertex_in(0, 'VEC4', 'colour')
arc_shader.vertex_in(1, 'VEC2', 'position')
arc_shader_iface = gpu.types.GPUStageInterfaceInfo('arc_interface')
arc_shader_iface.flat('VEC4', 'a_colour')
arc_shader.vertex_out(arc_shader_iface)
arc_shader.fragment_out(0, 'VEC4', 'FragColour')
arc_shader.vertex_source(
'''
void main()
{
float xpos = spos[0] + position[0] * size[0];
float ypos = spos[1] + position[1] * size[1];
gl_Position = ModelViewProjectionMatrix * vec4(int(xpos), int(ypos), zpos, 1.0f);
a_colour = colour;
}
'''
)
arc_shader.fragment_source(
'''
void main()
{
FragColour = a_colour;
}
'''
)
(vl_coords, v_coords, f_indices, va_coords, fa_colours, fa_indices) = self.ret_coords()
if sel == 'all':
b_coords = [(0, 0), (0, 1), (1, 1), (1, 0)]
b_indices = [(0, 1, 3), (1, 2, 3)]
b_colours = [(1, 1, 1, 1), (1, 1, 1, 1), (1, 1, 1, 1), (1, 1, 1, 1)]
self.back_shader = gpu.shader.create_from_info(arc_shader)
self.arcline_shader = gpu.shader.create_from_info(line_shader)
self.image_shader = gpu.shader.from_builtin('IMAGE')
self.vi2_coords = [(self.lspos[0], self.lspos[1]), (self.lspos[0], self.lspos[1] + self.isize[1]), (self.lspos[0] + self.isize[0], self.lspos[1] + self.isize[1]), (self.lspos[0] + self.isize[0], self.lspos[1])]
self.image_batch = batch_for_shader(self.image_shader, 'TRI_FAN', {"pos": self.vi2_coords, "texCoord": self.tex_coords})
self.vi3_coords = [(self.lspos[0] + 50, self.lepos[1] - 280), (self.lspos[0] + 50, self.lepos[1] - 280 + self.iisize[1]), (self.lspos[0] + 50 + self.iisize[0], self.lepos[1] - 280 + self.iisize[1]), (self.lspos[0] + 50 + self.iisize[0], self.lepos[1] - 280)]
self.iimage_shader = gpu.shader.from_builtin('IMAGE')
self.iimage_batch = batch_for_shader(self.iimage_shader, 'TRI_FAN', {"pos": self.vi3_coords, "texCoord": self.tex_coords})
self.back_batch = batch_for_shader(self.back_shader, 'TRIS', {"position": b_coords, "colour": b_colours}, indices=b_indices)