[Bf-extensions-cvs] [eb3dcfc7] master: glTF exporter: Various hooks and fixed to better animation filtering / management

Julien Duroure noreply at git.blender.org
Tue Oct 4 09:29:19 CEST 2022


Commit: eb3dcfc70c7f0a7f4050509c7cded9a657e2f560
Author: Julien Duroure
Date:   Tue Oct 4 09:29:10 2022 +0200
Branches: master
https://developer.blender.org/rBAeb3dcfc70c7f0a7f4050509c7cded9a657e2f560

glTF exporter: Various hooks and fixed to better animation filtering / management

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

M	io_scene_gltf2/__init__.py
M	io_scene_gltf2/blender/exp/gltf2_blender_gather_animations.py
M	io_scene_gltf2/blender/exp/gltf2_blender_gather_tree.py

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

diff --git a/io_scene_gltf2/__init__.py b/io_scene_gltf2/__init__.py
index b355f372..2a630e3f 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, 4, 30),
+    "version": (3, 4, 31),
     'blender': (3, 3, 0),
     'location': 'File > Import-Export',
     'description': 'Import-Export as glTF 2.0',
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 95cec833..7a6fd6c3 100755
--- a/io_scene_gltf2/blender/exp/gltf2_blender_gather_animations.py
+++ b/io_scene_gltf2/blender/exp/gltf2_blender_gather_animations.py
@@ -82,6 +82,8 @@ def gather_animations(  obj_uuid: int,
         current_use_nla = blender_object.animation_data.use_nla
         blender_object.animation_data.use_nla = False
 
+    export_user_extensions('animation_switch_loop_hook', export_settings, blender_object, False)
+
     # Export all collected actions.
     for blender_action, track_name, on_type in blender_actions:
 
@@ -93,7 +95,9 @@ def gather_animations(  obj_uuid: int,
                     blender_object.animation_data.use_tweak_mode = False
                 try:
                     __reset_bone_matrix(blender_object, export_settings)
+                    export_user_extensions('pre_animation_switch_hook', export_settings, blender_object, blender_action, track_name, on_type)
                     blender_object.animation_data.action = blender_action
+                    export_user_extensions('post_animation_switch_hook', export_settings, blender_object, blender_action, track_name, on_type)
                 except:
                     error = "Action is readonly. Please check NLA editor"
                     print_console("WARNING", "Animation '{}' could not be exported. Cause: {}".format(blender_action.name, error))
@@ -130,6 +134,8 @@ def gather_animations(  obj_uuid: int,
         blender_object.animation_data.use_tweak_mode = restore_tweak_mode
         blender_object.animation_data.use_nla = current_use_nla
 
+    export_user_extensions('animation_switch_loop_hook', export_settings, blender_object, True)
+
     return animations, tracks
 
 
@@ -313,7 +319,21 @@ def __get_blender_actions(blender_object: bpy.types.Object,
                     blender_tracks[act.name] = None
                     action_on_type[act.name] = "OBJECT"
 
-    export_user_extensions('gather_actions_hook', export_settings, blender_object, blender_actions, blender_tracks, action_on_type)
+    # Use a class to get parameters, to be able to modify them
+    class GatherActionHookParameters:
+        def __init__(self, blender_actions, blender_tracks, action_on_type):
+            self.blender_actions = blender_actions
+            self.blender_tracks = blender_tracks
+            self.action_on_type = action_on_type
+
+    gatheractionhookparams = GatherActionHookParameters(blender_actions, blender_tracks, action_on_type)
+
+    export_user_extensions('gather_actions_hook', export_settings, blender_object, gatheractionhookparams)
+
+    # Get params back from hooks
+    blender_actions = gatheractionhookparams.blender_actions
+    blender_tracks = gatheractionhookparams.blender_tracks
+    action_on_type = gatheractionhookparams.action_on_type
 
     # Remove duplicate actions.
     blender_actions = list(set(blender_actions))
diff --git a/io_scene_gltf2/blender/exp/gltf2_blender_gather_tree.py b/io_scene_gltf2/blender/exp/gltf2_blender_gather_tree.py
index 88b19731..180327a2 100644
--- a/io_scene_gltf2/blender/exp/gltf2_blender_gather_tree.py
+++ b/io_scene_gltf2/blender/exp/gltf2_blender_gather_tree.py
@@ -289,6 +289,7 @@ class VExportTree:
         self.filter_tag()
         export_user_extensions('gather_tree_filter_tag_hook', self.export_settings, self)
         self.filter_perform()
+        self.remove_filtered_nodes()
 
 
     def recursive_filter_tag(self, uuid, parent_keep_tag):
@@ -404,6 +405,9 @@ class VExportTree:
 
         return True
 
+    def remove_filtered_nodes(self):
+        self.nodes = {k:n for (k, n) in self.nodes.items() if n.keep_tag is True}
+
     def search_missing_armature(self):
         for n in [n for n in self.nodes.values() if hasattr(n, "armature_needed") is True]:
             candidates = [i for i in self.nodes.values() if i.blender_type == VExportNode.ARMATURE and i.blender_object.name == n.armature_needed]



More information about the Bf-extensions-cvs mailing list