From 776c0ade9f73445eb78781be4b65deefd7ddfa46 Mon Sep 17 00:00:00 2001 From: rintrint Date: Tue, 25 Jun 2024 03:48:28 +0900 Subject: [PATCH 1/3] Update model.py --- mmd_tools/core/model.py | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/mmd_tools/core/model.py b/mmd_tools/core/model.py index 5cf7278b..6802d790 100644 --- a/mmd_tools/core/model.py +++ b/mmd_tools/core/model.py @@ -607,12 +607,26 @@ def create(name: str, name_e: str = "", scale: float = 1, obj_name: Optional[str if add_root_bone: bone_name = "全ての親" + bone_name_english = "Root" + + # Create the root bone with bpyutils.edit_object(armature_object) as data: bone = data.edit_bones.new(name=bone_name) - bone.head = [0.0, 0.0, 0.0] - bone.tail = [0.0, 0.0, getattr(root, Props.empty_display_size)] - armature_object.pose.bones[bone_name].mmd_bone.name_j = bone_name - armature_object.pose.bones[bone_name].mmd_bone.name_e = "Root" + bone.head = (0.0, 0.0, 0.0) + bone.tail = (0.0, 0.0, getattr(root, Props.empty_display_size)) + + # Set MMD bone properties + pose_bone = armature_object.pose.bones[bone_name] + pose_bone.mmd_bone.name_j = bone_name + pose_bone.mmd_bone.name_e = bone_name_english + + # Create a bone collection named "Root" + bone_collection_name = bone_name_english + bone_collection = armature_object.data.collections.new(name=bone_collection_name) + + # Assign the new bone to the bone collection + data_bone = armature_object.data.bones[bone_name] + bone_collection.assign(data_bone) FnContext.set_active_and_select_single_object(context, root) return Model(root) From 054bb6cce671f6ba69f2572e306c7f13b9c4c724 Mon Sep 17 00:00:00 2001 From: rintrint Date: Tue, 25 Jun 2024 04:14:41 +0900 Subject: [PATCH 2/3] Update exporter.py --- mmd_tools/core/pmx/exporter.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/mmd_tools/core/pmx/exporter.py b/mmd_tools/core/pmx/exporter.py index 27895514..b341b5ad 100644 --- a/mmd_tools/core/pmx/exporter.py +++ b/mmd_tools/core/pmx/exporter.py @@ -376,7 +376,11 @@ def __to_pmx_axis(axis, pose_bone): pmx_bone.location = __to_pmx_location(p_bone.head) pmx_bone.parent = bone.parent - pmx_bone.visible = not bone.hide and any(c.is_visible for c in bone.collections) + # Determine bone visibility: visible if not hidden and either has no collections or belongs to at least one visible collection + pmx_bone.visible = ( + not bone.hide + and (not bone.collections or any(collection.is_visible for collection in bone.collections)) + ) pmx_bone.isControllable = mmd_bone.is_controllable pmx_bone.isMovable = not all(p_bone.lock_location) pmx_bone.isRotatable = not all(p_bone.lock_rotation) From 880615a93991e205b81df03a5aba64373628123f Mon Sep 17 00:00:00 2001 From: rintrint Date: Tue, 25 Jun 2024 22:11:44 +0900 Subject: [PATCH 3/3] Update exporter.py --- mmd_tools/core/pmx/exporter.py | 1 + 1 file changed, 1 insertion(+) diff --git a/mmd_tools/core/pmx/exporter.py b/mmd_tools/core/pmx/exporter.py index b341b5ad..ab33c490 100644 --- a/mmd_tools/core/pmx/exporter.py +++ b/mmd_tools/core/pmx/exporter.py @@ -377,6 +377,7 @@ def __to_pmx_axis(axis, pose_bone): pmx_bone.location = __to_pmx_location(p_bone.head) pmx_bone.parent = bone.parent # Determine bone visibility: visible if not hidden and either has no collections or belongs to at least one visible collection + # This logic is the same as Blender's pmx_bone.visible = ( not bone.hide and (not bone.collections or any(collection.is_visible for collection in bone.collections))