From 464a9c9bf8ec1ad802559336000ce77f8c419347 Mon Sep 17 00:00:00 2001 From: rintrint <152774318+rintrint@users.noreply.github.com> Date: Thu, 27 Jun 2024 03:45:45 +0900 Subject: [PATCH 1/4] Update importer.py --- mmd_tools/core/vpd/importer.py | 37 +++++++++++++++++++++++++--------- 1 file changed, 28 insertions(+), 9 deletions(-) diff --git a/mmd_tools/core/vpd/importer.py b/mmd_tools/core/vpd/importer.py index ff048bf7..75ab9a2f 100644 --- a/mmd_tools/core/vpd/importer.py +++ b/mmd_tools/core/vpd/importer.py @@ -35,7 +35,7 @@ def __assignToArmaturePoseMode(self, armObj): for bone, matrix_basis in pose_orig.items(): bone.matrix_basis = matrix_basis - def __assignToArmatureSimple(self, armObj: bpy.types.Object, reset_transform=True): + def __assignToArmatureSimple(self, armObj: bpy.types.Object, reset_transform=False): logging.info(' - assigning to armature "%s"', armObj.name) pose_bones = armObj.pose.bones @@ -54,22 +54,41 @@ def __assignToArmatureSimple(self, armObj: bpy.types.Object, reset_transform=Tru assert bone not in pose_data pose_data[bone] = Matrix.Translation(loc) @ rot.to_matrix().to_4x4() + # Check if animation data exists + if armObj.animation_data is None: + armObj.animation_data_create() + + # Check if an action exists + if armObj.animation_data.action is None: + action = bpy.data.actions.new(name="PoseLib") + armObj.animation_data.action = action + else: + action = armObj.animation_data.action + + # Get the current frame + current_frame = bpy.context.scene.frame_current + + # Update and keyframe only the bones affected by the current VPD file for bone in armObj.pose.bones: vpd_pose = pose_data.get(bone, None) - bone.bone.select = bool(vpd_pose) if vpd_pose: bone.matrix_basis = vpd_pose + bone.keyframe_insert(data_path="location", frame=current_frame) + bone.keyframe_insert(data_path="rotation_quaternion", frame=current_frame) elif reset_transform: bone.matrix_basis.identity() + bone.keyframe_insert(data_path="location", frame=current_frame) + bone.keyframe_insert(data_path="rotation_quaternion", frame=current_frame) - # FIXME: armObj.pose_library is None when the armature is not in pose mode - if armObj.pose_library is None: - armObj.pose_library = bpy.data.actions.new(name="PoseLib") + # Add or update a pose marker + if self.__pose_name not in action.pose_markers: + marker = action.pose_markers.new(self.__pose_name) + else: + marker = action.pose_markers[self.__pose_name] + marker.frame = current_frame - frames = [m.frame for m in armObj.pose_library.pose_markers] - frame_max = max(frames) if len(frames) else 0 - # FIXME: poselib.pose_add is deprecated, use animation_data instead - bpy.ops.poselib.pose_add(frame=frame_max + 1, name=self.__pose_name) + # Ensure the timeline is updated + bpy.context.view_layer.update() def __assignToMesh(self, meshObj): if meshObj.data.shape_keys is None: From 5cfd3030eabe95ff2d0e3b4bc655e36e7414ecc4 Mon Sep 17 00:00:00 2001 From: rintrint <152774318+rintrint@users.noreply.github.com> Date: Thu, 27 Jun 2024 04:11:31 +0900 Subject: [PATCH 2/4] Update importer.py --- mmd_tools/core/vpd/importer.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mmd_tools/core/vpd/importer.py b/mmd_tools/core/vpd/importer.py index 75ab9a2f..77fe32fb 100644 --- a/mmd_tools/core/vpd/importer.py +++ b/mmd_tools/core/vpd/importer.py @@ -35,7 +35,7 @@ def __assignToArmaturePoseMode(self, armObj): for bone, matrix_basis in pose_orig.items(): bone.matrix_basis = matrix_basis - def __assignToArmatureSimple(self, armObj: bpy.types.Object, reset_transform=False): + def __assignToArmatureSimple(self, armObj: bpy.types.Object, reset_transform=True): logging.info(' - assigning to armature "%s"', armObj.name) pose_bones = armObj.pose.bones From 8a38a7b8b3c85d50f1f1b61024e2a325d48ad027 Mon Sep 17 00:00:00 2001 From: rintrint <152774318+rintrint@users.noreply.github.com> Date: Thu, 27 Jun 2024 04:35:36 +0900 Subject: [PATCH 3/4] Update importer.py --- mmd_tools/core/vpd/importer.py | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/mmd_tools/core/vpd/importer.py b/mmd_tools/core/vpd/importer.py index 77fe32fb..90d71471 100644 --- a/mmd_tools/core/vpd/importer.py +++ b/mmd_tools/core/vpd/importer.py @@ -20,7 +20,8 @@ def __init__(self, filepath, scale=1.0, bone_mapper=None, use_pose_mode=False): self.__scale = scale self.__bone_mapper = bone_mapper if use_pose_mode: - self.__bone_util_cls = importer.BoneConverterPoseMode + self.__bone_util_cls = importer.BoneConverter + #self.__bone_util_cls = importer.BoneConverterPoseMode self.__assignToArmature = self.__assignToArmaturePoseMode else: self.__bone_util_cls = importer.BoneConverter @@ -28,12 +29,13 @@ def __init__(self, filepath, scale=1.0, bone_mapper=None, use_pose_mode=False): logging.info("Loaded %s", self.__vpd_file) def __assignToArmaturePoseMode(self, armObj): - pose_orig = {b: b.matrix_basis.copy() for b in armObj.pose.bones} - try: - self.__assignToArmatureSimple(armObj, reset_transform=False) - finally: - for bone, matrix_basis in pose_orig.items(): - bone.matrix_basis = matrix_basis + self.__assignToArmatureSimple(armObj, reset_transform=False) + #pose_orig = {b: b.matrix_basis.copy() for b in armObj.pose.bones} + #try: + # self.__assignToArmatureSimple(armObj, reset_transform=False) + #finally: + # for bone, matrix_basis in pose_orig.items(): + # bone.matrix_basis = matrix_basis def __assignToArmatureSimple(self, armObj: bpy.types.Object, reset_transform=True): logging.info(' - assigning to armature "%s"', armObj.name) From 7811d16bd0f5bb0f95e2fb6a2792d172f00bdcc6 Mon Sep 17 00:00:00 2001 From: fmnijk <152774318+rintrint@users.noreply.github.com> Date: Wed, 30 Oct 2024 15:47:02 +0900 Subject: [PATCH 4/4] Update importer.py --- mmd_tools/core/vpd/importer.py | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/mmd_tools/core/vpd/importer.py b/mmd_tools/core/vpd/importer.py index 90d71471..eea24454 100644 --- a/mmd_tools/core/vpd/importer.py +++ b/mmd_tools/core/vpd/importer.py @@ -113,13 +113,7 @@ def assign(self, obj): if obj is None: return if obj.type == "ARMATURE": - with FnContext.temp_override_objects( - FnContext.ensure_context(), - active_object=obj, - selected_objects=[obj], - ): - bpy.ops.object.mode_set(mode="POSE") - self.__assignToArmature(obj) + self.__assignToArmature(obj) elif obj.type == "MESH": self.__assignToMesh(obj) else: