diff --git a/mmd_tools/core/model.py b/mmd_tools/core/model.py index 5cf7278..6802d79 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) diff --git a/mmd_tools/core/pmx/exporter.py b/mmd_tools/core/pmx/exporter.py index 2789551..ab33c49 100644 --- a/mmd_tools/core/pmx/exporter.py +++ b/mmd_tools/core/pmx/exporter.py @@ -376,7 +376,12 @@ 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 + # 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)) + ) 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)