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 ec95692bc4ebdbf65036394693042fad5eed2c0e..c08849661e4e26833ad01731d6fa572a49223835 100755 --- a/io_scene_gltf2/blender/imp/gltf2_blender_animation_bone.py +++ b/io_scene_gltf2/blender/imp/gltf2_blender_animation_bone.py @@ -172,7 +172,7 @@ class BlenderBoneAnim(): 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 action) + # (is an action from a deleted object) if action.users == 1: bpy.data.actions.remove(action) action = bpy.data.actions.new(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 2a04f469007560d63de2f55b2448a9e5194aa0a1..9302afd576d146534a605921b767ac151b045174 100755 --- a/io_scene_gltf2/blender/imp/gltf2_blender_animation_node.py +++ b/io_scene_gltf2/blender/imp/gltf2_blender_animation_node.py @@ -55,7 +55,7 @@ class BlenderNodeAnim(): action = bpy.data.actions.new(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 action) + # (is an action from a deleted object) if action.users == 1: bpy.data.actions.remove(action) action = bpy.data.actions.new(name) @@ -63,6 +63,10 @@ class BlenderNodeAnim(): obj.animation_data_create() obj.animation_data.action = bpy.data.actions[action.name] + # There is an animation on object + # We can't remove Yup2Zup oject + gltf.animation_object = True + for channel_idx in node.animations[anim_idx]: channel = animation.channels[channel_idx] diff --git a/io_scene_gltf2/blender/imp/gltf2_blender_gltf.py b/io_scene_gltf2/blender/imp/gltf2_blender_gltf.py index 0c819f9c9310a30381fe98389e299896f4245dba..9afc12ded9a99ef30acba6a37f3396dd8be97143 100755 --- a/io_scene_gltf2/blender/imp/gltf2_blender_gltf.py +++ b/io_scene_gltf2/blender/imp/gltf2_blender_gltf.py @@ -77,6 +77,10 @@ class BlenderGlTF(): # default scene used gltf.blender_scene = None + # Check if there is animation on object + # Init is to False, and will be set to True during creation + gltf.animation_object = False + # Blender material if gltf.data.materials: for material in gltf.data.materials: diff --git a/io_scene_gltf2/blender/imp/gltf2_blender_scene.py b/io_scene_gltf2/blender/imp/gltf2_blender_scene.py index 14310fb8fc1d04e2e8c19d0f3649b9c2d98a8f56..c155b1155043470487ac988618594c8fb1ebef12 100755 --- a/io_scene_gltf2/blender/imp/gltf2_blender_scene.py +++ b/io_scene_gltf2/blender/imp/gltf2_blender_scene.py @@ -80,16 +80,18 @@ class BlenderScene(): for node_idx in pyscene.nodes: bpy.data.objects[gltf.data.nodes[node_idx].blender_object].parent = obj_rotation + if gltf.animation_object is False: - for node_idx in pyscene.nodes: - for obj_ in bpy.context.scene.objects: - obj_.select_set(False) - bpy.data.objects[gltf.data.nodes[node_idx].blender_object].select_set(True) - bpy.context.view_layer.objects.active = bpy.data.objects[gltf.data.nodes[node_idx].blender_object] - bpy.ops.object.parent_clear(type='CLEAR_KEEP_TRANSFORM') + for node_idx in pyscene.nodes: + for obj_ in bpy.context.scene.objects: + obj_.select_set(False) + bpy.data.objects[gltf.data.nodes[node_idx].blender_object].select_set(True) + bpy.context.view_layer.objects.active = bpy.data.objects[gltf.data.nodes[node_idx].blender_object] + + bpy.ops.object.parent_clear(type='CLEAR_KEEP_TRANSFORM') - # remove object - bpy.context.scene.collection.objects.unlink(obj_rotation) - bpy.data.objects.remove(obj_rotation) + # remove object + bpy.context.scene.collection.objects.unlink(obj_rotation) + bpy.data.objects.remove(obj_rotation)