Skip to content

Instantly share code, notes, and snippets.

@minetoblend
Created October 15, 2021 20:38
Show Gist options
  • Save minetoblend/938db866feefb805da7f1bbfdc95a862 to your computer and use it in GitHub Desktop.
Save minetoblend/938db866feefb805da7f1bbfdc95a862 to your computer and use it in GitHub Desktop.
Blender animation to java keyframes exporter
import bpy
obj = bpy.context.object
action = obj.animation_data.action
fcurve = action.fcurves[0]
print("Timeline.floatTimeline()")
for idx, current in enumerate(fcurve.keyframe_points) :
if idx == 0:
print(".addKeyframe({}f, {}f)".format(current.co[0], current.co[1]))
else:
previous = fcurve.keyframe_points[idx - 1]
startTime = previous.co[0]
endTime = current.co[0]
startValue = previous.co[1]
endValue = current.co[1]
duration = endTime - startTime
valueChange = endValue - startValue
cx1 = (previous.handle_right[0] - startTime) / duration
cy1 = (previous.handle_right[1] - startValue) / valueChange
cx2 = (current.handle_left[0] - startTime) / duration
cy2 = (current.handle_left[1] - startValue) / valueChange
print(".addKeyframe({}f, {}f, new Easing.CubicBezier({}f, {}f, {}f, {}f))".format(endTime, endValue, cx1, cy1, cx2, cy2))
print(";");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment