Skip to content

Commit

Permalink
implement foot bone workaround
Browse files Browse the repository at this point in the history
  • Loading branch information
sovietspaceship committed Jan 2, 2020
1 parent 75e5a53 commit fc69705
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 8 deletions.
16 changes: 12 additions & 4 deletions __init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,10 @@ class MixamoPropertyGroup(bpy.types.PropertyGroup):
name="Quaternion Clean Post",
description="Performs quaternion cleanup after conversion",
default=True)
foot_bone_workaround = bpy.props.BoolProperty(
name="Foot Bone Workaround",
description="Attempts to fix twisting of the foot bones",
default=False)


class OBJECT_OT_RemoveNamespace(bpy.types.Operator):
Expand Down Expand Up @@ -231,7 +235,8 @@ def execute(self, context):
apply_rotation = mixamo.apply_rotation,
apply_scale = mixamo.apply_scale,
quaternion_clean_pre=mixamo.quaternion_clean_pre,
quaternion_clean_post=mixamo.quaternion_clean_post)
quaternion_clean_post=mixamo.quaternion_clean_post,
foot_bone_workaround=mixamo.foot_bone_workaround)

try:
for status in mixamoconv_iterator:
Expand Down Expand Up @@ -278,7 +283,8 @@ def execute(self, context):
apply_rotation = mixamo.apply_rotation,
apply_scale = mixamo.apply_scale,
quaternion_clean_pre=mixamo.quaternion_clean_pre,
quaternion_clean_post=mixamo.quaternion_clean_post)
quaternion_clean_post=mixamo.quaternion_clean_post,
foot_bone_workaround=mixamo.foot_bone_workaround)
self.report({'INFO'}, "New conversion started")
try:
try:
Expand Down Expand Up @@ -363,7 +369,8 @@ def execute(self, context):
ignore_leaf_bones = mixamo.ignore_leaf_bones,
automatic_bone_orientation = mixamo.automatic_bone_orientation,
quaternion_clean_pre=mixamo.quaternion_clean_pre,
quaternion_clean_post=mixamo.quaternion_clean_post)
quaternion_clean_post=mixamo.quaternion_clean_post,
foot_bone_workaround=mixamo.foot_bone_workaround)
if numfiles == -1:
self.report({'ERROR_INVALID_INPUT'}, 'Error: Not all files could be converted, look in console for more information')
return{ 'CANCELLED'}
Expand Down Expand Up @@ -429,7 +436,8 @@ def draw(self, context):
# row = box.row()
# row.prop(scene.mixamo, "quaternion_clean_pre")
# row.prop(scene.mixamo, "quaternion_clean_post")

row = box.row()
row.prop(scene.mixamo, "foot_bone_workaround")

row = box.row()
row.prop(scene.mixamo, "apply_scale")
Expand Down
19 changes: 15 additions & 4 deletions mixamoconv.py
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,15 @@ def quaternion_cleanup(object, prevent_flips=True, prevent_inverts=True):
if change_amount > 1.0:
for j in range(4):
zipped[i][j].co.y *= -1.0


def apply_foot_bone_workaround(armature, bonenames=['RightToeBase', 'LeftToeBase']):
"""workaround for the twisting of the foot bones in some skeletons"""
if bpy.context.scene.mixamo.b_unreal_bones:
bonenames = ["ball_r", "ball_l"]

bpy.ops.object.mode_set(mode='EDIT')
for name in bonenames:
armature.data.edit_bones[name].roll = pi

class Status:
def __init__(self, msg, status_type='default'):
Expand All @@ -218,7 +226,7 @@ def __str__(self):
return str(self.msg)

def hip_to_root(armature, use_x=True, use_y=True, use_z=True, on_ground=True, use_rotation=True, scale=1.0, restoffset=(0, 0, 0),
hipname='', fixbind=True, apply_rotation=True, apply_scale=False, quaternion_clean_pre=True, quaternion_clean_post=True):
hipname='', fixbind=True, apply_rotation=True, apply_scale=False, quaternion_clean_pre=True, quaternion_clean_post=True, foot_bone_workaround=False):
"""function to bake hipmotion to RootMotion in MixamoRigs"""

yield Status("starting hip_to_root")
Expand Down Expand Up @@ -254,6 +262,9 @@ def hip_to_root(armature, use_x=True, use_y=True, use_z=True, on_ground=True, us
quaternion_cleanup(root)
yield Status("quaternion clean pre")

if foot_bone_workaround:
apply_foot_bone_workaround(armature)

# apply restoffset to restpose and correct animation
apply_restoffset(root, hips, restoffset)
yield Status("restoffset")
Expand Down Expand Up @@ -413,7 +424,7 @@ def hip_to_root(armature, use_x=True, use_y=True, use_z=True, on_ground=True, us

def batch_hip_to_root(source_dir, dest_dir, use_x=True, use_y=True, use_z=True, on_ground=True, use_rotation=True, scale=1.0,
restoffset=(0, 0, 0), hipname='', fixbind=True, apply_rotation=True, apply_scale=False,
b_remove_namespace=True, b_unreal_bones=False, add_leaf_bones=False, knee_offset=(0, 0, 0), ignore_leaf_bones=True, automatic_bone_orientation=True, quaternion_clean_pre=True, quaternion_clean_post=True):
b_remove_namespace=True, b_unreal_bones=False, add_leaf_bones=False, knee_offset=(0, 0, 0), ignore_leaf_bones=True, automatic_bone_orientation=True, quaternion_clean_pre=True, quaternion_clean_post=True, foot_bone_workaround=False):
"""Batch Convert MixamoRigs"""

bpy.context.scene.unit_settings.system = 'METRIC'
Expand Down Expand Up @@ -490,7 +501,7 @@ def getArmature(objects):
try:
for step in hip_to_root(armature, use_x=use_x, use_y=use_y, use_z=use_z, on_ground=on_ground, use_rotation=use_rotation, scale=scale,
restoffset=restoffset, hipname=hipname, fixbind=fixbind, apply_rotation=apply_rotation,
apply_scale=apply_scale, quaternion_clean_pre=quaternion_clean_pre, quaternion_clean_post=quaternion_clean_post):
apply_scale=apply_scale, quaternion_clean_pre=quaternion_clean_pre, quaternion_clean_post=quaternion_clean_post, foot_bone_workaround=foot_bone_workaround):
#DEBUG log.error(str(step))
pass
except Exception as e:
Expand Down

0 comments on commit fc69705

Please sign in to comment.