Skip to content

Instantly share code, notes, and snippets.

@BryantAvey
Forked from Bioblaze/MakehumanUE4BoneFix.py
Created July 6, 2018 12:39
Show Gist options
  • Save BryantAvey/5487952ff152b694dfb032fc2145d64e to your computer and use it in GitHub Desktop.
Save BryantAvey/5487952ff152b694dfb032fc2145d64e to your computer and use it in GitHub Desktop.
This is a Fix for Makehuman to UE4 Skeleton Reassignment When you import a avatar from Makehuman, normally you`ll retarget the UE4 Skeleton to Match. When you do that, as you import animations from the UE4 Skeleton it changes them slightly, joints are out of line, bones are resized. This fixes that, bring them into Blender, and run this script. …
import bpy
bl_info = {
"name": "Fix Makehuman UE4 Animation",
"description": "Goes through and fixes all the Scale and Location of all Bones other then Root.",
"author": "Bioblaze Payne",
"version": (0,1),
"location": "View3D > Pose Mode > Unreal Engine",
"category": "Animation"
}
class FixMakeHumanSkeletonforAnimationPanel(bpy.types.Panel):
bl_space_type = "VIEW_3D"
bl_region_type = "TOOLS"
bl_context = "posemode"
bl_label = "Fix MakeHuman UE4 Animation"
def draw(self,context) :
col = self.layout.column(align = True)
col.operator("bioblaze.ue4_makehuman_skeleton_fix", text = "Fix MakeHuman UE4 Animation")
class FixMakeHumanSkeletonforAnimation(bpy.types.Operator):
bl_idname="bioblaze.ue4_makehuman_skeleton_fix"
bl_label = "Fixes the Animations that are retargeted to the UE4 Skeleton from Make Human Avatars"
bl_options = {'REGISTER', 'UNDO'}
def draw(self,context) :
col = self.layout.column(align = True)
def execute(self,context) :
self.start(context)
return {"FINISHED"}
def invoke(self,context,event) :
self.start(context)
return {"FINISHED"}
def start(self,context):
for f in range(bpy.context.scene.frame_start, bpy.context.scene.frame_end+1):
bpy.context.scene.frame_set(f)
print("Frame %i" % f)
for bone in bpy.context.object.pose.bones:
print(bone.name)
if bone.name not in "pelvis":
bone.scale = [1.0,1.0,1.0]
bone.location = [0.0,0.0,0.0]
bpy.ops.anim.keyframe_insert(type='Location')
bpy.ops.anim.keyframe_insert(type='Scaling')
#bpy.data.objects["Armature"].data.bones[bone.name].loc_clear()
#bpy.data.objects["Armature"].data.bones[bone.name].scale_clear()
#bone.loc_clear()
#bone.scale_clear()
#bpy.ops.pose.bones[bone.name].loc_clear()
#bpy.ops.pose.bones[bone.name].scale_clear()
return {"FINISHED"}
def add_to_menu(self,context) :
self.layout.operator("pose.fixmakehumanue4", icon = "PLUGIN")
def register() :
bpy.utils.register_class(FixMakeHumanSkeletonforAnimation)
bpy.utils.register_class(FixMakeHumanSkeletonforAnimationPanel)
bpy.types.VIEW3D_MT_pose.append(add_to_menu)
def unregister() :
bpy.utils.unregister_class(FixMakeHumanSkeletonforAnimation)
bpy.utils.unregister_class(FixMakeHumanSkeletonforAnimationPanel)
bpy.types.VIEW3D_MT_pose.remove(add_to_menu)
if __name__ == "__main__":
register()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment