Artnet "DMX" Server (Blender 2.5)

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.

More about the project:

http://www.groupe-laps.org/spip.php?rubrique138&id_mot=49&id_groupe=2

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.

Hope it’ll be usefull for someone.

Thanks

Skuax

ps: sure it’s not perfect but it works.

Attachments

receiveUDP.blend (401 KB)

How to use this?

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.

Thanks,
–Tirnion

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.

gonna tell you more about this as i ll be back from hollydays.

regards

skuax

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.

2 Likes

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 have sent you a message with more info in your box.
As my code is really “dirty”. I don’t think it’s a good idea to publish it for the moment…

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.

Try my new version. Much cleaner, converted to classes and now it’s a full addon.

re your edit2, that’s already in the code. Take a look at the FixtureTypeStore and how the BlenderSynchronizer uses it

Added a full UI so you can now connect your blender lights direct to ArtNet

Demo here - [https://www.youtube.com/watch?v=aSekSai2qUo]

About Lux. I don’t know if you have already read this but in case of not:

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 ) :grin:.
Or Copy the fixture type text configuration on the readme.txt

Absolutely agree, but not implemented yet. The readme does say to add your fixtures in the fixture type store (clue is in the name…!)

And I’m accepting contributions if you’d like to set up the dropdown

I think we shouldn’t need the hard coded type store - we should be reading the data from an open fixture dictionary. Or from qxf files!

If you know where is it?