diff options
author | Julien Duroure <julien.duroure@gmail.com> | 2018-11-25 18:26:12 +0300 |
---|---|---|
committer | Julien Duroure <julien.duroure@gmail.com> | 2018-11-25 18:26:12 +0300 |
commit | f89d1c9581c03160485a7b4b09fa5d538331fdeb (patch) | |
tree | 62f9e2c261fb8be43ceb43bab519468ddf5b9aad /io_scene_gltf2 | |
parent | 8ac09109617d8acd81747bd3dffed915aa99c8cc (diff) |
Fix orientation issue in object animation
Diffstat (limited to 'io_scene_gltf2')
4 files changed, 21 insertions, 11 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 ec95692b..c0884966 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 2a04f469..9302afd5 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 0c819f9c..9afc12de 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 14310fb8..c155b115 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) |