From 7cfa101d422fe87cb859a11e29b4fc052c05ffdf Mon Sep 17 00:00:00 2001 From: William Herald Snyder Date: Wed, 28 Sep 2022 14:01:25 -0400 Subject: [PATCH] Catch models that are marked as bones but still have geometry --- addons/io_scene_swbf_msh/msh_to_blend.py | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/addons/io_scene_swbf_msh/msh_to_blend.py b/addons/io_scene_swbf_msh/msh_to_blend.py index c2e7b19..24ae749 100644 --- a/addons/io_scene_swbf_msh/msh_to_blend.py +++ b/addons/io_scene_swbf_msh/msh_to_blend.py @@ -221,19 +221,26 @@ def extract_scene(filepath: str, scene: Scene): # Parent the object to a bone if necessary else: - if curr_model.parent in armature.data.bones and curr_model.name not in armature.data.bones: + parent_bone_name = "" + if curr_model.name in armature.data.bones and curr_model.geometry: + parent_bone_name = curr_model.name + elif curr_model.parent in armature.data.bones and curr_model.name not in armature.data.bones: + parent_bone_name = curr_model.parent + + if parent_bone_name: # Not sure what the different mats do, but saving the worldmat and # applying it after clearing the other mats yields correct results... worldmat = curr_obj.matrix_world curr_obj.parent = armature curr_obj.parent_type = 'BONE' - curr_obj.parent_bone = curr_model.parent + curr_obj.parent_bone = parent_bone_name # '' curr_obj.matrix_basis = Matrix() curr_obj.matrix_parent_inverse = Matrix() curr_obj.matrix_world = worldmat + ''' Sometimes skins are parented to other skins. We need to find the skin highest in the hierarchy and parent all skins to its parent (armature_reparent_obj). @@ -264,7 +271,7 @@ def extract_scene(filepath: str, scene: Scene): # object counterpart (as created in extract_models) for bone in skel: model_to_remove = model_map[bone.name] - if model_to_remove: + if model_to_remove and model_to_remove.parent_bone == "": bpy.data.objects.remove(model_to_remove, do_unlink=True) model_map.pop(bone.name)