[Bf-extensions-cvs] [63dd8498] master: glTF exporter: Add support for use_inherit_rotation and inherit_scale.

Julien Duroure noreply at git.blender.org
Tue Jul 21 20:33:17 CEST 2020


Commit: 63dd8498ac106b5645822a124aa0edb0d917d5a8
Author: Julien Duroure
Date:   Tue Jul 21 20:14:06 2020 +0200
Branches: master
https://developer.blender.org/rBA63dd8498ac106b5645822a124aa0edb0d917d5a8

glTF exporter: Add support for use_inherit_rotation and inherit_scale.

Thanks Skywolf285!

===================================================================

M	io_scene_gltf2/__init__.py
M	io_scene_gltf2/blender/exp/gltf2_blender_gather_animation_sampler_keyframes.py
M	io_scene_gltf2/blender/exp/gltf2_blender_gather_joints.py

===================================================================

diff --git a/io_scene_gltf2/__init__.py b/io_scene_gltf2/__init__.py
index cb663fca..9329c556 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, Norbert Nopper, Urs Hanselmann, Moritz Becher, Benjamin Schmithüsen, Jim Eckerlein, and many external contributors',
-    "version": (1, 3, 31),
+    "version": (1, 3, 32),
     'blender': (2, 90, 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 822aa6a1..f8ab333e 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
@@ -161,8 +161,14 @@ def get_bone_matrix(blender_object_if_armature: typing.Optional[bpy.types.Object
             if bake_bone is None:
                 matrix = pbone.matrix_basis.copy()
             else:
-                matrix = pbone.matrix
-                matrix = blender_object_if_armature.convert_space(pose_bone=pbone, matrix=matrix, from_space='POSE', to_space='LOCAL')
+                if (pbone.bone.use_inherit_rotation == False or pbone.bone.inherit_scale != "FULL") and pbone.parent != None:
+                    rest_mat = (pbone.parent.bone.matrix_local.inverted_safe() @ pbone.bone.matrix_local)
+                    matrix = (rest_mat.inverted_safe() @ pbone.parent.matrix.inverted_safe() @ pbone.matrix)
+                else:
+                    matrix = pbone.matrix
+                    matrix = blender_object_if_armature.convert_space(pose_bone=pbone, matrix=matrix, from_space='POSE', to_space='LOCAL')
+
+
             data[frame][pbone.name] = matrix
 
 
diff --git a/io_scene_gltf2/blender/exp/gltf2_blender_gather_joints.py b/io_scene_gltf2/blender/exp/gltf2_blender_gather_joints.py
index af086c1b..1cb26551 100755
--- a/io_scene_gltf2/blender/exp/gltf2_blender_gather_joints.py
+++ b/io_scene_gltf2/blender/exp/gltf2_blender_gather_joints.py
@@ -43,7 +43,14 @@ def gather_joint(blender_object, blender_bone, export_settings):
     else:
         correction_matrix_local = gltf2_blender_math.multiply(
             blender_bone.parent.bone.matrix_local.inverted(), blender_bone.bone.matrix_local)
-    matrix_basis = blender_bone.matrix_basis
+
+    if (blender_bone.bone.use_inherit_rotation == False or blender_bone.bone.inherit_scale != "FULL") and blender_bone.parent != None:
+        rest_mat = (blender_bone.parent.bone.matrix_local.inverted_safe() @ blender_bone.bone.matrix_local)
+        matrix_basis = (rest_mat.inverted_safe() @ blender_bone.parent.matrix.inverted_safe() @ blender_bone.matrix)
+    else:
+        matrix_basis = blender_bone.matrix
+        matrix_basis = blender_object.convert_space(pose_bone=blender_bone, matrix=matrix_basis, from_space='POSE', to_space='LOCAL')
+
     trans, rot, sca = gltf2_blender_extract.decompose_transition(
         gltf2_blender_math.multiply(correction_matrix_local, matrix_basis), export_settings)
     translation, rotation, scale = (None, None, None)



More information about the Bf-extensions-cvs mailing list