summaryrefslogtreecommitdiff
path: root/collada_superbmd_export.py
diff options
context:
space:
mode:
Diffstat (limited to 'collada_superbmd_export.py')
-rw-r--r--collada_superbmd_export.py54
1 files changed, 25 insertions, 29 deletions
diff --git a/collada_superbmd_export.py b/collada_superbmd_export.py
index ad1363b..9ef08b2 100644
--- a/collada_superbmd_export.py
+++ b/collada_superbmd_export.py
@@ -15,26 +15,25 @@ def write_bmd_bdl_collada(context, filepath, triangulate):
scene = bpy.context.scene
# if nothing is selected end the exporter
- if (scene.objects.active == None or scene.objects.active.type != 'ARMATURE'):
+ if (scene.objects.active == None or scene.objects.active.type != "ARMATURE"):
if (scene.objects.active == None):
blender_funcs.disp_msg("No Armature selected. Select one and try again.")
else:
blender_funcs.disp_msg("No Armature selected. Currently selecting: \"%s\""
% (scene.objects.active.name))
- return {'FINISHED'}
+ return {"FINISHED"}
# get armature object
armature = scene.objects.active
print("\nArmature found: \"%s\"" % (armature.name))
- # change to object mode
- bpy.ops.object.mode_set(mode='OBJECT')
+ # select it
+ blender_funcs.select_obj(armature, False, "OBJECT")
# check if the armature contains only mesh objects inside
- for obj in armature.children:
- if (obj.type != 'MESH'):
- blender_funcs.disp_msg("\"%s\": contains non-mesh object (%s)."
- % (armature.name, obj.name))
- return {'FINISHED'}
+ for child in armature.children:
+ if (child.type != "MESH"):
+ blender_funcs.disp_msg("\"%s\": contains non-mesh object (%s)." % (armature.name, child.name))
+ return {"FINISHED"}
# check if all meshes have an armature modifier that is
# assigned to the armature object and it is binded to
@@ -43,18 +42,16 @@ def write_bmd_bdl_collada(context, filepath, triangulate):
for mesh in armature.children:
if("Armature" not in mesh.modifiers):
blender_funcs.disp_msg("\"%s\": has no armature modifier. Adding one..." % (mesh.name))
- blender_funcs.select_obj(scene, mesh, False)
- bpy.ops.object.modifier_add(type = 'ARMATURE')
+ 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
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):
- blender_funcs.disp_msg("\"%s\": armature modifier wasn't binded to vertex groups"
- % (mesh.name))
+ 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):
- blender_funcs.disp_msg("\"%s\": armature modifier was binded to another armature object"
- % (mesh.name))
+ blender_funcs.disp_msg("\"%s\": armature modifier was binded to another armature object" % (mesh.name))
mesh.modifiers["Armature"].object = armature;
# check if all the vertex groups in each mesh correspond to the name of a skeleton bone
@@ -65,16 +62,16 @@ def write_bmd_bdl_collada(context, filepath, triangulate):
for mesh in armature.children:
for v_group in mesh.vertex_groups:
if (v_group.name not in bone_name_list):
- blender_funcs.disp_msg(("\"%s\": contains non-valid vert group \"%s\"."
- % (mesh.name, v_group.name)) + " Unable to continue.")
- return {'FINISHED'}
+ blender_funcs.disp_msg(("\"%s\": contains non-valid vert group \"%s\"." % (mesh.name, v_group.name))
+ + " Unable to continue.")
+ return {"FINISHED"}
# vertex weight check
for mesh in armature.children:
for vertex in mesh.data.vertices:
if (len(vertex.groups) == 0):
blender_funcs.disp_msg(("\"%s\": contains unweighted vertices."
% (mesh.name)) + " Unable to continue.")
- return {'FINISHED'}
+ return {"FINISHED"}
# get the object names
obj_name = armature.name
@@ -83,13 +80,12 @@ def write_bmd_bdl_collada(context, filepath, triangulate):
child_names.append(child.name)
# change to object view and make a copy of the armature object (with its children)
- bpy.ops.object.mode_set(mode='OBJECT')
- blender_funcs.select_obj(scene, armature, True)
+ blender_funcs.select_obj(armature, True, "OBJECT")
bpy.ops.object.duplicate(linked = True)
- bpy.ops.object.make_single_user(type = 'SELECTED_OBJECTS', object = True, obdata = True)
+ bpy.ops.object.make_single_user(type = "SELECTED_OBJECTS", object = True, obdata = True)
old_armature = armature
armature = scene.objects.active
- blender_funcs.select_obj(scene, armature, False)
+ blender_funcs.select_obj(armature, False, "OBJECT")
# apply the transformations to the armature
armature.rotation_euler[0] = math.radians(-90)
@@ -98,9 +94,9 @@ def write_bmd_bdl_collada(context, filepath, triangulate):
# apply the transformations to the meshes inside the armature
for i in range(0, len(armature.children)):
- blender_funcs.select_obj(scene, armature.children[i], False)
+ blender_funcs.select_obj(armature.children[i], False, "OBJECT")
bpy.ops.object.transform_apply(location = True, rotation = True, scale = True)
- blender_funcs.select_obj(scene, armature, False)
+ blender_funcs.select_obj(armature, False, "OBJECT")
# handle the object names so that they match the original model names
armature.name = obj_name
@@ -112,10 +108,10 @@ def write_bmd_bdl_collada(context, filepath, triangulate):
# export the object
bpy.ops.wm.collada_export(filepath = filepath, use_blender_profile = False,
selected = True, include_children = True,
- triangulate = triangulate)
+ triangulate = triangulate)
# delete the duplicate object
- blender_funcs.select_obj(scene, armature, True)
+ blender_funcs.select_obj(armature, True, "OBJECT")
bpy.ops.object.delete(use_global = False)
# re-assign the original object names
@@ -127,9 +123,9 @@ def write_bmd_bdl_collada(context, filepath, triangulate):
armature.children[i].data.name = child_names[i]
# done!
- blender_funcs.select_obj(scene, armature, False)
+ blender_funcs.select_obj(armature, False, "OBJECT")
blender_funcs.disp_msg("Armature \"%s\" exported!" % (armature.name))
- return {'FINISHED'}
+ return {"FINISHED"}
# Stuff down is for the menu appending
# of the exporter to work plus some setting stuff