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

Avoid Bone ID conflict during merging models. (main branch) #144

Merged
merged 2 commits into from
Apr 23, 2024
Merged
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
16 changes: 15 additions & 1 deletion mmd_tools/core/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,21 @@ def _change_bone_id(bone: bpy.types.PoseBone, new_bone_id: int, bone_morphs, pos
continue
mmd_bone.additional_transform_bone_id = new_bone_id

# Change the Bone ID if necessary to make sure that each ID is still unique after joining models.
# Change Child Bone IDs temporarily to large numbers to completely avoid Bone ID conflict.
tmp_bone_id = 1000000000
for child_root_object in child_root_objects:
child_armature_object = FnModel.find_armature(child_root_object)
child_pose_bones = child_armature_object.pose.bones
child_bone_morphs = child_root_object.mmd_root.bone_morphs

for pose_bone in child_pose_bones:
if pose_bone.is_mmd_shadow_bone:
continue
if pose_bone.mmd_bone.bone_id != -1:
tmp_bone_id += 1
_change_bone_id(pose_bone, tmp_bone_id, child_bone_morphs, child_pose_bones)

# Reorder Child Bone IDs.
max_bone_id = max((b.mmd_bone.bone_id for b in parent_armature_object.pose.bones if not b.is_mmd_shadow_bone), default=-1)

child_root_object: bpy.types.Object
Expand Down