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 vpd import #162

Open rintrint opened 4 months ago

rintrint commented 4 months ago

As title.

rintrint commented 4 months ago

I don't know what is the purpose of BoneConverterPoseMode. And what is the different between BoneConverter and BoneConverterPoseMode. In my case, I can deprecate BoneConverterPoseMode. So I'm not sure it is necessary or not.

Here is my test case. The behavior is as expected when deprecating BoneConverterPoseMode. The leg issue is due to the IK settings. Enabling rotation and setting it to 0.01 can temporarily fix it. Finding a suitable value for mmd_ik_limit_override takes some time.

https://bowlroll.net/file/315881 https://bowlroll.net/file/316794

Snipaste_2024-06-27_04-38-20 Snipaste_2024-06-27_04-41-08
Kashouryo commented 3 weeks ago

rintrint, your fix doesn't work on Blender version 4.2.3 according to #180 It will simply crash. More error information on the issue mentioned above.

rintrint commented 3 weeks ago

rintrint, your fix doesn't work on Blender version 4.2.3 according to #180 It will simply crash. More error information on the issue mentioned above.

The VPD file and model I tested work fine. Could you provide more details about which VPD and model you used? Where did you download them from? That way I can test it myself.

I think we don't need to open a new issue since this hasn't been merged into the main branch yet. Let's just discuss it here.

rintrint commented 3 weeks ago

The problem is fixed now.

Blender itself provides context.temp_override for safe context overriding in Blender 3.0+. However, the script was using its own custom implementation FnContext.temp_override_objects, which tried to handle multiple context properties at once and could cause instability.

I removed FnContext.temp_override_objects from importer because I discovered that the bone and shape key modifications don't actually require context override. The crashes were happening because doing complex bone modifications within a context override block is risky.

The fix was simple - just remove the context override and directly call self.__assignToArmature(obj). The bone transformations work fine without it since they're just property modifications, not operator calls.

I kept FnContext.temp_override_objects in the exporter since it's working properly there, with proper state backup and restoration. The exporter's usage is also simpler - just reading states rather than modifying them extensively.

This demonstrates that sometimes the best solution is to remove unnecessary complexity rather than trying to fix it.

rintrint commented 3 weeks ago

The reason why I didn't experience crashes before is because I clicked on the MMD root (the cross-shaped empty object at the feet). Generally, this is the most correct approach, unless you want to discard shape keys for some reason.

Kashouryo commented 3 weeks ago

Thanks! This fixes the issue. I never seen a python plugin that crashes Blender entirely without even giving it a chance to spit out error messages.

rintrint commented 2 weeks ago

This appears to be a Blender API issue. I have reported it to the Blender developers.