Skip to content

Commit

Permalink
added options to disable quaternion fix, also cleaned up some code
Browse files Browse the repository at this point in the history
  • Loading branch information
enziop committed May 25, 2018
1 parent b7d788a commit c7df649
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 23 deletions.
32 changes: 19 additions & 13 deletions __init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
bl_info = {
"name": "Mixamo Converter",
"author": "Enzio Probst",
"version": (1, 1, 0),
"version": (1, 1, 1),
"blender": (2, 7, 8),
"location": "3D View > Tool Shelve > Mixamo Tab",
"description": ("Script to bake Root motion for Mixamo Animations"),
Expand Down Expand Up @@ -148,6 +148,14 @@ class MixamoPropertyGroup(bpy.types.PropertyGroup):
name="Apply Scale",
description="Applies scale during conversion to prevent rotation and scaling issues",
default=False)
quaternion_clean_pre = bpy.props.BoolProperty(
name="Quaternion Clean Pre",
description="Performs quaternion cleanup to before conversion",
default=True)
quaternion_clean_post = bpy.props.BoolProperty(
name="Quaternion Clean Post",
description="Performs quaternion cleanup after conversion",
default=True)


class OBJECT_OT_RemoveNamespace(bpy.types.Operator):
Expand Down Expand Up @@ -216,7 +224,9 @@ def execute(self, context):
hipname = mixamo.hipname.decode('UTF-8'),
fixbind = mixamo.fixbind,
apply_rotation = mixamo.apply_rotation,
apply_scale = mixamo.apply_scale)
apply_scale = mixamo.apply_scale,
quaternion_clean_pre=mixamo.quaternion_clean_pre,
quaternion_clean_post=mixamo.quaternion_clean_post)
if status == -1:
self.report({'ERROR_INVALID_INPUT'}, 'Error: Hips not found')
return{ 'CANCELLED'}
Expand Down Expand Up @@ -289,7 +299,9 @@ def execute(self, context):
b_unreal_bones = mixamo.b_unreal_bones,
add_leaf_bones = mixamo.add_leaf_bones,
knee_offset = mixamo.knee_offset,
ignore_leaf_bones = mixamo.ignore_leaf_bones)
ignore_leaf_bones = mixamo.ignore_leaf_bones,
quaternion_clean_pre=mixamo.quaternion_clean_pre,
quaternion_clean_post=mixamo.quaternion_clean_post)
if numfiles == -1:
self.report({'ERROR_INVALID_INPUT'}, 'Error: Hips not found')
return{ 'CANCELLED'}
Expand All @@ -310,16 +322,6 @@ def draw(self, context):

scene = bpy.context.scene

''' Annoying warning Box
#box with general info
infobox = layout.box()
infobox.label(icon = 'ERROR', text = "Attention:")
row = infobox.row()
row.label("Batch Convert will delete everything from your current scene")
row = infobox.row()
row.label("Only use in empty or startup scene")
'''

box = layout.box()
# Options for how to do the conversion
row = box.row()
Expand Down Expand Up @@ -362,6 +364,10 @@ def draw(self, context):
row = box.row()
row.prop(scene.mixamo, "fixbind")
row.prop(scene.mixamo, "apply_rotation")
row = box.row()
row.prop(scene.mixamo, "quaternion_clean_pre")
row.prop(scene.mixamo, "quaternion_clean_post")


row = box.row()
row.prop(scene.mixamo, "apply_scale")
Expand Down
21 changes: 11 additions & 10 deletions mixamoconv.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,11 @@
along with this program. If not, see <http://www.gnu.org/licenses/>.
'''

import bpy
from bpy_types import Object
from math import copysign
import os
import re
import logging
import bpy
from bpy_types import Object

log = logging.getLogger(__name__)

Expand Down Expand Up @@ -183,9 +182,9 @@ def quaternion_cleanup(object):
zipped[i][j].co.y *= -1.0

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):
hipname='', fixbind=True, apply_rotation=True, apply_scale=False, quaternion_clean_pre=True, quaternion_clean_post=True):
"""function to bake hipmotion to RootMotion in MixamoRigs"""

root = armature
root.name = "root"
root.rotation_mode = 'QUATERNION'
Expand All @@ -208,7 +207,8 @@ def hip_to_root(armature, use_x=True, use_y=True, use_z=True, on_ground=True, us
root.scale *= scale

# fix quaternion sign swapping
quaternion_cleanup(root)
if quaternion_clean_pre:
quaternion_cleanup(root)

# apply restoffset to restpose and correct animation
apply_restoffset(root, hips, restoffset)
Expand Down Expand Up @@ -306,7 +306,8 @@ def hip_to_root(armature, use_x=True, use_y=True, use_z=True, on_ground=True, us
bpy.ops.nla.bake(frame_start=framerange[0], frame_end=framerange[1], step=1, only_selected=True, visual_keying=True,
clear_constraints=True, clear_parents=False, use_current_action=True, bake_types={'POSE'})

quaternion_cleanup(root)
if quaternion_clean_post:
quaternion_cleanup(root)

# Delete helpers
bpy.ops.object.mode_set(mode='OBJECT')
Expand All @@ -326,7 +327,7 @@ def hip_to_root(armature, use_x=True, use_y=True, use_z=True, on_ground=True, us
if mod.object == root:
bindmesh = child
break
if bindmesh == None:
if bindmesh is None:
bpy.ops.object.select_all(action='DESELECT')
bpy.ops.mesh.primitive_plane_add(radius=1, view_align=False, enter_editmode=False, location=(0, 0, 0),
layers=(
Expand All @@ -347,7 +348,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):
b_remove_namespace=True, b_unreal_bones=False, add_leaf_bones=False, knee_offset=(0, 0, 0), ignore_leaf_bones=True, quaternion_clean_pre=True, quaternion_clean_post=True):
"""Batch Convert MixamoRigs"""

bpy.context.scene.unit_settings.system = 'METRIC'
Expand Down Expand Up @@ -422,7 +423,7 @@ def getArmature(objects):
# do hip to Root conversion
if 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) == -1:
apply_scale=apply_scale, quaternion_clean_pre=quaternion_clean_pre, quaternion_clean_post=quaternion_clean_post) == -1:
return -1


Expand Down

0 comments on commit c7df649

Please sign in to comment.