Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender-addons.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJulien Duroure <julien.duroure@gmail.com>2019-04-02 23:11:26 +0300
committerJulien Duroure <julien.duroure@gmail.com>2019-04-02 23:11:26 +0300
commit0a232c94806bc1f0128cc8e807466c46a5083497 (patch)
tree86b1326e05e5562058ffdee379c8fef5fa9899f6 /io_scene_gltf2/blender/exp/gltf2_blender_gather_skins.py
parent3e70027f579b29c65d4b6f6eac20a5d431fce5a5 (diff)
glTF exporter: fix skinning export
Diffstat (limited to 'io_scene_gltf2/blender/exp/gltf2_blender_gather_skins.py')
-rwxr-xr-xio_scene_gltf2/blender/exp/gltf2_blender_gather_skins.py50
1 files changed, 22 insertions, 28 deletions
diff --git a/io_scene_gltf2/blender/exp/gltf2_blender_gather_skins.py b/io_scene_gltf2/blender/exp/gltf2_blender_gather_skins.py
index c3b975c3..5c4907b8 100755
--- a/io_scene_gltf2/blender/exp/gltf2_blender_gather_skins.py
+++ b/io_scene_gltf2/blender/exp/gltf2_blender_gather_skins.py
@@ -63,33 +63,44 @@ def __gather_extras(blender_object, export_settings):
return None
def __gather_inverse_bind_matrices(blender_object, mesh_object, export_settings):
- inverse_matrices = []
-
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)))
- # # artificial torso, as needed by glTF
- # inverse_bind_matrix = blender_object.matrix_world.inverted() * axis_basis_change.inverted()
- # for column in range(0, 4):
- # for row in range(0, 4):
- # inverse_matrices.append(inverse_bind_matrix[row][column])
-
- #
+ # build the hierarchy of nodes out of the bones
+ root_bones = []
for blender_bone in blender_object.pose.bones:
+ if not blender_bone.parent:
+ root_bones.append(blender_bone)
+
+ matrices = []
+
+ # traverse the matrices in the same order as the joints and compute the inverse bind matrix
+ def __collect_matrices(bone):
matrix_world = gltf2_blender_math.multiply(blender_object.matrix_world, mesh_object.matrix_world.inverted())
inverse_bind_matrix = gltf2_blender_math.multiply(
axis_basis_change,
gltf2_blender_math.multiply(
matrix_world,
- blender_bone.bone.matrix_local
+ bone.bone.matrix_local
)
).inverted()
+ matrices.append(inverse_bind_matrix)
+
+ for child in bone.children:
+ __collect_matrices(child)
+
+ # start with the "root" bones and recurse into children, in the same ordering as the how joints are gathered
+ for root_bone in root_bones:
+ __collect_matrices(root_bone)
+ # flatten the matrices
+ inverse_matrices = []
+ for matrix in matrices:
for column in range(0, 4):
for row in range(0, 4):
- inverse_matrices.append(inverse_bind_matrix[row][column])
+ inverse_matrices.append(matrix[row][column])
binary_data = gltf2_io_binary_data.BinaryData.from_list(inverse_matrices, gltf2_io_constants.ComponentType.Float)
return gltf2_blender_gather_accessors.gather_accessor(
@@ -104,23 +115,6 @@ def __gather_inverse_bind_matrices(blender_object, mesh_object, export_settings)
def __gather_joints(blender_object, export_settings):
- # # the skeletal hierarchy groups below a 'root' joint
- # # TODO: add transform?
- # torso = gltf2_io.Node(
- # camera=None,
- # children=[],
- # extensions={},
- # extras=None,
- # matrix=[],
- # mesh=None,
- # name="Skeleton_" + blender_object.name,
- # rotation=None,
- # scale=None,
- # skin=None,
- # translation=None,
- # weights=None
- # )
-
root_joints = []
# build the hierarchy of nodes out of the bones
for blender_bone in blender_object.pose.bones: