glTF exporter: fix onl def bone animation export

This commit is contained in:
Julien Duroure 2022-02-06 21:49:45 +01:00
parent a674a92800
commit d3043e6b42
3 changed files with 27 additions and 6 deletions

View File

@ -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',

View File

@ -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

View File

@ -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: