Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Root bone collection problem #160

Open
wants to merge 3 commits into
base: blender-v4
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 18 additions & 4 deletions mmd_tools/core/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
7 changes: 6 additions & 1 deletion mmd_tools/core/pmx/exporter.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down