using the BlenderGameEngine as OSC client
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 OSC.py 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 mesh = own.getMesh() for i in range(mesh.getVertexArrayLength(0)): v = mesh.getVertex(0,i) v.color = [ msg/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)) GameLogic.socket.setblocking(0) GameLogic.socket.settimeout(0.1) else: try: #while 1: msg = OSC.decodeOSC(GameLogic.socket.recv(1024)) if msg == "/color": changeColor( own, msg ) except socket.error: pass
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
grease pencil experiment 4 - filled shapes
grease pencil experiment 4 - depth of field
grease pencil experiment 3 - animated circles
grease pencil experiment 2 - freestyle
Love this example, this has got me started with OSC->Blender Game engine, and I'm very excited about the possibilities! Thank-you!
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.
simpleOSC work like a charm on Macosx 10.5.8 :-)
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!
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.
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 firstname.lastname@example.org or email@example.com
I hope you have a good day.
@firstname.lastname@example.org 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?
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
The OSC->Blender Game engine is very good,thanks so much!
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?
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
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?
Cool. You could try wire it up to a Kinect using this https://github.com/rabidgremlin/OSCeleton-Puppet