Skip to content

Commit f7547cf

Browse files
committed
Fix breaking changes in Blender 5.0
I dont know if any other changes are still breaking lol.
1 parent 82f3f06 commit f7547cf

3 files changed

Lines changed: 53 additions & 10 deletions

File tree

MIDIAnimator/utils/blender.py

Lines changed: 39 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
from mathutils import Vector
44
from mathutils.bvhtree import BVHTree
55
from typing import Any, Tuple, List, Union, Set, TYPE_CHECKING
6+
from bpy_extras import anim_utils
67

78
if TYPE_CHECKING:
89
from ..data_structures import ObjectShapeKey
@@ -32,7 +33,13 @@ def FCurvesFromObject(obj: bpy.types.Object) -> List[bpy.types.FCurve]:
3233
if obj.animation_data is None: return []
3334
if obj.animation_data.action is None: return []
3435

35-
return list(obj.animation_data.action.fcurves)
36+
if bpy.app.version < (5, 0, 0):
37+
return list(obj.animation_data.action.fcurves)
38+
else:
39+
anim_data = obj.animation_data
40+
channelbag = anim_utils.action_get_channelbag_for_slot(anim_data.action, anim_data.action_slot)
41+
return list(channelbag.fcurves) if channelbag else []
42+
3643

3744
def shapeKeyFCurvesFromObject(obj: bpy.types.Object) -> List[bpy.types.FCurve]:
3845
"""Gets shape key (`bpy.types.ShapeKey`) FCurves from a object (`bpy.types.Object`).
@@ -44,7 +51,12 @@ def shapeKeyFCurvesFromObject(obj: bpy.types.Object) -> List[bpy.types.FCurve]:
4451
if obj.data.shape_keys is None: return []
4552
if obj.data.shape_keys.animation_data.action is None: return []
4653

47-
return list(obj.data.shape_keys.animation_data.action.fcurves)
54+
if bpy.app.version < (5, 0, 0):
55+
return list(obj.data.shape_keys.animation_data.action.fcurves)
56+
else:
57+
anim_data = obj.data.shape_keys.animation_data
58+
channelbag = anim_utils.action_get_channelbag_for_slot(anim_data.action, anim_data.action_slot)
59+
return list(channelbag.fcurves) if channelbag else []
4860
return []
4961

5062
def validateFCurves(noteOnFCurves: List[Union[bpy.types.FCurve, 'ObjectShapeKey']], noteOffFCurves: List[Union[bpy.types.FCurve, 'ObjectShapeKey']], haveSorted: bool=False) -> bool:
@@ -87,12 +99,31 @@ def cleanKeyframes(obj: bpy.types.Object, channels: Set={"all_channels"}):
8799
"""
88100
fCurves = FCurvesFromObject(obj)
89101

90-
for fCurve in fCurves:
91-
if {fCurve.data_path, "all_channels"}.intersection(channels):
92-
obj.animation_data.action.fcurves.remove(fCurve)
93-
94-
for fCurve in shapeKeyFCurvesFromObject(obj):
95-
obj.data.shape_keys.animation_data.action.fcurves.remove(fCurve)
102+
if bpy.app.version < (5, 0, 0):
103+
for fCurve in fCurves:
104+
if {fCurve.data_path, "all_channels"}.intersection(channels):
105+
obj.animation_data.action.fcurves.remove(fCurve)
106+
107+
for fCurve in shapeKeyFCurvesFromObject(obj):
108+
obj.data.shape_keys.animation_data.action.fcurves.remove(fCurve)
109+
else:
110+
# Object fcurves
111+
anim_data = obj.animation_data
112+
if anim_data and anim_data.action:
113+
channelbag = anim_utils.action_get_channelbag_for_slot(anim_data.action, anim_data.action_slot)
114+
if channelbag:
115+
for fCurve in fCurves:
116+
if {fCurve.data_path, "all_channels"}.intersection(channels):
117+
channelbag.fcurves.remove(fCurve)
118+
119+
# Shape key fcurves
120+
if obj.data.shape_keys and obj.data.shape_keys.animation_data:
121+
sk_anim_data = obj.data.shape_keys.animation_data
122+
if sk_anim_data.action:
123+
sk_channelbag = anim_utils.action_get_channelbag_for_slot(sk_anim_data.action, sk_anim_data.action_slot)
124+
if sk_channelbag:
125+
for fCurve in shapeKeyFCurvesFromObject(obj):
126+
sk_channelbag.fcurves.remove(fCurve)
96127

97128
def secToFrames(sec: float) -> float:
98129
"""converts (using the Blender scene's FPS) specified time (in seconds) to frames

rust-impl/blender-addon/src/tracker.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
# Detects important scene changes and sends updates via the Server singleton
33

44
import bpy
5+
from bpy_extras import anim_utils
56
from bpy.app.handlers import persistent
67
import json
78
import time
@@ -56,7 +57,12 @@ def FCurvesFromObject(obj):
5657
if obj.animation_data is None: return []
5758
if obj.animation_data.action is None: return []
5859

59-
return list(obj.animation_data.action.fcurves)
60+
if bpy.app.version < (5, 0, 0):
61+
return list(obj.animation_data.action.fcurves)
62+
else:
63+
anim_data = obj.animation_data
64+
channelbag = anim_utils.action_get_channelbag_for_slot(anim_data.action, anim_data.action_slot)
65+
return list(channelbag.fcurves) if channelbag else []
6066

6167
def get_fcurve_data(fcurve):
6268
"""Converts an FCurve into a dictionary representation."""

rust-impl/midianimator/src-tauri/src/blender/python/blender_scene_builder.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import json
22
import bpy
3+
from bpy_extras import anim_utils
34

45
def shape_keys_from_object(obj):
56
"""gets shape keys from object
@@ -26,7 +27,12 @@ def FCurvesFromObject(obj):
2627
if obj.animation_data is None: return []
2728
if obj.animation_data.action is None: return []
2829

29-
return list(obj.animation_data.action.fcurves)
30+
if bpy.app.version < (5, 0, 0):
31+
return list(obj.animation_data.action.fcurves)
32+
else:
33+
anim_data = obj.animation_data
34+
channelbag = anim_utils.action_get_channelbag_for_slot(anim_data.action, anim_data.action_slot)
35+
return list(channelbag.fcurves) if channelbag else []
3036

3137
def get_fcurve_data(fcurve):
3238
"""Converts an FCurve into a dictionary representation.

0 commit comments

Comments
 (0)