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 mathutils
import bl_math
class G:
selected_keys = []
bezier = []
def inverse_lerp(minimum, maximum, val):
return (val - minimum) / (maximum - minimum)
def convert_handles_to_bezier(keyframes):
bezier = []
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
handles = [keyframes[0].handle_right, keyframes[1].handle_left]
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
def generate_new_handles(in_key, out_key):
x_diff = abs(in_key.co[0] - out_key.co[0])
y_diff = abs(in_key.co[1] - out_key.co[1])
y_direction = (1 if (in_key.co[1] - out_key.co[1]) < 0 else -1)
new_in_handle = mathutils.Vector((
in_key.co[0] + (G.bezier[0] * x_diff),
in_key.co[1] + (G.bezier[1] * y_diff * y_direction)
handles = list(map(
lambda fac: list(map(
lambda dimension: bl_math.lerp(in_key.co[dimension], out_key.co[dimension], fac[dimension]),
range(2)
)),
G.bezier
))
new_out_handle = mathutils.Vector((
in_key.co[0] + (G.bezier[2] * x_diff),
in_key.co[1] + (G.bezier[3] * y_diff * y_direction)
))
return [new_in_handle, new_out_handle]
return [
mathutils.Vector(
(handles[0][0], handles[0][1])
),
mathutils.Vector(
(handles[1][0], handles[1][1])
)
]
class FCurveHandleCopyValue(bpy.types.Operator):
"""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.")
return {'CANCELLED'}
for keyframe in 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)
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.")