summaryrefslogtreecommitdiff
path: root/collada_superbmd_import.py
diff options
context:
space:
mode:
Diffstat (limited to 'collada_superbmd_import.py')
-rw-r--r--collada_superbmd_import.py32
1 files changed, 19 insertions, 13 deletions
diff --git a/collada_superbmd_import.py b/collada_superbmd_import.py
index 7e8de8b..8187fb9 100644
--- a/collada_superbmd_import.py
+++ b/collada_superbmd_import.py
@@ -38,8 +38,6 @@ def import_collada_superbmd(context, filepath):
# get asset's unit element
root = xml.getroot()
- unit_elem = root.find("asset").find("unit")
- unit_elem.attrib["meter"] = "0.01"
# texture files path
if (os.name == "posix"):
@@ -141,27 +139,35 @@ def import_collada_superbmd(context, filepath):
# get to pose mode
bpy.ops.object.mode_set(mode='POSE')
- # set the "pose position" to be the rest position (for animations)
- # and keep the "rest position" as the bind position (cannot be altered)
+ # set current pose to be rest pose and rest pose to be rest pose
for bone in armature.pose.bones:
if (bone.parent != None):
bone.matrix = bone.parent.matrix * rest_matrices[bone.name]
else:
bone.matrix = rest_matrices[bone.name]
- # store the bind_mat and rest_mat custom properties on each bone
+ # apply visual transform to all meshes
bpy.ops.object.mode_set(mode='OBJECT')
- for bone in armature.data.bones:
- if ((bone.name in bind_matrices) and (bone.name in rest_matrices)):
- blender_funcs.set_bone_bind_mat(bone, bind_matrices[bone.name])
- else:
- blender_funcs.set_bone_bind_mat(bone, rest_matrices[bone.name])
- blender_funcs.set_bone_rest_mat(bone, rest_matrices[bone.name])
+ for child in armature.children:
+ blender_funcs.select_obj(scene, child, False)
+ bpy.ops.object.convert(target='MESH')
- # scale down the model and apply transformations
+ # apply pose to rest pose
+ blender_funcs.select_obj(scene, armature, False)
+ bpy.ops.object.mode_set(mode='POSE')
+ bpy.ops.pose.armature_apply()
+
+ # reassign the armature modifiers to all meshes
bpy.ops.object.mode_set(mode='OBJECT')
+ for child in armature.children:
+ blender_funcs.select_obj(scene, child, False)
+ bpy.ops.object.modifier_add(type = 'ARMATURE')
+ child.modifiers["Armature"].object = armature
+ child.modifiers["Armature"].use_vertex_groups = True
+
+ # scale down the model and apply transformations
armature.scale = (0.01, 0.01, 0.01)
- bpy.ops.object.transforms_to_deltas(mode = 'ALL')
+ blender_funcs.transf_apply_recurse(scene, armature, True, True, True)
# done!
blender_funcs.disp_msg("SuperBMD Collada file imported!")