mirror of
https://github.com/ynput/ayon-core.git
synced 2026-01-01 16:34:53 +01:00
Merge pull request #6153 from ynput/bugfix/OP-7659-blender_keep_action_when_updating
Blender: Restore actions to objects after update
This commit is contained in:
commit
a9e683f1e3
1 changed files with 17 additions and 1 deletions
|
|
@ -102,7 +102,6 @@ class BlendLoader(plugin.AssetLoader):
|
||||||
|
|
||||||
# Link all the container children to the collection
|
# Link all the container children to the collection
|
||||||
for obj in container.children_recursive:
|
for obj in container.children_recursive:
|
||||||
print(obj)
|
|
||||||
bpy.context.scene.collection.objects.link(obj)
|
bpy.context.scene.collection.objects.link(obj)
|
||||||
|
|
||||||
# Remove the library from the blend file
|
# Remove the library from the blend file
|
||||||
|
|
@ -194,8 +193,20 @@ class BlendLoader(plugin.AssetLoader):
|
||||||
|
|
||||||
transform = asset_group.matrix_basis.copy()
|
transform = asset_group.matrix_basis.copy()
|
||||||
old_data = dict(asset_group.get(AVALON_PROPERTY))
|
old_data = dict(asset_group.get(AVALON_PROPERTY))
|
||||||
|
old_members = old_data.get("members", [])
|
||||||
parent = asset_group.parent
|
parent = asset_group.parent
|
||||||
|
|
||||||
|
actions = {}
|
||||||
|
objects_with_anim = [
|
||||||
|
obj for obj in asset_group.children_recursive
|
||||||
|
if obj.animation_data]
|
||||||
|
for obj in objects_with_anim:
|
||||||
|
# Check if the object has an action and, if so, add it to a dict
|
||||||
|
# so we can restore it later. Save and restore the action only
|
||||||
|
# if it wasn't originally loaded from the current asset.
|
||||||
|
if obj.animation_data.action not in old_members:
|
||||||
|
actions[obj.name] = obj.animation_data.action
|
||||||
|
|
||||||
self.exec_remove(container)
|
self.exec_remove(container)
|
||||||
|
|
||||||
asset_group, members = self._process_data(libpath, group_name)
|
asset_group, members = self._process_data(libpath, group_name)
|
||||||
|
|
@ -206,6 +217,11 @@ class BlendLoader(plugin.AssetLoader):
|
||||||
asset_group.matrix_basis = transform
|
asset_group.matrix_basis = transform
|
||||||
asset_group.parent = parent
|
asset_group.parent = parent
|
||||||
|
|
||||||
|
# Restore the actions
|
||||||
|
for obj in asset_group.children_recursive:
|
||||||
|
if obj.name in actions:
|
||||||
|
obj.animation_data.action = actions[obj.name]
|
||||||
|
|
||||||
# Restore the old data, but reset memebers, as they don't exist anymore
|
# Restore the old data, but reset memebers, as they don't exist anymore
|
||||||
# This avoids a crash, because the memory addresses of those members
|
# This avoids a crash, because the memory addresses of those members
|
||||||
# are not valid anymore
|
# are not valid anymore
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue