How to convert Quaternions keyframes to Euler ones in several Actions?

There is a script here to convert Quaternion keyframes to Euler for objects (not bones, so rigify wont work), is there one to do the opposite? Thanks.


1 Answer 1

def animation_curve(obj, channel=''):
    fcurves = []
    if obj.animation_data and obj.animation_data.action:
        for fcurve in obj.animation_data.action.fcurves:
            data_path = fcurve.data_path
            if data_path.split('"')[1] == obj.name: 
                if channel: 
                    if data_path.endswith(channel): fcurves.append(fcurve)
                else: fcurves.append(fcurve)
    return fcurves

based on the answer here, above will help you identify the curve.

def evaluated(obj, frame, channel='rotation'):
    if channel=='rotation':
        if obj.rotation_mode == "QUATERNION": 
            curves = animation_curve(obj, 'quaternion')
            curves.sort(key=lambda x: x.array_index, reverse=False)
            quat = obj.rotation_quaternion.copy()
            for curve in curves: quat[curve.array_index] = curve.evaluate(frame)
            return quat
            curves = self.animation_curve(obj, 'euler')
            curves.sort(key=lambda x: x.array_index, reverse=False)
            euler = obj.rotation_euler.copy()
            for curve in curves: euler[curve.array_index] = curve.evaluate(frame)
            return euler.to_quaternion()

will get you the quaternion out. then you can get the euler with,

euler_xyz = evaluated(obj, frame_number).to_euler('XYZ')

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .