feat: fcurve modifiers support
This commit is contained in:
parent
e5651151d9
commit
d2108facab
@ -61,7 +61,6 @@ def dump_fcurve(fcurve: bpy.types.FCurve, use_numpy: bool = True) -> dict:
|
|||||||
points = fcurve.keyframe_points
|
points = fcurve.keyframe_points
|
||||||
fcurve_data['keyframes_count'] = len(fcurve.keyframe_points)
|
fcurve_data['keyframes_count'] = len(fcurve.keyframe_points)
|
||||||
fcurve_data['keyframe_points'] = np_dump_collection(points, KEYFRAME)
|
fcurve_data['keyframe_points'] = np_dump_collection(points, KEYFRAME)
|
||||||
|
|
||||||
else: # Legacy method
|
else: # Legacy method
|
||||||
dumper = Dumper()
|
dumper = Dumper()
|
||||||
fcurve_data["keyframe_points"] = []
|
fcurve_data["keyframe_points"] = []
|
||||||
@ -71,6 +70,18 @@ def dump_fcurve(fcurve: bpy.types.FCurve, use_numpy: bool = True) -> dict:
|
|||||||
dumper.dump(k)
|
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
|
return fcurve_data
|
||||||
|
|
||||||
|
|
||||||
@ -83,7 +94,7 @@ def load_fcurve(fcurve_data, fcurve):
|
|||||||
:type fcurve: bpy.types.FCurve
|
:type fcurve: bpy.types.FCurve
|
||||||
"""
|
"""
|
||||||
use_numpy = fcurve_data.get('use_numpy')
|
use_numpy = fcurve_data.get('use_numpy')
|
||||||
|
loader = Loader()
|
||||||
keyframe_points = fcurve.keyframe_points
|
keyframe_points = fcurve.keyframe_points
|
||||||
|
|
||||||
# Remove all keyframe points
|
# Remove all keyframe points
|
||||||
@ -128,6 +139,21 @@ def load_fcurve(fcurve_data, fcurve):
|
|||||||
|
|
||||||
fcurve.update()
|
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):
|
class BlAction(BlDatablock):
|
||||||
bl_id = "actions"
|
bl_id = "actions"
|
||||||
|
@ -8,6 +8,7 @@ import random
|
|||||||
from multi_user.bl_types.bl_action import BlAction
|
from multi_user.bl_types.bl_action import BlAction
|
||||||
|
|
||||||
INTERPOLATION = ['CONSTANT', 'LINEAR', 'BEZIER', 'SINE', 'QUAD', 'CUBIC', 'QUART', 'QUINT', 'EXPO', 'CIRC', 'BACK', 'BOUNCE', 'ELASTIC']
|
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'])
|
# @pytest.mark.parametrize('blendname', ['test_action.blend'])
|
||||||
def test_action(clear_blend):
|
def test_action(clear_blend):
|
||||||
@ -22,6 +23,9 @@ def test_action(clear_blend):
|
|||||||
point.co[1] = random.randint(-10,10)
|
point.co[1] = random.randint(-10,10)
|
||||||
point.interpolation = INTERPOLATION[random.randint(0, len(INTERPOLATION)-1)]
|
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.ops.mesh.primitive_plane_add()
|
||||||
bpy.data.objects[0].animation_data_create()
|
bpy.data.objects[0].animation_data_create()
|
||||||
bpy.data.objects[0].animation_data.action = datablock
|
bpy.data.objects[0].animation_data.action = datablock
|
||||||
|
Loading…
x
Reference in New Issue
Block a user