Artnet "DMX" Server (Blender 2.5)


(skuax) #1

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)


(bankbaa) #2

How to use this?


(skuax) #3

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.


(Tirnion) #4

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


(uekeueke) #5

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.


(skuax) #6

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

regards

skuax


(offtools) #7

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)


(skuax) #8

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.