Commit 5ac69e23 authored by Bruno Laurencich's avatar Bruno Laurencich

record animation

parent a5e2d032
No preview for this file type
......@@ -62,15 +62,15 @@ class Armature_Handler:
def set_key(self, context):
for b in self.object.pose.bones:
# print("Setting key to %s"% b.name)
self.object.keyframe_insert(\
'pose.bones["'+ b.name +'"].rotation_quaternion',
index=-1,
frame=context.scene.frame_current,
group=b.name)
def reset_pose(self):
for b in self.object.pose.bones:
print("RESET" , b.name)
b.rotation_quaternion.identity()
......
......@@ -38,6 +38,7 @@ class Chord_Receive_OSC(bpy.types.Operator):
bl_label = "Chordata: Receive pose Data"
bl_options = {'REGISTER'}
# ----------- UTILS -----------
def text(self, text = None):
if text:
u.write_blender_console(self.context, text)
......@@ -46,17 +47,58 @@ class Chord_Receive_OSC(bpy.types.Operator):
else:
for a in self.views_3d:
a.header_text_set()
def clean_prev_animations(self):
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.")
def prepare_armature(self):
self.clean_prev_animations()
self.armature.reset_pose()
self.do_set_keyframes = False
self.context.scene.frame_current = 0
self.context.scene.frame_start = 0
self.text(self.armature.message)
def start_stop_animation(self):
if self.do_set_keyframes:
self.do_set_keyframes = False
self.report({"INFO"}, "Stop registering animation")
else:
self.clean_prev_animations()
self.do_set_keyframes = True
self.report({"INFO"}, "Registering animation!")
def set_keyframe(self):
if self.do_set_keyframes:
self.armature.set_key(self.context)
self.context.scene.frame_current += 1
# ----------- MODAL -----------
def modal(self, context, event):
if event.type == 'TIMER':
osc_process()
self.set_keyframe()
return {'PASS_THROUGH'}
elif event.type == 'RET' and event.value == "RELEASE":
self.armature.get_rot_diff()
self.text(self.armature.message)
elif event.type == "K" and event.value == "RELEASE":
self.start_stop_animation()
elif event.type in {'RIGHTMOUSE', 'ESC'} or not self.chord_global.receiving:
if self.chord_global.manage_notochord:
bpy.ops.chordata.close_notochord("EXEC_DEFAULT")
......@@ -77,7 +119,7 @@ class Chord_Receive_OSC(bpy.types.Operator):
return self.execute(context)
# ----------- EXECUTE -----------
def execute(self, context):
self.context = context
self.views_3d = [area for area in bpy.context.screen.areas if area.type == 'VIEW_3D' ]
......@@ -87,10 +129,8 @@ class Chord_Receive_OSC(bpy.types.Operator):
return {"CANCELLED"}
chord_scene = context.scene.chordata
self.armature = arm.Armature_Handler(chord_scene.target, chord_scene.helpers)
self.armature.reset_pose()
self.text(self.armature.message)
self.prepare_armature()
self.chord_global = context.user_preferences.addons[__package__].preferences
self.chord_global.receiving = True
......@@ -133,8 +173,8 @@ class Chord_Receive_OSC(bpy.types.Operator):
# udpsock.setsockopt(socket.IPPROTO_IP, socket.IP_ADD_MEMBERSHIP, mreq)
###
#"/Chordata/.*"
osc_method("*", self.receive_bones,\
#TODO: work on the OSC routing, the library is not using regex but glob??
osc_method("/Chordata/*", self.receive_bones,\
argscheme=osm.OSCARG_ADDRESS + osm.OSCARG_DATA)
self.report({"INFO"}, "Receiving OSC")
......@@ -148,18 +188,13 @@ class Chord_Receive_OSC(bpy.types.Operator):
self.armature.put_quad_on_bones(sensor.group(1), Quaternion(values))
# print("{} ({:06.4f} {:06.4f} {:06.4f} {:06.4f})".format(addr, w, x, y, z))
# D.objects["Cube"].rotation_quaternion.w = values[0]
# D.objects["Cube"].rotation_quaternion.x = values[1]
# D.objects["Cube"].rotation_quaternion.y = values[2]
# D.objects["Cube"].rotation_quaternion.z = values[3]
# ----------- CANCEL -----------
def cancel(self, context):
del self.armature
self.context.scene.frame_end = \
self.context.scene.frame_current
self.context.scene.frame_current = 0
wm = context.window_manager
wm.event_timer_remove(self._timer)
osch.get_channel("chordata_armature_server").terminate()
......
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