[Bf-extensions-cvs] [438ca980] master: glTF importer: fix import multiple animations with same name

Julien Duroure noreply at git.blender.org
Sun Jan 27 19:36:43 CET 2019


Commit: 438ca980e6b1ab0b0f22c2b35e319738ae494c26
Author: Julien Duroure
Date:   Sun Jan 27 19:36:17 2019 +0100
Branches: master
https://developer.blender.org/rBA438ca980e6b1ab0b0f22c2b35e319738ae494c26

glTF importer: fix import multiple animations with same name

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

M	io_scene_gltf2/blender/imp/gltf2_blender_animation_bone.py
M	io_scene_gltf2/blender/imp/gltf2_blender_animation_node.py
M	io_scene_gltf2/blender/imp/gltf2_blender_scene.py

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

diff --git a/io_scene_gltf2/blender/imp/gltf2_blender_animation_bone.py b/io_scene_gltf2/blender/imp/gltf2_blender_animation_bone.py
index 343e66b7..bdafae5e 100755
--- a/io_scene_gltf2/blender/imp/gltf2_blender_animation_bone.py
+++ b/io_scene_gltf2/blender/imp/gltf2_blender_animation_bone.py
@@ -225,13 +225,22 @@ class BlenderBoneAnim():
         if name not in bpy.data.actions:
             action = bpy.data.actions.new(name)
         else:
-            action = bpy.data.actions[name]
-            # Check if this action has some users.
-            # If no user (only 1 indeed), that means that this action must be deleted
-            # (is an action from a deleted object)
-            if action.users == 1:
-                bpy.data.actions.remove(action)
-                action = bpy.data.actions.new(name)
+            if name in gltf.animation_managed:
+                # multiple animation with same name in glTF file
+                # Create a new action with new name if needed
+                if name in gltf.current_animation_names.keys():
+                    action = bpy.data.actions[gltf.current_animation_names[name]]
+                    name = gltf.current_animation_names[name]
+                else:
+                    action = bpy.data.actions.new(name)
+            else:
+                action = bpy.data.actions[name]
+                # Check if this action has some users.
+                # If no user (only 1 indeed), that means that this action must be deleted
+                # (is an action from a deleted object)
+                if action.users == 1:
+                    bpy.data.actions.remove(action)
+                    action = bpy.data.actions.new(name)
         if not obj.animation_data:
             obj.animation_data_create()
         obj.animation_data.action = bpy.data.actions[action.name]
@@ -248,3 +257,6 @@ class BlenderBoneAnim():
             elif channel.target.path == "scale":
                 BlenderBoneAnim.parse_scale_channel(gltf, node, obj, bone, channel, animation)
 
+        if action.name not in gltf.current_animation_names.keys():
+            gltf.current_animation_names[name] = action.name
+
diff --git a/io_scene_gltf2/blender/imp/gltf2_blender_animation_node.py b/io_scene_gltf2/blender/imp/gltf2_blender_animation_node.py
index 0d36fb50..12c54e6a 100755
--- a/io_scene_gltf2/blender/imp/gltf2_blender_animation_node.py
+++ b/io_scene_gltf2/blender/imp/gltf2_blender_animation_node.py
@@ -147,3 +147,6 @@ class BlenderNodeAnim():
                             group='ShapeKeys'
                         )
 
+        if action.name not in gltf.current_animation_names.keys():
+            gltf.current_animation_names[name] = action.name
+
diff --git a/io_scene_gltf2/blender/imp/gltf2_blender_scene.py b/io_scene_gltf2/blender/imp/gltf2_blender_scene.py
index 2d986b0d..cf8f58a1 100755
--- a/io_scene_gltf2/blender/imp/gltf2_blender_scene.py
+++ b/io_scene_gltf2/blender/imp/gltf2_blender_scene.py
@@ -80,10 +80,14 @@ class BlenderScene():
                     BlenderSkin.create_armature_modifiers(gltf, skin_id)
 
         if gltf.data.animations:
+            gltf.animation_managed = []
             for anim_idx, anim in enumerate(gltf.data.animations):
+                gltf.current_animation_names = {}
                 if list_nodes is not None:
                     for node_idx in list_nodes:
                         BlenderAnimation.anim(gltf, anim_idx, node_idx)
+                for an in gltf.current_animation_names.values():
+                    gltf.animation_managed.append(an)
 
         # Parent root node to rotation object
         if list_nodes is not None:



More information about the Bf-extensions-cvs mailing list