diff --git a/multi_user/bl_types/bl_action.py b/multi_user/bl_types/bl_action.py index 8672fb6..893fe30 100644 --- a/multi_user/bl_types/bl_action.py +++ b/multi_user/bl_types/bl_action.py @@ -61,7 +61,6 @@ def dump_fcurve(fcurve: bpy.types.FCurve, use_numpy: bool = True) -> dict: points = fcurve.keyframe_points fcurve_data['keyframes_count'] = len(fcurve.keyframe_points) fcurve_data['keyframe_points'] = np_dump_collection(points, KEYFRAME) - else: # Legacy method dumper = Dumper() fcurve_data["keyframe_points"] = [] @@ -71,6 +70,18 @@ def dump_fcurve(fcurve: bpy.types.FCurve, use_numpy: bool = True) -> dict: dumper.dump(k) ) + if fcurve.modifiers: + dumper = Dumper() + dumper.exclude_filter = [ + 'is_valid', + 'active' + ] + dumped_modifiers = [] + for modfifier in fcurve.modifiers: + dumped_modifiers.append(dumper.dump(modfifier)) + + fcurve_data['modifiers'] = dumped_modifiers + return fcurve_data @@ -83,7 +94,7 @@ def load_fcurve(fcurve_data, fcurve): :type fcurve: bpy.types.FCurve """ use_numpy = fcurve_data.get('use_numpy') - + loader = Loader() keyframe_points = fcurve.keyframe_points # Remove all keyframe points @@ -128,6 +139,21 @@ def load_fcurve(fcurve_data, fcurve): fcurve.update() + dumped_fcurve_modifiers = fcurve_data.get('modifiers', None) + + if dumped_fcurve_modifiers: + # clear modifiers + for fmod in fcurve.modifiers: + fcurve.modifiers.remove(fmod) + + # Load each modifiers in order + for modifier_data in dumped_fcurve_modifiers: + modifier = fcurve.modifiers.new(modifier_data['type']) + + loader.load(modifier, modifier_data) + elif fcurve.modifiers: + for fmod in fcurve.modifiers: + fcurve.modifiers.remove(fmod) class BlAction(BlDatablock): bl_id = "actions" diff --git a/tests/test_bl_types/test_action.py b/tests/test_bl_types/test_action.py index 3659777..0c95b8c 100644 --- a/tests/test_bl_types/test_action.py +++ b/tests/test_bl_types/test_action.py @@ -8,6 +8,7 @@ import random from multi_user.bl_types.bl_action import BlAction INTERPOLATION = ['CONSTANT', 'LINEAR', 'BEZIER', 'SINE', 'QUAD', 'CUBIC', 'QUART', 'QUINT', 'EXPO', 'CIRC', 'BACK', 'BOUNCE', 'ELASTIC'] +FMODIFIERS = ['GENERATOR', 'FNGENERATOR', 'ENVELOPE', 'CYCLES', 'NOISE', 'LIMITS', 'STEPPED'] # @pytest.mark.parametrize('blendname', ['test_action.blend']) def test_action(clear_blend): @@ -22,6 +23,9 @@ def test_action(clear_blend): point.co[1] = random.randint(-10,10) point.interpolation = INTERPOLATION[random.randint(0, len(INTERPOLATION)-1)] + for mod_type in FMODIFIERS: + fcurve_sample.modifiers.new(mod_type) + bpy.ops.mesh.primitive_plane_add() bpy.data.objects[0].animation_data_create() bpy.data.objects[0].animation_data.action = datablock