powroupi / blender_mmd_tools

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

local axis of imported bones are not compatible with blender x-mirror mode #309

Open Mirviy opened 3 years ago

Mirviy commented 3 years ago

(see also https://github.com/sugiany/blender_mmd_tools/issues/74 )

For a pair of symmetric bones in .pmx with "local axes" enabled(eg. 左腕 and 右腕 ), imported bones in blender are having same local X axes and opposite local Z axes, which is not compatible with default blender X-mirror manner, and also not compatible with imported symmetric bones with "local axes" disabled in .pmx. (symmetric bones should have same Z axes and opposite X axes).

( by word 'same' I mean a vector {x,y,z} is mirrored into {-x,y,z}, 'opposite' means {x,y,z} -> {x,-y,-z} .)

Editing one bone in X-mirror mode will instantly flip the roll (bpy.types.EditBone.roll) of another bone, causing it's highly inconvenient to edit imported models. (Also highly inconvenient to apply a imported .vmd file onto a character which is created in blender with x-mirror on)

Could you please change this (or add an option) to be compatible with default blender x-mirror manner? (Importing of .vmd files may also be changed accordingly)

Thanks!!!

nagadomi commented 3 years ago

As far as I know,

VMD is recorded on the global axis, so the VMD motion is not affected by the bone's local axis.

MMD has an algorithm that automatically sets the local axis of arm-related bones that do not have a local axis setting. If the imported bone does not have a local axis setting, the bone's local axis will be set in the same way as MMD. If the bone has a local axis setting, the local axis will be set accordingly.

The bone's local axis is related to MMD's Rotation Constraint, so it can be difficult to follow blender manner. If the bone do not have a local axis setting and is not referenced by constraints, then the bone roll in blender should be fine to change as it do not affect the exported PMX.

Mirviy commented 3 years ago

Thanks for replying!

I created a model in blender (without using PE/.pmx) and trying importing .vmd file and make it move properly. For now I just tested one .vmd file, and it works like .vmd is recorded on local axes of bones(not global)? On an imported .pmx model (downloaded from elsewhere), .vmd works fine, but on my model, only one arm could have correct motion and the other one's motion is reversed. (Actually, at very beginning, my model's local axes of arms are rotated 90degs compared to imported .pmx model, and both of arms move weird). I may try other .vmd files and see if this manner consists.

I understand it may be very difficult to make MMD bones fully compatible with blender bones. Since most of .vmd files are created by MMD, I may have to edit my model(sadly disable x-mirror) to meet MMD convention.

MMD has an algorithm that automatically sets the local axis of arm-related bones that do not have a local axis setting.

How does this algorithm implemented? (Is there a list of bone names for which local axis are set by MMD automatically?)

Mirviy commented 3 years ago

How does this algorithm implemented? (Is there a list of bone names for which local axis are set by MMD automatically?)

My question is solved, I found the list in blender_mmd_tools/mmd_tools/core/bone.py. (XD

nagadomi commented 3 years ago

but on my model, only one arm could have correct motion and the other one's motion is reversed.

VMD motion is imported to the bone name that matches Bone Properties > MMD Bone Tools > Name, not the bone name on blender by default. Due to issue #20, sometimes the bone name is reversed or both arms are right arms. Or, if you change the bone rolls after importing the motion, the motion will be broken because the motion after importing works on local axis (it should be imported correctly if you import it again).

Mirviy commented 3 years ago

Thanks!

VMD is recorded on the global axis, so the VMD motion is not affected by the bone's local axis.

You are right, my model now moves fine, without adjusting local axes!

I finally found my real problem is additional arm IK bones(not present in .vmx motion, stay at original position and drag arms to wrong direction). XD

Sorry for wasting your time...

nagadomi commented 3 years ago

np. Most shared motions target standard bones or their extensions, semi-standard bones. It does not contain arm IK, so turn it off when importing motion.

nathanvasil commented 3 years ago

I think this would be fixable, but it would take one of three things:

1) Abandon the thing where the point-to determines Blender's local axes, and give each imported bone axes aligned with world in rest position. If you want to remember offsets or point-tos, do it with custom properties. (And, optionally, create custom bone shapes to mimic MMD's display.)

2) Use drivers in place of Blender's existing constraints, to mimic Blender's constraints but from MMD style axes.

3) Create shadow bones with different orientations (as in 1 above.)

But I don't think any of those are actually good ideas. MMD Tools has reached a certain level of complexity with trying to create perfect MMD functionality and there comes a point where that complexity gets in the way without adding anything for experienced users.

If the goal is editing models for use with animating/rendering in MMD, then it's perfectly safe to use X-mirror in edit mode, since local axes are abandoned on export anyways. If I'm thinking it through correctly, importing MMD motions onto the edited armature in Blender won't work properly without an export/import cycle however, not without drivers. (The simplest solution to that would be to mimic 1 above, which would be relatively safe for MMD export-- would probably leave you with an ugly but functional skeletal structure.)