-
Notifications
You must be signed in to change notification settings - Fork 14
/
dmx.py
2034 lines (1737 loc) · 75.4 KB
/
dmx.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
# Copyright Hugo Aboud, vanous
#
# This file is part of BlenderDMX.
#
# BlenderDMX 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 3 of the License, or (at your option)
# any later version.
#
# BlenderDMX 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, see <https://www.gnu.org/licenses/>.
import sys
import bpy
import os
from threading import Timer
import time
import json
import uuid as py_uuid
import re
from datetime import datetime
import traceback
from types import SimpleNamespace
import pymvr
from .mvr import load_mvr
from . import param as param
from . import fixture as fixture
from . import tracker as tracker
from .universe import DMX_Universe
from .data import DMX_Value, DMX_Data
from .gdtf import DMX_GDTF
from .artnet import DMX_ArtNet
from .acn import DMX_sACN
from .network import DMX_Network
from .logging import DMX_Log
from .blender_utils import copy_blender_profiles
from .panels import recorder as recorder
from .panels import setup as setup
from .panels.protocols import protocols as panels_protocols
from .panels.protocols import artnet as panels_artnet
from .panels.protocols import sacn as panels_sacn
from .panels.protocols import osc as panels_osc
from .panels.protocols import psn as panels_psn
from .panels.protocols import mvr as panels_mvr
from .panels.protocols import universes as panels_universes
from .panels.protocols import live as panels_live
from .panels import fixtures as fixtures
from .panels import groups as groups
from .panels import programmer as programmer
from .panels import profiles as Profiles
from .panels import distribute as distribute
from .panels import classing as classing
from .panels import subfixtures as subfixtures
from .preferences import DMX_Preferences, DMX_Regenrate_UUID
from .group import FixtureGroup, DMX_Group
from .osc_utils import DMX_OSC_Templates
from .osc import DMX_OSC
from .mdns import DMX_Zeroconf
from .node_arranger import DMX_OT_ArrangeSelected
from .util import rgb_to_cmy, ShowMessageBox, cmy_to_rgb, flatten_color, draw_top_message
from .mvr_objects import DMX_MVR_Object, DMX_MVR_Class
from .mvr_xchange import DMX_MVR_Xchange_Commit, DMX_MVR_Xchange_Client, DMX_MVR_Xchange
from .mvrx_protocol import DMX_MVR_X_Client, DMX_MVR_X_Server
import bpy.utils.previews
from .material import set_light_nodes, get_gobo_material
from bpy.props import (BoolProperty,
StringProperty,
IntProperty,
FloatProperty,
FloatVectorProperty,
PointerProperty,
EnumProperty,
CollectionProperty)
from bpy.types import (PropertyGroup,
Object,
Collection,
NodeTree)
from .i18n import DMX_Lang
_ = DMX_Lang._
class DMX(PropertyGroup):
# Base classes to be registered
# These should be registered before the DMX class, so it can register properly
classes_base = (param.DMX_Param,
param.DMX_Model_Param,
fixture.DMX_Fixture_Object,
fixture.DMX_Fixture_Image,
fixture.DMX_Emitter_Material,
fixture.DMX_IES_Data,
fixture.DMX_Geometry_Node,
fixture.DMX_Fixture_Channel,
fixture.DMX_Fixture,
tracker.DMX_Tracker_Object,
tracker.DMX_Tracker,
DMX_MVR_Object,
DMX_Group,
DMX_MVR_Class,
DMX_Universe,
DMX_Value,
setup.DMX_PT_Setup,
panels_mvr.DMX_OP_MVR_Download,
panels_mvr.DMX_OP_MVR_Import,
DMX_MVR_Xchange_Commit,
DMX_MVR_Xchange_Client,
DMX_MVR_Xchange,
DMX_Regenrate_UUID,
DMX_Preferences,
subfixtures.DMX_Subfixture)
# Classes to be registered
# The registration is done in two steps. The second only runs
# after the user requests to setup the addon.
classes_setup = (setup.DMX_OT_Setup_NewShow,)
classes = ( panels_protocols.DMX_PT_DMX,
panels_universes.DMX_UL_Universe,
panels_universes.DMX_MT_Universe,
panels_universes.DMX_PT_DMX_Universes,
panels_live.DMX_PT_DMX_LiveDMX,
panels_artnet.DMX_PT_DMX_ArtNet,
panels_sacn.DMX_PT_DMX_sACN,
setup.DMX_OT_Setup_Volume_Create,
setup.DMX_PT_Setup_Volume,
setup.DMX_PT_Setup_Viewport,
setup.DMX_PT_Setup_Logging,
setup.DMX_OT_Setup_Open_LogFile,
setup.DMX_PT_Setup_Import,
setup.DMX_PT_Setup_Export,
setup.DMX_PT_Setup_Extras,
fixtures.DMX_MT_Fixture,
fixtures.DMX_MT_Fixture_Manufacturers,
fixtures.DMX_MT_Fixture_Profiles,
fixtures.DMX_MT_Fixture_Mode,
fixtures.DMX_OT_Fixture_Item,
fixtures.DMX_OT_Fixture_Profiles,
fixtures.DMX_OT_Fixture_Mode,
panels_live.DMX_UL_LiveDMX_items,
fixtures.DMX_OT_Fixture_Add,
fixtures.DMX_OT_Fixture_Edit,
fixtures.DMX_OT_Fixture_Remove,
setup.DMX_OT_Export_Custom_Data,
setup.DMX_OT_Import_Custom_Data,
setup.DMX_OT_Clear_Custom_Data,
setup.DMX_OT_Copy_Custom_Data,
setup.DMX_OT_Setup_RemoveDMX,
setup.DMX_OT_Reload_Addon,
fixtures.DMX_OT_IES_Import,
fixtures.DMX_OT_IES_Remove,
fixtures.DMX_PT_Fixtures,
groups.DMX_UL_Group,
groups.DMX_MT_Group,
groups.DMX_OT_Group_Create,
groups.DMX_OT_Group_Update,
groups.DMX_OT_Group_Rename,
groups.DMX_OT_Group_Remove,
groups.DMX_PT_Groups,
classing.DMX_UL_Class,
classing.DMX_PT_Classes,
subfixtures.DMX_PT_Subfixtures,
subfixtures.DMX_UL_Subfixture,
subfixtures.DMX_OT_Subfixture_Clear,
subfixtures.DMX_OT_Subfixture_SelectVisible,
programmer.DMX_OT_Programmer_DeselectAll,
programmer.DMX_OT_Programmer_SelectAll,
programmer.DMX_OT_Programmer_SelectFiltered,
programmer.DMX_OT_Programmer_SelectInvert,
programmer.DMX_OT_Programmer_SelectEveryOther,
programmer.DMX_OT_Programmer_Clear,
programmer.DMX_OT_Programmer_SelectBodies,
programmer.DMX_OT_Programmer_SelectTargets,
programmer.DMX_OT_Programmer_SelectCamera,
programmer.DMX_OT_Programmer_TargetsToZero,
programmer.DMX_OT_Programmer_CenterToSelected,
programmer.DMX_OT_Programmer_Apply_Manually,
programmer.DMX_OT_Programmer_Set_Ignore_Movement,
programmer.DMX_OT_Programmer_Reset_Color,
programmer.DMX_OT_Programmer_ResetTargets,
programmer.DMX_MT_PIE_Reset,
programmer.DMX_OT_Programmer_Unset_Ignore_Movement,
programmer.DMX_OT_Programmer_Set_Lock_Movement_Rotation,
distribute.DMX_PT_AlignAndDistributePanel,
distribute.DMX_OP_AlignLocationOperator,
distribute.DMX_OP_DistributeWithGapOperator,
distribute.DMX_OP_DistributeEvenlyOperator,
distribute.DMX_OP_DistributeCircle,
panels_osc.DMX_PT_DMX_OSC,
panels_psn.DMX_UL_Tracker,
panels_psn.DMX_OP_DMX_Tracker_Add,
panels_psn.DMX_OP_DMX_Tracker_Remove,
panels_psn.DMX_PT_DMX_Trackers,
panels_psn.DMX_OT_Tracker_Followers,
panels_psn.DMX_OT_Tracker_Followers_Add_Target,
panels_psn.DMX_OT_Tracker_Followers_Remove_Target,
panels_psn.DMX_UL_Tracker_Followers,
panels_psn.DMX_OP_Unlink_Fixture_Tracker,
panels_psn.DMX_OP_Link_Fixture_Tracker,
fixtures.DMX_UL_Fixtures,
panels_mvr.DMX_PT_DMX_MVR_X,
panels_mvr.DMX_UL_MVR_Commit,
panels_mvr.DMX_OP_MVR_Refresh,
panels_mvr.DMX_OP_MVR_Request,
fixtures.DMX_OT_Fixture_ForceRemove,
fixtures.DMX_OT_Fixture_SelectNext,
fixtures.DMX_OT_Fixture_SelectPrevious,
fixtures.DMX_OT_Fixture_SelectNextTarget,
fixtures.DMX_OT_Fixture_SelectPreviousTarget,
setup.DMX_OT_VersionCheck,
programmer.DMX_PT_Programmer,
recorder.DMX_OT_Recorder_AddKeyframe,
recorder.DMX_PT_Recorder,
recorder.DMX_PT_DMX_Recorder_Delete,
recorder.DMX_OT_Recorder_Delete_Keyframes_Selected,
recorder.DMX_OT_Recorder_Delete_Keyframes_All,
setup.DMX_OT_Fixture_Set_Cycles_Beams_Size_Small,
setup.DMX_OT_Fixture_Set_Cycles_Beams_Size_Normal)
linkedToFile = False
_keymaps = []
fixtures_filter = []
custom_icons = None
def register():
#custom icons
DMX.custom_icons = bpy.utils.previews.new()
ADDON_PATH = os.path.dirname(os.path.abspath(__file__))
path = os.path.join(ADDON_PATH, "assets", "icons")
DMX.custom_icons.load("DEFAULT_TEST", os.path.join(path, "erlenmeyer.png"), "IMAGE")
DMX.custom_icons.load("PRODUCTION_ASSIST", os.path.join(path, "pa.png"), "IMAGE")
DMX.custom_icons.load("GMA3", os.path.join(path, "ma.png"), "IMAGE")
DMX.custom_icons.load("GDTF_FILE", os.path.join(path, "gdtf_file_icon_small.png"), "IMAGE")
DMX.custom_icons.load("MVR_FILE", os.path.join(path, "mvr_file_icon_small.png"), "IMAGE")
for cls in DMX.classes_setup:
bpy.utils.register_class(cls)
# register key shortcuts
wm = bpy.context.window_manager
km = wm.keyconfigs.addon.keymaps.new(name='3D View Generic', space_type='VIEW_3D')
kmi = km.keymap_items.new('dmx.fixture_next', 'RIGHT_ARROW', 'PRESS', ctrl=True, shift=False)
DMX._keymaps.append((km, kmi))
kmi = km.keymap_items.new('dmx.fixture_previous', 'LEFT_ARROW', 'PRESS', ctrl=True, shift=False)
DMX._keymaps.append((km, kmi))
kmi = km.keymap_items.new('dmx.fixture_next_target', 'RIGHT_ARROW', 'PRESS', ctrl=True, shift=True)
DMX._keymaps.append((km, kmi))
kmi = km.keymap_items.new('dmx.fixture_previous_target', 'LEFT_ARROW', 'PRESS', ctrl=True, shift=True)
DMX._keymaps.append((km, kmi))
kmi = km.keymap_items.new('dmx.reload_addon', 'R', 'PRESS', ctrl=True, alt=True)
DMX._keymaps.append((km, kmi))
def unregister():
# unregister keymaps
for km, kmi in DMX._keymaps: km.keymap_items.remove(kmi)
DMX._keymaps.clear()
bpy.utils.previews.remove(DMX.custom_icons)
if (DMX.linkedToFile):
for cls in DMX.classes:
bpy.utils.unregister_class(cls)
DMX.linkedToFile = False
else:
for cls in DMX.classes_setup:
bpy.utils.unregister_class(cls)
# Blender RNA Properties
# fixture listing columns
column_fixture_id: BoolProperty(
name = _("Fixture ID"),
default = True)
column_unit_number: BoolProperty(
name = _("Unit Number"),
default = False)
column_custom_id: BoolProperty(
name = _("Custom ID"),
default = False)
column_fixture_id_numeric: BoolProperty(
name = "Fixture ID Numeric",
default = False)
column_dmx_address: BoolProperty(
name = _("DMX Address"),
default = True)
column_fixture_position: BoolProperty(
name = _("Position"),
default = False)
column_fixture_rotation: BoolProperty(
name = _("Rotation"),
default = False)
column_fixture_footprint: BoolProperty(
name = _("Footprint"),
default = False)
collection: PointerProperty(
name = _("DMX Collection"),
type = Collection)
volume: PointerProperty(
name = "Volume Scatter Box",
type = Object)
volume_nodetree: PointerProperty(
name = "Volume Scatter Shader Node Tree",
type = NodeTree)
# DMX Properties
# These should be parsed to file
fixtures: CollectionProperty(
name = "DMX Fixtures",
type = fixture.DMX_Fixture)
trackers: CollectionProperty(
name = "PSN Servers",
type = tracker.DMX_Tracker)
trackers_i : IntProperty(
name = _("Selected PSN Server"),
description=_("The selected element on the PSN server list"),
default = 0
)
groups: CollectionProperty(
name = "DMX Groups",
type = DMX_Group)
classing: CollectionProperty(
name = "DMX MVR Classes",
type = DMX_MVR_Class)
class_list_i : IntProperty(
name = _("Class List i"),
description=_("The selected element on the class list"),
default = 0,
)
universes: CollectionProperty(
name = "DMX Groups",
type = DMX_Universe)
mvr_objects: CollectionProperty(
name = "MVR Objects",
type = DMX_MVR_Object)
def prepare_empty_buffer(self, context):
# Clear the buffer on change of every protocol
DMX_Data.prepare_empty_buffer()
def get_dmx_universes(self, context):
data = []
for universe in self.universes:
data.append((str(universe.id), universe.name, str(universe.input), "", universe.id))
return data
def get_selected_live_dmx_universe(self):
selected_universe = None
for universe in self.universes:
selected_universe = universe
if self.selected_live_dmx == str(universe.id):
break
return selected_universe
def reset_live_dmx_data(self, context):
DMX_Data._live_view_data = [0] * 512
selected_live_dmx: EnumProperty(
name = _("Universe"),
description="",
update = reset_live_dmx_data,
items = get_dmx_universes
)
dmx_values: CollectionProperty( # this only creates an array which is used for live view panel.
name = "DMX buffer", # but the values themselves come from DMX_Data class because
type = DMX_Value # updating this RNA many times per second crashed blender
)
dmx_value_index: IntProperty() # Unused, but the live DMX UI Panel requires it
data_version: IntProperty(
name = "BlenderDMX data version, bump when changing RNA structure and provide migration script",
default = 11,
)
def get_fixture_by_index(self, index):
for idx, fixture in enumerate(self.fixtures):
if idx == index:
return fixture
def on_ui_selection_change(self, context):
""" If fixture selection is changed via UILists 'normal' interaction, rather then an operator.
Not currently used, as this starts to create circular updates and we would need to pass info
if fixture was actually being selected or unselected.
"""
return
for idx, fixture in enumerate(self.fixtures):
if idx == self.selected_fixture_index:
if not fixture.is_selected():
#fixture.toggleSelect()
fixture.select()
return
selected_fixture_index: IntProperty(
default = 0,
update = on_ui_selection_change
) # Just a fake value, we need as the Fixture list requires it
fixture_properties_editable: BoolProperty(
name = _("Editable"),
default = False)
# New DMX Scene
# - Remove any previous DMX objects/collections
# - Create DMX collection
# - Create DMX universes
# - Link to file
def new(self):
# Remove old DMX collection from file if present
if ("DMX" in bpy.data.collections):
bpy.data.collections.remove(bpy.data.collections["DMX"])
# Remove old Volume object from file if present
if ("DMX_Volume" in bpy.data.objects):
bpy.data.objects.remove(bpy.data.objects["DMX_Volume"])
# Create a new DMX collection on the file
bpy.ops.collection.create(name="DMX")
collection = bpy.data.collections["DMX"]
# Unlink any objects or collections
for c in collection.objects:
collection.objects.unlink(c)
for c in collection.children:
collection.children.unlink(c)
# Link collection to scene
bpy.context.scene.collection.children.link(collection)
# Set background to black (so it match the panel)
scene = bpy.context.scene
if scene.world is None:
# create a new world
new_world = bpy.data.worlds.new("New World")
new_world.use_nodes = True
scene.world = new_world
world = scene.world
world.use_nodes = True
SHADER_NODE_BG = bpy.app.translations.pgettext("ShaderNodeBackground")
SHADER_NODE_WO = bpy.app.translations.pgettext("ShaderNodeOutputWorld")
new_link = False
if "Background" not in world.node_tree.nodes:
bg=world.node_tree.nodes.new(SHADER_NODE_BG)
bg.name="Background"
new_link = True
else:
bg=world.node_tree.nodes["Background"]
if "World Output" not in world.node_tree.nodes:
wo = world.node_tree.nodes.new(SHADER_NODE_WO)
wo.name = "World Output"
new_link = True
else:
wo = world.node_tree.nodes["World Output"]
if new_link:
world.node_tree.links.new(bg.outputs[0], wo.inputs[0])
scene.world.node_tree.nodes['Background'].inputs[0].default_value = (0,0,0,1)
# Create a DMX universe
self.addUniverse()
# Link addon to file
self.linkFile()
# Link Add-on to file
# This is only called on two situations: "Create New Show" or "onLoadFile"
# - Link DMX Collection (if present)
# - Link Volume Object (if present)
# - If DMX collection was linked, register addon
# - Allocate static universe data
def linkFile(self):
print("INFO", "Linking to file")
DMX_Log.enable(self.logging_level)
DMX_Log.log.info("BlenderDMX: Linking to file")
# Link pointer properties to file objects
if ("DMX" in bpy.data.collections):
self.collection = bpy.data.collections["DMX"]
else:
self.collection = None
if ("DMX_Volume" in bpy.data.objects):
self.volume = bpy.data.objects["DMX_Volume"]
else:
self.volume = None
DMX_Log.log.info(f"DMX collection: {self.collection}")
DMX_Log.log.info(f"DMX_Volume object: {self.volume}")
if (self.collection):
# Second step registration (if not already registered)
if (not DMX.linkedToFile):
for cls in self.classes:
bpy.utils.register_class(cls)
DMX.linkedToFile = True
# Sync number of universes
self.universes_n = len(self.universes)
# Allocate universes data
DMX_Data.setup(self.universes_n)
# make sure that selection of ip address points to an item in enum
dmx = bpy.context.scene.dmx
if not len(dmx.artnet_ipaddr):
if len(DMX_Network.cards(None, None)):
dmx.artnet_ipaddr = DMX_Network.cards(None, None)[0][0]
else:
DMX_Log.log.warning("No network card detected")
return
# Reset network status
dmx = bpy.context.scene.dmx
if (dmx.artnet_enabled and dmx.artnet_status != 'online'):
dmx.artnet_enabled = False
dmx.artnet_status = 'offline'
if (dmx.sacn_enabled and dmx.sacn_status != 'online'):
dmx.sacn_enabled = False
dmx.sacn_status = 'offline'
if dmx.osc_enabled:
dmx.osc_enabled = False
for tracker_item in dmx.trackers:
tracker_item.enabled = False
if not len(tracker_item.ip_address):
if len(DMX_Network.cards(None, None)):
tracker_item.ip_address = DMX_Network.cards(None, None)[0][0]
else:
DMX_Log.log.warning("No network card detected")
# Rebuild group runtime dictionary (evaluating if this is gonna stay here)
#DMX_Group.runtime = {}
#for group in self.groups:
# group.rebuild()
self.logging_level = "DEBUG" # setting high logging level to see initialization
try:
self.migrations()
except Exception as e:
traceback.print_exception(e)
self.ensure_application_uuid()
# enable in extension
self.ensure_directories_exist()
Timer(1, self.copy_default_profiles_to_user_folder, ()).start()
#self.copy_default_profiles_to_user_folder()
self.check_python_version()
self.check_blender_version()
if bpy.app.version >= (4, 2):
# do not do version check online in 4.2 and up
pass
else:
Timer(1, bpy.ops.dmx.check_version, ()).start()
DMX_GDTF.getManufacturerList()
Profiles.DMX_Fixtures_Local_Profile.loadLocal()
Profiles.DMX_Fixtures_Import_Gdtf_Profile.loadShare()
self.logging_level = "ERROR" # setting default logging level
# Unlink Add-on from file
# This is only called when the DMX collection is externally removed
def unlinkFile(self):
print("INFO", "Unlinking from file")
# Unlink pointer properties
self.collection = None
self.volume = None
# Second step unregistration
if (DMX.linkedToFile):
for cls in self.classes:
bpy.utils.unregister_class(cls)
DMX.linkedToFile = False
# Callback Properties
# # Setup > Background > Color
def check_python_version(self):
if not sys.version_info >= (3, 8):
DMX_Log.log.error(f"Python version of at least 3.8 is needed, you are using {sys.version} ❌")
return
DMX_Log.log.info(f"Python version: {sys.version} ✅")
def check_blender_version(self):
if not bpy.app.version >= (3, 4):
DMX_Log.log.error(f"Blender version of at least 3.4 is needed, you are using {bpy.app.version} ❌")
return
DMX_Log.log.info(f"Blender version: {bpy.app.version} ✅")
def ensure_directories_exist(self):
list_paths=[]
list_paths.append(os.path.join("assets", "profiles"))
list_paths.append(os.path.join("assets", "models"))
list_paths.append(os.path.join("assets", "models", "mvr"))
list_paths.append(os.path.join("assets", "mvrs"))
for path in list_paths:
bpy.utils.extension_path_user(__package__, path=path, create=True)
def copy_default_profiles_to_user_folder(self):
copy_blender_profiles()
DMX_GDTF.getManufacturerList()
Profiles.DMX_Fixtures_Local_Profile.loadLocal()
def ensure_application_uuid(self):
prefs = bpy.context.preferences.addons[__package__].preferences
application_uuid = prefs.get("application_uuid", 0)
if application_uuid == 0:
prefs["application_uuid"] = str(py_uuid.uuid4()) # must never be 0
def migrations(self):
"""Provide migration scripts when bumping the data_version"""
file_data_version = 1 # default data version before we started setting it up
hide_gobo_message = False
if ("DMX_DataVersion" in self.collection):
file_data_version = self.collection["DMX_DataVersion"]
DMX_Log.log.info(f"Data version: {file_data_version}")
if file_data_version < 2: # migration for sw. version 0.5 → 1.0
DMX_Log.log.info("Running migration 1→2")
dmx = bpy.context.scene.dmx
for fixture in dmx.fixtures:
for obj in fixture.objects:
if any(obj.name == name for name in ['Body', 'Base']):
DMX_Log.log.info(f"updating {obj.name}")
obj.name = 'Root'
for light in fixture.lights:
DMX_Log.log.info("Adding shutter and dimmer value fields to light object")
if "shutter_value" not in light.object.data:
light.object.data["shutter_value"] = 0
if "shutter_dimmer_value" not in light.object.data:
light.object.data["shutter_dimmer_value"] = 0
if "shutter_counter" not in light.object.data:
light.object.data["shutter_counter"] = 0
if file_data_version < 3:
hide_gobo_message = True
DMX_Log.log.info("Running migration 2→3")
dmx = bpy.context.scene.dmx
DMX_Log.log.info("Add UUID to fixtures")
for fixture in dmx.fixtures:
if "uuid" not in fixture:
DMX_Log.log.info(f"Adding UUID to {fixture.name}")
fixture.uuid = str(py_uuid.uuid4())
DMX_Log.log.info("Add UUID to groups, convert groups to json")
for group in dmx.groups:
if "uuid" not in group:
DMX_Log.log.info("Adding UUID to {group.name}")
group.uuid = str(py_uuid.uuid4())
DMX_Log.log.info("Migrating group")
group.dump = json.dumps([x[1:-1] for x in group.dump.strip('[]').split(', ')])
if file_data_version < 4:
DMX_Log.log.info("Running migration 3→4")
dmx = bpy.context.scene.dmx
def findFixtureUuidDuplicates(uuid):
found = []
for fixture in self.fixtures:
if fixture is None:
continue
if fixture.uuid == uuid:
found.append(fixture)
return found
def findGroupUuidDuplicates(uuid):
found = []
for group in self.groups:
if group is None:
continue
if group.uuid == uuid:
found.append(group)
return found
DMX_Log.log.info("Ensure unique fixture UUID")
duplicates = []
for fixture in dmx.fixtures:
duplicates = findFixtureUuidDuplicates(fixture.uuid)
if len(duplicates) > 1:
for fixture in duplicates:
u = fixture.uuid
fixture.uuid = str(py_uuid.uuid4())
DMX_Log.log.info(("Updating fixture", fixture.name, u, fixture.uuid))
DMX_Log.log.info("Ensure unique group UUID")
duplicates = []
for group in dmx.groups:
duplicates = findGroupUuidDuplicates(group.uuid)
if len(duplicates) > 1:
for group in duplicates:
u = group.uuid
group.uuid = str(py_uuid.uuid4())
DMX_Log.log.info(("Updating group", group.name, u, group.uuid))
DMX_Log.log.info("Convert groups from fixture names to UUIDs")
for group in dmx.groups:
grouped_fixtures = json.loads(group.dump)
uuid_list = []
for g_fixture in grouped_fixtures:
if g_fixture in dmx.fixtures:
fixture = dmx.fixtures[g_fixture]
if fixture is not None:
uuid_list.append(fixture.uuid)
group.dump = json.dumps(uuid_list)
DMX_Log.log.info("Groups updated")
if file_data_version < 5:
DMX_Log.log.info("Running migration 4→5")
dmx = bpy.context.scene.dmx
for fixture in dmx.fixtures:
if "dmx_values" not in fixture:
DMX_Log.log.info("Adding dmx_value array to fixture")
fixture["dmx_values"] = []
if file_data_version < 6:
DMX_Log.log.info("Running migration 5→6")
DMX_Log.log.info("To make gobos working again, edit fixtures with gobos - re-load GDTF files (Fixtures → Edit, uncheck Re-address only)")
if file_data_version < 7:
DMX_Log.log.info("Running migration 6→7")
dmx = bpy.context.scene.dmx
for fixture in dmx.fixtures:
for light in fixture.lights:
DMX_Log.log.info("Adding nodes to light")
set_light_nodes(light)
if "DMX_Volume" in bpy.data.objects:
objs = bpy.data.objects
objs.remove(objs["DMX_Volume"], do_unlink=True)
DMX_Log.log.info("Removing Volume box due to old structure, you need to create it new")
if "DMX_Volume" in bpy.data.materials:
objs = bpy.data.materials
objs.remove(objs["DMX_Volume"], do_unlink=True)
DMX_Log.log.info("Removing Volume box material due to old structure, you need to create it new")
if file_data_version < 8:
DMX_Log.log.info("Running migration 7→8")
dmx = bpy.context.scene.dmx
for fixture in dmx.fixtures:
if "slot_colors" not in fixture:
DMX_Log.log.info("Adding slot_colors array to fixture")
fixture["slot_colors"] = []
if file_data_version < 9:
DMX_Log.log.info("Running migration 8→9")
dmx = bpy.context.scene.dmx
for fixture in dmx.fixtures:
fixture.gel_color_rgb = list(int((255/1)*i) for i in fixture.gel_color[:3])
DMX_Log.log.info("Converting gel color to rgb")
if file_data_version < 10:
DMX_Log.log.info("Running migration 9→10")
dmx = bpy.context.scene.dmx
for fixture in dmx.fixtures:
for obj in fixture.objects:
if 'Target' in obj.name:
if "uuid" not in obj.object:
DMX_Log.log.info(f"Add uuid to {obj.name}")
obj.object["uuid"] = str(py_uuid.uuid4())
if file_data_version < 11:
DMX_Log.log.info("Running migration 10→11")
dmx = bpy.context.scene.dmx
d=DMX_OT_ArrangeSelected()
for fixture in dmx.fixtures:
fixture.gobo_materials.clear()
for obj in fixture.collection.objects:
if "gobo" in obj.get("geometry_type", ""):
material = fixture.gobo_materials.add()
material.name = obj.name
gobo_material = get_gobo_material(obj.name)
obj.active_material = gobo_material
obj.active_material.shadow_method = "CLIP"
obj.active_material.blend_method = "BLEND"
obj.material_slots[0].link = 'OBJECT' # ensure that each fixture has it's own material
obj.material_slots[0].material = gobo_material
material.material = gobo_material
DMX_Log.log.info(f"Recreate gobo material {fixture.name}")
for light in fixture.lights:
set_light_nodes(light)
if len(fixture.images)>0:
old_gobos = fixture.images["gobos"]
if old_gobos is not None:
gobo1 = fixture.images.add()
gobo1.name = "gobos1"
gobo1.image = old_gobos.image
gobo1.count = old_gobos.count
gobo2 = fixture.images.add()
gobo2.name = "gobos2"
gobo2.image = old_gobos.image
gobo2.count = old_gobos.count
fixture.hide_gobo()
for item in fixture.gobo_materials:
ntree = item.material.node_tree
d.process_tree(ntree)
for item in fixture.geometry_nodes:
ntree = item.node
d.process_tree(ntree)
for light in fixture.lights: #CYCLES
light_obj = light.object
ntree = light_obj.data.node_tree
d.process_tree(ntree)
if not hide_gobo_message:
temp_data = bpy.context.window_manager.dmx
message = "This show file has been made in older version of BlenderDMX. Most likely you need to re-edit fixtures: Fixtures → Edit, uncheck Re-address only, this will re-build the fixtures from their GDTF files. Sorry for the inconvenience."
temp_data.migration_message = message
ShowMessageBox(message=message,title="Updating info!",icon="ERROR")
bpy.types.VIEW3D_HT_tool_header.prepend(draw_top_message)
DMX_Log.log.info("Migration done.")
# add here another if statement for next migration condition... like:
# if file_data_version < 6: #...
self.collection["DMX_DataVersion"] = self.data_version # set data version to current
def onBackgroundColor(self, context):
context.scene.world.node_tree.nodes['Background'].inputs[0].default_value = self.background_color
background_color: FloatVectorProperty(
name = "Background Color",
subtype = "COLOR",
size = 4,
min = 0.0,
max = 1.0,
default = (0.0,0.0,0.0,1.0),
update = onBackgroundColor
)
# # Setup > Models > Display Pigtails, Select geometries
def onDisplayLabel(self, context):
for fixture in self.fixtures:
for obj in fixture.collection.objects:
if obj.get("geometry_root", False):
if self.display_device_label == "NONE":
obj.show_name = False
elif self.display_device_label == "NAME":
obj.name = f"{fixture.name}"
obj.show_name = self.enable_device_label
elif self.display_device_label == "DMX":
obj.name = f"{fixture.universe}.{fixture.address}"
obj.show_name = self.enable_device_label
elif self.display_device_label == "FIXTURE_ID":
if fixture.fixture_id:
obj.name = f"{fixture.fixture_id}"
obj.show_name = self.enable_device_label
else:
obj.show_name = False
break
def onDisplayPigtails(self, context):
for fixture in self.fixtures:
for obj in fixture.collection.objects:
if "pigtail" in obj.get("geometry_type", ""):
obj.hide_set(not self.display_pigtails)
obj.hide_viewport = not self.display_pigtails
obj.hide_render = not self.display_pigtails
def onDisplay2D(self, context):
bpy.context.window_manager.dmx.pause_render = True # this stops the render loop, to prevent slowness and crashes
if self.display_2D:
self.volume_enabled = False
area = [area for area in bpy.context.window.screen.areas if area.type == "VIEW_3D"][0]
with bpy.context.temp_override(
window=bpy.context.window,
area=area,
region=[region for region in area.regions if region.type == 'WINDOW'][0],
screen=bpy.context.window.screen
):
bpy.ops.view3d.view_axis(type='TOP', align_active=True)
bpy.ops.view3d.view_selected()
area.spaces[0].shading.type = 'MATERIAL'
for fixture in self.fixtures:
for obj in fixture.collection.objects:
if obj.get("2d_symbol", None) == "all":
obj.hide_set(not self.display_2D)
obj.hide_viewport = not self.display_2D
obj.hide_render = not self.display_2D
if self.display_device_label == "NONE":
obj.show_name = False
elif self.display_device_label == "NAME":
obj.name = f"{fixture.name}"
obj.show_name = True
elif self.display_device_label == "DMX":
obj.name = f"{fixture.universe}.{fixture.address}"
obj.show_name = True
elif self.display_device_label == "FIXTURE_ID":
if fixture.fixture_id:
obj.name = f"{fixture.fixture_id}"
obj.show_name = True
else:
obj.show_name = False
else:
obj.hide_set(self.display_2D)
obj.hide_viewport = self.display_2D
obj.hide_render = self.display_2D
if "pigtail" in obj.get("geometry_type", ""):
obj.hide_set(not self.display_pigtails)
obj.hide_viewport = not self.display_pigtails
obj.hide_render = not self.display_pigtails
bpy.context.window_manager.dmx.pause_render = self.display_2D # re-enable renderer if in 3D
def update_device_label(self, context):
self.onDisplay2D(context)
self.onDisplayLabel(context)
display_pigtails: BoolProperty(
name = _("Display Pigtails"),
default = False,
update = onDisplayPigtails)
display_2D: BoolProperty(
name = _("Display 2D View"),
default = False,
update = onDisplay2D)
enable_device_label: BoolProperty(
name = _("Display Device Label"),
default = False,
update = onDisplayLabel)
display_device_label: EnumProperty(
name = _("Device Label"),
default = "NAME",
items= [
("NONE", _("None"), "Do not display any label"),
("NAME", _("Name"), "Name"),
("DMX", _("DMX"), "DMX Address"),
("FIXTURE_ID", _("Fixture ID"), "Fixture ID"),
],
update = update_device_label)
def onSelectGeometries(self, context):
for fixture in self.fixtures:
for obj in fixture.collection.objects:
if obj.get("geometry_root", False):
continue
if obj.get("2d_symbol", None):
continue
if "Target" in obj.name:
continue
obj.hide_select = not self.select_geometries
select_geometries: BoolProperty(
name = _("Allow Selecting Geometries"),
default = False,