[Bf-extensions-cvs] [ba969e8b] master: glTF exporter: cleanup object animation curves when animation is constant

Julien Duroure noreply at git.blender.org
Fri Sep 24 16:48:34 CEST 2021


Commit: ba969e8b536781450d8b43959c95ca07e886b2b6
Author: Julien Duroure
Date:   Fri Sep 24 16:47:51 2021 +0200
Branches: master
https://developer.blender.org/rBAba969e8b536781450d8b43959c95ca07e886b2b6

glTF exporter: cleanup object animation curves when animation is constant

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

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

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

diff --git a/io_scene_gltf2/__init__.py b/io_scene_gltf2/__init__.py
index 44d0ec92..41f09df9 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, Scurest, Norbert Nopper, Urs Hanselmann, Moritz Becher, Benjamin Schmithüsen, Jim Eckerlein, and many external contributors',
-    "version": (1, 7, 29),
+    "version": (1, 7, 30),
     'blender': (2, 91, 0),
     'location': 'File > Import-Export',
     'description': 'Import-Export as glTF 2.0',
diff --git a/io_scene_gltf2/blender/exp/gltf2_blender_gather_animation_sampler_keyframes.py b/io_scene_gltf2/blender/exp/gltf2_blender_gather_animation_sampler_keyframes.py
index df069f79..d70f4de2 100755
--- a/io_scene_gltf2/blender/exp/gltf2_blender_gather_animation_sampler_keyframes.py
+++ b/io_scene_gltf2/blender/exp/gltf2_blender_gather_animation_sampler_keyframes.py
@@ -317,7 +317,7 @@ def gather_keyframes(blender_object_if_armature: typing.Optional[bpy.types.Objec
     # We can ignore this keyframes
     # if there are some fcurve, we can keep only 2 keyframes, first and last
     if blender_object_if_armature is not None:
-        cst = all([j < 0.0001 for j in np.ptp([[k.value[i] for i in range(len(keyframes[0].value))] for k in keyframes], axis=0)])
+        cst = fcurve_is_constant(keyframes)
 
         if node_channel_is_animated is True: # fcurve on this bone for this property
              # Keep animation, but keep only 2 keyframes if data are not changing
@@ -325,10 +325,18 @@ def gather_keyframes(blender_object_if_armature: typing.Optional[bpy.types.Objec
         else: # bone is not animated (no fcurve)
             # Not keeping if not changing property
             return None if cst is True else keyframes
+    else:
+        # For objects, if all values are the same, we keep only first and last
+        cst = fcurve_is_constant(keyframes)
+        return [keyframes[0], keyframes[-1]] if cst is True and len(keyframes) >= 2 else keyframes
+
 
     return keyframes
 
 
+def fcurve_is_constant(keyframes):
+    return all([j < 0.0001 for j in np.ptp([[k.value[i] for i in range(len(keyframes[0].value))] for k in keyframes], axis=0)])
+
 def complete_key(key: Keyframe, non_keyed_values: typing.Tuple[typing.Optional[float]]):
     """
     Complete keyframe with non keyed values



More information about the Bf-extensions-cvs mailing list