Created
October 15, 2021 20:38
-
-
Save minetoblend/938db866feefb805da7f1bbfdc95a862 to your computer and use it in GitHub Desktop.
Blender animation to java keyframes exporter
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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