From d3043e6b429d70c01dd73767465cfb301d8d8671 Mon Sep 17 00:00:00 2001 From: Julien Duroure Date: Sun, 6 Feb 2022 21:49:45 +0100 Subject: glTF exporter: fix onl def bone animation export --- io_scene_gltf2/__init__.py | 2 +- ...2_blender_gather_animation_sampler_keyframes.py | 6 +++++- .../exp/gltf2_blender_gather_animation_samplers.py | 25 ++++++++++++++++++---- 3 files changed, 27 insertions(+), 6 deletions(-) diff --git a/io_scene_gltf2/__init__.py b/io_scene_gltf2/__init__.py index b8fd09b3..116d9a2a 100755 --- a/io_scene_gltf2/__init__.py +++ b/io_scene_gltf2/__init__.py @@ -15,7 +15,7 @@ bl_info = { 'name': 'glTF 2.0 format', 'author': 'Julien Duroure, Scurest, Norbert Nopper, Urs Hanselmann, Moritz Becher, Benjamin Schmithüsen, Jim Eckerlein, and many external contributors', - "version": (3, 2, 1), + "version": (3, 2, 2), 'blender': (3, 1, 0), 'location': 'File > Import-Export', 'description': 'Import-Export as glTF 2.0', diff --git a/io_scene_gltf2/blender/exp/gltf2_blender_gather_animation_sampler_keyframes.py b/io_scene_gltf2/blender/exp/gltf2_blender_gather_animation_sampler_keyframes.py index 33dd08c9..741c7c0c 100755 --- a/io_scene_gltf2/blender/exp/gltf2_blender_gather_animation_sampler_keyframes.py +++ b/io_scene_gltf2/blender/exp/gltf2_blender_gather_animation_sampler_keyframes.py @@ -244,7 +244,11 @@ def get_bone_matrix(blender_obj_uuid_if_armature: typing.Optional[str], rest_mat = blender_bone_parent.bone.matrix_local.inverted_safe() @ blender_bone.bone.matrix_local matrix = rest_mat.inverted_safe() @ blender_bone_parent.matrix.inverted_safe() @ blender_bone.matrix else: - matrix = blender_bone.bone.matrix_local.inverted_safe() @ blender_bone.matrix + if blender_bone.parent is None: + matrix = blender_bone.bone.matrix_local.inverted_safe() @ blender_bone.matrix + else: + # Bone has a parent, but in export, after filter, is at root of armature + matrix = blender_bone.matrix.copy() data[frame][blender_bone.name] = matrix diff --git a/io_scene_gltf2/blender/exp/gltf2_blender_gather_animation_samplers.py b/io_scene_gltf2/blender/exp/gltf2_blender_gather_animation_samplers.py index a27184b7..fbd0b222 100755 --- a/io_scene_gltf2/blender/exp/gltf2_blender_gather_animation_samplers.py +++ b/io_scene_gltf2/blender/exp/gltf2_blender_gather_animation_samplers.py @@ -14,6 +14,7 @@ import typing +from io_scene_gltf2.blender.exp.gltf2_blender_gather_tree import VExportNode import bpy import mathutils @@ -386,6 +387,7 @@ def __gather_output(channels: typing.Tuple[bpy.types.FCurve], bone = blender_object_if_armature.pose.bones[bake_bone] if isinstance(bone, bpy.types.PoseBone): if bone.parent is None: + # bone at root of armature axis_basis_change = mathutils.Matrix.Identity(4) if export_settings[gltf2_blender_export_keys.YUP]: axis_basis_change = mathutils.Matrix( @@ -395,10 +397,25 @@ def __gather_output(channels: typing.Tuple[bpy.types.FCurve], (0.0, 0.0, 0.0, 1.0))) correction_matrix_local = axis_basis_change @ bone.bone.matrix_local else: - correction_matrix_local = ( - bone.parent.bone.matrix_local.inverted_safe() @ - bone.bone.matrix_local - ) + # Bone is not at root of armature + # There are 2 cases : + parent_uuid = export_settings['vtree'].nodes[export_settings['vtree'].nodes[blender_obj_uuid].bones[bone.name]].parent_uuid + if parent_uuid is not None and export_settings['vtree'].nodes[parent_uuid].blender_type == VExportNode.BONE: + # export bone is not at root of armature neither + correction_matrix_local = ( + bone.parent.bone.matrix_local.inverted_safe() @ + bone.bone.matrix_local + ) + else: + # exported bone (after filter) is at root of armature + axis_basis_change = mathutils.Matrix.Identity(4) + if export_settings[gltf2_blender_export_keys.YUP]: + axis_basis_change = mathutils.Matrix( + ((1.0, 0.0, 0.0, 0.0), + (0.0, 0.0, 1.0, 0.0), + (0.0, -1.0, 0.0, 0.0), + (0.0, 0.0, 0.0, 1.0))) + correction_matrix_local = axis_basis_change transform = correction_matrix_local else: -- cgit v1.2.3