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.py56
1 files changed, 38 insertions, 18 deletions
diff --git a/collada_superbmd_import.py b/collada_superbmd_import.py
index 39e7ce6..2fa7ef0 100644
--- a/collada_superbmd_import.py
+++ b/collada_superbmd_import.py
@@ -4,7 +4,7 @@ from . import collada_funcs
from . import blender_funcs
from . import math_funcs
-# Comments (spanish) (reescribir):
+# Comments (español) (reescribir):
# Bind Pose o Pose de Vínculo (aplica a huesos): es la posición (transformación) que tienen los huesos de un modelo en 3D cuando asignas los huesos a las mallas de dicho modelo. Cualquier otra posición deforma las mallas del modelo. A las matrices que llevan esta información se les denomina matriz de vínculo o bind matrix. En los archivos collada las matrices de vínculo (inversas) de los huesos nombrados en el elemento <Name_array> pueden obtenerse del elemento <float_array> (que viene después de <Name_array>) en el elemento <skin> de dicho archivo. Hay que invertir las matrices en esta sección para obtener las que se van a palicar a los huesos. Estas transformaciones son con respecto al sistema del objeto armadura (no son locales!).
@@ -53,19 +53,23 @@ def import_collada_superbmd(context, filepath):
# remove the temporal file
os.remove(filepath + ".xml")
- ########################################
# reconstruct the skeleton for bind pose
# get the armature object and start doing math shidge
- armature = bpy.data.objects[-1] # last object imported
+ armature = None
+ for obj in scene.objects:
+ if (obj.select == True and obj.type == "ARMATURE"):
+ armature = obj
+ break
+ # ^ the collada importer selects the armature and its children
+ # last children is scene's active object
- # apply transform and select only the object
- blender_funcs.select_obj(scene, armature, False)
+ # apply transform and select only the object in edit mode
+ blender_funcs.select_obj(armature, False, "EDIT")
# Showtime (bind pose, meshes are already in their correct position)
# delete all bones in the armature
- bpy.ops.object.mode_set(mode = 'EDIT')
- bpy.ops.armature.select_all(action = 'SELECT')
+ bpy.ops.armature.select_all(action = "SELECT")
bpy.ops.armature.delete()
# get the bones bind matrices
@@ -92,7 +96,6 @@ def import_collada_superbmd(context, filepath):
break
# get the bone rest pose information
- bpy.ops.object.mode_set(mode='EDIT')
jnts_same_level = [jnt_root_node]
is_first_jnt = True
while (jnts_same_level != []):
@@ -136,8 +139,8 @@ def import_collada_superbmd(context, filepath):
else:
bone.matrix = rest_matrices[bone.name]
- # get to pose mode
- bpy.ops.object.mode_set(mode='POSE')
+ # get to pose mode and deform the meshes
+ blender_funcs.select_obj(armature, False, "POSE")
# set current pose to be rest pose and rest pose to be rest pose
for bone in armature.pose.bones:
@@ -147,21 +150,18 @@ def import_collada_superbmd(context, filepath):
bone.matrix = rest_matrices[bone.name]
# apply visual transform 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.convert(target='MESH')
+ blender_funcs.select_obj(child, False, "OBJECT")
+ bpy.ops.object.convert(target = "MESH")
# apply pose to rest pose
- blender_funcs.select_obj(scene, armature, False)
- bpy.ops.object.mode_set(mode='POSE')
+ blender_funcs.select_obj(armature, False, "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')
+ blender_funcs.select_obj(child, False, "OBJECT")
+ bpy.ops.object.modifier_add(type = "ARMATURE")
child.modifiers["Armature"].object = armature
child.modifiers["Armature"].use_vertex_groups = True
@@ -169,6 +169,22 @@ def import_collada_superbmd(context, filepath):
armature.scale = (0.01, 0.01, 0.01)
blender_funcs.transf_apply_recurse(scene, armature, True, True, True)
+ # change the rotation mode of the pose bones
+ for bone in armature.pose.bones:
+ bone.rotation_mode = "XYZ"
+
+ # remove doubles
+ for mesh in armature.children:
+ if (mesh.type == "MESH"):
+ blender_funcs.select_obj(mesh, False, "EDIT")
+ bpy.ops.mesh.select_all(action = "SELECT")
+ bpy.ops.mesh.remove_doubles()
+ bpy.ops.mesh.select_all(action = "DESELECT")
+ blender_funcs.select_obj(mesh, False, "OBJECT")
+
+ # re-select the armature object
+ blender_funcs.select_obj(armature, False, "OBJECT")
+
# done!
blender_funcs.disp_msg("SuperBMD Collada file imported!")
return {'FINISHED'}
@@ -193,6 +209,10 @@ class import_superbmd_collada(Operator, ExportHelper):
# ExportHelper mixin class uses this
filename_ext = ".dae"
filter_glob = StringProperty(default = "*.dae", options = {'HIDDEN'}, maxlen = 255)
+ bruh = BoolProperty(name = "Bruh?",
+ description = "LMAOOOOO I made you read",
+ default = False)
+
# execute function
def execute(self, context):
return import_collada_superbmd(context, self.filepath)