Rotating bones using python-script and sockets

Animation tools, character animation, non linear animation

Moderators: jesterKing, stiv

Post Reply
jonasBrazil
Posts: 0
Joined: Thu May 09, 2013 10:46 pm

Rotating bones using python-script and sockets

Post by jonasBrazil » Thu May 09, 2013 11:08 pm

Hello,
I'm trying to make a human model in Blender receive the rotations for each bone trough a socket.
I'm doing it in real time.
The Blender's program receives the bone, angle of rotation and axis, and then, it should only rotate the bone.. But it's not working...
I've verified and Blender is actually receiving everything from the socket, so the problem is not in the socket, I beleive it's in the act.setChannel() function. Maybe this function was not continued in the newers versions...
Can someone help me on this? Here is the code I'm using...
The packet is organized by [Bone_Name, axis, angle]

import bge
from bgl import *

from datetime import datetime


import mathutils
from math import radians

import time
import socket

Controller = bge.logic.getCurrentController()

if hasattr(bge.logic,'test')==False:
Host = ''
ServerPort = 5000
bge.logic.server = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
bge.logic.server.bind((Host,ServerPort))
bge.logic.server.setblocking(0)
bge.logic.test = True
print(datetime.now())

if True:

try:
packet, address = bge.logic.server.recvfrom(256)
packet = packet.decode('utf-8')
packet = packet.split(",")
print(packet)

if(len(packet)==3):
packet[0] = str(packet[0])
packet[1] = str(packet[1])
packet[2] = int(packet[2])
print(packet)

act = Controller.actuators["Action"]

mat = mathutils.Matrix.Rotation(radians(float(packet[2])), 4, packet[1]).to_quaternion()
print(mat)
act.setChannel(packet[0], [ 0.0, 0.0, 0.0], [ 1.0, 1.0, 1.0], mat)

Controller.activate(act)
except:
pass

Post Reply