From f2c0507001b106bfd0d0f5576e1cda811bab0426 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?F=C3=A9lix=20David?= Date: Fri, 3 Feb 2023 10:35:02 +0100 Subject: [PATCH] Change: Remove action auto assignation to objects (#56) * Change: Remove action auto assignation to objects * fix loader listing --- openpype/hosts/blender/api/properties.py | 6 --- .../blender/plugins/load/load_animation.py | 51 +------------------ 2 files changed, 1 insertion(+), 56 deletions(-) diff --git a/openpype/hosts/blender/api/properties.py b/openpype/hosts/blender/api/properties.py index afc57774661..c4ff1949eb1 100644 --- a/openpype/hosts/blender/api/properties.py +++ b/openpype/hosts/blender/api/properties.py @@ -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 diff --git a/openpype/hosts/blender/plugins/load/load_animation.py b/openpype/hosts/blender/plugins/load/load_animation.py index f0544aeda1e..991fcf62550 100644 --- a/openpype/hosts/blender/plugins/load/load_animation.py +++ b/openpype/hosts/blender/plugins/load/load_animation.py @@ -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" @@ -76,8 +29,6 @@ class LinkAnimationLoader(AnimationLoader): class AppendAnimationLoader(AnimationLoader): """Append animations from a .blend file.""" - - families = ["animation"] representations = ["blend"] label = "Append Animation"