Skip to content

Commit

Permalink
ms2 - import RagdollConstraint matrix correction
Browse files Browse the repository at this point in the history
  • Loading branch information
HENDRIX-ZT2 committed Oct 17, 2023
1 parent 80cebe8 commit cbdb459
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 4 deletions.
9 changes: 6 additions & 3 deletions plugin/modules_import/armature.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

from plugin.utils.object import create_ob, link_to_collection, set_collection_visibility
from plugin.utils import matrix_util
from plugin.utils.matrix_util import mat3_to_vec_roll
from plugin.utils.matrix_util import mat3_to_vec_roll, CorrectorRagdoll


def import_armature(scene, model_info, b_bone_names):
Expand Down Expand Up @@ -190,6 +190,7 @@ def import_joints(scene, armature_ob, bone_info, b_bone_names, corrector):
bone_name = b_bone_names[bone_index]
parent_to(armature_ob, b_joint, bone_name)

corrector_rag = CorrectorRagdoll(False)
# ragdoll constraints
for ragdoll in j.ragdoll_constraints:
parent_name = ragdoll.parent.joint.name
Expand Down Expand Up @@ -223,9 +224,11 @@ def import_joints(scene, armature_ob, bone_info, b_bone_names, corrector):
b_ragdoll = create_ob(scene, f"{'ragdoll'}_{child_name}", None, coll_name="ragdoll")
b_ragdoll.empty_display_type = "ARROWS"
b_ragdoll.empty_display_size = 0.05
# mat = mathutils.Matrix(ragdoll.rot.data).to_4x4()
mat = mathutils.Matrix(ragdoll.rot.data).inverted().to_4x4()
mat = corrector.nif_bind_to_blender_bind(mat)
mat = corrector_rag.nif_bind_to_blender_bind(mat)
mat = mat.to_3x3()
mat *= -1
mat = mat.to_4x4()
joint_transform = j.joint_transforms[ragdoll.child.index]
mat.translation = get_matrix(corrector, joint_transform).translation
b_ragdoll.matrix_local = mat
Expand Down
18 changes: 18 additions & 0 deletions plugin/utils/matrix_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,24 @@ def blender_bind_to_nif_bind(self, blender_armature_space_matrix):
return self.correction_glob_inv @ bind @ self.correction


class CorrectorRagdoll(Corrector):
def __init__(self, is_zt):
# axis_conversion(from_forward='Y', from_up='Z', to_forward='Y', to_up='Z')
self.correction_glob = axis_conversion("-Z", "Y").to_4x4()
self.correction_glob_inv = self.correction_glob.inverted()
if is_zt:
self.correction = axis_conversion("X", "Y").to_4x4()
else:
# self.correction = axis_conversion("-X", "Y").to_4x4() # default for bones
# self.correction = axis_conversion("X", "-Y").to_4x4()
self.correction = axis_conversion("-X", "-Y").to_4x4() # total inversion
# self.correction = axis_conversion("-X", "-Y", to_forward='Y', to_up='-Z').to_4x4()
self.correction_inv = self.correction.inverted()
# mirror about x axis too:
self.xflip = mathutils.Matrix().to_4x4()
self.xflip[0][0] = -1


def import_matrix(m):
"""Retrieves a niBlock's transform matrix as a Mathutil.Matrix."""
return mathutils.Matrix(m.as_list())
Expand Down
2 changes: 1 addition & 1 deletion version.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
23f746c79 - Tue Oct 17 17:18:29 2023 +0200
80cebe88b - Tue Oct 17 18:00:51 2023 +0200

0 comments on commit cbdb459

Please sign in to comment.