Skip to content

Commit

Permalink
save
Browse files Browse the repository at this point in the history
  • Loading branch information
vanous committed Aug 26, 2024
1 parent 810f2da commit 0a3d11c
Show file tree
Hide file tree
Showing 4 changed files with 160 additions and 86 deletions.
78 changes: 56 additions & 22 deletions dmx.py
Original file line number Diff line number Diff line change
Expand Up @@ -1372,27 +1372,45 @@ def onProgrammerColorWheel(self, context):
})
self.render()

def onProgrammerGobo(self, context):
def onProgrammerGobo1(self, context):
for fixture in self.fixtures:
if fixture.collection is None:
continue
if fixture.is_selected():
fixture.setDMX({
'Gobo1':int(self.programmer_gobo),
'Gobo2':int(self.programmer_gobo)
'Gobo1':int(self.programmer_gobo1),
})
self.render()

def onProgrammerGoboIndex(self, context):
def onProgrammerGoboIndex1(self, context):
for fixture in self.fixtures:
if fixture.collection is None:
continue
if fixture.is_selected():
fixture.setDMX({
'Gobo1Pos':int(self.programmer_gobo_index),
'Gobo1PosRotate':int(self.programmer_gobo_index),
'Gobo2Pos':int(self.programmer_gobo_index),
'Gobo2PosRotate':int(self.programmer_gobo_index)
'Gobo1Pos':int(self.programmer_gobo_index1),
'Gobo1PosRotate':int(self.programmer_gobo_index1),
})
self.render()

def onProgrammerGobo2(self, context):
for fixture in self.fixtures:
if fixture.collection is None:
continue
if fixture.is_selected():
fixture.setDMX({
'Gobo2':int(self.programmer_gobo2),
})
self.render()

def onProgrammerGoboIndex2(self, context):
for fixture in self.fixtures:
if fixture.collection is None:
continue
if fixture.is_selected():
fixture.setDMX({
'Gobo2Pos':int(self.programmer_gobo_index2),
'Gobo2PosRotate':int(self.programmer_gobo_index2),
})
self.render()

Expand Down Expand Up @@ -1441,19 +1459,33 @@ def onProgrammerShutter(self, context):
default = 0,
update = onProgrammerIris)

programmer_gobo: IntProperty(
name = "Programmer Gobo",
programmer_gobo1: IntProperty(
name = "Programmer Gobo1",
min = 0,
max = 255,
default = 0,
update = onProgrammerGobo1)

programmer_gobo_index1: IntProperty(
name = "Gobo1 Rotation",
min = 0,
max = 255,
default = 63,
update = onProgrammerGoboIndex1)

programmer_gobo2: IntProperty(
name = "Programmer Gobo2",
min = 0,
max = 255,
default = 0,
update = onProgrammerGobo)
update = onProgrammerGobo2)

programmer_gobo_index: IntProperty(
name = "Gobo Rotation",
programmer_gobo_index2: IntProperty(
name = "Gobo2 Rotation",
min = 0,
max = 255,
default = 63,
update = onProgrammerGoboIndex)
update = onProgrammerGoboIndex2)

programmer_shutter: IntProperty(
name = "Programmer Shutter",
Expand All @@ -1477,8 +1509,10 @@ def syncProgrammer(self):
self.programmer_color_wheel = 0
self.programmer_color_temperature = 0
self.programmer_iris = 0
self.programmer_gobo = 0
self.programmer_gobo_index = 63
self.programmer_gobo1 = 0
self.programmer_gobo_index1 = 63
self.programmer_gobo2 = 0
self.programmer_gobo_index2 = 63
return
elif (n > 1): return
active = selected[0]
Expand All @@ -1504,17 +1538,17 @@ def syncProgrammer(self):
if ('Iris' in data):
self.programmer_iris = int(data['Iris'])
if ('Gobo1' in data):
self.programmer_gobo = int(data['Gobo1'])
self.programmer_gobo1 = int(data['Gobo1'])
if ('Gobo2' in data):
self.programmer_gobo = int(data['Gobo2'])
self.programmer_gobo2 = int(data['Gobo2'])
if ('Gobo1Pos' in data):
self.programmer_gobo_index = int(data['Gobo1Pos'])
self.programmer_gobo_index1 = int(data['Gobo1Pos'])
if ('Gobo1PosRotate' in data):
self.programmer_gobo_index = int(data['Gobo1PosRotate'])
self.programmer_gobo_index1 = int(data['Gobo1PosRotate'])
if ('Gobo2Pos' in data):
self.programmer_gobo_index = int(data['Gobo2Pos'])
self.programmer_gobo_index2 = int(data['Gobo2Pos'])
if ('Gobo2PosRotate' in data):
self.programmer_gobo_index = int(data['Gobo2PosRotate'])
self.programmer_gobo_index2 = int(data['Gobo2PosRotate'])
if ('ColorAdd_R' in data and 'ColorAdd_G' in data and 'ColorAdd_B' in data):
rgb = [data['ColorAdd_R'],data['ColorAdd_G'],data['ColorAdd_B']]
self.programmer_color = (*flatten_color(rgb), 255)
Expand Down
77 changes: 41 additions & 36 deletions fixture.py
Original file line number Diff line number Diff line change
Expand Up @@ -606,7 +606,8 @@ def render(self, skip_cache = False, current_frame = None):
shutter_dimmer_geometries={} # item: shutter, dimmer, unused, dimmer bits
pan_rotating_geometries={}
tilt_rotating_geometries={}
gobo1 = [None, None] #gobo selection (Gobo1, Gobo2), gobo indexing/rotation (Gobo1Pos, Gobo2Pos)
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
Expand Down Expand Up @@ -721,8 +722,8 @@ def render(self, skip_cache = False, current_frame = None):
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'): gobo1[0] = data[c]
elif (channels[c] == 'Gobo2Pos' or channels[c] == 'Gobo2PosRotate'): 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]
Expand Down Expand Up @@ -793,7 +794,10 @@ def render(self, skip_cache = False, current_frame = None):
self.updateZoom(zoom, current_frame)

if gobo1[0] is not None:
self.updateGobo(gobo1, current_frame)
self.updateGobo(gobo1, 1, current_frame)

if gobo2[0] is not None:
self.updateGobo(gobo2, 2, 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)
Expand Down Expand Up @@ -1008,12 +1012,13 @@ def updateRGB(self, colors, geometry, colorwheel_color, color_temperature, curre
def updateCMY(self, cmy, colorwheel_color, color_temperature, current_frame):
rgb=[0,0,0]
rgb=cmy_to_rgb(cmy)

print("rgb", rgb)
if all([c == 255 for c in rgb]) and (colorwheel_color is not None or color_temperature is not None):
rgb=[0,0,0] # without this, default white would always be overwriting ctc

if colorwheel_color is not None:
rgb = add_rgb(rgb, colorwheel_color[:3])
print("cw", colorwheel_color[:3])
rgb = add_rgb(rgb, colorwheel_color)
if color_temperature is not None:
rgb = add_rgb(rgb, color_temperature[:3])
if not all([c == 255 for c in self.gel_color_rgb]):
Expand All @@ -1026,6 +1031,7 @@ def updateCMY(self, cmy, colorwheel_color, color_temperature, current_frame):
if current_frame and self.dmx_cache_dirty:
emitter_material.material.node_tree.nodes[1].inputs[COLOR].keyframe_insert(data_path='default_value', frame=current_frame)
for light in self.lights:
print("final", rgb)
light.object.data.color = rgb
if current_frame and self.dmx_cache_dirty:
light.object.data.keyframe_insert(data_path='color', frame=current_frame)
Expand Down Expand Up @@ -1079,7 +1085,7 @@ def get_colorwheel_color(self, color1):
index = int(color1/int(255/(len(colors)-1)))

if len(colors) > index:
return colors[index]
return list(colors[index])

def get_color_temperature(self, ctc):
if ctc == 0:
Expand All @@ -1102,54 +1108,54 @@ def update_iris(self, iris, current_frame):
light_obj.data.keyframe_insert(data_path="shadow_soft_size", frame=current_frame)
iris_size.keyframe_insert(data_path="default_value", frame=current_frame)

def updateGobo(self, gobo1, current_frame):
def updateGobo(self, gobo, n, current_frame):
if "gobos" not in self.images:
self.hide_gobo(current_frame=current_frame)
self.hide_gobo([n], current_frame=current_frame)
return

gobos = self.images["gobos"]
if gobo1[0] == 0:
self.hide_gobo(current_frame=current_frame)
if gobo[0] == 0:
self.hide_gobo([n], current_frame=current_frame)
return

if not gobos.count:
self.hide_gobo(current_frame=current_frame)
self.hide_gobo([n], current_frame=current_frame)
return

self.hide_gobo(False, current_frame=current_frame)
index = int(gobo1[0]/int(255/(gobos.count-1)))
self.set_gobo(index, current_frame=current_frame)
self.hide_gobo([n], False, current_frame=current_frame)
index = int(gobo[0]/int(255/(gobos.count-1)))
self.set_gobo(n, index, current_frame=current_frame)

if gobo1[1] is None:
if gobo[1] is None:
#self.hide_gobo() #?
return

for obj in self.collection.objects: #EEVEE
if "gobo" in obj.get("geometry_type", ""):
if gobo1[1]<128: # half for indexing
if gobo[1]<128: # half for indexing
obj.driver_remove("rotation_euler")
obj.rotation_euler[2] = (gobo1[1]/62.0-1)*360*(math.pi/360)
obj.rotation_euler[2] = (gobo[1]/62.0-1)*360*(math.pi/360)
else: # half for rotation
driver = obj.driver_add("rotation_euler", 2)
value = gobo1[1]-128-62 # rotating in both direction, slowest in the middle
value = gobo[1]-128-62 # rotating in both direction, slowest in the middle
driver.driver.expression=f"frame*{value*0.005}"

if current_frame and self.dmx_cache_dirty:
obj.keyframe_insert(data_path='rotation_euler', frame=current_frame)

for light in self.lights: #CYCLES
light_obj = light.object
gobo_rotation = light_obj.data.node_tree.nodes.get("Gobo1Rotation")
if gobo1[1]<128: # half for indexing
gobo_rotation.inputs[3].driver_remove("rotation_euler")
gobo_rotation.inputs[3].default_value = (gobo1[1]/62.0-1)*360*(math.pi/360)
gobo_rotation = light_obj.data.node_tree.nodes.get(f"Gobo{n}Rotation")
if gobo[1]<128: # half for indexing
gobo_rotation.inputs[3].driver_remove("default_value")
gobo_rotation.inputs[3].default_value = (gobo[1]/62.0-1)*360*(math.pi/360)
else: # half for rotation
driver = gobo_rotation.inputs[3].driver_add("rotation_euler")
value = gobo1[1]-128-62 # rotating in both direction, slowest in the middle
driver = gobo_rotation.inputs[3].driver_add("default_value")
value = gobo[1]-128-62 # rotating in both direction, slowest in the middle
driver.driver.expression=f"frame*{value*0.005}"

if current_frame and self.dmx_cache_dirty:
gobo_rotation.inputs[3].keyframe_insert(data_path='rotation_euler', frame=current_frame)
gobo_rotation.inputs[3].keyframe_insert(data_path="default_value", frame=current_frame)

def updatePosition(self, geometry = None, x=None, y=None, z=None, current_frame=None):
if geometry is None:
Expand Down Expand Up @@ -1383,7 +1389,7 @@ def clear(self):
DMX_Data.set(self.universe, self.address+i, ch.default)
self.render()

def set_gobo(self, index=-1, current_frame=None):
def set_gobo(self, n, index=-1, current_frame=None):
gobos = self.images["gobos"]
for obj in self.collection.objects: #EEVEE
if "gobo" in obj.get("geometry_type", ""):
Expand All @@ -1403,7 +1409,7 @@ def set_gobo(self, index=-1, current_frame=None):

for light in self.lights: # CYCLES
light_obj = light.object
texture = light_obj.data.node_tree.nodes.get("Gobo1Texture")
texture = light_obj.data.node_tree.nodes.get(f"Gobo{n}Texture")
if texture.image is None:
texture.image = gobos.image
texture.image.source = "SEQUENCE"
Expand All @@ -1430,27 +1436,26 @@ def set_spot_diameter_to_normal(self, light_obj):
size = light_obj.data.get("beam_radius", 0.01)
light_obj.data.shadow_soft_size = size

def hide_gobo(self, hide = True, current_frame = None):
def hide_gobo(self, n=[1,2], hide = True, current_frame = None):
for obj in self.collection.objects:
if "gobo" in obj.get("geometry_type", ""):
obj.hide_viewport = hide
if current_frame and self.dmx_cache_dirty:
obj.keyframe_insert("hide_viewport", frame = current_frame)
for light in self.lights: # CYCLES
light_obj = light.object
mix = light_obj.data.node_tree.nodes.get("Mix")
if hide:
mix.blend_type = "MIX"
else:
mix.blend_type = "MULTIPLY"
for i in n:
#mix = light_obj.data.node_tree.nodes.get(f"Gobo{i}Mix")
mix_factor = light_obj.data.node_tree.nodes.get(f"Gobo{i}Mix").inputs["Factor"]
mix_factor.default_value = 1 if hide else 0

#mix_factor = light_obj.data.node_tree.nodes.get("Mix").inputs["Factor"]
#mix_factor.default_value = 1 if hide else 0
self.set_spot_diameter_to_normal(light_obj) # make the beam large if no gobo is used
if current_frame and self.dmx_cache_dirty:
light_obj.data.keyframe_insert(data_path="shadow_soft_size", frame=current_frame)
#mix_factor.keyframe_insert(data_path="default_value", frame=current_frame)
mix.keyframe_insert(data_path="blend_type", frame=current_frame)
mix_factor.keyframe_insert(data_path="default_value", frame=current_frame)
#mix.keyframe_insert(data_path="blend_type", frame=current_frame)

def has_attributes(self, attributes, lower = False):

Expand Down
Loading

0 comments on commit 0a3d11c

Please sign in to comment.