Skip to content

Commit

Permalink
introduce bvh export option to sort bone child node name appearances …
Browse files Browse the repository at this point in the history
…in the downstream hierarchy format
  • Loading branch information
PierceLBrooks committed Jan 13, 2024
1 parent 2791f29 commit 3f005e5
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
6 changes: 6 additions & 0 deletions io_anim_bvh/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -321,6 +326,7 @@ def draw(self, context):
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):
Expand Down
8 changes: 7 additions & 1 deletion io_anim_bvh/export_bvh.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -36,10 +37,13 @@ def ensure_rot_order(rot_order_str):
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 = []
Expand Down Expand Up @@ -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,
Expand All @@ -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'}

0 comments on commit 3f005e5

Please sign in to comment.