i have keyframed an objects rotation, im using quaternion rotation mode cuz i wanna avoid gimbal lock, however a new issue arises. i need there to be proper linear interpolation between these keyframes, selecting linear interpolation mode wont do the trick if im using quaternion rotations. i figured there must be some code involved, im not very good at coding, but is there a function somewhere in the API that would make this possible, or am i down the wrong path?


1 Answer 1


For emphasis that you can control the individual rotation components, I keyframed both w and x of the quaternion rotations and gave them different interpolations. For completeness, I also included easing for the x rotation. Since I keyframed two components, there are two fcurves in obj.animation_data.action.fcurves. The 0th index belongs to w and the 1st to x. The keyframe points are extracted from an fcurve using fcurve.keyframe_points. For interpolating/easing between two keyframes, you only need to set the interpolation/easing for the first of those two keyframes, which is why I only use pts[0] and not both pts[0] and pts[1].

import bpy 
# keyframe the object           
obj = bpy.context.object
bpy.context.object.rotation_quaternion.w = 0
bpy.context.object.rotation_quaternion.x = 0
obj.keyframe_insert("rotation_quaternion", frame = 1)
bpy.context.object.rotation_quaternion.w = 1
bpy.context.object.rotation_quaternion.x = 1
obj.keyframe_insert("rotation_quaternion", frame = 100)

# get the interpolation curves
fcurves = obj.animation_data.action.fcurves

# get the keyframe points of w
fcurve = fcurves[0]
pts = fcurve.keyframe_points

# interpolation = 'CONSTANT', 'LINEAR', 'BEZIER', 'SINE', 'QUAD', 'CUBIC', 'QUART', 'QUINT', 'EXPO', 'CIRC', 'BACK', 'BOUNCE', 'ELASTIC'
# easing = 'AUTO', 'EASE_IN', 'EASE_OUT', 'EASE_IN_OUT'

# set interpolation of w 
pts[0].interpolation = 'LINEAR'

# set interpolation/easing of x    
fcurve = fcurves[1]
pts = fcurve.keyframe_points
pts[0].interpolation = 'SINE'
pts[0].easing = 'EASE_IN'

If you don't care about the individual component keyframes, you can also just select the only the object in question, go into the fcurves editor, and set interpolation/easing for all the object's keyframes using

bpy.context.area.ui_type = "FCURVES"
bpy.ops.graph.interpolation_type(type = "BEZIER")
bpy.ops.graph.easing_type(type = "EASE_IN_OUT")
bpy.context.area.ui_type = "TEXT_EDITOR"

You must log in to answer this question.

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