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.
Blender Stack Exchange is a question and answer site for people who use Blender to create 3D graphics, animations, or games. It only takes a minute to sign up.
Sign up to join this communityHow 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.
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
else:
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')