Skip to content
Snippets Groups Projects
Commit f89d1c95 authored by Julien Duroure's avatar Julien Duroure
Browse files

Fix orientation issue in object animation

parent 8ac09109
No related branches found
No related tags found
No related merge requests found
......@@ -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)
......
......@@ -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]
......
......@@ -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:
......
......@@ -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)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment