+
+ armature_def = graph_lookup[obj]
+ armature = obj
+ bones = armature_def['bones']
+ skeleton.channels = len(bones)
+ skeleton.ik_count = armature_def["ik_count"]
+
+ if armature.animation_data:
+ previous_frame = bpy.context.scene.frame_current
+ previous_action = armature.animation_data.action
+
+ skeleton.anim_start = len(anim_buffer)
+ skeleton.anim_count = 0
+
+ for NLALayer in obj.animation_data.nla_tracks:
+ for NLAStrip in NLALayer.strips:
+ # Use action
+ for a in bpy.data.actions:
+ if a.name == NLAStrip.name:
+ armature.animation_data.action = a
+ break
+
+ anim_start = int(NLAStrip.action_frame_start)
+ anim_end = int(NLAStrip.action_frame_end)
+
+ # export strips
+ anim = mdl_animation()
+ anim.pstr_name = emplace_string( NLAStrip.action.name )
+ anim.rate = 30.0
+ anim.offset = animdata_length
+ anim.length = anim_end-anim_start
+
+ # Export the fucking keyframes
+ for frame in range(anim_start,anim_end):
+ bpy.context.scene.frame_set(frame)
+
+ for bone_name in bones:
+ for pb in armature.pose.bones:
+ if pb.name == bone_name:
+ rb = armature.data.bones[ bone_name ]
+
+ loc, rot, sca = pb.matrix_basis.decompose()
+
+ # local position
+ vp = rb.matrix @ loc
+ final_pos = Vector(( vp[0], vp[2], -vp[1] ))
+
+ # rotation
+ lc_m = pb.matrix_channel.to_3x3()
+ if pb.parent is not None:
+ smtx = pb.parent.matrix_channel.to_3x3()
+ lc_m = smtx.inverted() @ lc_m
+ rq = lc_m.to_quaternion()
+
+ kf = mdl_keyframe()
+ kf.co[0] = final_pos[0]
+ kf.co[1] = final_pos[1]
+ kf.co[2] = final_pos[2]
+
+ kf.q[0] = rq[1]
+ kf.q[1] = rq[3]
+ kf.q[2] = -rq[2]
+ kf.q[3] = rq[0]
+
+ # scale
+ kf.s[0] = sca[0]
+ kf.s[1] = sca[2]
+ kf.s[2] = sca[1]
+
+ animdata_buffer += [kf]
+ animdata_length += sizeof(mdl_keyframe)
+ break
+
+ anim_buffer += [anim]
+ skeleton.anim_count += 1
+
+ s000 = F" [{uid: 3}/{header.node_count-1}]" + " |"*(depth-1)
+ print( F"{s000} | *anim: {NLAStrip.action.name}" )
+
+ bpy.context.scene.frame_set( previous_frame )
+ armature.animation_data.action = previous_action