UuuNyaa / blender_mmd_tools

MMD Tools is a blender addon for importing/exporting Models and Motions of MikuMikuDance.
GNU General Public License v3.0
2.27k stars 109 forks source link

Fix migrated rigidbodies cannot drive new skeleton. #41

Closed One-sixth closed 2 years ago

One-sixth commented 2 years ago

Hello. When I replace a set of rigid bodies and joints to a new model skeleton, and then delete the old model skeleton, the target object of the rigid body constraint will be lost. This causes the rigid body to not be able to drive the new skeleton.

I made the following fixes so that when rebuilding a rigid body, the constraint targets are automatically updated to the new skeleton.

Just replace https://github.com/UuuNyaa/blender_mmd_tools/blob/main/mmd_tools/core/model.py#L969-L970

        arm = relation.target
        bone_name = relation.subtarget

to

        # auto update target to new armature start
        if relation.target is None:
            relation.target = self.armature()
        arm = relation.target
        if relation.subtarget not in arm.pose.bones:
            bone_name = ''
            # relation.subtarget = ''
        else:
            bone_name = relation.subtarget
        # auto update target to new armature end

Then the problem is solved.

UuuNyaa commented 2 years ago

Thank you for your patch 😃 I will merge your code!

UuuNyaa commented 2 years ago

Released as v2.2.6 :tada: