-
Notifications
You must be signed in to change notification settings - Fork 12
/
__init__.py
196 lines (152 loc) · 5.03 KB
/
__init__.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
# Copyright Hugo Aboud, Kaspars Jaudzems, Mark Steward, 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/>.
bl_info = {
"name": "DMX",
"description": "DMX visualization and programming, with GDTF/MVR and Network support",
"author": "open-stage",
"version": (1, 6, 0),
"blender": (3, 4, 0),
"location": "3D View > DMX",
"doc_url": "https://blenderdmx.eu/docs/faq/",
"tracker_url": "https://github.com/open-stage/blender-dmx/issues",
"category": "Lighting",
}
import sys
import bpy
from threading import Timer
from . import fixture as fixture
from .data import DMX_Data
from .artnet import DMX_ArtNet
from .acn import DMX_sACN
from .panels import profiles as Profiles
from .osc import DMX_OSC
from .mdns import DMX_Zeroconf
from .mvrx_protocol import DMX_MVR_X_Client, DMX_MVR_X_Server
from bpy.props import PointerProperty
from .i18n import DMX_Lang
_ = DMX_Lang._
from .dmx import DMX
from .dmx_temp_data import DMX_TempData
@bpy.app.handlers.persistent
def onLoadFile(scene):
if "Scene" in bpy.data.scenes:
if "DMX" in bpy.data.scenes["Scene"].collection.children:
print("INFO", "File contains DMX show, linking...")
bpy.context.scene.dmx.linkFile()
else:
bpy.context.scene.dmx.unlinkFile()
# Selection callback
handle = object()
subscribe_to = bpy.types.LayerObjects, "active"
bpy.msgbus.subscribe_rna(
key=subscribe_to,
owner=handle,
args=(None,),
notify=onActiveChanged,
options={
"PERSISTENT",
},
)
# Stop ArtNet
DMX_ArtNet.disable()
DMX_sACN.disable()
DMX_OSC.disable()
DMX_MVR_X_Client.disable()
DMX_MVR_X_Server.disable()
DMX_Zeroconf.close()
# register a "bdmx" namespace to get current value of a DMX channel,
# the syntax is #bdmx(universe, channel(s)), where the channel can be
# multiple, to receive 8, 16, 24... bits of data:
# for example: #bdmx(1,1) , #bdmx(1,1,2)
bpy.app.driver_namespace["bdmx"] = DMX_Data.get_value
@bpy.app.handlers.persistent
def onUndo(scene):
if not scene.dmx.collection and DMX.linkedToFile:
scene.dmx.unlinkFile()
# Callbacks #
def onActiveChanged(*args):
dmx = bpy.context.scene.dmx
if dmx.volume_preview == "SELECTED":
dmx.updatePreviewVolume()
if dmx.display_2D:
selected = False
for fixture in dmx.fixtures:
if bpy.context.active_object is not None and bpy.context.active_object.name in fixture.collection.objects:
selected = True
fixture.select()
else:
fixture.unselect()
if selected:
bpy.context.window_manager.dmx.pause_render = False
else:
bpy.context.window_manager.dmx.pause_render = True
#
# Hot-Reload
#
def clean_module_imports():
modules = dict(sys.modules)
for name in modules.keys():
if name == __name__:
continue
if name.startswith(__name__):
del sys.modules[name]
return None
#
# Blender Add-On
#
def onRegister():
onLoadFile(None)
def register():
# Register Base Classes
for cls in DMX.classes_base:
bpy.utils.register_class(cls)
# Register addon main class
bpy.utils.register_class(DMX)
bpy.types.Scene.dmx = PointerProperty(type=DMX)
for cls in Profiles.classes:
bpy.utils.register_class(cls)
bpy.utils.register_class(DMX_TempData)
bpy.types.WindowManager.dmx = PointerProperty(type=DMX_TempData)
# Append handlers
bpy.app.handlers.load_post.append(onLoadFile)
bpy.app.handlers.undo_post.append(onUndo)
Timer(1, onRegister, ()).start()
def unregister():
# Stop ArtNet
DMX_ArtNet.disable()
DMX_sACN.disable()
DMX_OSC.disable()
DMX_MVR_X_Client.disable()
DMX_MVR_X_Server.disable()
DMX_Zeroconf.close()
try:
for cls in Profiles.classes:
bpy.utils.unregister_class(cls)
# Unregister Base Classes
for cls in DMX.classes_base:
bpy.utils.unregister_class(cls)
# Unregister addon main class
bpy.utils.unregister_class(DMX_TempData)
bpy.utils.unregister_class(DMX)
except Exception as e:
print("INFO", e)
# Append handlers
bpy.app.handlers.load_post.clear()
bpy.app.handlers.undo_post.clear()
clean_module_imports()
if __name__ == "__main__":
register()