Commit 6aaeac4f authored by Bruno Laurencich's avatar Bruno Laurencich

basic retransmision

parent 44332544
......@@ -58,35 +58,59 @@ class Chord_Properties(bpy.types.AddonPreferences):
notochord_msg = props.StringProperty( default = "" )
notochord_hostname = props.StringProperty( name="Notochord hostname",
description="The hostname to be used for the ip resolution", default = "notochord" )
multicast_grp_addr = props.StringProperty( default = "239.0.0.1" )
local_ip_addr = props.StringProperty( default = u.get_local_ip() )
notochord_dest_port = props.IntProperty( default = 6565 )
notochord_parameters = props.StringProperty( default = "" )
notochord_ip = props.StringProperty( default = "" )
last_check = props.IntProperty( default = 0 , options={'SKIP_SAVE'})
max_ip_discover_attempts = props.IntProperty( default = 3 )
receiving = props.BoolProperty(default = False , options={'SKIP_SAVE'})
manage_notochord = props.BoolProperty( name="Manage notochord",
description="Start the notochord when receiving, and finish it on close", default = False )
show_advanced = props.BoolProperty( name="Show advanced panel", default = False )
show_send = props.BoolProperty( name="Show retransmision panel", default = False )
# ----------- ADVANCED -----------
debug_osc = props.BoolProperty( name="Debug osc to console", default = False )
notochord_parameters = props.StringProperty( default = "" )
notochord_hostname = props.StringProperty( name="Notochord hostname",
description="The hostname to be used for the ip resolution", default = "notochord" )
capture_quat_patt = props.StringProperty( name = "Capture OSC pattern",
description = "Regex pattern to filter bone quaternion data only", default = r"^/Chordata/(\w.*)" )
# ----------- SEND -----------
class Send_Properties(bpy.types.PropertyGroup):
trans_method = props.EnumProperty(\
items= u.transmition_methods(),
default="Unicast")
ip_addr = props.StringProperty( default = "127.0.0.1" )
multicast_grp_addr = props.StringProperty( default = "239.0.0.2" )
dest_port = props.IntProperty( default = 7000 )
send_rot = props.BoolProperty( name="Send rotation", default = True )
send_pos = props.BoolProperty( name="Send position", default = False )
send_vel = props.BoolProperty( name="Send velocity", default = False )
# props = props.EnumProperty(\
# items= u.sending_props(),
# default={"Rotation"},
# options={"ENUM_FLAG"})
send = bpy.props.PointerProperty(name="Retransmit properties",
description="Properties to be used when retransmiting OSC to another program",
type=Send_Properties)
# ----------- INTERNALS -----------
receiving = props.BoolProperty(default = False , options={'SKIP_SAVE'})
max_ip_discover_attempts = props.IntProperty( default = 3 )
last_check = props.IntProperty( default = 0 , options={'SKIP_SAVE'})
def target_update(self, context):
"""TODO: this function should block from selecting a non armature typed object """
pass
......@@ -101,6 +125,7 @@ class Chord_Scene_Properties(bpy.types.PropertyGroup):
helpers = bpy.props.PointerProperty(name = "Sensor helpers parent",
description="An empty that have as children sensor helper objects",
type=bpy.types.Object)#, update=target_update
# ====== End of GLOBAL PROPERTIES =======
# =======================================
......
......@@ -78,7 +78,7 @@ class Chord_tools_panel(bpy.types.Panel):
### BOX
layout.separator()
box = layout.box()
box.label("Transmision method")
box.label("Notochord Transmision method", icon="NLA_PUSHDOWN")
row = box.row()
row.prop(self.chord_global, "trans_method", expand=True)
......@@ -98,11 +98,61 @@ class Chord_tools_panel(bpy.types.Panel):
col.label("Port")
col.prop(self.chord_global, "notochord_dest_port", text="")
if self.chord_global.trans_method == "Broadcast":
row = box.row()
row.prop(self.chord_global, "net_submask", text="Net submask")
layout.prop(self.chord_global, "show_advanced")
layout.prop(self.chord_global, "show_send")
class Chord_send_panel(bpy.types.Panel):
"""Retransmision options panel for the chordata client addon"""
bl_label = "Chordata Retransmit"
bl_category = "Chordata"
bl_space_type = "VIEW_3D"
bl_region_type = "TOOLS"
@classmethod
def poll(cls, context):
chord_global = context.user_preferences.addons[__package__].preferences
return chord_global.show_send
def draw(self, context):
self.chord_global = context.user_preferences.addons[__package__].preferences
layout = self.layout
box = layout.box()
box.label("Retransmision method", icon="MAN_TRANS")
row = box.row()
row.prop(self.chord_global.send, "trans_method", expand=True)
row = box.row()
split = row.split()#percentage=0.25
col = split.column()
# col.operator("my.button", text="21").loc="5 21"
if self.chord_global.send.trans_method == "Multicast":
col.label("Multicast group")
col.prop(self.chord_global.send, "multicast_grp_addr", text="")
else:
col.label("Destination address")
col.prop(self.chord_global.send, "ip_addr", text="")
split = row.split()#percentage=0.25
col = split.column()
col.label("Port")
col.prop(self.chord_global.send, "dest_port", text="")
if self.chord_global.send.trans_method == "Broadcast":
row = box.row()
row.prop(self.chord_global, "net_submask", text="Net submask")
layout.label("Send properties:")
layout.prop(self.chord_global.send, "send_rot", text="Rotation")
layout.prop(self.chord_global.send, "send_pos", text="Position")
layout.prop(self.chord_global.send, "send_vel", text="Velocity")
class Chord_advanced_panel(bpy.types.Panel):
......
......@@ -94,7 +94,7 @@ class Chord_Receive_OSC(bpy.types.Operator):
if event.type == 'TIMER':
osc_process()
self.set_keyframe()
send.send_Armature(self.armature.object)
send.send_Armature(self.armature.object, self.chord_global.send)
return {'PASS_THROUGH'}
......
......@@ -48,17 +48,19 @@ def init_osc(type, addr, port):
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
def send_Armature(arm, options):
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]]))
if options.send_rot:
q = b.matrix.to_quaternion()
msgs.append(oscbuildparse.OSCMessage("/Chordata/quaternion/"+b.name,
None, [q[0], q[1], q[2], q[3]]))
if options.send_pos:
pos = b.tail
msgs.append(oscbuildparse.OSCMessage("/Chordata/position/"+b.name,
None, [pos[0], pos[1], pos[2]]))
bun = oscbuildparse.OSCBundle(oscbuildparse.OSC_IMMEDIATELY, msgs)
osc_send(bun, "chordata_client")
......
......@@ -7,11 +7,6 @@ from osc4py3.as_comthreads import *
import ipaddress
import socket
print(osc4py3.as_comthreads)
print(osc4py3.as_comthreads.osc_multicast_server)
print(path)
def get_local_ip():
"""Get local ip, from https://stackoverflow.com/a/28950776 """
......@@ -35,9 +30,7 @@ def get_chordata_armature():
def transmition_methods(as_tuples = True):
"""Transmision method to be used"""
# import pdb; pdb.set_trace()
o = osc4py3.as_comthreads
d = {
"Unicast": ("uni", 0, o.osc_udp_server, o.osc_udp_client),
"Multicast": ("multi", 1, o.osc_multicast_server, o.osc_multicast_client),
......@@ -49,6 +42,20 @@ def transmition_methods(as_tuples = True):
return d
def sending_props(as_tuples = True):
"""properties to retransmit"""
d = {
"None":("none", 0),
"Rotation": ("rot", 1, ),
"Position": ("pos", 2, ),
"Velocity": ("vel", 3, ),
}
if as_tuples:
return [(name, v[0], name + "_lala", "", v[1] ) for name, v in d.items()]
return d
def get_broadcast_addr(addr, submask):
return ipaddress.IPv4Network( "%s/%s" % (addr, submask), False).broadcast_address
......
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