From 8d14f88bfc1047b1fef508efae71edfdc8e329c9 Mon Sep 17 00:00:00 2001 From: Finepointcgi Date: Sun, 26 Mar 2023 15:42:20 -0400 Subject: [PATCH 1/2] Fixed random crashes on mac --- __init__.py | 4 ++-- mixamoroot.py | 25 +++++++++++++------------ 2 files changed, 15 insertions(+), 14 deletions(-) diff --git a/__init__.py b/__init__.py index 4225816..9408315 100644 --- a/__init__.py +++ b/__init__.py @@ -24,8 +24,8 @@ bl_info = { "name": "Mixamo Root", "author": "Richard Perry, Johngoss725", - "version": (1, 2, 2), - "blender": (2, 80, 0), + "version": (1, 2, 3), + "blender": (3, 3, 1), "location": "3D View > UI (Right Panel) > Mixamo Tab", "description": ("Script to bake insert root motion bone for Mixamo Animations"), "warning": "", # used for warning icon and text in addons panel diff --git a/mixamoroot.py b/mixamoroot.py index 285001d..e8ff5cd 100644 --- a/mixamoroot.py +++ b/mixamoroot.py @@ -338,18 +338,19 @@ def get_all_anims(source_dir, root_bone_name="Root", hip_bone_name="mixamorig:Hi for file in files: print("file: " + str(file)) - try: - filepath = source_dir+"/"+file - import_armature(filepath, root_bone_name, hip_bone_name, remove_prefix, name_prefix, insert_root, delete_armatures) - imported_objects = set(bpy.context.scene.objects) - old_objs - if delete_armatures and num_files > 1: - deleteArmature(imported_objects) - num_files -= 1 - - - except Exception as e: - log.error("[Mixamo Root] ERROR get_all_anims raised %s when processing %s" % (str(e), file)) - return -1 + if not file.endswith('.DS_Store') and file.endswith('.fbx'): + try: + filepath = source_dir+"/"+file + import_armature(filepath, root_bone_name, hip_bone_name, remove_prefix, name_prefix, insert_root, delete_armatures) + imported_objects = set(bpy.context.scene.objects) - old_objs + if delete_armatures and num_files > 1: + deleteArmature(imported_objects) + num_files -= 1 + + + except Exception as e: + log.error("[Mixamo Root] ERROR get_all_anims raised %s when processing %s" % (str(e), file)) + return -1 bpy.context.area.ui_type = current_context bpy.context.scene.frame_start = 0 bpy.ops.object.mode_set(mode='OBJECT') From 08f1ec1a0a053e21e5255465b8345b67d9d53816 Mon Sep 17 00:00:00 2001 From: Finepointcgi Date: Sat, 22 Apr 2023 17:04:25 -0400 Subject: [PATCH 2/2] Fixes root going below 0 on z axis --- __init__.py | 4 ++-- mixamoroot.py | 33 +++++++++++++++++++++++++++------ 2 files changed, 29 insertions(+), 8 deletions(-) diff --git a/__init__.py b/__init__.py index 9408315..4225816 100644 --- a/__init__.py +++ b/__init__.py @@ -24,8 +24,8 @@ bl_info = { "name": "Mixamo Root", "author": "Richard Perry, Johngoss725", - "version": (1, 2, 3), - "blender": (3, 3, 1), + "version": (1, 2, 2), + "blender": (2, 80, 0), "location": "3D View > UI (Right Panel) > Mixamo Tab", "description": ("Script to bake insert root motion bone for Mixamo Animations"), "warning": "", # used for warning icon and text in addons panel diff --git a/mixamoroot.py b/mixamoroot.py index e8ff5cd..6d3faba 100644 --- a/mixamoroot.py +++ b/mixamoroot.py @@ -3,20 +3,16 @@ ''' Copyright (C) 2022 Richard Perry Copyright (C) Average Godot Enjoyer (Johngoss725) - This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. - This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. - You should have received a copy of the GNU General Public License along with this program. If not, see . - Note that Johngoss725's original contributions were published under a Creative Commons 1.0 Universal License (CC0-1.0) located at . @@ -107,12 +103,37 @@ def copyHips(root_bone_name="Root", hip_bone_name="mixamorig:Hips", name_prefix= for i in myFcurves: hip_bone_fcvurve = 'pose.bones["'+hip_bone_name+'"].location' if str(i.data_path)==hip_bone_fcvurve: - myFcurves.remove(i) + if i.array_index != 1: + myFcurves.remove(i) bpy.ops.pose.select_all(action='DESELECT') bpy.context.object.pose.bones[name_prefix + root_bone_name].bone.select = True bpy.ops.graph.paste() - + + # Get the animation data and action + anim_data = bpy.context.object.animation_data + action = anim_data.action if anim_data else None + + # Get the fcurves for the root bone's location + fcurves = [fcurve for fcurve in action.fcurves if fcurve.data_path == 'pose.bones["{}"].location'.format(name_prefix + root_bone_name) and fcurve.array_index in range(3)] + for i in fcurves: + print(i.data_path) + + # Set the minimum Y value of the root bone to 0 + z_fcurve = fcurves[1] + for keyframe in z_fcurve.keyframe_points: + if keyframe.co.y < 0: + keyframe.co.y = 0 + + + anim_data = bpy.context.object.animation_data + action = anim_data.action if anim_data else None + hips_fcurves = [hips_fcurve for hips_fcurve in action.fcurves if hips_fcurve.data_path == 'pose.bones["{}"].location'.format(hip_bone_name) and hips_fcurve.array_index in range(3)] + for keyframe in hips_fcurves[0].keyframe_points: + if keyframe.co.y > 0: + keyframe.co.y = 0 + #keyframe.co.y = keyframe.co.y / 2 + bpy.context.area.ui_type = 'VIEW_3D' bpy.ops.object.mode_set(mode='OBJECT')