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:
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) # 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) # 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.
ps: sure it’s not perfect but it works.
receiveUDP.blend (401 KB)