Fix T46040: Bake action cleans existing keyframes

This commit is contained in:
Campbell Barton 2015-09-08 03:59:03 +10:00
parent 9de20963cd
commit 946b850b3e
Notes: blender-bot 2023-02-14 08:41:37 +01:00
Referenced by issue #46056, User Preferences-> install from File freezes Blender
Referenced by issue #46051, Loading certain Jpeg causes system alert sound (Win32)
Referenced by issue #46052, Ray intersection errors and slowdown
Referenced by issue #46040, Bake Action Selected is Cleaning another keys
1 changed files with 16 additions and 2 deletions

View File

@ -141,6 +141,13 @@ def bake_action(frame_start,
if do_object:
obj_info.append(obj_frame_info(obj))
# -------------------------------------------------------------------------
# Clean (store initial data)
if do_clean and action is not None:
clean_orig_data = {fcu: {p.co[1] for p in fcu.keyframe_points} for fcu in action.fcurves}
else:
clean_orig_data = {}
# -------------------------------------------------------------------------
# Create action
@ -230,12 +237,19 @@ def bake_action(frame_start,
if do_clean:
for fcu in action.fcurves:
fcu_orig_data = clean_orig_data.get(fcu, set())
keyframe_points = fcu.keyframe_points
i = 1
while i < len(fcu.keyframe_points) - 1:
while i < len(keyframe_points) - 1:
val = keyframe_points[i].co[1]
if val in fcu_orig_data:
i += 1
continue
val_prev = keyframe_points[i - 1].co[1]
val_next = keyframe_points[i + 1].co[1]
val = keyframe_points[i].co[1]
if abs(val - val_prev) + abs(val - val_next) < 0.0001:
keyframe_points.remove(keyframe_points[i])