VRM のボーン名を VRChat や MMD 用に変更する

Blender では、ボーンの名前が「.L」や「.R」でないと左右対称のボーンとして認識されない。
そのため、スクリプトを用いて、VRM のボーンの名前を Unity Humanoid(VRChat)や MMD に合わせて変更する。

VRM to Unity Humanoid

import bpy

def rename_bones():
    dic = {
        'Root': 'Root', #基本のボーンにはない
        'J_Bip_C_Hips': 'Hips',
        'J_Bip_C_Spine': 'Spine',
        'J_Bip_C_Chest': 'Chest',
        'J_Bip_C_UpperChest': 'Upper_Chest',
        'J_Sec_L_Bust1': 'Bust.L',
        'J_Sec_R_Bust1': 'Bust.R',
        'J_Sec_L_Bust2': 'Bust2.L', #基本のボーンにはない
        'J_Sec_R_Bust2': 'Bust2.R', #基本のボーンにはない
        'J_Bip_C_Neck': 'Neck',
        'J_Bip_C_Head': 'Head',
        'J_Adj_L_FaceEye': 'Eye.L',
        'J_Adj_R_FaceEye': 'Eye.R',
        'J_Bip_L_Shoulder': 'Shoulder.L',
        'J_Bip_L_UpperArm': 'Upper_Arm.L',
        'J_Bip_L_LowerArm': 'Lower_Arm.L',
        'J_Bip_L_Hand': 'Hand.L',
        'J_Bip_L_Thumb1': 'Thumb_Proximal.L',
        'J_Bip_L_Thumb2': 'Thumb_Intermediate.L',
        'J_Bip_L_Thumb3': 'Thumb_Distal.L',
        'J_Bip_L_Index1': 'Index_Proximal.L',
        'J_Bip_L_Index2': 'Index_Intermediate.L',
        'J_Bip_L_Index3': 'Index_Distal.L',
        'J_Bip_L_Middle1': 'Middle_Proximal.L',
        'J_Bip_L_Middle2': 'Middle_Intermediate.L',
        'J_Bip_L_Middle3': 'Middle_Distal.L',
        'J_Bip_L_Ring1': 'Ring_Proximal.L',
        'J_Bip_L_Ring2': 'Ring_Intermediate.L',
        'J_Bip_L_Ring3': 'Ring_Distal.L',
        'J_Bip_L_Little1': 'Little_Proximal.L',
        'J_Bip_L_Little2': 'Little_Intermediate.L',
        'J_Bip_L_Little3': 'Little_Distal.L',
        'J_Bip_R_Shoulder': 'Shoulder.R',
        'J_Bip_R_UpperArm': 'Upper_Arm.R',
        'J_Bip_R_LowerArm': 'Lower_Arm.R',
        'J_Bip_R_Hand': 'Hand.R',
        'J_Bip_R_Thumb1': 'Thumb_Proximal.R',
        'J_Bip_R_Thumb2': 'Thumb_Intermediate.R',
        'J_Bip_R_Thumb3': 'Thumb_Distal.R',
        'J_Bip_R_Index1': 'Index_Proximal.R',
        'J_Bip_R_Index2': 'Index_Intermediate.R',
        'J_Bip_R_Index3': 'Index_Distal.R',
        'J_Bip_R_Middle1': 'Middle_Proximal.R',
        'J_Bip_R_Middle2': 'Middle_Intermediate.R',
        'J_Bip_R_Middle3': 'Middle_Distal.R',
        'J_Bip_R_Ring1': 'Ring_Proximal.R',
        'J_Bip_R_Ring2': 'Ring_Intermediate.R',
        'J_Bip_R_Ring3': 'Ring_Distal.R',
        'J_Bip_R_Little1': 'Little_Proximal.R',
        'J_Bip_R_Little2': 'Little_Intermediate.R',
        'J_Bip_R_Little3': 'Little_Distal.R',
        'J_Bip_L_UpperLeg': 'Upper_Leg.L',
        'J_Bip_L_LowerLeg': 'Lower_Leg.L',
        'J_Bip_L_Foot': 'Foot.L',
        'J_Bip_L_ToeBase': 'Toes.L',
        'J_Bip_R_UpperLeg': 'Upper_Leg.R',
        'J_Bip_R_LowerLeg': 'Lower_Leg.R',
        'J_Bip_R_Foot': 'Foot.R',
        'J_Bip_R_ToeBase': 'Toes.R'
    }
    for bone in bpy.context.active_object.data.bones:
        if bone.name in dic:
            bone.name = dic[bone.name]
rename_bones()

VRM to PMX

import bpy

def rename_bones():
    dic = {
        'Root': 'グルーブ',
        'J_Bip_C_Hips': '下半身',
        'J_Bip_C_Spine': '上半身',
        'J_Bip_C_Chest': '上半身1', #MMDの標準ボーンにはない
        'J_Bip_C_UpperChest': '上半身2',
        'J_Sec_L_Bust1': 'おっぱい.L',
        'J_Sec_R_Bust1': 'おっぱい.R',
        'J_Sec_L_Bust2': 'おっぱい2.L', #MMDの標準ボーンにはない
        'J_Sec_R_Bust2': 'おっぱい2.R', #MMDの標準ボーンにはない
        'J_Bip_C_Neck': '首',
        'J_Bip_C_Head': '頭',
        'J_Adj_L_FaceEye': '目.L',
        'J_Adj_R_FaceEye': '目.R',
        'J_Bip_L_Shoulder': '肩.L',
        'J_Bip_L_UpperArm': '腕.L',
        'J_Bip_L_LowerArm': 'ひじ.L',
        'J_Bip_L_Hand': '手首.L',
        'J_Bip_L_Thumb1': '親指0.L',
        'J_Bip_L_Thumb2': '親指1.L',
        'J_Bip_L_Thumb3': '親指2.L',
        'J_Bip_L_Index1': '人指1.L',
        'J_Bip_L_Index2': '人指2.L',
        'J_Bip_L_Index3': '人指3.L',
        'J_Bip_L_Middle1': '中指1.L',
        'J_Bip_L_Middle2': '中指2.L',
        'J_Bip_L_Middle3': '中指3.L',
        'J_Bip_L_Ring1': '薬指1.L',
        'J_Bip_L_Ring2': '薬指2.L',
        'J_Bip_L_Ring3': '薬指3.L',
        'J_Bip_L_Little1': '小指1.L',
        'J_Bip_L_Little2': '小指2.L',
        'J_Bip_L_Little3': '小指3.L',
        'J_Bip_R_Shoulder': '肩.R',
        'J_Bip_R_UpperArm': '腕.R',
        'J_Bip_R_LowerArm': 'ひじ.R',
        'J_Bip_R_Hand': '手首.R',
        'J_Bip_R_Thumb1': '親指0.R',
        'J_Bip_R_Thumb2': '親指1.R',
        'J_Bip_R_Thumb3': '親指2.R',
        'J_Bip_R_Index1': '人指1.R',
        'J_Bip_R_Index2': '人指2.R',
        'J_Bip_R_Index3': '人指3.R',
        'J_Bip_R_Middle1': '中指1.R',
        'J_Bip_R_Middle2': '中指2.R',
        'J_Bip_R_Middle3': '中指3.R',
        'J_Bip_R_Ring1': '薬指1.R',
        'J_Bip_R_Ring2': '薬指2.R',
        'J_Bip_R_Ring3': '薬指3.R',
        'J_Bip_R_Little1': '小指1.R',
        'J_Bip_R_Little2': '小指2.R',
        'J_Bip_R_Little3': '小指3.R',
        'J_Bip_L_UpperLeg': '足.L',
        'J_Bip_L_LowerLeg': 'ひざ.L',
        'J_Bip_L_Foot': '足首.L',
        'J_Bip_L_ToeBase': 'つま先.L',
        'J_Bip_R_UpperLeg': '足.R',
        'J_Bip_R_LowerLeg': 'ひざ.R',
        'J_Bip_R_Foot': '足首.R',
        'J_Bip_R_ToeBase': 'つま先.R'
    }
    for bone in bpy.context.active_object.data.bones:
        if bone.name in dic:
            bone.name = dic[bone.name]
rename_bones()

Unity Humanoid to PMX

import bpy

def rename_bones():
    dic = {
        'Root': 'グルーブ',
        'Hips': '下半身',
        'Spine': '上半身',
        'Chest': '上半身1', #MMDの標準ボーンにはない
        'UpperChest': '上半身2',
        'Bust.L': 'おっぱい.L',
        'Bust.R': 'おっぱい.R',
        'Bust2.L': 'おっぱい2.L', #MMDの標準ボーンにはない
        'Bust2.R': 'おっぱい2.R', #MMDの標準ボーンにはない
        'Neck': '首',
        'Head': '頭',
        'Eye.L': '目.L',
        'Eye.R': '目.R',
        'Jaw': '口.R', #若干異なる
        'Shoulder.L': '肩.L',
        'Upper_Arm.L': '腕.L',
        'Lower_Arm.L': 'ひじ.L',
        'Hand.L': '手首.L',
        'Thumb_Proximal.L': '親指0.L',
        'Thumb_Intermediate.L': '親指1.L',
        'Thumb_Distal.L': '親指2.L',
        'Index_Proximal.L': '人指1.L',
        'Index_Intermediate.L': '人指2.L',
        'Index_Distal.L': '人指3.L',
        'Middle_Proximal.L': '中指1.L',
        'Middle_Intermediate.L': '中指2.L',
        'Middle_Distal.L': '中指3.L',
        'Ring_Proximal.L': '薬指1.L',
        'Ring_Intermediate.L': '薬指2.L',
        'Ring_Distal.L': '薬指3.L',
        'Little_Proximal.L': '小指1.L',
        'Little_Intermediate.L': '小指2.L',
        'Little_Distal.L': '小指3.L',
        'Shoulder.R' : '肩.R',
        'Upper_Arm.R' : '腕.R',
        'Lower_Arm.R' : 'ひじ.R',
        'Hand.R' : '手首.R',
        'Thumb_Proximal.R' : '親指0.R',
        'Thumb_Intermediate.R' : '親指1.R',
        'Thumb_Distal.R' : '親指2.R',
        'Index_Proximal.R' : '人指1.R',
        'Index_Intermediate.R' : '人指2.R',
        'Index_Distal.R' : '人指3.R',
        'Middle_Proximal.R' : '中指1.R',
        'Middle_Intermediate.R' : '中指2.R',
        'Middle_Distal.R' : '中指3.R',
        'Ring_Proximal.R' : '薬指1.R',
        'Ring_Intermediate.R' : '薬指2.R',
        'Ring_Distal.R' : '薬指3.R',
        'Little_Proximal.R' : '小指1.R',
        'Little_Intermediate.R' : '小指2.R',
        'Little_Distal.R' : '小指3.R',
        'Upper_Leg.L': '足.L',
        'Lower_Leg.L': 'ひざ.L',
        'Foot.L': '足首.L',
        'Toes.L': 'つま先.L',
        'Upper_Leg.R': '足.R',
        'Lower_Leg.R': 'ひざ.R',
        'Foot.R': '足首.R',
        'Toes.R': 'つま先.R'
    }
    for bone in bpy.context.active_object.data.bones:
        if bone.name in dic:
            bone.name = dic[bone.name]
rename_bones()

PMX to VRM

import bpy

def rename_bones():
    dic = {
        "グルーブ": "Root",
        "下半身": "J_Bip_C_Hips",
        "上半身": "J_Bip_C_Spine",
        "上半身1#MMDの標準ボーンにはない": "J_Bip_C_Chest",
        "上半身2": "J_Bip_C_UpperChest",
        "おっぱい.L": "J_Sec_L_Bust1",
        "おっぱい.R": "J_Sec_R_Bust1",
        "おっぱい2.L#MMDの標準ボーンにはない": "J_Sec_L_Bust2",
        "おっぱい2.R#MMDの標準ボーンにはない": "J_Sec_R_Bust2",
        "首": "J_Bip_C_Neck",
        "頭": "J_Bip_C_Head",
        "目.L": "J_Adj_L_FaceEye",
        "目.R": "J_Adj_R_FaceEye",
        "肩.L": "J_Bip_L_Shoulder",
        "腕.L": "J_Bip_L_UpperArm",
        "ひじ.L": "J_Bip_L_LowerArm",
        "手首.L": "J_Bip_L_Hand",
        "親指0.L": "J_Bip_L_Thumb1",
        "親指1.L": "J_Bip_L_Thumb2",
        "親指2.L": "J_Bip_L_Thumb3",
        "人指1.L": "J_Bip_L_Index1",
        "人指2.L": "J_Bip_L_Index2",
        "人指3.L": "J_Bip_L_Index3",
        "中指1.L": "J_Bip_L_Middle1",
        "中指2.L": "J_Bip_L_Middle2",
        "中指3.L": "J_Bip_L_Middle3",
        "薬指1.L": "J_Bip_L_Ring1",
        "薬指2.L": "J_Bip_L_Ring2",
        "薬指3.L": "J_Bip_L_Ring3",
        "小指1.L": "J_Bip_L_Little1",
        "小指2.L": "J_Bip_L_Little2",
        "小指3.L": "J_Bip_L_Little3",
        "肩.R": "J_Bip_R_Shoulder",
        "腕.R": "J_Bip_R_UpperArm",
        "ひじ.R": "J_Bip_R_LowerArm",
        "手首.R": "J_Bip_R_Hand",
        "親指0.R": "J_Bip_R_Thumb1",
        "親指1.R": "J_Bip_R_Thumb2",
        "親指2.R": "J_Bip_R_Thumb3",
        "人指1.R": "J_Bip_R_Index1",
        "人指2.R": "J_Bip_R_Index2",
        "人指3.R": "J_Bip_R_Index3",
        "中指1.R": "J_Bip_R_Middle1",
        "中指2.R": "J_Bip_R_Middle2",
        "中指3.R": "J_Bip_R_Middle3",
        "薬指1.R": "J_Bip_R_Ring1",
        "薬指2.R": "J_Bip_R_Ring2",
        "薬指3.R": "J_Bip_R_Ring3",
        "小指1.R": "J_Bip_R_Little1",
        "小指2.R": "J_Bip_R_Little2",
        "小指3.R": "J_Bip_R_Little3",
        "足.L": "J_Bip_L_UpperLeg",
        "ひざ.L": "J_Bip_L_LowerLeg",
        "足首.L": "J_Bip_L_Foot",
        "つま先.L": "J_Bip_L_ToeBase",
        "足.R": "J_Bip_R_UpperLeg",
        "ひざ.R": "J_Bip_R_LowerLeg",
        "足首.R": "J_Bip_R_Foot",
        "つま先.R": "J_Bip_R_ToeBase"
    }
    for bone in bpy.context.active_object.data.bones:
        if bone.name in dic:
            bone.name = dic[bone.name]
rename_bones()

コメントする

メールアドレスが公開されることはありません。 が付いている欄は必須項目です