[Bf-extensions-cvs] [a0ce684a] master: glTF exporter: Better armature action detection

Julien Duroure noreply at git.blender.org
Fri Apr 22 21:25:14 CEST 2022


Commit: a0ce684afe3ef7c37599941d1c3d1f46ca967e61
Author: Julien Duroure
Date:   Fri Apr 22 21:16:20 2022 +0200
Branches: master
https://developer.blender.org/rBAa0ce684afe3ef7c37599941d1c3d1f46ca967e61

glTF exporter: Better armature action detection

===================================================================

M	io_scene_gltf2/__init__.py
M	io_scene_gltf2/blender/com/gltf2_blender_data_path.py
M	io_scene_gltf2/blender/exp/gltf2_blender_gather_animations.py

===================================================================

diff --git a/io_scene_gltf2/__init__.py b/io_scene_gltf2/__init__.py
index e6653a5d..7585813a 100755
--- a/io_scene_gltf2/__init__.py
+++ b/io_scene_gltf2/__init__.py
@@ -4,7 +4,7 @@
 bl_info = {
     'name': 'glTF 2.0 format',
     'author': 'Julien Duroure, Scurest, Norbert Nopper, Urs Hanselmann, Moritz Becher, Benjamin Schmithüsen, Jim Eckerlein, and many external contributors',
-    "version": (3, 2, 27),
+    "version": (3, 2, 28),
     'blender': (3, 1, 0),
     'location': 'File > Import-Export',
     'description': 'Import-Export as glTF 2.0',
diff --git a/io_scene_gltf2/blender/com/gltf2_blender_data_path.py b/io_scene_gltf2/blender/com/gltf2_blender_data_path.py
index 9f238da7..a329193a 100755
--- a/io_scene_gltf2/blender/com/gltf2_blender_data_path.py
+++ b/io_scene_gltf2/blender/com/gltf2_blender_data_path.py
@@ -29,3 +29,6 @@ def get_rotation_modes(target_property: str) -> str:
         return True, False, ["AXIS_ANGLE"]
     else:
         return False, False, []
+
+def is_bone_anim_channel(data_path: str) -> bool:
+    return data_path[:10] == "pose.bones"
\ No newline at end of file
diff --git a/io_scene_gltf2/blender/exp/gltf2_blender_gather_animations.py b/io_scene_gltf2/blender/exp/gltf2_blender_gather_animations.py
index 6dd401e9..6e62507a 100755
--- a/io_scene_gltf2/blender/exp/gltf2_blender_gather_animations.py
+++ b/io_scene_gltf2/blender/exp/gltf2_blender_gather_animations.py
@@ -10,6 +10,7 @@ from io_scene_gltf2.io.com.gltf2_io_debug import print_console
 from ..com.gltf2_blender_extras import generate_extras
 from io_scene_gltf2.io.exp.gltf2_io_user_extensions import export_user_extensions
 from io_scene_gltf2.blender.exp.gltf2_blender_gather_tree import VExportNode
+from ..com.gltf2_blender_data_path import is_bone_anim_channel
 
 
 def __gather_channels_baked(obj_uuid, export_settings):
@@ -311,9 +312,15 @@ def __get_blender_actions(blender_object: bpy.types.Object,
     # If there are only 1 armature, include all animations, even if not in NLA
     if blender_object.type == "ARMATURE":
         if len(export_settings['vtree'].get_all_node_of_type(VExportNode.ARMATURE)) == 1:
-            # Keep all actions on objects (no keyframe animation)
-            # Some other object animation can be added here, and will affect armature object itself :-/
+            # Keep all actions on objects (no Shapekey animation)
             for act in [a for a in bpy.data.actions if a.id_root == "OBJECT"]:
+                # We need to check this is an armature action
+                # Checking that at least 1 bone is animated
+                if not __is_armature_action(act):
+                    continue
+                # Check if this action is already taken into account
+                if act.name in blender_tracks.keys():
+                    continue
                 blender_actions.append(act)
                 blender_tracks[act.name] = None
                 action_on_type[act.name] = "OBJECT"
@@ -326,3 +333,10 @@ def __get_blender_actions(blender_object: bpy.types.Object,
     blender_actions.sort(key = lambda a: a.name.lower())
 
     return [(blender_action, blender_tracks[blender_action.name], action_on_type[blender_action.name]) for blender_action in blender_actions]
+
+
+def __is_armature_action(blender_action) -> bool:
+    for fcurve in blender_action.fcurves:
+        if is_bone_anim_channel(fcurve.data_path):
+            return True
+    return False
\ No newline at end of file



More information about the Bf-extensions-cvs mailing list