Skip to content

Commit

Permalink
Added recursive batching option
Browse files Browse the repository at this point in the history
I'm not python developer and It's my first fork project soo I strongly recommend you should check my update :)
  • Loading branch information
brkeejp authored Aug 19, 2020
1 parent 1d600bf commit a8119db
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
9 changes: 8 additions & 1 deletion __init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,10 @@ class MixamoPropertyGroup(bpy.types.PropertyGroup):
maxlen = 256,
default = "",
subtype='DIR_PATH')
discover_recursive: bpy.props.BoolProperty(
name="Recursive",
description="Discover animation files recursive",
default=True)
add_leaf_bones: bpy.props.BoolProperty(
name="Add Leaf Bones",
description="If enabled, adds leaf bones on export when batchconverting",
Expand Down Expand Up @@ -370,7 +374,8 @@ def execute(self, context):
automatic_bone_orientation = mixamo.automatic_bone_orientation,
quaternion_clean_pre=mixamo.quaternion_clean_pre,
quaternion_clean_post=mixamo.quaternion_clean_post,
foot_bone_workaround=mixamo.foot_bone_workaround)
foot_bone_workaround=mixamo.foot_bone_workaround,
discover_recursive=mixamo.discover_recursive)
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 @@ -470,6 +475,8 @@ def draw(self, context):
row = box.row()
row.prop(scene.mixamo, "inpath")
if scene.mixamo.advanced:
row = box.row()
row.prop(scene.mixamo, "discover_recursive")
row = box.row()
row.prop(scene.mixamo, "ignore_leaf_bones")
row.prop(scene.mixamo, "automatic_bone_orientation")
Expand Down
13 changes: 11 additions & 2 deletions mixamoconv.py
Original file line number Diff line number Diff line change
Expand Up @@ -417,7 +417,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, foot_bone_workaround=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, foot_bone_workaround=False, discover_recursive=True):
"""Batch Convert MixamoRigs"""

source_dir = Path(source_dir)
Expand All @@ -429,7 +429,14 @@ def batch_hip_to_root(source_dir, dest_dir, use_x=True, use_y=True, use_z=True,
numfiles = 0
for file in source_dir.iterdir():
if not file.is_file():

This comment has been minimized.

Copy link
@enziop

enziop Aug 20, 2020

Owner

change this from not file.is_file() to more explicit file.is_dir()

continue
if not discover_recursive:
continue
if file.stem in ["OUTPUT", "output"]:
continue
batch_hip_to_root(str(source_dir.joinpath(file.stem)), str(dest_dir.joinpath(file.stem)),
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,
b_remove_namespace=b_remove_namespace, b_unreal_bones=b_unreal_bones, add_leaf_bones=add_leaf_bones, knee_offset=knee_offset, ignore_leaf_bones=ignore_leaf_bones, automatic_bone_orientation=automatic_bone_orientation, quaternion_clean_pre=quaternion_clean_pre, quaternion_clean_post=quaternion_clean_post, foot_bone_workaround=foot_bone_workaround, discover_recursive=discover_recursive)
file_ext = file.suffix
file_loader = {
".fbx": lambda filename: bpy.ops.import_scene.fbx(
Expand Down Expand Up @@ -520,6 +527,8 @@ def getArmature(objects):
bpy.data.actions.remove(action, do_unlink=True)

# store file to disk
if not dest_dir.exists():
dest_dir.mkdir()
output_file = dest_dir.joinpath(file.stem + ".fbx")
bpy.ops.export_scene.fbx(filepath=str(output_file),
use_selection=False,
Expand Down

1 comment on commit a8119db

@brkeejp
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm looks like I need to update my code. I did mistake. while writing files to disk from recursive dir, need to create parent folder first.
Also planning to exclude output_dir from recursive search.

Please sign in to comment.