[Bf-extensions-cvs] [f505743b] master: glTF exporter: Basic SK driver export (driven by armature animation)

Julien Duroure noreply at git.blender.org
Sat Dec 14 09:02:56 CET 2019


Commit: f505743b2f9f75f53b1497796869f799aa16020e
Author: Julien Duroure
Date:   Sat Dec 14 09:02:16 2019 +0100
Branches: master
https://developer.blender.org/rBAf505743b2f9f75f53b1497796869f799aa16020e

glTF exporter: Basic SK driver export (driven by armature animation)

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

M	io_scene_gltf2/__init__.py
M	io_scene_gltf2/blender/com/gltf2_blender_conversion.py
M	io_scene_gltf2/blender/exp/gltf2_blender_gather_animation_channel_target.py
M	io_scene_gltf2/blender/exp/gltf2_blender_gather_animation_channels.py
M	io_scene_gltf2/blender/exp/gltf2_blender_gather_animation_sampler_keyframes.py
M	io_scene_gltf2/blender/exp/gltf2_blender_gather_animation_samplers.py
M	io_scene_gltf2/blender/exp/gltf2_blender_gather_cache.py
A	io_scene_gltf2/blender/exp/gltf2_blender_gather_drivers.py

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

diff --git a/io_scene_gltf2/__init__.py b/io_scene_gltf2/__init__.py
index 7b080697..40beaca1 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, 25),
+    "version": (1, 1, 26),
     'blender': (2, 81, 6),
     'location': 'File > Import-Export',
     'description': 'Import-Export as glTF 2.0',
diff --git a/io_scene_gltf2/blender/com/gltf2_blender_conversion.py b/io_scene_gltf2/blender/com/gltf2_blender_conversion.py
index 88026e54..6d9a901a 100755
--- a/io_scene_gltf2/blender/com/gltf2_blender_conversion.py
+++ b/io_scene_gltf2/blender/com/gltf2_blender_conversion.py
@@ -81,3 +81,15 @@ def texture_transform_gltf_to_blender(texture_transform):
         'scale': [scale[0], scale[1]],
     }
 
+def get_target(property):
+    return {
+        "delta_location": "translation",
+        "delta_rotation_euler": "rotation",
+        "location": "translation",
+        "rotation_axis_angle": "rotation",
+        "rotation_euler": "rotation",
+        "rotation_quaternion": "rotation",
+        "scale": "scale",
+        "value": "weights"
+    }.get(property)
+
diff --git a/io_scene_gltf2/blender/exp/gltf2_blender_gather_animation_channel_target.py b/io_scene_gltf2/blender/exp/gltf2_blender_gather_animation_channel_target.py
index 5fcd4ede..0b23ec85 100755
--- a/io_scene_gltf2/blender/exp/gltf2_blender_gather_animation_channel_target.py
+++ b/io_scene_gltf2/blender/exp/gltf2_blender_gather_animation_channel_target.py
@@ -27,13 +27,14 @@ def gather_animation_channel_target(channels: typing.Tuple[bpy.types.FCurve],
                                     blender_object: bpy.types.Object,
                                     bake_bone: typing.Union[str, None],
                                     bake_channel: typing.Union[str, None],
+                                    driver_obj,
                                     export_settings
                                     ) -> gltf2_io.AnimationChannelTarget:
 
         animation_channel_target = gltf2_io.AnimationChannelTarget(
             extensions=__gather_extensions(channels, blender_object, export_settings, bake_bone),
             extras=__gather_extras(channels, blender_object, export_settings, bake_bone),
-            node=__gather_node(channels, blender_object, export_settings, bake_bone),
+            node=__gather_node(channels, blender_object, export_settings, bake_bone, driver_obj),
             path=__gather_path(channels, blender_object, export_settings, bake_bone, bake_channel)
         )
 
@@ -66,8 +67,13 @@ def __gather_extras(channels: typing.Tuple[bpy.types.FCurve],
 def __gather_node(channels: typing.Tuple[bpy.types.FCurve],
                   blender_object: bpy.types.Object,
                   export_settings,
-                  bake_bone: typing.Union[str, None]
+                  bake_bone: typing.Union[str, None],
+                  driver_obj
                   ) -> gltf2_io.Node:
+
+    if driver_obj is not None:
+        return gltf2_blender_gather_nodes.gather_node(driver_obj, None, export_settings)
+
     if blender_object.type == "ARMATURE":
         # TODO: get joint from fcurve data_path and gather_joint
 
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 50918b68..199d73a9 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
@@ -23,6 +23,7 @@ from io_scene_gltf2.blender.exp import gltf2_blender_gather_animation_samplers
 from io_scene_gltf2.blender.exp import gltf2_blender_gather_animation_channel_target
 from io_scene_gltf2.blender.exp import gltf2_blender_get
 from io_scene_gltf2.blender.exp import gltf2_blender_gather_skins
+from io_scene_gltf2.blender.exp import gltf2_blender_gather_drivers
 from io_scene_gltf2.io.exp.gltf2_io_user_extensions import export_user_extensions
 
 
@@ -77,18 +78,41 @@ def gather_animation_channels(blender_action: bpy.types.Action,
                     p,
                     bake_range_start,
                     bake_range_end,
-                    blender_action.name)
+                    blender_action.name,
+                    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:
+            channel = __gather_animation_channel(
+                fcurves,
+                blender_object,
+                export_settings,
+                None,
+                None,
+                bake_range_start,
+                bake_range_end,
+                blender_action.name,
+                obj)
+            channels.append(channel)
+
     else:
         for channel_group in __get_channel_groups(blender_action, blender_object, export_settings):
             channel_group_sorted = __get_channel_group_sorted(channel_group, blender_object)
             if len(channel_group_sorted) == 0:
                 # Only errors on channels, ignoring
                 continue
-            channel = __gather_animation_channel(channel_group_sorted, blender_object, export_settings, None, None, bake_range_start, bake_range_end, blender_action.name)
+            channel = __gather_animation_channel(channel_group_sorted, blender_object, export_settings, None, None, bake_range_start, bake_range_end, blender_action.name, None)
             if channel is not None:
                 channels.append(channel)
 
+
+    # resetting driver caches
+    gltf2_blender_gather_drivers.get_sk_driver_values.reset_cache()
+    gltf2_blender_gather_drivers.get_sk_drivers.reset_cache()
+
     return channels
 
 def __get_channel_group_sorted(channels: typing.Tuple[bpy.types.FCurve], blender_object: bpy.types.Object):
@@ -145,7 +169,8 @@ def __gather_animation_channel(channels: typing.Tuple[bpy.types.FCurve],
                                bake_channel: typing.Union[str, None],
                                bake_range_start,
                                bake_range_end,
-                               action_name: str
+                               action_name: str,
+                               driver_obj
                                ) -> typing.Union[gltf2_io.AnimationChannel, None]:
     if not __filter_animation_channel(channels, blender_object, export_settings):
         return None
@@ -153,8 +178,8 @@ def __gather_animation_channel(channels: typing.Tuple[bpy.types.FCurve],
     animation_channel = gltf2_io.AnimationChannel(
         extensions=__gather_extensions(channels, blender_object, export_settings, bake_bone),
         extras=__gather_extras(channels, blender_object, export_settings, bake_bone),
-        sampler=__gather_sampler(channels, blender_object, export_settings, bake_bone, bake_channel, bake_range_start, bake_range_end, action_name),
-        target=__gather_target(channels, blender_object, export_settings, bake_bone, bake_channel)
+        sampler=__gather_sampler(channels, blender_object, export_settings, bake_bone, bake_channel, bake_range_start, bake_range_end, action_name, driver_obj),
+        target=__gather_target(channels, blender_object, export_settings, bake_bone, bake_channel, driver_obj)
     )
 
     export_user_extensions('gather_animation_channel_hook',
@@ -201,7 +226,8 @@ def __gather_sampler(channels: typing.Tuple[bpy.types.FCurve],
                      bake_channel: typing.Union[str, None],
                      bake_range_start,
                      bake_range_end,
-                     action_name
+                     action_name,
+                     driver_obj
                      ) -> gltf2_io.AnimationSampler:
     return gltf2_blender_gather_animation_samplers.gather_animation_sampler(
         channels,
@@ -211,6 +237,7 @@ def __gather_sampler(channels: typing.Tuple[bpy.types.FCurve],
         bake_range_start,
         bake_range_end,
         action_name,
+        driver_obj,
         export_settings
     )
 
@@ -219,10 +246,11 @@ def __gather_target(channels: typing.Tuple[bpy.types.FCurve],
                     blender_object: bpy.types.Object,
                     export_settings,
                     bake_bone: typing.Union[str, None],
-                    bake_channel: typing.Union[str, None]
+                    bake_channel: typing.Union[str, None],
+                    driver_obj
                     ) -> gltf2_io.AnimationChannelTarget:
     return gltf2_blender_gather_animation_channel_target.gather_animation_channel_target(
-        channels, blender_object, bake_bone, bake_channel, export_settings)
+        channels, blender_object, bake_bone, bake_channel, driver_obj, export_settings)
 
 
 def __get_channel_groups(blender_action: bpy.types.Action, blender_object: bpy.types.Object, export_settings):
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 09df7d53..bb59b8a9 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
@@ -20,6 +20,7 @@ from io_scene_gltf2.blender.exp.gltf2_blender_gather_cache import cached, boneca
 from io_scene_gltf2.blender.com import gltf2_blender_math
 from io_scene_gltf2.blender.exp import gltf2_blender_get
 from io_scene_gltf2.blender.exp import gltf2_blender_extract
+from io_scene_gltf2.blender.exp.gltf2_blender_gather_drivers import get_sk_drivers, get_sk_driver_values
 from . import gltf2_blender_export_keys
 from io_scene_gltf2.io.com import gltf2_io_debug
 
@@ -164,6 +165,13 @@ def get_bone_matrix(blender_object_if_armature: typing.Optional[bpy.types.Object
                 matrix = pbone.matrix
                 matrix = blender_object_if_armature.convert_space(pose_bone=pbone, 

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-extensions-cvs mailing list