[Bf-extensions-cvs] [171648da] blender-v2.82-release: glTF exporter: export animation on armature itself when sampled animation export

Julien Duroure noreply at git.blender.org
Sun Jan 26 09:31:10 CET 2020


Commit: 171648da578dc2783e17a9fd456893f5bb4ff9d6
Author: Julien Duroure
Date:   Sun Jan 26 09:30:39 2020 +0100
Branches: blender-v2.82-release
https://developer.blender.org/rBA171648da578dc2783e17a9fd456893f5bb4ff9d6

glTF exporter: export animation on armature itself when sampled animation export

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

M	io_scene_gltf2/__init__.py
M	io_scene_gltf2/blender/exp/gltf2_blender_gather_animation_channels.py

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

diff --git a/io_scene_gltf2/__init__.py b/io_scene_gltf2/__init__.py
index e6027d76..5644853e 100755
--- a/io_scene_gltf2/__init__.py
+++ b/io_scene_gltf2/__init__.py
@@ -15,7 +15,7 @@
 bl_info = {
     'name': 'glTF 2.0 format',
     'author': 'Julien Duroure, Norbert Nopper, Urs Hanselmann, Moritz Becher, Benjamin Schmithüsen, Jim Eckerlein, and many external contributors',
-    "version": (1, 1, 41),
+    "version": (1, 1, 42),
     'blender': (2, 81, 6),
     'location': 'File > Import-Export',
     'description': 'Import-Export as glTF 2.0',
diff --git a/io_scene_gltf2/blender/exp/gltf2_blender_gather_animation_channels.py b/io_scene_gltf2/blender/exp/gltf2_blender_gather_animation_channels.py
index 199d73a9..36b850df 100755
--- a/io_scene_gltf2/blender/exp/gltf2_blender_gather_animation_channels.py
+++ b/io_scene_gltf2/blender/exp/gltf2_blender_gather_animation_channels.py
@@ -83,6 +83,18 @@ def gather_animation_channels(blender_action: bpy.types.Action,
                 channels.append(channel)
 
 
+        # Retrieve animation on armature object itself, if any
+        fcurves_armature = __gather_armature_object_channel_groups(blender_action, blender_object, export_settings)
+        for channel_group in fcurves_armature:
+            # No need to sort on armature, that can't have SK
+            if len(channel_group) == 0:
+                # Only errors on channels, ignoring
+                continue
+            channel = __gather_animation_channel(channel_group, blender_object, export_settings, None, None, bake_range_start, bake_range_end, blender_action.name, None)
+            if channel is not None:
+                channels.append(channel)
+
+
         # Retrieve channels for drivers, if needed
         drivers_to_manage = gltf2_blender_gather_drivers.get_sk_drivers(blender_object)
         for obj, fcurves in drivers_to_manage:
@@ -316,6 +328,46 @@ def __get_channel_groups(blender_action: bpy.types.Action, blender_object: bpy.t
     if multiple_rotation_mode_detected is True:
         gltf2_io_debug.print_console("WARNING", "Multiple rotation mode detected for {}".format(blender_object.name))
 
+    return map(tuple, groups)
+
+def __gather_armature_object_channel_groups(blender_action: bpy.types.Action, blender_object: bpy.types.Object, export_settings):
+
+    targets = {}
+
+    if blender_object.type != "ARMATURE":
+        return tuple()
+
+    for fcurve in blender_action.fcurves:
+        object_path = get_target_object_path(fcurve.data_path)
+        if object_path != "":
+            continue
+
+        # In some invalid files, channel hasn't any keyframes ... this channel need to be ignored
+        if len(fcurve.keyframe_points) == 0:
+            continue
+        try:
+            target_property = get_target_property_name(fcurve.data_path)
+        except:
+            gltf2_io_debug.print_console("WARNING", "Invalid animation fcurve name on action {}".format(blender_action.name))
+            continue
+        target = gltf2_blender_get.get_object_from_datapath(blender_object, object_path)
+
+        # Detect that armature is not multiple keyed for euler and quaternion
+        # Keep only the current rotation mode used by object
+        rotation, rotation_modes = get_rotation_modes(target_property)
+        if rotation and target.rotation_mode not in rotation_modes:
+            continue
+
+        # group channels by target object and affected property of the target
+        target_properties = targets.get(target, {})
+        channels = target_properties.get(target_property, [])
+        channels.append(fcurve)
+        target_properties[target_property] = channels
+        targets[target] = target_properties
+
+    groups = []
+    for p in targets.values():
+        groups += list(p.values())
 
     return map(tuple, groups)



More information about the Bf-extensions-cvs mailing list