diff options
author | Julien Duroure <julien.duroure@gmail.com> | 2019-01-27 21:36:17 +0300 |
---|---|---|
committer | Julien Duroure <julien.duroure@gmail.com> | 2019-01-27 21:36:39 +0300 |
commit | 438ca980e6b1ab0b0f22c2b35e319738ae494c26 (patch) | |
tree | 9711162fe5b5992133d915982b418c81c875be46 /io_scene_gltf2 | |
parent | 00fe1f9d27ef81d535c4ebfea11e7793a41fe373 (diff) |
glTF importer: fix import multiple animations with same name
Diffstat (limited to 'io_scene_gltf2')
3 files changed, 26 insertions, 7 deletions
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: |