diff options
author | Julien Duroure <julien.duroure@gmail.com> | 2019-09-26 17:58:13 +0300 |
---|---|---|
committer | Julien Duroure <julien.duroure@gmail.com> | 2019-09-26 17:58:13 +0300 |
commit | ba3c5b0b3b82b2c8668492c2c0a5dd8937ab01ba (patch) | |
tree | 4228a74d8b81f69a5edcdcf628a745d2597668c2 /io_scene_gltf2/blender/imp/gltf2_blender_animation_utils.py | |
parent | a0c33fe957a9c7db0a239be0791e4715862c45ec (diff) |
glTF importer: fcurve code refactor
Diffstat (limited to 'io_scene_gltf2/blender/imp/gltf2_blender_animation_utils.py')
-rw-r--r-- | io_scene_gltf2/blender/imp/gltf2_blender_animation_utils.py | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/io_scene_gltf2/blender/imp/gltf2_blender_animation_utils.py b/io_scene_gltf2/blender/imp/gltf2_blender_animation_utils.py index c835ceb7..cc9c3aa1 100644 --- a/io_scene_gltf2/blender/imp/gltf2_blender_animation_utils.py +++ b/io_scene_gltf2/blender/imp/gltf2_blender_animation_utils.py @@ -45,3 +45,35 @@ def restore_animation_on_object(obj, anim_name): obj.animation_data.action = None +def make_fcurve(action, co, data_path, index=0, group_name=None, interpolation=None): + fcurve = action.fcurves.new(data_path=data_path, index=index) + + if group_name: + if group_name not in action.groups: + action.groups.new(group_name) + group = action.groups[group_name] + fcurve.group = group + + fcurve.keyframe_points.add(len(co) // 2) + fcurve.keyframe_points.foreach_set('co', co) + + # Setting interpolation + if interpolation == 'CUBICSPLINE': + for kf in fcurve.keyframe_points: + kf.interpolation = 'BEZIER' + kf.handle_right_type = 'AUTO' + kf.handle_left_type = 'AUTO' + else: + if interpolation == 'LINEAR': + blender_interpolation = 'LINEAR' + elif interpolation == 'STEP': + blender_interpolation = 'CONSTANT' + else: + blender_interpolation = 'LINEAR' + for kf in fcurve.keyframe_points: + kf.interpolation = blender_interpolation + + fcurve.update() # force updating tangents (this may change when tangent will be managed) + + return fcurve + |