Open NaughtDZ opened 5 months ago
It should be possible with a script, but I have never successfully gotten it to work. The best I've got so far is pasted below:
#If exporting for MMD...
if prep_type == 'C':
#Create the empty
bpy.ops.object.mode_set(mode='OBJECT')
bpy.ops.object.empty_add(type='PLAIN_AXES', align='WORLD', location=(0, 0, 0))
empty = bpy.data.objects['Empty']
bpy.ops.object.select_all(action='DESELECT')
armature.parent = empty
bpy.context.view_layer.objects.active = armature
#rename bones to stock
if armature.data.bones.get('Center'):
bpy.ops.kkbp.switcharmature('INVOKE_DEFAULT')
#then rename bones to japanese
pmx_rename_dict = {
'全ての親':'cf_n_height',
'センター':'cf_j_hips',
'上半身':'cf_j_spine01',
'上半身2':'cf_j_spine02',
'上半身3':'cf_j_spine03',
'首':'cf_j_neck',
'頭':'cf_j_head',
'両目':'Eyesx',
'左目':'cf_J_hitomi_tx_L',
'右目':'cf_J_hitomi_tx_R',
'左腕':'cf_j_arm00_L',
'右腕':'cf_j_arm00_R',
'左ひじ':'cf_j_forearm01_L',
'右ひじ':'cf_j_forearm01_R',
'左肩':'cf_j_shoulder_L',
'右肩':'cf_j_shoulder_R',
'左手首':'cf_j_hand_L',
'右手首':'cf_j_hand_R',
'左親指0':'cf_j_thumb01_L',
'左親指1':'cf_j_thumb02_L',
'左親指2':'cf_j_thumb03_L',
'左薬指1':'cf_j_ring01_L',
'左薬指2':'cf_j_ring02_L',
'左薬指3':'cf_j_ring03_L',
'左中指1':'cf_j_middle01_L',
'左中指2':'cf_j_middle02_L',
'左中指3':'cf_j_middle03_L',
'左小指1':'cf_j_little01_L',
'左小指2':'cf_j_little02_L',
'左小指3':'cf_j_little03_L',
'左人指1':'cf_j_index01_L',
'左人指2':'cf_j_index02_L',
'左人指3':'cf_j_index03_L',
'右親指0':'cf_j_thumb01_R',
'右親指1':'cf_j_thumb02_R',
'右親指2':'cf_j_thumb03_R',
'右薬指1':'cf_j_ring01_R',
'右薬指2':'cf_j_ring02_R',
'右薬指3':'cf_j_ring03_R',
'右中指1':'cf_j_middle01_R',
'右中指2':'cf_j_middle02_R',
'右中指3':'cf_j_middle03_R',
'右小指1':'cf_j_little01_R',
'右小指2':'cf_j_little02_R',
'右小指3':'cf_j_little03_R',
'右人指1':'cf_j_index01_R',
'右人指2':'cf_j_index02_R',
'右人指3':'cf_j_index03_R',
'下半身':'cf_j_waist01',
'左足':'cf_j_thigh00_L',
'右足':'cf_j_thigh00_R',
'左ひざ':'cf_j_leg01_L',
'右ひざ':'cf_j_leg01_R',
'左足首':'cf_j_leg03_L',
'右足首':'cf_j_leg03_R',
}
for bone in pmx_rename_dict:
armature.data.bones[pmx_rename_dict[bone]].name = bone
#Rearrange bones to match a random pmx model I found
bpy.ops.object.mode_set(mode='EDIT')
armature.data.edit_bones['左肩'].parent = armature.data.edit_bones['上半身3']
armature.data.edit_bones['右肩'].parent = armature.data.edit_bones['上半身3']
armature.data.edit_bones['左足'].parent = armature.data.edit_bones['下半身']
armature.data.edit_bones['右足'].parent = armature.data.edit_bones['下半身']
#refresh the vertex groups? Bones will act as if they're detached if this isn't done
body.vertex_groups.active=body.vertex_groups['BodyTop']
#combine all objects into one
#create leg IKs?
#use mmd_tools to convert
bpy.ops.mmd_tools.convert_to_mmd_model()
使用脚本应该是可能的,但我从未成功让它工作过。到目前为止,我得到的最好的粘贴在下面:
#If exporting for MMD... if prep_type == 'C': #Create the empty bpy.ops.object.mode_set(mode='OBJECT') bpy.ops.object.empty_add(type='PLAIN_AXES', align='WORLD', location=(0, 0, 0)) empty = bpy.data.objects['Empty'] bpy.ops.object.select_all(action='DESELECT') armature.parent = empty bpy.context.view_layer.objects.active = armature #rename bones to stock if armature.data.bones.get('Center'): bpy.ops.kkbp.switcharmature('INVOKE_DEFAULT') #then rename bones to japanese pmx_rename_dict = { '全ての親':'cf_n_height', 'センター':'cf_j_hips', '上半身':'cf_j_spine01', '上半身2':'cf_j_spine02', '上半身3':'cf_j_spine03', '首':'cf_j_neck', '頭':'cf_j_head', '両目':'Eyesx', '左目':'cf_J_hitomi_tx_L', '右目':'cf_J_hitomi_tx_R', '左腕':'cf_j_arm00_L', '右腕':'cf_j_arm00_R', '左ひじ':'cf_j_forearm01_L', '右ひじ':'cf_j_forearm01_R', '左肩':'cf_j_shoulder_L', '右肩':'cf_j_shoulder_R', '左手首':'cf_j_hand_L', '右手首':'cf_j_hand_R', '左親指0':'cf_j_thumb01_L', '左親指1':'cf_j_thumb02_L', '左親指2':'cf_j_thumb03_L', '左薬指1':'cf_j_ring01_L', '左薬指2':'cf_j_ring02_L', '左薬指3':'cf_j_ring03_L', '左中指1':'cf_j_middle01_L', '左中指2':'cf_j_middle02_L', '左中指3':'cf_j_middle03_L', '左小指1':'cf_j_little01_L', '左小指2':'cf_j_little02_L', '左小指3':'cf_j_little03_L', '左人指1':'cf_j_index01_L', '左人指2':'cf_j_index02_L', '左人指3':'cf_j_index03_L', '右親指0':'cf_j_thumb01_R', '右親指1':'cf_j_thumb02_R', '右親指2':'cf_j_thumb03_R', '右薬指1':'cf_j_ring01_R', '右薬指2':'cf_j_ring02_R', '右薬指3':'cf_j_ring03_R', '右中指1':'cf_j_middle01_R', '右中指2':'cf_j_middle02_R', '右中指3':'cf_j_middle03_R', '右小指1':'cf_j_little01_R', '右小指2':'cf_j_little02_R', '右小指3':'cf_j_little03_R', '右人指1':'cf_j_index01_R', '右人指2':'cf_j_index02_R', '右人指3':'cf_j_index03_R', '下半身':'cf_j_waist01', '左足':'cf_j_thigh00_L', '右足':'cf_j_thigh00_R', '左ひざ':'cf_j_leg01_L', '右ひざ':'cf_j_leg01_R', '左足首':'cf_j_leg03_L', '右足首':'cf_j_leg03_R', } for bone in pmx_rename_dict: armature.data.bones[pmx_rename_dict[bone]].name = bone #Rearrange bones to match a random pmx model I found bpy.ops.object.mode_set(mode='EDIT') armature.data.edit_bones['左肩'].parent = armature.data.edit_bones['上半身3'] armature.data.edit_bones['右肩'].parent = armature.data.edit_bones['上半身3'] armature.data.edit_bones['左足'].parent = armature.data.edit_bones['下半身'] armature.data.edit_bones['右足'].parent = armature.data.edit_bones['下半身'] #refresh the vertex groups? Bones will act as if they're detached if this isn't done body.vertex_groups.active=body.vertex_groups['BodyTop'] #combine all objects into one #create leg IKs? #use mmd_tools to convert bpy.ops.mmd_tools.convert_to_mmd_model()
I tried to think of renaming bones through scripts, but in reality, using Vrm exported from UniVRM in Unity seems to directly and intelligently replace bones with Humanoid types? https://github.com/vrm-c/UniVRM UniVRM is open source, but unfortunately VRM2PMXConverter does not seem to be open source software. However, it would be great if KKBP could support importing VRM standard armatures in addition to the initial Rigify.
My current workflow is to use plugins to import into KKBP bones, simplify armature preparation for Unity, bake light color textures, and export FBX file. Next, I need to open Unity,import FBX , fix the material, change the Animation Type of the rig to Humanoid, export the vrm file using UniVRM-0.57.1, finally convert it to pmx format using VRM2PmxConverter, and Re-import it into Blender.
The reason why I operate this way is that the file processed through the above process,the pmx model file can perfectly apply VMD format animation files directly. Although KKBP supports turning it into a rigify bone during import, this rigify bone cannot be modified into a VMD animation compatible bone through the mmdtool plugin(https://github.com/UuuNyaa/blender_mmd_uuunyaa_tools). Using other Retarget plugins can lead to more or less problems and lengthy workflows.
So...Is it possible to convert KKBP bones to MMD bones directly using this plugin? Perhaps it is also possible to use scripts in Blender to restore the process of bone transformation in Unity?