Here is a simple sample *.blend file and a python script to drive the “player” from data received over the network using UDP. Its set up to use “localhost” so you can run Blender and the python script on the same computer for testing. It only really becomes useful with Blender on one machine and the controller on another like might exist in a virtual reality type setting.
I’m posting this because Googling didn’t find a straight answer about how to do such a thing. I did quickly find the BZoo project which is far more elaborate and uses TCP, and the OSC network sound loader (http://blenderartists.org/forum/archive/index.php/t-69804.html).
I put what I learned together from these and modified Social’s Beginning BGE Python sample *.blend (http://blendenzo.com/tutBeginningBGEPython.html) to show how a remote application can drive the player across a UDP network connection.
I’m new to Blender and Python so I make no claims as to it being the “best” way. In fact I’d love to have a better way or any improvements pointed out to me.
We envision a three computer setup. One running Blender to control the visual scene, one running a servo motion base, and the master reading sensors and running the contol algorithms to drive the visuals and motion base via network connections. We already have one such setup using Vizard for the visuals, I’m looking to avoid buying more $5000 Vizard software.
Tested/developed on Ubuntu 8.04 with Blender 2.45
–wally.
PS Can’t seem to upload the python script to drive the thing. Its short so I’ll paste it here: It just drives the player in a simple Lissajous curve.
-----------------------------------UDPdriverScript.py----------------------------------
import socket
import struct
import math
import sys, time
replace localhost with network name of game machine defined in game blend
HOST, PORT = “localhost”, 9999
SOCK_DGRAM is the socket type to use for UDP sockets
sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
for i in range(0,4000):
phi = 3.141592653589 * 2 * i / 200
theta = math.sin(phi/3) / 300
y = math.cos(phi/11) / 20
data=struct.pack(’<ff’,theta,y)
sock.sendto(data, (HOST, PORT))
time.sleep(0.0333) # try for 30fps motion updates
data=struct.pack(’<ff’,0,0)
sock.sendto(data, (HOST, PORT))
sock.close()
-------------------------------------------end script--------------------------------------------
Attachments
NetValuesTest_py.blend (195 KB)