Skip to content
Snippets Groups Projects
Commit 068109fe authored by Brecht Van Lommel's avatar Brecht Van Lommel
Browse files

Fix #34607: MDD import should default to linear instead of bezier keyframe

interpolation, otherwise the shape key weights do not add up to 1 which gives
bad results.
parent cc9f663c
No related branches found
No related tags found
No related merge requests found
...@@ -34,17 +34,27 @@ ...@@ -34,17 +34,27 @@
import bpy import bpy
from struct import unpack from struct import unpack
def obj_update_frame(file, scene, obj, fr, step): def set_linear_interpolation(obj, shapekey):
anim_data = obj.data.shape_keys.animation_data
data_path = "key_blocks[\"" + shapekey.name + "\"].value"
for fcu in anim_data.action.fcurves:
if fcu.data_path == data_path:
for keyframe in fcu.keyframe_points:
keyframe.interpolation = 'LINEAR'
def obj_update_frame(file, scene, obj, start, fr, step):
# Insert new shape key # Insert new shape key
new_shapekey = obj.shape_key_add() new_shapekey = obj.shape_key_add()
new_shapekey.name = ("frame_%.4d" % fr) new_shapekey.name = ("frame_%.4d" % fr)
new_shapekey_index = len(obj.data.shape_keys.key_blocks) - 1
obj.active_shape_key_index = len(obj.data.shape_keys.key_blocks) - 1 obj.active_shape_key_index = new_shapekey_index
index = len(obj.data.shape_keys.key_blocks) - 1
obj.show_only_shape_key = True obj.show_only_shape_key = True
verts = obj.data.shape_keys.key_blocks[len(obj.data.shape_keys.key_blocks) - 1].data verts = new_shapekey.data
for v in verts: # 12 is the size of 3 floats for v in verts: # 12 is the size of 3 floats
v.co[:] = unpack('>3f', file.read(12)) v.co[:] = unpack('>3f', file.read(12))
...@@ -53,19 +63,19 @@ def obj_update_frame(file, scene, obj, fr, step): ...@@ -53,19 +63,19 @@ def obj_update_frame(file, scene, obj, fr, step):
obj.show_only_shape_key = False obj.show_only_shape_key = False
# insert keyframes # insert keyframes
shape_keys = obj.data.shape_keys new_shapekey = obj.data.shape_keys.key_blocks[new_shapekey_index]
frame = start + fr*step
scene.frame_current -= step new_shapekey.value = 0.0
obj.data.shape_keys.key_blocks[index].value = 0.0 new_shapekey.keyframe_insert("value", frame=frame - step)
shape_keys.key_blocks[len(obj.data.shape_keys.key_blocks) - 1].keyframe_insert("value")
scene.frame_current += step new_shapekey.value = 1.0
obj.data.shape_keys.key_blocks[index].value = 1.0 new_shapekey.keyframe_insert("value", frame=frame)
shape_keys.key_blocks[len(obj.data.shape_keys.key_blocks) - 1].keyframe_insert("value")
scene.frame_current += step new_shapekey.value = 0.0
obj.data.shape_keys.key_blocks[index].value = 0.0 new_shapekey.keyframe_insert("value", frame=frame + step)
shape_keys.key_blocks[len(obj.data.shape_keys.key_blocks) - 1].keyframe_insert("value")
set_linear_interpolation(obj, new_shapekey)
obj.data.update() obj.data.update()
...@@ -93,9 +103,7 @@ def load(operator, context, filepath, frame_start=0, frame_step=1): ...@@ -93,9 +103,7 @@ def load(operator, context, filepath, frame_start=0, frame_step=1):
basis.name = "Basis" basis.name = "Basis"
obj.data.update() obj.data.update()
scene.frame_current = frame_start
for i in range(frames): for i in range(frames):
obj_update_frame(file, scene, obj, i, frame_step) obj_update_frame(file, scene, obj, frame_start, i, frame_step)
return {'FINISHED'} return {'FINISHED'}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment