-
Notifications
You must be signed in to change notification settings - Fork 14
/
fixture.py
1730 lines (1454 loc) · 74.8 KB
/
fixture.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 traceback
import bpy
import math
import mathutils
import random
import os
import uuid as py_uuid
from .material import getEmitterMaterial, get_gobo_material, set_light_nodes, get_ies_node, getGeometryNodes
from .model import DMX_Model
from .logging import DMX_Log
import pygdtf
import pymvr
from .gdtf import DMX_GDTF
from .data import DMX_Data
from .util import cmy_to_rgb, add_rgb, colors_to_rgb, rgb2xyY, kelvin_table
from .osc_utils import DMX_OSC_Handlers
from bpy.props import (IntProperty,
BoolProperty,
FloatVectorProperty,
IntVectorProperty,
PointerProperty,
StringProperty,
CollectionProperty)
from bpy.types import (PropertyGroup,
Collection,
Object,
Image,
Material,
GeometryNodeTree,
Text)
from .node_arranger import DMX_OT_ArrangeSelected
# Shader Nodes default labels
# Blender API naming convention is inconsistent for internationalization
# Every label used is listed here, so it's easier to fix it on new API updates
STRENGTH = "Strength"
COLOR = "Color"
class DMX_Manufacturer(PropertyGroup):
name: StringProperty (
name = "Name",
description = "Name of the manufacturer",
default = "Manufacturer 0")
manufacturers: CollectionProperty(
name = "Manufacturers",
description = "Fixture GDTF Manufacturers",
type = DMX_Manufacturer
)
class DMX_Fixture_Object(PropertyGroup):
object: PointerProperty(
name = "Fixture > Object",
type = Object)
class DMX_Fixture_Image(PropertyGroup):
image: PointerProperty(
name = "Fixture > Image",
type = Image)
count: IntProperty(
default = 0
)
class DMX_Emitter_Material(PropertyGroup):
material: PointerProperty(
name = "Emitter > Material",
type = Material)
class DMX_Geometry_Node(PropertyGroup):
node: PointerProperty(
name = "Geometry Node",
type = GeometryNodeTree)
class DMX_IES_Data(PropertyGroup):
ies: PointerProperty(
name = "Spot > IES",
type = Text)
class DMX_Fixture_Channel(PropertyGroup):
id: StringProperty(
name = "Fixture > Channel > ID",
default = '')
default: IntProperty(
name = "Fixture > Channel > Default",
default = 0)
geometry: StringProperty(
name = "Fixture > Geometry",
default = '')
class DMX_Fixture(PropertyGroup):
# Blender RNA #
collection: PointerProperty(
name = "Fixture > Collection",
type = Collection)
objects: CollectionProperty(
name = "Fixture > Objects",
type = DMX_Fixture_Object
)
lights: CollectionProperty(
name = "Fixture > Lights",
type = DMX_Fixture_Object
)
images: CollectionProperty(
name = "Fixture > Images",
type = DMX_Fixture_Image
)
emitter_materials: CollectionProperty(
name = "Fixture > Materials",
type = DMX_Emitter_Material)
geometry_nodes: CollectionProperty(
name = "Fixture > Geometry Nodes",
type = DMX_Geometry_Node)
gobo_materials: CollectionProperty(
name = "Fixture > Gobo Materials",
type = DMX_Emitter_Material)
ies_data: CollectionProperty(
name = "Fixture > IES Files",
type = DMX_IES_Data)
# DMX properties
profile: StringProperty(
name = "Fixture > Profile",
default = "")
mode : StringProperty(
name = "Fixture > Mode",
description="Fixture DMX Mode",
default = '')
channels: CollectionProperty(
name = "Fixture > Channels",
type = DMX_Fixture_Channel
)
virtual_channels: CollectionProperty(
name = "Fixture > Virtual Channels",
type = DMX_Fixture_Channel
)
gdtf_long_name: StringProperty(
name = "Fixture > Name",
default = "")
gdtf_manufacturer: StringProperty(
name = "Fixture > Manufacturer",
default = "")
def ensure_universe_exists(self, context):
dmx = bpy.context.scene.dmx
dmx.ensureUniverseExists(self.universe)
universe : IntProperty(
name = "Fixture > Universe",
description="Fixture DMX Universe",
default = 0,
min = 0,
max = 511,
update = ensure_universe_exists
)
address : IntProperty(
name = "Fixture > Address",
description="Fixture DMX Address",
default = 1,
min = 1,
max = 512)
uuid: StringProperty(
name = "UUID",
description = "Unique ID, used for MVR",
default = str(py_uuid.uuid4())
)
fixture_id: StringProperty(
name = "FixtureID",
description = "The Fixture ID is an identifier for the instance of this fixture that can be used to activate / select them for programming.",
default = ""
)
unit_number: IntProperty(
name = "UnitNumber",
description = "The identification of a fixture on its position. Use this as an alternative numbering scheme if the planning and programming numbering is different.",
default = 0
)
fixture_id_numeric: IntProperty(
name = "FixtureIDNumeric",
description = "The Fixture ID is an identifier for the instance of this fixture that can be used to activate / select them for programming.",
default = 0
)
custom_id: IntProperty(
name = "CustomId",
description = "The Fixture ID is an identifier for the instance of this fixture that can be used to activate / select them for programming.",
default = 0
)
display_beams: BoolProperty(
name = "Display beams",
description="Display beam projection and cone",
default = True)
add_target: BoolProperty(
name = "Add Target",
description="Add target for beam to follow",
default = True)
dmx_cache_dirty: BoolProperty(
name = "DMX cache dirty",
description="if dmx data has changed but keyframe has not been saved yet",
default = False)
gel_color_rgb: IntVectorProperty(
name = "Gel Color",
subtype = "COLOR",
size = 3,
min = 0,
max = 255,
default = (255,255,255))
gel_color: FloatVectorProperty(
name = "Unused",
subtype = "COLOR",
size = 4,
min = 0.0,
max = 1.0,
default = (1.0,1.0,1.0,1.0))
ignore_movement_dmx: BoolProperty(
name = "Ignore movement DMX",
description="Stay in position set by Target",
default = False)
classing: StringProperty(
name = "Classing UUID",
description = "Classing - logical grouping across different layers",
default = ""
)
lock_pan_rotation: BoolProperty(
name = "Lock Pan Rotation",
description="Lock Pan Rotation",
default = False)
lock_tilt_rotation: BoolProperty(
name = "Lock Tilt Rotation",
description="Lock Tilt Rotation",
default = False)
def build(self, name, profile, mode, universe, address, gel_color, display_beams, add_target, mvr_position = None,
focus_point = None, uuid = None, fixture_id="", custom_id=0, fixture_id_numeric=0, unit_number=0, classing=""):
# (Edit) Store objects positions
old_pos = {obj.name:obj.object.location.copy() for obj in self.objects}
old_rot = {obj.name:obj.object.rotation_euler.copy() for obj in self.objects}
# (Edit) Collection with this name already exists, delete it
if (self.name in bpy.data.collections):
for obj in bpy.data.collections[self.name].objects:
bpy.data.objects.remove(obj)
bpy.data.collections.remove(bpy.data.collections[self.name])
# Data Properties
self.name = name
self.profile = profile
self.mode = mode
if fixture_id is not None:
self.fixture_id = fixture_id
if custom_id is not None:
self.custom_id = custom_id
if fixture_id_numeric is not None:
self.fixture_id_numeric = fixture_id_numeric
if unit_number is not None:
self.unit_number = unit_number
if uuid is not None:
self.uuid = uuid
if classing is not None:
self.classing = classing
# DMX Properties
self.universe = universe
self.address = address
self.gel_color_rgb = list(int((255/1)*i) for i in gel_color[:3])
self.display_beams = display_beams
self.add_target = add_target
# (Edit) Clear links and channel cache
self.lights.clear()
self.images.clear()
self.objects.clear()
self.channels.clear()
self.virtual_channels.clear()
self.emitter_materials.clear()
self.geometry_nodes.clear()
self.gobo_materials.clear()
self.ies_data.clear()
self.dmx_cache_dirty = False
# Custom python data storage, outside of bpy.props. So called ID props
self["dmx_values"] = []
# Create clean Collection
# (Blender creates the collection with selected objects/collections)
bpy.ops.collection.create(name=name)
self.collection = bpy.data.collections[name]
for c in self.collection.objects:
self.collection.objects.unlink(c)
for c in self.collection.children:
self.collection.children.unlink(c)
# Import and deep copy Fixture Model Collection
gdtf_profile = DMX_GDTF.loadProfile(profile)
self.gdtf_long_name = gdtf_profile.long_name
self.gdtf_manufacturer = gdtf_profile.manufacturer
# Handle if dmx mode doesn't exist (maybe this is MVR import and GDTF files were replaced)
# use mode[0] as default
if not any(self.mode == mode.name for mode in gdtf_profile.dmx_modes):
self.mode = gdtf_profile.dmx_modes[0].name
model_collection = DMX_Model.getFixtureModelCollection(gdtf_profile, self.mode, self.display_beams, self.add_target)
# Build DMX channels cache
dmx_channels = pygdtf.utils.get_dmx_channels(gdtf_profile, self.mode)
# Merge all DMX breaks together
dmx_channels_flattened = [channel for break_channels in dmx_channels for channel in break_channels]
has_gobos = False
for ch in dmx_channels_flattened:
channel = self.channels.add()
channel.id = ch['id']
channel.geometry = ch['geometry']
# Set shutter to 0, we don't want strobing by default
# and are not reading real world values yet
if "shutter" in ch['id'].lower():
channel.default = 0
else:
channel.default = ch['default']
if "Gobo" in ch["id"]:
has_gobos = True
# Build cache of virtual channels
_virtual_channels = pygdtf.utils.get_virtual_channels(gdtf_profile, self.mode)
for ch in _virtual_channels:
virtual_channel = self.virtual_channels.add()
virtual_channel.id = ch['id']
virtual_channel.geometry = ch['geometry']
virtual_channel.default = ch['default']
if "Gobo" in ch["id"]:
has_gobos = True
# Get all gobos
if has_gobos:
gobo_seq = DMX_GDTF.extract_gobos_as_sequence(gdtf_profile)
if gobo_seq is not None:
gobo1 = self.images.add()
gobo1.name = "gobos1"
gobo1.image = gobo_seq[0]
gobo1.count = gobo_seq[0]["count"]
gobo1.image.pack()
gobo2 = self.images.add()
gobo2.name = "gobos2"
gobo2.image = gobo_seq[1]
gobo2.count = gobo_seq[1]["count"]
gobo2.image.pack()
if "gobos1" not in self.images:
has_gobos = False # faulty GDTF might have channels but no images
self["slot_colors"] = []
slot_colors = DMX_GDTF.get_wheel_slot_colors(gdtf_profile)
if len(slot_colors)>1:
self["slot_colors"]=slot_colors[:255] # limit number of colors to an 8bit control channel
links = {}
base = self.get_root(model_collection)
head = self.get_tilt(model_collection)
DMX_Log.log.info(f"Head: {head}, Base: {base}")
for obj in model_collection.objects:
# Copy object
links[obj.name] = obj.copy()
# If light, copy object data,
# Cache access to base (root) and head for faster rendering.
# Fixtures with multiple pan/tilts will still have issues
# but that would anyway require geometry → attribute approach
if obj.type == 'LIGHT':
links[obj.name].data = obj.data.copy()
self.lights.add()
light_name=f'Light{len(self.lights)}'
self.lights[-1].name = light_name
self.lights[light_name].object = links[obj.name]
if has_gobos:
self.lights[light_name].object.data.shadow_soft_size = 0.001 # larger spot diameter causes gobos to be blurry in Cycles
self.lights[light_name].object.data.shadow_buffer_clip_start = 0.002
elif 'Target' in obj.name:
self.objects.add()
self.objects[-1].name = 'Target'
self.objects['Target'].object = links[obj.name]
self.objects['Target'].object["uuid"] = str(py_uuid.uuid4())
elif base.name == obj.name:
self.objects.add()
self.objects[-1].name = "Root"
self.objects["Root"].object = links[obj.name]
elif head is not None and head.name == obj.name:
self.objects.add()
self.objects[-1].name = "Head"
self.objects["Head"].object = links[obj.name]
elif obj.get("2d_symbol", None) == "all":
self.objects.add().name = "2D Symbol"
self.objects["2D Symbol"].object = links[obj.name]
# Link all other object to collection
self.collection.objects.link(links[obj.name])
# Reparent children
for obj in model_collection.objects:
for child in obj.children:
if child.name in links:
links[child.name].parent=links[obj.name]
# Relink constraints
for obj in self.collection.objects:
for constraint in obj.constraints:
constraint.target = links[constraint.target.name]
# (Edit) Reload old positions and rotations
bpy.context.view_layer.update()
for obj in self.objects:
if obj.object.get("geometry_root", False):
if obj.name in old_pos:
obj.object.location = old_pos[obj.name]
if obj.name in old_rot:
obj.object.rotation_mode = 'XYZ'
obj.object.rotation_euler = old_rot[obj.name]
# Set position from MVR
if mvr_position is not None:
for obj in self.objects:
if obj.object.get("geometry_root", False):
obj.object.matrix_world=mvr_position
# Set target's position from MVR
if focus_point is not None:
for obj in self.objects:
if 'Target' in obj.name:
obj.object.matrix_world=focus_point
# Setup emitter
for obj in self.collection.objects:
if "beam" in obj.get("geometry_type", ""):
emitter = obj
self.emitter_materials.add()
self.emitter_materials[-1].name = obj.name
emitter_material = getEmitterMaterial(obj.name)
emitter.active_material = emitter_material
emitter.material_slots[0].link = 'OBJECT'
emitter.material_slots[0].material = emitter_material
emitter.material_slots[0].material.shadow_method = 'NONE' # eevee
self.emitter_materials[-1].material = emitter_material
if "gobo" in obj.get("geometry_type", ""):
material = self.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
gobo_radius = obj.get("gobo_radius", 0)
if gobo_radius:
obj.dimensions = (gobo_radius, gobo_radius, 0)
# Setup laser geometry nodes
if "laser" in obj.get("geometry_type", ""):
#emitter
emitter = obj
self.emitter_materials.add()
self.emitter_materials[-1].name = obj.name
emitter_material = getEmitterMaterial(obj.name)
emitter_material.shadow_method = "NONE" # laser beam should not cast shadows
self.emitter_materials[-1].material = emitter_material
#laser beam
geo_node = obj
node = self.geometry_nodes.add()
node.name = obj.name
modifier = geo_node.modifiers.new(type="NODES", name="base_object")
node_group = getGeometryNodes(obj)
modifier.node_group = node_group
node.node = node_group
# setup light for gobo in cycles
for light in self.lights:
set_light_nodes(light)
# Link collection to DMX collection
bpy.context.scene.dmx.collection.children.link(self.collection)
# Set Pigtail visibility and Beam selection
for obj in self.collection.objects:
if "pigtail" in obj.get("geometry_type", ""):
obj.hide_set(not bpy.context.scene.dmx.display_pigtails)
obj.hide_viewport = not bpy.context.scene.dmx.display_pigtails # keyframing
obj.hide_render = not bpy.context.scene.dmx.display_pigtails
if obj.get("geometry_root", False):
continue
if "Target" in obj.name:
continue
if obj.get("2d_symbol", None) == "all":
obj.hide_set(not bpy.context.scene.dmx.display_2D)
obj.hide_viewport = not bpy.context.scene.dmx.display_2D #keyframing
obj.hide_render = not bpy.context.scene.dmx.display_2D
continue
obj.hide_select = not bpy.context.scene.dmx.select_geometries
self.clear()
self.hide_gobo()
d=DMX_OT_ArrangeSelected()
for item in self.gobo_materials:
ntree = item.material.node_tree
d.process_tree(ntree)
for item in self.geometry_nodes:
ntree = item.node
d.process_tree(ntree)
for light in self.lights: #CYCLES
light_obj = light.object
ntree = light_obj.data.node_tree
d.process_tree(ntree)
self.render()
# Interface Methods #
def setDMX(self, pvalues):
temp_data = bpy.context.window_manager.dmx
#channels = [c.id for c in self.channels]
#virtuals = [c.id for c in self.virtual_channels]
for attribute, value in pvalues.items():
for idx, channel in enumerate(self.channels):
if channel.id == attribute:
if len(temp_data.active_subfixtures)>0:
if any(channel.geometry == g.name for g in temp_data.active_subfixtures):
DMX_Log.log.info(("Set DMX data", channel.id, value))
DMX_Data.set(self.universe, self.address+idx, value)
else:
DMX_Log.log.info(("Set DMX data", channel, value))
DMX_Data.set(self.universe, self.address+idx, value)
for vchannel in self.virtual_channels:
if vchannel.id == attribute:
if len(temp_data.active_subfixtures)>0:
if any(vchannel.geometry == g.name for g in temp_data.active_subfixtures):
DMX_Log.log.info(("Set Virtual data", attribute, value))
geometry = next(vchannel.geometry == g.name for g in temp_data.active_subfixtures)
DMX_Data.set_virtual(self.name, attribute, geometry, value)
else:
DMX_Log.log.info(("Set Virtual data", attribute, value))
DMX_Data.set_virtual(self.name, attribute, None, value)
def render(self, skip_cache = False, current_frame = None):
if bpy.context.window_manager.dmx.pause_render:
# do not run render loop when paused
return
channels = [c.id for c in self.channels]
#virtual_channels = [c.id for c in self.virtual_channels]
data = DMX_Data.get(self.universe, self.address, len(channels))
data_virtual = DMX_Data.get_virtual(self.name)
s_data = [int(b) for b in data] + [int(b["value"]) for b in data_virtual.values()] # create cache
if list(self["dmx_values"]) == s_data: # this helps to eliminate flicker with Ethernet DMX signal when the data for this particular device is not changing
if skip_cache is False: # allow to save a keyframe when using the programmer in Blender
DMX_Log.log.debug("caching DMX")
return
if self.dmx_cache_dirty is False: # we care about keyframe saving only if there is data to be saved
DMX_Log.log.debug("caching DMX")
return
else: # we have new dmx data, mark the cache as dirty, so we know we can save a keyframe when needed
self.dmx_cache_dirty = True
DMX_Log.log.debug(f"{current_frame=}, {self.dmx_cache_dirty=}")
self["dmx_values"] = s_data
panTilt = [None,None, 1, 1] # pan, tilt, 1 = 8bit, 256 = 16bit
cmy = [None,None,None]
zoom = None
color1 = None
ctc = None
iris = None
rgb_mixing_geometries={}
xyz_moving_geometries={}
xyz_rotating_geometries={}
shutter_dimmer_geometries={} # item: shutter, dimmer, unused, dimmer bits
pan_rotating_geometries={}
tilt_rotating_geometries={}
pan_cont_rotating_geometries={}
tilt_cont_rotating_geometries={}
gobo1 = [None, None] #gobo selection (Gobo1), gobo indexing/rotation (Gobo1Pos)
gobo2 = [None, None] #gobo selection (Gobo2), gobo indexing/rotation (Gobo2Pos)
for vchannel in self.virtual_channels:
geometry = vchannel.geometry # for now. But, no way to know, as BlenderDMX controls are universal
if geometry not in rgb_mixing_geometries.keys():
rgb_mixing_geometries[geometry] = [None] * 12 # R, G, B, White, WW, CW, Amber, Lime, UV, cyan, magenta, yellow
if geometry not in xyz_moving_geometries.keys():
xyz_moving_geometries[geometry]=[None, None, None]
if geometry not in xyz_rotating_geometries.keys():
xyz_rotating_geometries[geometry]=[None, None, None]
if geometry not in shutter_dimmer_geometries.keys():
shutter_dimmer_geometries[geometry]=[None, None, None, 1] # + bits
if geometry not in pan_rotating_geometries.keys():
pan_rotating_geometries[geometry]=[None, 1]
if geometry not in tilt_rotating_geometries.keys():
tilt_rotating_geometries[geometry]=[None, 1]
if geometry not in pan_cont_rotating_geometries.keys():
pan_cont_rotating_geometries[geometry]=[None, 1]
if geometry not in tilt_cont_rotating_geometries.keys():
tilt_cont_rotating_geometries[geometry]=[None, 1]
if vchannel.id in data_virtual:
if vchannel.id == "Shutter1": shutter_dimmer_geometries[geometry][0] = data_virtual[vchannel.id]["value"]
elif vchannel.id == "Dimmer": shutter_dimmer_geometries[geometry][1] = data_virtual[vchannel.id]["value"]
elif vchannel.id == "+Dimmer":
shutter_dimmer_geometries[geometry][1] = shutter_dimmer_geometries[geometry][1] * 256 + data_virtual[vchannel.id]["value"]
shutter_dimmer_geometries[geometry][3] = 256
elif (vchannel.id == "ColorAdd_R" or vchannel.id == "ColorRGB_Red"): rgb_mixing_geometries[geometry][0] = data_virtual[vchannel.id]["value"]
elif (vchannel.id == "ColorAdd_G" or vchannel.id == "ColorRGB_Green"): rgb_mixing_geometries[geometry][1] = data_virtual[vchannel.id]["value"]
elif (vchannel.id == "ColorAdd_B" or vchannel.id == "ColorRGB_Blue"): rgb_mixing_geometries[geometry][2] = data_virtual[vchannel.id]["value"]
elif vchannel.id == "ColorSub_C": cmy[0] = data_virtual[vchannel.id]["value"]
elif vchannel.id == "ColorSub_M": cmy[1] = data_virtual[vchannel.id]["value"]
elif vchannel.id == "ColorSub_Y": cmy[2] = data_virtual[vchannel.id]["value"]
elif vchannel.id == "Pan":
panTilt[0] = data_virtual[vchannel.id]["value"]
pan_rotating_geometries[geometry][0] = data_virtual[vchannel.id]["value"]
elif vchannel.id == "+Pan":
panTilt[0] = panTilt[0] * 256 + data_virtual[vchannel.id]["value"]
panTilt[2] = 256 # 16bit
pan_rotating_geometries[geometry][0] = pan_rotating_geometries[geometry][0] * 256 + data_virtual[vchannel.id]["value"]
pan_rotating_geometries[geometry][2] = 256
elif vchannel.id == "Tilt":
panTilt[1] = data_virtual[vchannel.id]["value"]
tilt_rotating_geometries[geometry][0] = data_virtual[vchannel.id]["value"]
elif vchannel.id == "+Tilt":
panTilt[1] = panTilt[1] * 256 + data_virtual[vchannel.id]["value"]
panTilt[3] = 256 # 16bit
tilt_rotating_geometries[geometry][0] = tilt_rotating_geometries[geometry][0] * 256 + data_virtual[vchannel.id]["value"]
tilt_rotating_geometries[geometry][2] = 256
elif vchannel.id == "PanRotate":
pan_cont_rotating_geometries[geometry][0] = data_virtual[vchannel.id]["value"]
elif vchannel.id == "TiltRotate":
tilt_cont_rotating_geometries[geometry][0] = data_virtual[vchannel.id]["value"]
elif vchannel.id == "Zoom": zoom = data_virtual[vchannel.id]["value"]
elif vchannel.id == "XYZ_X": xyz_moving_geometries[geometry][0] = data_virtual[vchannel.id]["value"]
elif vchannel.id == "XYZ_Y": xyz_moving_geometries[geometry][1] = data_virtual[vchannel.id]["value"]
elif vchannel.id == "XYZ_Z": xyz_moving_geometries[geometry][2] = data_virtual[vchannel.id]["value"]
elif vchannel.id == "Rot_X": xyz_rotating_geometries[geometry][0] = data_virtual[vchannel.id]["value"]
elif vchannel.id == "Rot_Y": xyz_rotating_geometries[geometry][1] = data_virtual[vchannel.id]["value"]
elif vchannel.id == "Rot_Z": xyz_rotating_geometries[geometry][2] = data_virtual[vchannel.id]["value"]
for c in range(len(channels)):
geometry=self.channels[c].geometry
if geometry not in rgb_mixing_geometries.keys():
rgb_mixing_geometries[geometry] = [None] * 12
if geometry not in xyz_moving_geometries.keys():
xyz_moving_geometries[geometry]=[None, None, None]
if geometry not in xyz_rotating_geometries.keys():
xyz_rotating_geometries[geometry]=[None, None, None]
if geometry not in shutter_dimmer_geometries.keys():
shutter_dimmer_geometries[geometry]=[None, None, None, 1] # + bits
if geometry not in pan_rotating_geometries.keys():
pan_rotating_geometries[geometry]=[None, 1]
if geometry not in tilt_rotating_geometries.keys():
tilt_rotating_geometries[geometry]=[None, 1]
if geometry not in pan_cont_rotating_geometries.keys():
pan_cont_rotating_geometries[geometry]=[None, 1]
if geometry not in tilt_cont_rotating_geometries.keys():
tilt_cont_rotating_geometries[geometry]=[None, 1]
if (channels[c] == 'Dimmer'): shutter_dimmer_geometries[geometry][1] = data[c]
if (channels[c] == '+Dimmer'):
shutter_dimmer_geometries[geometry][1] = shutter_dimmer_geometries[geometry][1] * 256 + data[c]
shutter_dimmer_geometries[geometry][3] = 256
elif (channels[c] == 'Shutter1'): shutter_dimmer_geometries[geometry][0] = data[c]
elif (channels[c] == 'ColorAdd_R' or channels[c] == 'ColorRGB_Red'): rgb_mixing_geometries[geometry][0] = data[c]
elif (channels[c] == 'ColorAdd_G' or channels[c] == 'ColorRGB_Green'): rgb_mixing_geometries[geometry][1] = data[c]
elif (channels[c] == 'ColorAdd_B' or channels[c] == 'ColorRGB_Blue'): rgb_mixing_geometries[geometry][2] = data[c]
elif channels[c] == 'ColorAdd_W': rgb_mixing_geometries[geometry][3] = data[c]
elif channels[c] == 'ColorAdd_WW': rgb_mixing_geometries[geometry][4] = data[c]
elif channels[c] == 'ColorAdd_CW': rgb_mixing_geometries[geometry][5] = data[c]
elif channels[c] == 'ColorAdd_RY': rgb_mixing_geometries[geometry][6] = data[c]
elif channels[c] == 'ColorAdd_GY': rgb_mixing_geometries[geometry][7] = data[c]
elif channels[c] == 'ColorAdd_UV': rgb_mixing_geometries[geometry][8] = data[c]
elif channels[c] == 'ColorAdd_C': rgb_mixing_geometries[geometry][9] = data[c]
elif channels[c] == 'ColorAdd_M': rgb_mixing_geometries[geometry][10] = data[c]
elif channels[c] == 'ColorAdd_Y': rgb_mixing_geometries[geometry][11] = data[c]
elif channels[c] == 'ColorSub_C': cmy[0] = data[c]
elif channels[c] == 'ColorSub_M': cmy[1] = data[c]
elif channels[c] == 'ColorSub_Y': cmy[2] = data[c]
elif (channels[c] == 'Pan'):
panTilt[0] = data[c]
pan_rotating_geometries[geometry][0] = data[c]
elif (channels[c] == '+Pan'):
panTilt[0] = panTilt[0] * 256 + data[c]
panTilt[2] = 256 # 16bit
pan_rotating_geometries[geometry][0] = pan_rotating_geometries[geometry][0] * 256 + data[c]
pan_rotating_geometries[geometry][1] = 256
elif (channels[c] == 'Tilt'):
panTilt[1] = data[c]
tilt_rotating_geometries[geometry][0] = data[c]
elif (channels[c] == '+Tilt'):
panTilt[1] = panTilt[1] * 256 + data[c]
panTilt[3] = 256 # 16bit
tilt_rotating_geometries[geometry][0] = tilt_rotating_geometries[geometry][0] * 256 + data[c]
tilt_rotating_geometries[geometry][1] = 256
elif (channels[c] == 'PanRotate'):
pan_cont_rotating_geometries[geometry][0] = data[c]
elif (channels[c] == 'TiltRotate'):
tilt_cont_rotating_geometries[geometry][0] = data[c]
elif (channels[c] == 'Zoom'): zoom = data[c]
elif (channels[c] == 'Color1'): color1 = data[c]
elif (channels[c] == 'Color2'): color1 = data[c]
elif (channels[c] == 'CTC'): ctc = data[c]
elif (channels[c] == 'CTO'): ctc = data[c]
elif (channels[c] == 'CTB'): ctc = data[c]
elif (channels[c] == 'Iris'): iris = data[c]
elif (channels[c] == 'ColorMacro1'): color1 = data[c]
elif (channels[c] == 'Gobo1'): gobo1[0] = data[c]
elif (channels[c] == 'Gobo1Pos' or channels[c] == 'Gobo1PosRotate'): gobo1[1] = data[c]
elif (channels[c] == 'Gobo2'): gobo2[0] = data[c]
elif (channels[c] == 'Gobo2Pos' or channels[c] == 'Gobo2PosRotate'): gobo2[1] = data[c]
elif (channels[c] == 'XYZ_X'): xyz_moving_geometries[geometry][0] = data[c]
elif (channels[c] == 'XYZ_Y'): xyz_moving_geometries[geometry][1] = data[c]
elif (channels[c] == 'XYZ_Z'): xyz_moving_geometries[geometry][2] = data[c]
elif (channels[c] == 'Rot_X'): xyz_rotating_geometries[geometry][0] = data[c]
elif (channels[c] == 'Rot_Y'): xyz_rotating_geometries[geometry][1] = data[c]
elif (channels[c] == 'Rot_Z'): xyz_rotating_geometries[geometry][2] = data[c]
self.remove_unset_geometries_from_multigeometry_attributes_all(rgb_mixing_geometries)
self.remove_unset_geometries_from_multigeometry_attributes_all(xyz_moving_geometries)
self.remove_unset_geometries_from_multigeometry_attributes_all(xyz_rotating_geometries)
self.remove_unset_geometries_from_multigeometry_attributes_3(shutter_dimmer_geometries)
self.remove_unset_geometries_from_multigeometry_attributes_1(pan_rotating_geometries)
self.remove_unset_geometries_from_multigeometry_attributes_1(tilt_rotating_geometries)
self.remove_unset_geometries_from_multigeometry_attributes_1(pan_cont_rotating_geometries)
self.remove_unset_geometries_from_multigeometry_attributes_1(tilt_cont_rotating_geometries)
colorwheel_color = None
if (color1 is not None):
colorwheel_color = self.get_colorwheel_color(color1)
color_temperature = None
if (ctc is not None):
color_temperature = self.get_color_temperature(ctc)
for geometry, colors in rgb_mixing_geometries.items():
if len(rgb_mixing_geometries)==1:
geometry = None
self.updateRGB(colors, geometry, colorwheel_color, color_temperature, current_frame)
if not len(rgb_mixing_geometries):# handle units without mixing
if not all([c == 255 for c in self.gel_color_rgb]) or colorwheel_color is not None or color_temperature is not None: #gel color is set and has priority or there is a color wheel or color_temperature
self.updateRGB([255] * 12, None, colorwheel_color, color_temperature, current_frame)
if (cmy[0] is not None and cmy[1] is not None and cmy[2] is not None):
self.updateCMY(cmy, colorwheel_color, color_temperature, current_frame)
if "Target" in self.objects:
if self.ignore_movement_dmx:
# programming by target, dmx for p/t locked
if "Target" in self.objects:
target = self.objects['Target'].object
if current_frame and self.dmx_cache_dirty:
target.keyframe_insert(data_path="location", frame=current_frame)
target.keyframe_insert(data_path="rotation_euler", frame=current_frame)
else:
if panTilt[0] is None:
panTilt[0] = 0 * panTilt[2] # if the device doesn't have pan, align head with base
if panTilt[1] is None:
panTilt[1] = 0 * panTilt[3]
pan = (panTilt[0]/(panTilt[2]*127.0)-1)*540*(math.pi/360)
tilt = (panTilt[1]/(panTilt[3]*127.0)-1)*270*(math.pi/360)
self.updatePanTiltViaTarget(pan, tilt, current_frame)
else:# no Target
for geometry, pan_vals in pan_rotating_geometries.items():
pan = (pan_vals[0]/(pan_vals[1]*127.0)-1)*540*(math.pi/360)
self.updatePTDirectly(geometry, "pan", pan, current_frame)
for geometry, tilt_vals in tilt_rotating_geometries.items():
tilt = (tilt_vals[0]/(tilt_vals[1]*127.0)-1)*270*(math.pi/360)
self.updatePTDirectly(geometry, "tilt", tilt, current_frame)
for geometry, pan_rotate in pan_cont_rotating_geometries.items():
self.set_pan_tilt_rotation(geometry=geometry, axis = "pan", rotation = pan_rotate[0], current_frame=current_frame)
for geometry, tilt_rotate in tilt_cont_rotating_geometries.items():
self.set_pan_tilt_rotation(geometry=geometry, axis = "tilt", rotation = tilt_rotate[0], current_frame=current_frame)
if (zoom is not None):
self.updateZoom(zoom, current_frame)
self.hide_gobo_geometry(gobo1, gobo2, iris, current_frame)
if gobo1[0] is not None:
self.updateGobo(gobo1, 1, current_frame)
if gobo2[0] is not None:
self.updateGobo(gobo2, 2, current_frame)
if iris is not None:
if 0 <= iris <= 255:
iris = iris * 12/255
self.update_iris(iris, current_frame)
for geometry, xyz in xyz_moving_geometries.items():
self.updatePosition(geometry=geometry, x=xyz[0], y=xyz[1], z=xyz[2], current_frame=current_frame)
for geometry, xyz in xyz_rotating_geometries.items():
self.updateRotation(geometry=geometry, x=xyz[0], y=xyz[1], z=xyz[2], current_frame=current_frame)
for geometry, shutter_dimmer in shutter_dimmer_geometries.items():
if len(shutter_dimmer_geometries)==1:
geometry = None
if shutter_dimmer[0] is not None or shutter_dimmer[1] is not None:
if shutter_dimmer[0] is None:
shutter_dimmer[0] = 0 # if device doesn't have shutter, set default value
if shutter_dimmer[1] is None:
shutter_dimmer[1] = 100 # if device doesn't have dimmer, set default value
self.updateShutterDimmer(shutter_dimmer[0], shutter_dimmer[1], geometry, shutter_dimmer[3], current_frame)
if current_frame:
self.dmx_cache_dirty = False
# end of render block
def set_pan_tilt_rotation(self, geometry, axis, rotation, current_frame):
if axis == "pan":
mobile_type = "yoke"
offset = 2
lock_rotation = self.lock_pan_rotation
else: # tilt
mobile_type = "head"
offset = 0
lock_rotation = self.lock_tilt_rotation
if geometry is None:
geometry = self.get_mobile_type(mobile_type)
else:
geometry = self.get_object_by_geometry_name(geometry)
if geometry:
geometry.rotation_mode = "XYZ"
geometry.driver_remove("rotation_euler", offset)
if lock_rotation:
rotation = rotation/128 * 360 *(math.pi/360)
geometry.rotation_euler[offset] = rotation # just some value, not very precise
else:
if rotation != 0:
driver = geometry.driver_add("rotation_euler", offset)
value = rotation-128 # rotating in both direction, slowest in the middle
driver.driver.expression=f"frame*{value*0.005}"
if current_frame and self.dmx_cache_dirty:
geometry.keyframe_insert(data_path="location", frame=current_frame)
geometry.keyframe_insert(data_path="rotation_euler", frame=current_frame)
def remove_unset_geometries_from_multigeometry_attributes_all(self, dictionary):
"""Remove items with values of all None"""
remove_empty_items = []
for geometry, items in dictionary.items():
if all([i == None for i in items]):
remove_empty_items.append(geometry)
for geo in remove_empty_items:
del(dictionary[geo])
def remove_unset_geometries_from_multigeometry_attributes_1(self, dictionary):
"""Remove items with 3 values of None"""
remove_empty_items = []
for geometry, items in dictionary.items():
if items[0] is None:
remove_empty_items.append(geometry)
for geo in remove_empty_items:
del(dictionary[geo])
def remove_unset_geometries_from_multigeometry_attributes_3(self, dictionary):
"""Remove items with 1 value of None"""
remove_empty_items = []
for geometry, items in dictionary.items():
if (items[0] is None and items[1] is None and items[2] is None):
remove_empty_items.append(geometry)
for geo in remove_empty_items:
del(dictionary[geo])
def light_object_for_geometry_exists(self, geometry):
"""Check if there is any light or emitter matching geometry name of a color attribute"""
for light in self.lights:
if geometry in light.object.data.name:
return True
for emitter_material in self.emitter_materials:
if geometry in emitter_material.name:
return True
return False
def get_channel_by_attribute(self, attribute):
for channel in self.channels:
if channel.id == attribute:
return channel
def updateShutterDimmer(self, shutter, dimmer, geometry, bits, current_frame):
DMX_Log.log.info(("set shutter, dimmer", shutter, dimmer, geometry))
dmx = bpy.context.scene.dmx
if geometry is not None:
geometry = geometry.replace(" ", "_")
last_shutter_value = 0
last_dimmer_value = 0
try:
for emitter_material in self.emitter_materials:
if (shutter > 0 and shutter != 255):
break # no need to do the expensive value settings if we do this anyway in shutter timer
if geometry is not None:
if f"{geometry}" in emitter_material.name:
DMX_Log.log.info("matched emitter")
emitter_material.material.node_tree.nodes[1].inputs[STRENGTH].default_value = 1*(dimmer/(255.0 * bits))
else:
emitter_material.material.node_tree.nodes[1].inputs[STRENGTH].default_value = 1*(dimmer/(255.0 * bits))
if current_frame and self.dmx_cache_dirty:
emitter_material.material.node_tree.nodes[1].inputs[STRENGTH].keyframe_insert(data_path='default_value', frame=current_frame)
for light in self.lights:
last_shutter_value = light.object.data['shutter_value']
last_dimmer_value = light.object.data['shutter_dimmer_value']
light.object.data['shutter_value']=shutter
light.object.data['shutter_dimmer_value']=dimmer
light.object.data['shutter_dimmer_bits']=bits
flux = light.object.data["flux"] * dmx.beam_intensity_multiplier