OSC is a well known protocol for communications between multimedia applications. This Add-on allows you to bind easily Blender properties to OSC messages and see the result in real-time in the viewport interface.
NEW: Now this Add-on installs a module for the Blender Game Engine, see this page.
This Add-on uses the UDP Internet protocol but is mostly intended to work on local networks. Be warned that letting the server to listen to an interface connected to the Internet may expose you to security risks. I could not be held as responsible if whatever bad happened using this Add-on.
All theses settings are stored in the Blend file and are not scene dependent. Changes in OSC settings are not applied while the engine is running, you will have to restart it.
You might want one day to add or remove AddOSC items by scripting.
The items are stored in the collection property (OSC_keys) belonging to a scene. Each item has several fields:
Let's define a shortcut in our script to that scene, you can either point to the current active scene or to a given scene by its name :
import bpy scene = bpy.context.scene (or : scene = bpy.data.scenes['Scene'])
To clean up a previous collection if needed:
scene.OSC_keys.clear()
To create a new item:
item = scene.OSC_keys.add() item.data_path = "bpy.data.objects['Cube']" item.id = "location[1]" item.address = "/blender/0" item.osc_type = "float"
You can if you need define item.idx:
item.idx = 1
...but there is no need to define item.value as it is recalculated automatically.
Since scene.OSC_keys is a collection you can access each element like an array:
scene.OSC_keys[-1].id = "location[0]" scene.OSC_keys[-1].idx = 0
...the value -1 given for the item in the collection is a python trick to point to the last.
To remove an item (here the first):
scene.OSC_keys.remove(0)
To ease the access of the values received by AddOSC we are going to write a custom script node in AN.
But fisrt and foremost, import a Keying Set in AddOSC and configure correctly the items so that they actually receive some OSC data.
Open the Blender script editor, copy/paste theses lines:
sce = bpy.context.scene
try:
String = sce.OSC_keys[Integer].value
except:
pass
Rename your script as "OSC_get.py"
Add a Script node (in "Subprograms") in the node editor of AN.
Click "New input" and chose "Integer", it will allow to choose the item from your AddOSC collection.
Click "New output" and chose "String", it will output the last content received for the item (remember it is only refreshed when AddOSC is running and receive something).
With the selector chose your script "OSC_get.py" and below change the name to "OSC_get".
Now in "Subprgrams/Invoke Subprrograms", pick "OSC_get".
Connect a Debug node to the String output of this node, and change the integer value to pick the item imported in AddOSC . That's it !
If you re-import a Keying Set, manual edition(s) of the OSC addresses will be preserved.
The first OSC 1.0 standard didn't implement boolean parameters natively however it was supported as an extension. Nowadays, every client/server should support them. It is the case of AddOSC but it could be a problem if you use an old software (or device ?) supporting only OSC version 1.0. Mail me if it's happen. Blender has boolean properties and they are sent as such without conversion currently, but a workaround could be implemented.
Enum properties (you know the drop-down menus to pick a value) are presented as string, just send the name of the item as it would appear in the Blender interface to select the good choice.
Blender treats angles in radians internally despite showing them in degrees in the user interface ! So to rotate an object by 180° you have to send the Pi value from your OSC source.
Blender has a tolerance concerning types:
This Add-on is now as easy to install as another Blender Add-on. It currently includes the pyhton-osc module (author: Thimote Faudot), on which it relies, for the sake of simplicity.
Grab the zip archive from my Github page (Download ZIP on the right), then do "install from file" in the "User Preferences/Add-ons" screen and enable it with the check-box once it is listed.
GPL v3
AddOSC doesn't currently allow to bind OSC messages to Blender operators but you can use update function in a script as a workaround, as shown in this simple example. Value 10 and 11 will toggle the mode between EDIT and OBJECT.
There is a thread on the BlenderArtist forum.
Thanks to MisterCroche and Winzs for their support, inspiration, testing, ideas. :)