Commit 1d66c206 authored by Bruno Laurencich's avatar Bruno Laurencich

OSC send (but library issue)

parent 5ac69e23
......@@ -15,9 +15,12 @@ if "u" in locals():
import imp
imp.reload(u)
imp.reload(arm)
imp.reload(send)
else:
from . import utils as u
from . import armature as arm
from . import send
D = bpy.data
......@@ -49,10 +52,10 @@ class Chord_Receive_OSC(bpy.types.Operator):
a.header_text_set()
def clean_prev_animations(self):
self.context.scene.frame_current = 0
try:
self.armature.object.animation_data.action.use_fake_user = True
self.armature.object.animation_data_clear()
self.context.scene.frame_current = 0
except AttributeError:
u.write_blender_console(self.context, "No previous animation data found.")
......@@ -69,12 +72,12 @@ class Chord_Receive_OSC(bpy.types.Operator):
def start_stop_animation(self):
if self.do_set_keyframes:
self.do_set_keyframes = False
self.report({"INFO"}, "Stop registering animation")
self.report({"INFO"}, "Stop recording animation")
else:
self.clean_prev_animations()
self.do_set_keyframes = True
self.report({"INFO"}, "Registering animation!")
self.report({"INFO"}, "Recording animation!")
def set_keyframe(self):
......@@ -89,6 +92,7 @@ class Chord_Receive_OSC(bpy.types.Operator):
if event.type == 'TIMER':
osc_process()
self.set_keyframe()
send.send_Armature(self.armature.object)
return {'PASS_THROUGH'}
......@@ -144,6 +148,8 @@ class Chord_Receive_OSC(bpy.types.Operator):
if not self.start_server(): return {"CANCELLED"}
send.init_osc("Unicast", "127.0.0.1", 7000)
return {'RUNNING_MODAL'}
# ----------- SERVER -----------
......@@ -198,6 +204,7 @@ class Chord_Receive_OSC(bpy.types.Operator):
wm = context.window_manager
wm.event_timer_remove(self._timer)
osch.get_channel("chordata_armature_server").terminate()
send.clean()
self.chord_global.receiving = False
self.text(None)
osc_terminate()
......
import bpy
# from mathutils import Vector
D=bpy.data
C=bpy.context
# cam = D.objects['the_cam']
# from pythonosc import osc_message_builder
# from pythonosc import osc_bundle_builder
# from pythonosc import udp_client
# from mathutils import Matrix, Euler
# from time import sleep
# from math import pi
# from os import system
# from os import path
# from sys import path as syspath
# Import needed modules from osc4py3
from osc4py3.as_comthreads import *
from osc4py3 import oscbuildparse
from osc4py3 import oscchannel as osch
import time
if "u" in locals():
import imp
imp.reload(u)
else:
from . import utils as u
def init_osc(type, addr, port):
# Start the system.
print("Starting CLIENT!")
try:
osc_startup()
except:
print("OSC already initialized")
client = u.transmition_methods(False)[type][3]
# Make client channels to send packets.
client(addr, port, "chordata_client")
def send_Armature(arm):
# msg = oscbuildparse.OSCMessage("/test/me", ",sif", ["text", 672, 8.871])
# osc_send(msg, "chordata_client")
# osc_process()
# return
msgs = []
for b in arm.pose.bones:
q = b.matrix.to_quaternion()
# q.rotate(Euler((-pi/2,pi/2,0)))
msgs.append(oscbuildparse.OSCMessage("/capture/"+b.name, None, [q[0], q[1], q[2], q[3]]))
bun = oscbuildparse.OSCBundle(oscbuildparse.OSC_IMMEDIATELY, msgs)
osc_send(bun, "chordata_client")
osc_process()
# print("send")
def clean():
osch.get_channel("chordata_client").terminate()
# def send_init_msg(arm):
# client.send_message("/init", len(arm.pose.bones))
# def send_animation(arm):
# timeline = C.scene.frame_start, C.scene.frame_end
# send_init_msg(arm)
# delay = 1/C.scene.render.fps
# for i in range(*timeline):
# C.scene.frame_set(i)
# send_Armature(arm)
# sleep(delay)
# class send_anim_osc(bpy.types.Operator):
# """Receive quaternions from OSC and move an armature"""
# bl_idname = "armature.send_anim_osc"
# bl_label = "Send the animation trought OSC"
# @classmethod
# def poll(cls, context):
# return True
# def invoke(self, context, ev):
# # print("SEND INVOKE")
# return self.execute(context)
# def execute(self, context):
# deb = note_debouncer()
# piano_collide.unregister()
# send_animation(context.object)
# return {"FINISHED"}
# class send_osc(bpy.types.Operator):
# """Receive quaternions from OSC and move an armature"""
# bl_idname = "armature.send_still_osc"
# bl_label = "Send the pose trought OSC"
# @classmethod
# def poll(cls, context):
# return True
# def invoke(self, context, ev):
# # print("SEND INVOKE")
# return self.execute(context)
# def execute(self, context):
# # deb = note_debouncer()
# # piano_collide.unregister()
# send_Armature(context.object)
# return {"FINISHED"}
# def register():
# print("SENDING OSC to {}:{}".format(IP, PORT))
# bpy.utils.register_class(send_osc)
# bpy.utils.register_class(send_anim_osc)
# def unregister():
# bpy.utils.unregister_class(send_osc)
# bpy.utils.unregister_class(send_anim_osc)
# if __name__ == '__main__':
# register()
# # send_animation(D.objects["TARGET"])
......@@ -2,7 +2,7 @@ import bpy
from sys import path
from os.path import join, abspath, dirname
path.append(join(dirname(abspath(__file__)), "osc4py3-1.0.4"))
from osc4py3.as_comthreads import osc_udp_server, osc_multicast_server, osc_broadcast_server
from osc4py3.as_comthreads import *
import ipaddress
import socket
......@@ -29,9 +29,9 @@ def get_chordata_armature():
def transmition_methods(as_tuples = True):
"""Transmision method to be used"""
d = {
"Unicast": ("uni", 0, osc_udp_server),
"Multicast": ("multi", 1, osc_multicast_server),
"Broadcast": ("broad", 2, osc_broadcast_server),
"Unicast": ("uni", 0, osc_udp_server, osc_udp_client),
"Multicast": ("multi", 1, osc_multicast_server, osc_multicast_client),
"Broadcast": ("broad", 2, osc_broadcast_server, osc_broadcast_client),
}
if as_tuples:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment