Commit 5142ad33 authored by Bruno Laurencich's avatar Bruno Laurencich

option: send relative rotations

parent de369b12
......@@ -150,6 +150,10 @@ Useful when the buffer of the receiving parts overflows""", default = False )
dest_port = props.IntProperty( default = 7000 )
net_submask = props.StringProperty( default = "255.255.255.0" )
relative_rotations = props.BoolProperty( name="Send root bone height", default = False )
send_root_z = props.BoolProperty( name="Send root bone height", default = False )
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 )
......
......@@ -63,7 +63,7 @@ class Armature_Handler:
for b in self.bones:
if not b.capture_bone:
continue
b.use_inherit_rotation = False
has_helper = ""
try:
......@@ -115,15 +115,18 @@ class Armature_Handler:
b = self.arm_repr[bone_name]
# for key, b in self.arm_repr.items():
if not b["diff_quat"]:
#while on calibration mode we just average the quaternions
b["avg_quat"] = quat.slerp(b["avg_quat"], 0.5)
else:
#this sets the bone to the same rotation than the cube in world space
#When in capture mode
#we set the rotation of the bone to the received sensor rotation
#taking into account the difference btw them measured during calibration
q = b["local_q"].conjugated() * quat.copy() * b["local_q"]
self.object.pose.bones[bone_name].rotation_quaternion = q * b["diff_quat"].conjugated()
def get_rot_diff(self):
for m in self.meshes: m.hide = False
for key, b in self.arm_repr.items():
......
......@@ -76,12 +76,13 @@ class Chord_tools_panel(bpy.types.Panel):
self.chord_global = context.user_preferences.addons[__package__].preferences
layout = self.layout
if time() - self.chord_global.last_check > CHECK_PERIOD:
self.chord_global.last_check = time()
if self.chord_global.state == "Connected":
self.check_connection()
if get_conn_state_attr(context, "value") > 2:
layout.enabled= False
#Watchdog removed momentarily: might incur on unnecesary overhead
# if time() - self.chord_global.last_check > CHECK_PERIOD:
# self.chord_global.last_check = time()
# if self.chord_global.state == "Connected":
# self.check_connection()
# if get_conn_state_attr(context, "value") > 2:
# layout.enabled= False
layout.label("Armature Object")
row = layout.row(align=True)
......@@ -216,6 +217,10 @@ class Chord_send_panel(bpy.types.Panel):
row = box.row()
row.prop(self.chord_global, "net_submask", text="Net submask")
layout.label("Options:")
layout.prop(self.chord_global.send, "relative_rotations", text="Use relative rotations")
layout.prop(self.chord_global.send, "send_root_z", text="Send root bone height")
layout.label("Send properties:")
layout.prop(self.chord_global.send, "send_rot", text="Rotation")
layout.prop(self.chord_global.send, "send_pos", text="Position")
......
......@@ -196,10 +196,17 @@ def send_Armature(arm, options):
global last_positions
msgs = []
chord_scene = bpy.context.scene.chordata
for b in arm.pose.bones:
if not b.transmit_bone: continue
if options.send_rot:
q = b.matrix.to_quaternion()
if not options.relative_rotations or not b.parent:
q = b.matrix.to_quaternion()
else:
q = b.parent.matrix.to_quaternion().rotation_difference(b.matrix.to_quaternion())
msgs.append(oscbuildparse.OSCMessage("/Chordata/rotation/"+b.name,
None, [q[0], q[1], q[2], q[3]]))
......@@ -233,14 +240,16 @@ def send_Armature(arm, options):
None, [dist.length]))
if not msgs: return
chord_global = context.user_preferences.addons[__package__].preferences
chord_global = bpy.context.user_preferences.addons[__package__].preferences
if chord_global.send.split_msg:
for ch in chunks(msgs, chord_global.send.chunks_n):
bun = oscbuildparse.OSCBundle(oscbuildparse.OSC_IMMEDIATELY, ch)
osc_send(bun, "chordata_client")
else:
bun = oscbuildparse.OSCBundle(oscbuildparse.OSC_IMMEDIATELY, msgs)
osc_send(bun, "chordata_client")
def clean():
......
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