diff --git a/io_anim_bvh/__init__.py b/io_anim_bvh/__init__.py index 918d8d8ed..77996fc42 100644 --- a/io_anim_bvh/__init__.py +++ b/io_anim_bvh/__init__.py @@ -264,6 +264,11 @@ class ExportBVH(bpy.types.Operator, ExportHelper): description="Only write out translation channels for the root bone", default=False, ) + sort_child_names: BoolProperty( + name="Sort Child Names", + description="Sort the name ordering of children for each bone alphabetically", + default=False, + ) @classmethod def poll(cls, context): @@ -321,6 +326,7 @@ class BVH_PT_export_transform(bpy.types.Panel): layout.prop(operator, "global_scale") layout.prop(operator, "rotate_mode") layout.prop(operator, "root_transform_only") + layout.prop(operator, "sort_child_names") class BVH_PT_export_animation(bpy.types.Panel): diff --git a/io_anim_bvh/export_bvh.py b/io_anim_bvh/export_bvh.py index f2fb237c0..999593696 100644 --- a/io_anim_bvh/export_bvh.py +++ b/io_anim_bvh/export_bvh.py @@ -13,6 +13,7 @@ def write_armature( global_scale=1.0, rotate_mode='NATIVE', root_transform_only=False, + sort_child_names=False, ): def ensure_rot_order(rot_order_str): @@ -36,10 +37,13 @@ def write_armature( for bone in arm.bones: children[bone.name] = [] - # keep bone order from armature, no sorting, not esspential but means + # keep bone order from armature, not essential but means # we can maintain order from import -> export which secondlife incorrectly expects. for bone in arm.bones: children[getattr(bone.parent, "name", None)].append(bone.name) + if sort_child_names: + for key in children: + children[key].sort() # bone name list in the order that the bones are written serialized_names = [] @@ -281,6 +285,7 @@ def save( global_scale=1.0, rotate_mode="NATIVE", root_transform_only=False, + sort_child_names=False, ): write_armature( context, filepath, @@ -289,6 +294,7 @@ def save( global_scale=global_scale, rotate_mode=rotate_mode, root_transform_only=root_transform_only, + sort_child_names=sort_child_names, ) return {'FINISHED'}