This commit is contained in:
lachrymaL 2021-07-09 21:57:31 -04:00 committed by GitHub
parent 8a55458264
commit 8380dbbf5c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -26,44 +26,45 @@ bl_info = {
import bpy import bpy
import mathutils import mathutils
import bl_math
class G: class G:
selected_keys = [] selected_keys = []
bezier = [] bezier = []
def inverse_lerp(minimum, maximum, val):
return (val - minimum) / (maximum - minimum)
def convert_handles_to_bezier(keyframes): def convert_handles_to_bezier(keyframes):
bezier = [] handles = [keyframes[0].handle_right, keyframes[1].handle_left]
in_key = keyframes[0]
out_key = keyframes[1]
in_handle = in_key.handle_right
out_handle = out_key.handle_left
bezier.append(in_handle[0] / (abs(in_key.co[0] - out_key.co[0]))) # x1
bezier.append(in_handle[1] / (abs(in_key.co[1] - out_key.co[1]))) # y1
bezier.append(out_handle[0] / (abs(in_key.co[0] - out_key.co[0]))) # x2
bezier.append(out_handle[1] / (abs(in_key.co[1] - out_key.co[1]))) # y2
bezier = list(map(
lambda x: list(map(
lambda v, dimension: inverse_lerp(keyframes[0].co[dimension], keyframes[1].co[dimension], v),
x,
range(2)
)),
handles
))
return bezier return bezier
def generate_new_handles(in_key, out_key): def generate_new_handles(in_key, out_key):
x_diff = abs(in_key.co[0] - out_key.co[0]) handles = list(map(
y_diff = abs(in_key.co[1] - out_key.co[1]) lambda fac: list(map(
lambda dimension: bl_math.lerp(in_key.co[dimension], out_key.co[dimension], fac[dimension]),
y_direction = (1 if (in_key.co[1] - out_key.co[1]) < 0 else -1) range(2)
)),
new_in_handle = mathutils.Vector(( G.bezier
in_key.co[0] + (G.bezier[0] * x_diff),
in_key.co[1] + (G.bezier[1] * y_diff * y_direction)
)) ))
new_out_handle = mathutils.Vector(( return [
in_key.co[0] + (G.bezier[2] * x_diff), mathutils.Vector(
in_key.co[1] + (G.bezier[3] * y_diff * y_direction) (handles[0][0], handles[0][1])
)) ),
mathutils.Vector(
return [new_in_handle, new_out_handle] (handles[1][0], handles[1][1])
)
]
class FCurveHandleCopyValue(bpy.types.Operator): class FCurveHandleCopyValue(bpy.types.Operator):
"""Copy FCurve handle values""" """Copy FCurve handle values"""
@ -79,13 +80,7 @@ class FCurveHandleCopyValue(bpy.types.Operator):
self.report({"WARNING"}, "Please only select one curve when copying an ease.") self.report({"WARNING"}, "Please only select one curve when copying an ease.")
return {'CANCELLED'} return {'CANCELLED'}
for keyframe in fcurves[0].keyframe_points: G.selected_keys = list(filter(lambda x: x.select_control_point, fcurves[0].keyframe_points))
if (len(G.selected_keys) > 2):
self.report({"WARNING"}, "Please select exactly two keyframes when copying an ease.")
return {'CANCELLED'}
if (keyframe.select_control_point):
G.selected_keys.append(keyframe)
if (len(G.selected_keys) != 2): if (len(G.selected_keys) != 2):
self.report({"WARNING"}, "Please select exactly two keyframes when copying an ease.") self.report({"WARNING"}, "Please select exactly two keyframes when copying an ease.")