From 43b1f9650eeb66e2ff30d0ce62c5fe4a3417e1a7 Mon Sep 17 00:00:00 2001 From: William Herald Snyder Date: Wed, 28 Sep 2022 11:27:52 -0400 Subject: [PATCH] When gathering bone transforms during armature expansion, don't assume armature's local transform is zeroed --- addons/io_scene_swbf_msh/msh_model_gather.py | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/addons/io_scene_swbf_msh/msh_model_gather.py b/addons/io_scene_swbf_msh/msh_model_gather.py index c98833b..d9d6df7 100644 --- a/addons/io_scene_swbf_msh/msh_model_gather.py +++ b/addons/io_scene_swbf_msh/msh_model_gather.py @@ -389,12 +389,26 @@ def expand_armature(armature: bpy.types.Object) -> List[Model]: # set model parent to SKIN object if there is one # set model parent to armature parent if there is one else: + + bone_world_matrix = armature.matrix_world @ transform + parent_obj = None + for child_obj in armature.original.children: if child_obj.vertex_groups and not get_is_model_hidden(child_obj) and not child_obj.parent_bone: - model.parent = child_obj.name + #model.parent = child_obj.name + parent_obj = child_obj break - if not model.parent and armature.parent: + + if parent_obj: + transform = parent_obj.matrix_world.inverted() @ bone_world_matrix + model.parent = parent_obj.name + elif not parent_obj and armature.parent: + transform = armature.parent.matrix_world.inverted() @ bone_world_matrix model.parent = armature.parent.name + else: + transform = bone_world_matrix + model.parent = "" + local_translation, local_rotation, _ = transform.decompose()