Skip to content

Commit

Permalink
Add support for koikatsu exporting armature #23
Browse files Browse the repository at this point in the history
  • Loading branch information
UuuNyaa committed May 13, 2021
1 parent b1a126d commit 3e13068
Show file tree
Hide file tree
Showing 3 changed files with 90 additions and 1 deletion.
2 changes: 1 addition & 1 deletion mmd_uuunyaa_tools/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
"name": "mmd_uuunyaa_tools",
"description": "Utility tools for MMD model & scene editing by Uuu(/>ω<)/Nyaa!.",
"author": "UuuNyaa",
"version": (0, 5, 4),
"version": (0, 5, 5),
"blender": (2, 80, 0),
"warning": "",
"location": "View3D > Tool Shelf > MMD Tools Panel",
Expand Down
80 changes: 80 additions & 0 deletions mmd_uuunyaa_tools/editors/armatures/mmd.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,3 +143,83 @@ def if_far_then_set(target: bpy.types.EditBone, head=None, tail=None, distance_f
else:
mmd_edit_bones['上半身'].tail = mmd_edit_bones['首'].head
mmd_edit_bones['首'].tail = mmd_edit_bones['頭'].head

def clean_koikatsu_armature_prepare(self):
mmd_pose_bones = self.pose_bones

mmd_bone_name_mapping = {
'cf_j_shoulder_L': '左肩',
'cf_j_shoulder_R': '右肩',
}

mmd_bone_name_j_mapping = {
'両目x': '両目',
'右目x': '右目',
'左目x': '左目',
'左肩': '_左肩',
}

for pose_bone in mmd_pose_bones:

mmd_bone_name = pose_bone.name
if mmd_bone_name in mmd_bone_name_mapping:
pose_bone.mmd_bone.name_j = mmd_bone_name_mapping[mmd_bone_name]
continue

mmd_bone_name_j = pose_bone.mmd_bone.name_j
if mmd_bone_name_j in mmd_bone_name_j_mapping:
pose_bone.mmd_bone.name_j = mmd_bone_name_j_mapping[mmd_bone_name_j]

def clean_koikatsu_armature(self):
mmd_edit_bones = self.edit_bones

strict_edit_bones = self.strict_edit_bones
strict_edit_bones['左肩'].tail = strict_edit_bones['左腕'].head
strict_edit_bones['左腕'].tail = strict_edit_bones['左ひじ'].head
strict_edit_bones['左ひじ'].tail = strict_edit_bones['左手首'].head
strict_edit_bones['左手首'].tail = mmd_edit_bones['a_n_hand_L'].head

strict_edit_bones['左親指0'].tail = strict_edit_bones['左親指1'].head
strict_edit_bones['左親指1'].tail = strict_edit_bones['左親指2'].head
strict_edit_bones['左親指2'].tail = mmd_edit_bones['cf_j_thumb04_L'].head

strict_edit_bones['左人指1'].tail = strict_edit_bones['左人指2'].head
strict_edit_bones['左人指2'].tail = strict_edit_bones['左人指3'].head
strict_edit_bones['左人指3'].tail = mmd_edit_bones['cf_j_index04_L'].head

strict_edit_bones['左中指1'].tail = strict_edit_bones['左中指2'].head
strict_edit_bones['左中指2'].tail = strict_edit_bones['左中指3'].head
strict_edit_bones['左中指3'].tail = mmd_edit_bones['cf_j_middle04_L'].head

strict_edit_bones['左薬指1'].tail = strict_edit_bones['左薬指2'].head
strict_edit_bones['左薬指2'].tail = strict_edit_bones['左薬指3'].head
strict_edit_bones['左薬指3'].tail = mmd_edit_bones['cf_j_ring04_L'].head

strict_edit_bones['左小指1'].tail = strict_edit_bones['左小指2'].head
strict_edit_bones['左小指2'].tail = strict_edit_bones['左小指3'].head
strict_edit_bones['左小指3'].tail = mmd_edit_bones['cf_j_little04_L'].head

strict_edit_bones['右肩'].tail = strict_edit_bones['右腕'].head
strict_edit_bones['右腕'].tail = strict_edit_bones['右ひじ'].head
strict_edit_bones['右ひじ'].tail = strict_edit_bones['右手首'].head
strict_edit_bones['右手首'].tail = mmd_edit_bones['a_n_hand_R'].head

strict_edit_bones['右親指0'].tail = strict_edit_bones['右親指1'].head
strict_edit_bones['右親指1'].tail = strict_edit_bones['右親指2'].head
strict_edit_bones['右親指2'].tail = mmd_edit_bones['cf_j_thumb04_R'].head

strict_edit_bones['右人指1'].tail = strict_edit_bones['右人指2'].head
strict_edit_bones['右人指2'].tail = strict_edit_bones['右人指3'].head
strict_edit_bones['右人指3'].tail = mmd_edit_bones['cf_j_index04_R'].head

strict_edit_bones['右中指1'].tail = strict_edit_bones['右中指2'].head
strict_edit_bones['右中指2'].tail = strict_edit_bones['右中指3'].head
strict_edit_bones['右中指3'].tail = mmd_edit_bones['cf_j_middle04_R'].head

strict_edit_bones['右薬指1'].tail = strict_edit_bones['右薬指2'].head
strict_edit_bones['右薬指2'].tail = strict_edit_bones['右薬指3'].head
strict_edit_bones['右薬指3'].tail = mmd_edit_bones['cf_j_ring04_R'].head

strict_edit_bones['右小指1'].tail = strict_edit_bones['右小指2'].head
strict_edit_bones['右小指2'].tail = strict_edit_bones['右小指3'].head
strict_edit_bones['右小指3'].tail = mmd_edit_bones['cf_j_little04_R'].head
9 changes: 9 additions & 0 deletions mmd_uuunyaa_tools/editors/operators.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ class MMDArmatureAddMetarig(bpy.types.Operator):
bl_options = {'REGISTER', 'UNDO'}

is_clean_armature: bpy.props.BoolProperty(name='Clean Armature', default=True)
is_clean_koikatsu_armature: bpy.props.BoolProperty(name='Clean Koikatsu Armature', default=False)

@classmethod
def poll(cls, context: bpy.types.Context):
Expand Down Expand Up @@ -64,7 +65,15 @@ def execute(self, context: bpy.types.Context):
mmd_object.select = True
metarig_object.select = True

if self.is_clean_koikatsu_armature:
mmd_armature_object.clean_koikatsu_armature_prepare()
mmd_armature_object = MMDArmatureObject(mmd_object)

bpy.ops.object.mode_set(mode='EDIT')

if self.is_clean_koikatsu_armature:
mmd_armature_object.clean_koikatsu_armature()

if self.is_clean_armature:
mmd_armature_object.clean_armature()

Expand Down

0 comments on commit 3e13068

Please sign in to comment.