Hello folks,
Here is my first Python code done in blender for receiving messages from network based on the Artnet protocol. This little piece of code is intended to be used for previsualisation of a “real life” light programation based on DMX in the game engine.
I have done it for an artistic project called “Keyframe”. It 'll be played at the “festival des lumieres” in the town of Lyon this year.
the softwares used for sending information to blender are “whitecat” and “live”
thanks to christophe the creator of whitecat who explain me the structure of an artnet packet.
For the moment there is no filtering of the header in the script. But it 'll be easy to add it.
As a non-programer, i’ve tryed to comment it as much as possible.
import GameLogic
import types
import socket
# Get controller and owner
controller = GameLogic.getCurrentController()
owner = controller.owner
ip_dump = '' # client ip adress (Listening all)
host_dump = 6454 # udp port setting
Channel = [] # Creating a dynamic list to receive filtered udp packets
if not owner['connected']:
owner['connected'] = True
print('Blender Connected')
GameLogic.socket = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
GameLogic.socket.bind((ip_dump, host_dump))
GameLogic.socket.setblocking(0)
GameLogic.socket.settimeout(0.01)
else:
try:
msg = (GameLogic.socket.recv(530)) # Creating a variable coming from network ((530) is the packet's range size)
# ( the UDP packet header's size is 18 , so, we add 512+18 )
x = 18 # Creating a variable to increment UDP content's reading's index
#print (msg[18]) # If you want to read the raw udp value in the console uncomment this
while x < 530: # Conditioning reading range in the udp packet (if you use less that 512 values decrease it to reduce the reading loop)
val = 0.1 # Creating a float variable for packet value to be converted later(integer to a float)
y = x-18 # Creating an integer to start at the first index of array Channel created later
val = msg[x] / 255 # integer to a float between 0 and 1
Channel.insert(y, val) # feeding the channel's array with converted UDP's Packet values
x = x+1 # incrementing the udp packet to read next
#print (Channel[6]) # uncomment this to print in the console the channel value
except socket.error:
pass
It was my first try and i must say a big thanks to the comunity for the help i found reading tons of post on the net. and a very big thanks to the blenderartist’s comunity.
i’ ve been inspired by all your posts guys.
if you own a light console or a dedicated light software like “whitecat” (free) you can connect it to whatever you want in blender (assuming you know a little bit of python and blender) then drive it via external input by ethernet.
Are there any further instructions on how to use this? I am using MagicQ for Artnet out and Blender 2.61 on Mac for receiving. At the moment, I am putting out data for every channel on DMX Universe 1 (Artnet 0), and I am not getting any response.
I’m trying to use it…
the first steps are fine, but i don’t know how to assign a property to the received information.
There’s any example file with more complete info?
Thanks for those who read this post.
u.
Thank you for the post, very interessting. Think I will use it with QLC -> OLA -> Blender || Gameengine. Very usefull.
(I used my own addon to receive DMX from ola during a show, but I needed it to convert dmx into OSC Messages, your way is much more elegant and direct)
Tanks for the ‘elegance’ . I’m not a coder at all. That was my first try. But, as usual, it’s when you have something concrete to do that you learn a lot.
Inspired by this, I’ve created an improved script that maps Artnet onto lights with fixture definitions.
It uses a background thread for the artnet socket which improves responsiveness.
Cool. Background task sounds good to me. Because I was in a struggling data flow when dealing with more than hundred channels.
edit1:
as i was reading your code it seems that you parse the scene for all object inside.
Perhaps it 'll be more elegant to determine a collection with the objects that need to be remoted by Artnet?
edit2: It could be interesting to create a fixture type by kind of light you are using in your show and feed it with a designed interface. and the by spot assigning there type and artnet adress in a pannel.
I only parse the scene at the beginning (see init and setup methods). You’d have to restart the script currently if the mapping is modified. I’m trying to avoid as much work as possible in the per-frame scripts.
I agree that it needs a UI panel in every light to map it to a fixture type, universe and base address - I don’t yet know how to achieve this.
IMO, the fixture type should be select able from a drop down menu instead of typing it. I have spent 10 minutes finding that it was written in a script ( src/fixture_type_store.py ) .
Or Copy the fixture type text configuration on the readme.txt