From cbdb459c2eaba50dfa0d0724e39e6aeb2f6a92bb Mon Sep 17 00:00:00 2001 From: HENDRIX-ZT2 Date: Tue, 17 Oct 2023 19:00:16 +0200 Subject: [PATCH] ms2 - import RagdollConstraint matrix correction --- plugin/modules_import/armature.py | 9 ++++++--- plugin/utils/matrix_util.py | 18 ++++++++++++++++++ version.txt | 2 +- 3 files changed, 25 insertions(+), 4 deletions(-) diff --git a/plugin/modules_import/armature.py b/plugin/modules_import/armature.py index 187dbd1c2..4f8383789 100644 --- a/plugin/modules_import/armature.py +++ b/plugin/modules_import/armature.py @@ -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): @@ -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 @@ -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 diff --git a/plugin/utils/matrix_util.py b/plugin/utils/matrix_util.py index 23dc32093..3dcbc3d72 100644 --- a/plugin/utils/matrix_util.py +++ b/plugin/utils/matrix_util.py @@ -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()) diff --git a/version.txt b/version.txt index 32c6f1686..79a850723 100644 --- a/version.txt +++ b/version.txt @@ -1 +1 @@ -23f746c79 - Tue Oct 17 17:18:29 2023 +0200 \ No newline at end of file +80cebe88b - Tue Oct 17 18:00:51 2023 +0200 \ No newline at end of file