fix: shapekey animation data
This commit is contained in:
@ -25,7 +25,7 @@ from enum import Enum
|
|||||||
from .. import utils
|
from .. import utils
|
||||||
from .dump_anything import (
|
from .dump_anything import (
|
||||||
Dumper, Loader, np_dump_collection, np_load_collection, remove_items_from_dict)
|
Dumper, Loader, np_dump_collection, np_load_collection, remove_items_from_dict)
|
||||||
from .bl_datablock import BlDatablock
|
from .bl_datablock import BlDatablock, has_action, has_driver, dump_driver, load_driver
|
||||||
|
|
||||||
|
|
||||||
KEYFRAME = [
|
KEYFRAME = [
|
||||||
@ -155,6 +155,49 @@ def load_fcurve(fcurve_data, fcurve):
|
|||||||
for fmod in fcurve.modifiers:
|
for fmod in fcurve.modifiers:
|
||||||
fcurve.modifiers.remove(fmod)
|
fcurve.modifiers.remove(fmod)
|
||||||
|
|
||||||
|
|
||||||
|
def dump_animation_data(datablock):
|
||||||
|
animation_data = {}
|
||||||
|
if has_action(datablock):
|
||||||
|
animation_data['action'] = datablock.animation_data.action.name
|
||||||
|
if has_driver(datablock):
|
||||||
|
animation_data['drivers'] = []
|
||||||
|
for driver in datablock.animation_data.drivers:
|
||||||
|
animation_data['drivers'].append(dump_driver(driver))
|
||||||
|
|
||||||
|
return animation_data
|
||||||
|
|
||||||
|
|
||||||
|
def load_animation_data(animation_data, datablock):
|
||||||
|
# Load animation data
|
||||||
|
if animation_data:
|
||||||
|
if datablock.animation_data is None:
|
||||||
|
datablock.animation_data_create()
|
||||||
|
|
||||||
|
for d in datablock.animation_data.drivers:
|
||||||
|
datablock.animation_data.drivers.remove(d)
|
||||||
|
|
||||||
|
if 'drivers' in animation_data:
|
||||||
|
for driver in animation_data['drivers']:
|
||||||
|
load_driver(datablock, driver)
|
||||||
|
|
||||||
|
if 'action' in animation_data:
|
||||||
|
datablock.animation_data.action = bpy.data.actions[animation_data['action']]
|
||||||
|
elif datablock.animation_data.action:
|
||||||
|
datablock.animation_data.action = None
|
||||||
|
|
||||||
|
# Remove existing animation data if there is not more to load
|
||||||
|
elif hasattr(datablock, 'animation_data') and datablock.animation_data:
|
||||||
|
datablock.animation_data_clear()
|
||||||
|
|
||||||
|
|
||||||
|
def resolve_animation_dependencies(datablock):
|
||||||
|
if has_action(datablock):
|
||||||
|
return [datablock.animation_data.action]
|
||||||
|
else:
|
||||||
|
return []
|
||||||
|
|
||||||
|
|
||||||
class BlAction(BlDatablock):
|
class BlAction(BlDatablock):
|
||||||
bl_id = "actions"
|
bl_id = "actions"
|
||||||
bl_class = bpy.types.Action
|
bl_class = bpy.types.Action
|
||||||
|
@ -24,6 +24,7 @@ from replication.exception import ContextError
|
|||||||
|
|
||||||
from .bl_datablock import BlDatablock, get_datablock_from_uuid
|
from .bl_datablock import BlDatablock, get_datablock_from_uuid
|
||||||
from .bl_material import IGNORED_SOCKETS
|
from .bl_material import IGNORED_SOCKETS
|
||||||
|
from .bl_action import dump_animation_data, load_animation_data, resolve_animation_dependencies
|
||||||
from .dump_anything import (
|
from .dump_anything import (
|
||||||
Dumper,
|
Dumper,
|
||||||
Loader,
|
Loader,
|
||||||
@ -320,7 +321,8 @@ def dump_shape_keys(target_key: bpy.types.Key)->dict:
|
|||||||
return {
|
return {
|
||||||
'reference_key': target_key.reference_key.name,
|
'reference_key': target_key.reference_key.name,
|
||||||
'use_relative': target_key.use_relative,
|
'use_relative': target_key.use_relative,
|
||||||
'key_blocks': dumped_key_blocks
|
'key_blocks': dumped_key_blocks,
|
||||||
|
'animation_data': dump_animation_data(target_key)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -354,6 +356,12 @@ def load_shape_keys(dumped_shape_keys: dict, target_object: bpy.types.Object):
|
|||||||
|
|
||||||
target_keyblock.relative_key = relative_key
|
target_keyblock.relative_key = relative_key
|
||||||
|
|
||||||
|
# Shape keys animation data
|
||||||
|
anim_data = dumped_shape_keys.get('animation_data')
|
||||||
|
|
||||||
|
if anim_data:
|
||||||
|
load_animation_data(anim_data, target_object.data.shape_keys)
|
||||||
|
|
||||||
|
|
||||||
def dump_modifiers(modifiers: bpy.types.bpy_prop_collection)->dict:
|
def dump_modifiers(modifiers: bpy.types.bpy_prop_collection)->dict:
|
||||||
""" Dump all modifiers of a modifier collection into a dict
|
""" Dump all modifiers of a modifier collection into a dict
|
||||||
@ -760,4 +768,6 @@ class BlObject(BlDatablock):
|
|||||||
deps.extend(find_textures_dependencies(self.instance.modifiers))
|
deps.extend(find_textures_dependencies(self.instance.modifiers))
|
||||||
deps.extend(find_geometry_nodes_dependencies(self.instance.modifiers))
|
deps.extend(find_geometry_nodes_dependencies(self.instance.modifiers))
|
||||||
|
|
||||||
|
if self.instance.data.shape_keys:
|
||||||
|
deps.extend(resolve_animation_dependencies(self.instance.data.shape_keys))
|
||||||
return deps
|
return deps
|
||||||
|
Reference in New Issue
Block a user