Using OSC in Blender 2.5 Game Engine (with Kinect-captured data)

Ah so your complete model scales to the size of the player? Btw: if you could tell me how to set bone head/tail in the GE, you’d make me happy :slight_smile:

Yes, although I’m aiming for the other way round (player scales to the size of the model - not literally of course, blender’s powerful but not that powerful) :slight_smile:

And to set bone/tail/length in GE:

import bpy
import bge

# Simple example for setting bone locations in BGE

armature = bpy.context.scene.objects[bge.logic.getCurrentController().owner.name]
obj = armature.data.bones['neck']
obj.head = ( 0.4, 0.2, 0.7 )
obj.tail = ( 0.4, 0.2, 0.7 )

# And if you're interested:
# with a few custom functions to perform simple maths routines
# this is how I'm scaling from player's bone length to model's bone length:

player_vector = joint.tail.sub(joint.head) # Vector of player's bone
player_length = player_vector.magnitude() # Length of player's bone

model_vector = obj.tail.sub(obj.parent.head) # Vector of model's bone
model_length = model_vector.magnitude() # Length of model's bone

scale_to = model_length / player_length # Find scale

obj.tail = obj.parent.head.add(player_vector.scale(scale_to)) # Get tail location

OMG , what an amazing feature, I tried to capture movement with several programs and trying to bring back the data to blender without luck, hopefully you can. Using the BGE directly to capture movement is simple amazing, best workflow ever.

Ah yeah and for child bones, you just add the vectors added to the parents :slight_smile:

btw: setting head and tail position doesn’t seem to have any effect to the model. (the change is stored though and i do have this “run armature” actuator)

edit
I tried the tracking way as well (also a test with tracking generated by your script) and that doesn’t change the model either. I guess there’s something you have that i don’t :stuck_out_tongue:

edit2 finally managed to get tracking working, apparently the armature has to be parent of the mesh AND the mesh needs the armature modifier.

FYI - I found this osc module for Py31

http://docs.ryancoyner.com/python-osc/releases/0.1/

tried it with B2.56 and got it to print out osc messages.


import oscd
import threading

class PrintMethod(oscd.Method):
    def __call__(self, address, typetags, data):
        print(('Address: %s' % address))
        print(('Typetags: %s' % typetags))
        print(('Data: %s' % data))

if __name__ == '__main__':
    HOST = 'localhost'
    PORT = 2222
    server = oscd.Server((HOST, PORT))
    server.add_method(PrintMethod('/print'))
    st = threading.Thread(target=server.serve_forever)
    st.start()

I just downloaded the newest version (0.2) went to the /ocsd folder and renamed init.py to ocsd.py. Then copied it to the folder with my blender.exe

pyliblo is compiling well on Python3.1 … just I had to recompile blender to make it import, I suppose the version of python3.1 used by the compiler is not stricly the same than the one on ubuntu 10.04 …

How far did you test this? Cause i managed to print the messages just fine, but the extra thread only executes after you stop the game (i heard multi threading isn’t supported yet)

I’ve had some success with this. I’m able to drive object locations in the game engine and in regular obj mode with this but they’re are instability problems and it tends to crash if things move around too quickly.

Hi! Great project! Can’t wait to play with a kinect aswell!

For the time being I’m want to connect the BGE to supercollider but I’m having difficulties receiving OSC in blender 2.5.
I don’t know how to make blender recognize my pyLiblo install and using the posted script for python-osc-0.2 I’m not receiving anything and I’m getting errors (already in use) as soon as I restart the BGE (Do you attach it to an always sensor?)

Can you help me with a basic “receive OSC in BGE” example. Maybe a blend-file?
I’m on Ubuntu 10.10 64bit, python 2.6 and 3.1, blender 35290

I hope I’m not hijacking your thread! but this is the most recent info on OSC that I found and it’s kind of on-topic ; )

hi feadi.
Here you have another OSC example (a little simpler) with liblo, and a .blend file: http://blenderartists.org/forum/showthread.php?t=210098&p=1797975#post1797975

but if you cannot import liblo in the blender console the blend file will not work…

the trick for me to install liblo and pyliblo correctly was to change (in the instalation guides) python with python3:

i.e: if the readme says: sudo python setup.py install > i do >> sudo python3 setup.py install

but i dont remember exactly all the steps… and maybe it depends on your python setup…

Hi Carlos!
Thanks a lot! I tried running the pyliblo install like this: >> sudo python3.1 setup.py build
but I get an error involving liblo. I guess I need a python3.1 install for liblo as well, but I have no idea how.
The whole situation of having python2.6, 3.1 and blenders python confuses me a bit. Isn’t there a way of just including a script with blender, like teldredge did?

Any progress on this? Would love to get me some sweet Blender / Kinect based mocap :smiley:

I initially posted this in the wrong thread with two threads open in different windows. Silly me. It is far more relevant here though so I’ve reposted it. Apologies for any confusion for people checking on both threads.

Post begins:

[edit]
This will teach me to read threads properly before I post… It seems that you’ve found a way to set bones in bge using bpy. :eek:

My post is probably not relevant. Sorry for the clutter, but I’ll leave it since it’s a good example of why just using the bge api is a bad idea. :slight_smile:

I’m really gonna have to read through the scripts here to see how you’re doing stuff.
[/edit]

Hi folks. Interesting stuff here.

Regarding setting bone positions in bge:

I’ve played with setting bone positions/rotations directly but it’s not an easy task. The bpy api will not directly set the bones in a bge armature. The armature that exists in the game engine is different from the one that you see in the main Blender editor.

The object that you need to manipulate is the BL_ArmatureObject. However, the BL_ArmatureBone objects cannot be set directly:

Proxy to Blender bone structure. All fields are read-only and comply to RNA names. All space attribute correspond to the rest pose.
It is possible to set the pose of the armature using BL_ArmatureChannels, but you need to do it using rotations since the location can only be set on unconnected bones
Note :

You can only move a bone if it is unconnected to its parent. An action playing on the armature may change the value. An IK chain does not update this value, see joint_rotation.

There might be a way of controlling an armature using unconnected bones, but this seems strange to me and I’m not sure how this would affect mesh deformation.

It is possible to set bone rotation directly in a connected armature, but you’ll need some math skills in order to change the head/tail positions into a rotation and allow for the bone parent’s rotations. I think the rotations need to be set relative a bone’s rest position.

A bone’s rest position is given relative to it’s parent bone. eg. When a parent bone is rotated, the child bone is rotated with it, but since the child has bone has not actually been rotated itself relative to the parent bone, it will still be in it’s rest position even though it will appear to have been rotated (just like any parent-child rotation relationship when using “local” rather than “global”).

Unfortunately, bone matrices are also read-only.

I would strongly advise using quaternions in order to avoid gimbal lock and other errors associated with the order that x,y,z euler rotations are applied.

BL_ArmatureChannel.rotation_quaternion

rotation of the bone relative to its parent expressed as a quaternion, read-write. :smiley:
Edit:

joint_rotation might be better, but I’ve never used it so I cant really say more than it might be worth looking at and playing with.

I wish you success with this folks, it would be a great addition to Blender. :slight_smile:

Edit 2:

joint_rotation allows the setting of bone rotaions using joint angles.

im very happy this project exists int the world as i was about to start work on this myself. maybe i can learn from your work and contribute :slight_smile:

Brekel Kinect -> Blender mocap script. (UNFINISHED)

I got pretty far on a script to allow Brekel Kinect data to show in the bge. Had some trouble with the shoulder rotations.

Thought I’d post this here in case it helps anyone looking into this.

Great work! I’ve got it into a blend with a base armature but when I run the script on startup it doesn’t create a object tab with the skeleton maps? Know of any quick troubleshooting tips?

Nice! I’ve got a basic blend with only an armature and the script, connected to startup as shown but no love on creating the skeleton mapping panel. Any troubleshooting tips or updates?

Hi,

am working on a project that needs this general idea, which needs to passing an osc message from processing to blender game engine …

i have multi object in the scene and based on a message recieved initially i want to :

  • fire the right function based on the object nedd to be activated at this time
  • apply the content of the message to the object location, rotation …

i want to select a single object in each time the message recieved by osc and the selected object will be based in the object name in the osc message … so i need help for such python script to do that so i can express it as a base to continue

and i don’t know exactly if i can write this script as general which include a script that access the right object and make this script a controller to all object , is this possible ?

thanks in advance …

jab.superharmer.k3.blend (539 KB)

FWIW I did finally get this working but without the control panel, and just using python bricks instead. A couple differences: empties instead of cubes, and ratios of the osceleton joints are used to generate the joint position for the target armature.

I’d love someone who knows more about rigging than me to have a look at the armature and give me any pointers! It does deform in strange ways occasionally. Youtube video of it here: http://www.youtube.com/watch?v=s85NME5QZR4

.blend file attached.

Youtube video: http://www.youtube.com/watch?v=s85NME5QZR4