diff options
Diffstat (limited to 'collada_superbmd_export.py')
-rw-r--r-- | collada_superbmd_export.py | 41 |
1 files changed, 32 insertions, 9 deletions
diff --git a/collada_superbmd_export.py b/collada_superbmd_export.py index f66085c..2f92fa3 100644 --- a/collada_superbmd_export.py +++ b/collada_superbmd_export.py @@ -53,19 +53,42 @@ def write_bmd_bdl_collada(context, filepath, triangulate): # vertex groups if none of those are just create them, # I don't think it is bad to automate that for mesh in armature.children: - if("Armature" not in mesh.modifiers): + # check if all meshes have an armature modifier + has_armature_modifier = False + has_multiple_armature_modifiers = False + armature_modifier = None + + # iterate over the mesh modifiers + i = 0 + while (i < len(mesh.modifiers)): + # check the existance of an armature modifier + if (mesh.modifiers[i].type == "ARMATURE"): + if (has_armature_modifier == False): + has_armature_modifier = True + armature_modifier = mesh.modifiers[i] # save current armature modifier + else: # 2 armature modifiers? (remove duplicates) + has_multiple_armature_modifiers = True + mesh.modifiers.remove(mesh.modifiers[i]) + i -= 1 + i += 1 + + # notify the user about duplicate armature modifiers + if (has_multiple_armature_modifiers == True): + blender_funcs.disp_msg("\"%s\": has two or armature modifiers. Removing duplicates..." % (mesh.name)) + + # check if there is actually an armature modifier + if (has_armature_modifier == False): blender_funcs.disp_msg("\"%s\": has no armature modifier. Adding one..." % (mesh.name)) - blender_funcs.select_obj(mesh, False, "OBJECT") - bpy.ops.object.modifier_add(type = "ARMATURE") - mesh.modifiers["Armature"].object = armature - mesh.modifiers["Armature"].use_vertex_groups = True + armature_modifier = mesh.modifiers.new(name = armature.name, type = "ARMATURE") + armature_modifier.object = armature + armature_modifier.use_vertex_groups = True else: # ensure bind is to a vertex group and that the bind is to the actual parent armature - if (mesh.modifiers["Armature"].use_vertex_groups == False): + if (armature_modifier.use_vertex_groups == False): blender_funcs.disp_msg("\"%s\": armature modifier wasn't binded to vertex groups" % (mesh.name)) - mesh.modifiers["Armature"].use_vertex_groups = True - if (mesh.modifiers["Armature"].object != armature): + armature_modifier.use_vertex_groups = True + if (armature_modifier.object != armature): blender_funcs.disp_msg("\"%s\": armature modifier was binded to another armature object" % (mesh.name)) - mesh.modifiers["Armature"].object = armature; + armature_modifier.object = armature; # check if all the vertex groups in each mesh correspond to the name of a skeleton bone bone_name_list = [] |