summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--collada_superbmd_export.py18
-rw-r--r--collada_superbmd_import.py32
2 files changed, 19 insertions, 31 deletions
diff --git a/collada_superbmd_export.py b/collada_superbmd_export.py
index 27d63c7..5d6f83f 100644
--- a/collada_superbmd_export.py
+++ b/collada_superbmd_export.py
@@ -103,24 +103,6 @@ def write_bmd_bdl_collada(context, filepath, triangulate):
armature.children[i].name = child_names[i]
armature.children[i].data.name = child_names[i]
- # store the new bind_mat and rest_mat (the user might want to update them)
- for data_bone in armature.data.bones:
- # related pose bone
- pose_bone = armature.pose.bones[data_bone.name]
- # bind matrix
- bpy.data.armatures[armature.data.name].pose_position = 'REST'
- bpy.context.scene.update() # update scene
- blender_funcs.set_bone_bind_mat(data_bone, pose_bone.matrix)
- # rest matrix
- bpy.data.armatures[armature.data.name].pose_position = 'POSE'
- bpy.context.scene.update() # update scene
- mat = None
- if (pose_bone.parent != None):
- mat = pose_bone.parent.matrix.inverted() * pose_bone.matrix
- else:
- mat = pose_bone.matrix
- blender_funcs.set_bone_rest_mat(data_bone, mat)
-
# export the object
bpy.ops.wm.collada_export(filepath = filepath, use_blender_profile = False,
selected = True, include_children = True,
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!")