using the BlenderGameEngine as OSC client

Nikolaus Gradwohl2009-03-08T15:18:00+01:00

i just managed to use the GameEngine of blender as a client for OSC events :-)

now i can change the color of a cube by sending osc events from my pd-patch or the ruby-script i wrote for my openframeworks-demo


the blend file can be downloaded here

the blend file needs by Daniel W. Holth to be in the python searchpath, so either copy it to location you start blender form or copy it to your site-package folder (obviously i'm not the only one who had the idea of using this lib with the blender game engine :-] )

in the panel on the bottom of the screen switch to the game mode by clicking the little "pacman"-Icon


add a property to the default cube


then create a textfile and name it "script1"


and enter the following python code

import GameLogic
import Blender
from Blender import Material
import socket
import OSC

cont = GameLogic.getCurrentController()
own = cont.getOwner()

def changeColor(own, *msg):
    print msg[0]
    mesh = own.getMesh()
    for i in range(mesh.getVertexArrayLength(0)):
        v = mesh.getVertex(0,i)
        v.color = [ msg[0][2]/255.0, 0.0, 0.0, 1.0]

if not own.connected:
    print "Hallo blender Welt"
    own.connected = True

    mesh = own.getMesh()
    for i in range(mesh.getVertexArrayLength(0)):
        v = mesh.getVertex(0,i)
        v.color = [0.0, 1.0, 0.0, 1.0]

    GameLogic.socket = socket.socket( socket.AF_INET, socket.   SOCK_DGRAM )

    GameLogic.socket.bind(('', 1234))
        #while 1:
        msg = OSC.decodeOSC(GameLogic.socket.recv(1024))    
        if msg[0] == "/color":
            changeColor( own, msg )
    except socket.error:

then create the following logic blocks in the gamemode panel


finally move the mouse cursor over the cube and enter the gamemode by pressing "P". Now send osc events to port 1234 and watch the cube change its red-level :-)

the editor window of blender is a bit instable and i managed to crash it several times - so save often

Tweet This! submit to reddit Digg!   Tags: | 13 comments | no trackbacks

See also:

sound visualizer experiment 1
object traces
blender physics experiments - collision
blender physics experiments
blender physics experiments - wall



Leave a response

  1. bridd 2009-05-21T10:47:19+02:00

    Love this example, this has got me started with OSC->Blender Game engine, and I'm very excited about the possibilities! Thank-you!

  2. Bmud 2009-06-05T00:48:07+02:00

    I'm really tearing my hair out with this stuff. It's the ports that I don't understand mostly.

    There are two different OSC python libraries. There's the one that the wiimote guy used which is "unsupported" and doesn't work on OSX, and there's the simpleOSC module that... seems to not work either.

  3. predat 2009-09-14T09:41:12+02:00

    simpleOSC work like a charm on Macosx 10.5.8 :-)

  4. capheen 2009-11-13T19:43:45+01:00

    Awesome. I have seen few examples of this, and this is the first 'works out of the box' demonstration I have found. Tested it with Pd~ oscTestPatch. Thanks!

  5. cristian 2009-11-26T01:16:10+01:00

    Hi, í was looking for this script. i´m a newbie in blender and i have a question, can I change the color of the cube without the script? i mean, is there another way to do that without learning python? sorry for my english,i´m from argentina.

  6. 2010-04-06T16:12:18+02:00

    Mostrar forma romanizada Hello, I'm Sebastian, I speak little English but I hope you understand.

    is incredible, I was looking for this long ago! I am doing a project to encourage MIDI sequences, it is my graduation project.

    you've seen the new Blender 2.5?, there are ways to visualize stereoscopic (3D image with different ways to see), imagine create animations in real-time stereoscopy!

    thank you very much indeed, is a great contribution from you for my thesis

    if you want to write to my e-mail is or

    I hope you have a good day.

  7. Nikolaus Gradwohl 2010-04-06T16:45:43+02:00 i read about it but i didn't test it yet - but combining midi width 3d rendering sounds interesting, do you have a project page?

  8. bernardo 2010-04-21T23:24:05+02:00


    your example looks like it might help me for a project i'm working on, which involves controlling two separate instances of blender of two different computers via a tuio enabled device. if pd could handle all the tuio interaction and simply send osc to blender, that would help me a lot, as i am not really familiar with python or blender's python api. my question is related to this, as i would like to be able to extrapolate from your example to what i'm actually trying to do. the problem is... i can't figure out how to make blender interpret the data recieved from pd, namely, access the position and rotation of an object in blender. while i think i understand the basic structure of what's going on in your "script1" example, i can't understand the basics of accessing, even while looking at the blender api reference. any general pointers?

    thanks for reading

  9. Hebe 2010-09-03T08:51:06+02:00

    The OSC->Blender Game engine is very good,thanks so much!

  10. Ale 2011-06-09T04:15:06+02:00

    Very usefull!!Thanks it works great.. may you post a second tutorial in which we can read a second variable from osc toghether with the first one,like moving and changing color?

    thanks again

  11. Tim Bright 2011-11-09T10:56:07+01:00

    Super Stuff mate, this is just excellent.

    Exactly as the others have said above. I have spent a lot of time looking at this over the past week, this is the first site that sets it out step by step,

    thanks a lot

  12. Isaac Segura 2013-04-12T16:10:07+02:00

    I was able to follow the instructions on the newer version of Blender, but the script does not run ( on line 11 says : sintaxError: invalid sintax) and the pd patch prints it has "no method for send" when I use the slider, What can I do to fix this issues?

  13. Rabidgremlin 2013-04-12T22:38:04+02:00

    Cool. You could try wire it up to a Kinect using this

Leave a comment