UuuNyaa / blender_mmd_tools

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

how to apply additional MMD rotation via python script #85

Open wikid24 opened 1 year ago

wikid24 commented 1 year ago

Hi,

I am trying to automate some of the MMD model conversion stuff I am doing via python.

I want to apply MMD additional rotation to bone 'ankle_L_D', and the transformation target is 'ankle_L'.

Is there a way to do this via code? if I were to import an MMD library (not sure which one) is there any code I could write that would be similar to writing something like:

import one_of_the_mmd_tools_libraries

apply_MMD_additional_transformation(armature_name,"ankle_L_D","ankle_L")

if there is a way, it would save me a TON of time vs trying to reverse engineer the whole thing

image

wikid24 commented 1 year ago

I think I found out how to do it with this code:

import bpy
from mmd_tools.core.bone import FnBone

armature = bpy.context.active_object
pose_bone = bpy.context.active_object.pose.bones['ankle_L_D']
pose_bone.mmd_bone.has_additional_rotation = True
pose_bone.mmd_bone.additional_transform_bone = 'ankle_L'

FnBone.apply_additional_transformation(armature)
#FnBone.clean_additional_transformation(armature)
UuuNyaa commented 1 year ago

There is no API yet that can do the operation you want. 😢

Each properties are updated with the following functions: Property Update functions
has_additional_rotation _updateMMDBoneAdditionalTransform
additional_transform_bone _setAdditionalTransformBone, _updateMMDBoneAdditionalTransform

I think that properties can be safely updated by programming the same thing as these functions.

wikid24 commented 1 year ago

thanks for this!

Yesterday I spent almost the entire day trying to debug a defect with function I created. Function was using was working perfectly fine in one library, but in another library, it was applying a completely random pose bone. I didn't know about the .as_pointer(), but now that I know it is needed, I will attempt to recreate your code. :)