Skip to content

Commit

Permalink
Change: Remove action auto assignation to objects (#56)
Browse files Browse the repository at this point in the history
* Change: Remove action auto assignation to objects

* fix loader listing
  • Loading branch information
Tilix4 authored and kaamaurice committed Feb 9, 2023
1 parent ac18f5a commit 1de7863
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 56 deletions.
6 changes: 0 additions & 6 deletions openpype/hosts/blender/api/properties.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,17 +150,11 @@ def register():
name="OpenPype Containers", type=OpenpypeContainer, options={"HIDDEN"}
)

bpy.types.Object.original_action = bpy.props.PointerProperty(
name="Original action kept", type=bpy.types.Action
)


def unregister():
"""Unregister the properties."""
factory_unregister()

del bpy.types.Object.original_action

del bpy.types.Scene.openpype_instances
del bpy.types.Scene.openpype_instance_active_index
del bpy.types.Collection.is_openpype_instance
Expand Down
51 changes: 1 addition & 50 deletions openpype/hosts/blender/plugins/load/load_animation.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,62 +9,15 @@

class AnimationLoader(plugin.AssetLoader):
"""Load animations from a .blend file."""
families = ["animation"]

color = "orange"

bl_types = frozenset({bpy.types.Action})

def load(
self,
context: dict,
name: Optional[str] = None,
namespace: Optional[str] = None,
options: Optional[Dict] = None,
) -> Optional[bpy.types.Collection]:
container, datablocks = super().load(context, name, namespace, options)

# Try to assign linked actions by parsing their name
for action in datablocks:
users = action.get("users", {})
for user_name in users:
obj = bpy.context.scene.objects.get(user_name)
if obj:
# Ensure animation data
if not obj.animation_data:
obj.animation_data_create()

# Assign action
obj.original_action = obj.animation_data.action
obj.animation_data.action = action
else:
self.log.debug(
f"Cannot match armature by name '{user_name}' "
f"for action: {action.name}"
)
continue

return container, datablocks

def remove(self, container: Dict) -> bool:
"""Override `remove` to restore original actions to objects."""
# Restore original actions
scene_container = self._get_scene_container(container)
for d_ref in scene_container.datablock_refs:
for obj in bpy.context.scene.collection.all_objects:
if (
obj.type == "ARMATURE"
and obj.animation_data
and obj.animation_data.action == d_ref.datablock
):
obj.animation_data.action = obj.original_action

return super().remove(container)


class LinkAnimationLoader(AnimationLoader):
"""Link animations from a .blend file."""

families = ["animation"]
representations = ["blend"]

label = "Link Animation"
Expand All @@ -76,8 +29,6 @@ class LinkAnimationLoader(AnimationLoader):

class AppendAnimationLoader(AnimationLoader):
"""Append animations from a .blend file."""

families = ["animation"]
representations = ["blend"]

label = "Append Animation"
Expand Down

0 comments on commit 1de7863

Please sign in to comment.