summaryrefslogtreecommitdiff
path: root/collada_bmd_bdl_import.py
diff options
context:
space:
mode:
Diffstat (limited to 'collada_bmd_bdl_import.py')
-rw-r--r--collada_bmd_bdl_import.py79
1 files changed, 71 insertions, 8 deletions
diff --git a/collada_bmd_bdl_import.py b/collada_bmd_bdl_import.py
index 9187193..8894af6 100644
--- a/collada_bmd_bdl_import.py
+++ b/collada_bmd_bdl_import.py
@@ -262,7 +262,7 @@ def read_bmd_bdl_collada(context, filepath, debug_messages, show_armature_pose):
[a[4], a[5], a[6], a[7]],
[a[8], a[9], a[10], a[11]],
[a[12], a[13], a[14], a[15]]
- ))
+ )).normalized()
controller_data[i].append(matrix)
@@ -323,7 +323,7 @@ def read_bmd_bdl_collada(context, filepath, debug_messages, show_armature_pose):
[a[4], a[5], a[6], a[7]],
[a[8], a[9], a[10],a[11]],
[a[12], a[13],a[14],a[15]]
- ))
+ )).normalized()
# append matrix to temp_matrices
temp_matrices.append(temp_matrix)
@@ -392,7 +392,7 @@ def read_bmd_bdl_collada(context, filepath, debug_messages, show_armature_pose):
[a[1], a[5], a[9], a[13]],
[a[2], a[6], a[10], a[14]],
[a[3], a[7], a[11], a[15]]
- ))
+ )).normalized()
###########
# bone data
@@ -478,8 +478,12 @@ def read_bmd_bdl_collada(context, filepath, debug_messages, show_armature_pose):
[a[4], a[5], a[6], a[7]],
[a[8], a[9], a[10], a[11]],
[a[12], a[13], a[14], a[15]]
- ))
-
+ )).normalized()
+ if (bone_matrix.determinant() == 0):
+ bone_matrix = Matrix(([1, 0, 0, 0],
+ [0, 1, 0, 0],
+ [0, 0, 1, 0],
+ [0, 0, 0, 1]))
rest_matrices.append(bone_matrix)
@@ -688,7 +692,7 @@ def read_bmd_bdl_collada(context, filepath, debug_messages, show_armature_pose):
# bone_parenting_diagram[i][j] == 1 returns True
# bone found, create it and assign name
- bpy.ops.armature.bone_primitive_add(name = bones_array[i])
+ bpy.ops.armature.bone_primitive_add(name = bones_array[i])
# find parent bone
# read the rows above the bone row to find its parent
@@ -717,7 +721,8 @@ def read_bmd_bdl_collada(context, filepath, debug_messages, show_armature_pose):
# apply transformation matrix (bind matrix)
armature.data.edit_bones[bones_array[i]].matrix = bind_matrices[i]
- break
+ break
+
# leave edit mode
bpy.ops.object.mode_set(mode='OBJECT')
@@ -775,7 +780,7 @@ def read_bmd_bdl_collada(context, filepath, debug_messages, show_armature_pose):
# armature has finished being built
- print("Re-build done!")
+ print("Re-build done!")
# assign meshes from old armature into new armature
# also reconect mesh's armature modifiers to the new armature
@@ -1004,7 +1009,65 @@ def read_bmd_bdl_collada(context, filepath, debug_messages, show_armature_pose):
elif (show_armature_pose == "OPT_C"):
print("Ignore Rest Pose done!")
+
+ # ~ ####################
+ # ~ # add model textures
+ # ~ ####################
+
+ # ~ # will search for textures in the same place the DAE file is
+ # ~ # if they are not there the program won't do anything
+
+ # ~ print("Getting Texture data...")
+ # ~ mat_json_path = filepath.split(".dae")[0] + "_materials.json"
+ # ~ print(mat_json_path)
+
+ # ~ # open materials JSON
+ # ~ f = open(mat_json_path, 'r', encoding='utf-8')
+
+ # ~ for i in range(len(armature.children)):
+ # ~ while True:
+ # ~ line = f.readline()
+ # ~ # material data start
+ # ~ if (line.find("\"Name\":") + 1):
+
+ # ~ # get mat name
+ # ~ mat_name = re.search(': "(.+?)",', line).group(1)
+
+ # ~ # find material along the
+
+
+ # ~ # get textures associated with this material
+ # ~ while True:
+ # ~ line = f.readline()
+ # ~ tex_name = "dummy"
+ # ~ if (line.find("\"TextureNames\":") + 1):
+ # ~ while (tex_name != ""):
+ # ~ tex_name = re.search('"(.+?)",', f.readline()).group(1)
+ # ~ break
+ # ~ break
+ # ~ break
+
+
+ # ~ for mesh in armature.children:
+ # ~ for i in range(len(mesh.data.materials)):
+ # ~ mesh.active_material_index = i
+ # ~ tex_slot = mesh.data.materials[i].texture_slots.add()
+ # ~ bpy.ops.texture.new() # create new texture
+ # ~ tex_slot.texture = bpy.data.textures[-1]
+
+ # ~ while True:
+
+ # ~ line = f.readline()
+
+ # ~ #########################
+ # ~ # controller start
+ # ~ # the skin stuff for each
+ # ~ # mesh is defined there
+ # ~ #########################
+ # ~ if (line.find("<controller") + 1):
+
# end importer
+ print("Done importing!")
return {'FINISHED'}