powroupi / blender_mmd_tools

mmd_tools is a blender addon for importing Models and Motions of MikuMikuDance.
GNU General Public License v3.0
1.82k stars 277 forks source link

mmd_bone.name_j is broken when using pose.paste(flipped=True) #20

Open nagadomi opened 8 years ago

nagadomi commented 8 years ago

Sometimes, mmd_bone.name_j is broken, and VMD importer fails to import a motion. This problem is caused by pose.paste(flipped=True).

Reproducing:

  1. Select the armature
  2. Pose Mode
  3. Press A (select all bones)
  4. CTRL+C (copy pose)
  5. SHIFT+CTRL+V (paste pose(flip))
  6. Select right arm bone
  7. See Bone tab -> MMD Bone Tools -> Name(or Name eng). "右(right)" and "左(left)" are reversed.

I don't know whether this is my fault or unexpected issues.

powroupi commented 8 years ago

Interesting..., i can confirm it, it seems blender copies&pastes the "name_j" and "name_e" as well.

If i select left side bones, copy pose, paste pose(flip), then the "name_j" and "name_e" of right side bones will be the same with left side bones. :sob:

I need more time to debug it, hopefully solve it. :smile:

nagadomi commented 8 years ago

If i select left side bones, copy pose, paste pose(flip), then the "name_j" and "name_e" of right side bones will be the same with left side bones. :sob:

I found this issue when model's left arm is stuck. After I've debug this issue, I noticed that mmd_bone.name_j of both arms are "右腕(right arm)". :sob:

powroupi commented 8 years ago

I noticed that it copies & pastes many values, also affects manually added custom properties. The same behavior can be confirmed in order blender versions as well.

I can sovle it by changing bpy.types.PoseBone to bpy.types.Bone here, and do a lot of related fixes. It is a disaster. :sweat: Not sure if there is any other way to solve it ? I would like to wait for the opinions. :thought_balloon:

For now, please do not use that feature... :disappointed:

nagadomi commented 8 years ago

In my situation(a problem of VMD importer), it can solve by fixing utils.makePmxBoneMap. So I think it's not a serious problem for me. But it's a quick fix, and this issue maybe deeply related to the exporter. (I am not using the export feature) Wishing you the best :smile:

diff --git a/mmd_tools/utils.py b/mmd_tools/utils.py
index 88cabe6..4ee80a3 100644
--- a/mmd_tools/utils.py
+++ b/mmd_tools/utils.py
@@ -76,6 +76,19 @@ def convertNameToLR(name):
         name = m.group(1) + m.group(2) + '.R'
     return name

+## Revert blender style name to original japanese name
+## This is not a perfect fix. because 右/左 are not a prefix in some cases.
+__REVERT_NAME_TO_L_REGEXP = re.compile('^(.*).L$')
+__REVERT_NAME_TO_R_REGEXP = re.compile('^(.*).R$')
+def revertNameToLR(name):
+    m = __REVERT_NAME_TO_L_REGEXP.match(name)
+    if m:
+        name = '左' + m.group(1)
+    m = __REVERT_NAME_TO_R_REGEXP.match(name)
+    if m:
+        name = '右' + m.group(1)
+    return name
+
 ## src_vertex_groupのWeightをdest_vertex_groupにaddする
 def mergeVertexGroup(meshObj, src_vertex_group_name, dest_vertex_group_name):
     mesh = meshObj.data
@@ -136,7 +149,8 @@ def makePmxBoneMap(armObj):
         # Maintain backward compatibility with mmd_tools v0.4.x or older.
         name = i.get('mmd_bone_name_j', i.get('name_j', None))
         if name is None:
-            name = i.mmd_bone.name_j or i.name
+            name = revertNameToLR(i.name)
+        # print(name, i.mmd_bone.name_j, i.name)
         boneMap[name] = i
     return boneMap
powroupi commented 8 years ago

I think your problem of VMD importer should be solved now. (The bone name conversion should be more natural in my solution, thanks for the hint of your patch.) :smile:

When import motions, you can choose the bone mapper 'Renamed bones' if you import the armature with the option 'Rename bones', so motion data will be imported properly even if mmd_bone.name_j is broken. :smile:

But the true bug is not solved yet, i'm struggling whether I should change bpy.types.PoseBone to bpy.types.Bone or not... :sweat:

nagadomi commented 8 years ago

Thanks