def format_matrix(list_in): rt_list = [] for mat in list_in: vec_list = export_static.format_vector(mat) temp = vec_list[0] for ix in range(1, len(vec_list)): temp += " "+vec_list[ix] rt_list.append(temp) return rt_list
def package_mesh_anim(scene, objects_mesh, o_arma, arma, coll_action): # bone offset, all meshes need to has same matrix_basis o_mesh = bpy.data.objects[objects_mesh[0]] offset = data_offset(o_mesh, o_arma, arma) # hierarchy = data_hierarchy(arma) txt_offset = package_offset(format_matrix(offset)) txt_hierarchy = package_hierarchy(hierarchy) txt_coll_anim_clip = [] len_anim_clip = 0 # action for action in coll_action: anim_clip = data_anim_clip(scene, action, o_arma) txt_time = number_to_str(anim_clip[0]) txt_pos = export_static.format_vector(anim_clip[1]) txt_sca = export_static.format_vector(anim_clip[2]) txt_rot = export_static.format_vector(anim_clip[3]) txt_anim_clip = package_anim_clip(txt_time, txt_pos, txt_sca, txt_rot) txt_coll_anim_clip.append("AnimationClip "+action.name) txt_coll_anim_clip.append("{") txt_coll_anim_clip += txt_anim_clip txt_coll_anim_clip.append("}") len_anim_clip += 1 # mesh data init txt_vertex = [] txt_triangle = [] sub_vertex_start = [0] sub_vertex_count = [] sub_face_start = [0] sub_face_count = [] txt_material = [] # build mesh data for ix in objects_mesh: # arrange vertex accroding uv o_mesh = bpy.data.objects[ix] mesh = bpy.data.objects[ix].data uv, uv_ex_dict, tessface = export_static.data_uv_and_face(mesh) len_uv = len(uv) # triangle and vertex triangle = export_static.data_triangle(tessface) position = export_static.data_position(mesh, len_uv, uv_ex_dict) normal = export_static.data_normal(mesh, len_uv, uv_ex_dict) tangent = export_static.data_tangent(len_uv, position, normal, uv, triangle) # vertex txt_uv = export_static.format_vector(uv) txt_position = export_static.format_vector(position) txt_normal = export_static.format_vector(normal) txt_tangent = export_static.format_vector(tangent) # subset sub_vertex_count.append(len_uv) sub_face_count.append(len(triangle)) if len(sub_vertex_count) > 1: sub_vertex_start.append(sub_vertex_start[-1]+sub_vertex_count[-2]) sub_face_start.append(sub_face_start[-1]+sub_face_count[-2]) triangle = export_static.offset_triangle(triangle, sub_vertex_start[-1]) txt_triangle += export_static.format_triangle(triangle) # material txt_material += export_static.txt_matrial(mesh) # bone weight and index ble_index_weight = data_ble_index_weight(mesh, o_mesh) ble_index_weight = data_ble_index_weight_add(len_uv, uv_ex_dict, ble_index_weight) txt_ble_index = format_index(ble_index_weight[0]) txt_ble_weight = export_static.format_vector(ble_index_weight[1]) txt_vertex += package_vertex_anim\ (len_uv, txt_position, txt_normal, txt_tangent, txt_uv, txt_ble_index, txt_ble_weight) # subset table txt_subset = [] for ix in range(0, len(sub_vertex_start)): temp_str = "SubsetID: "+str(ix)+" " temp_str += "VertexStart: "+str(sub_vertex_start[ix])+" " temp_str += "VertexCount: "+str(sub_vertex_count[ix])+" " temp_str += "FaceStart: "+str(sub_face_start[ix])+" " temp_str += "FaceCount: "+str(sub_face_count[ix]) txt_subset.append(temp_str) txt_subset.append("") return [txt_vertex, txt_triangle, txt_subset, txt_material, \ txt_offset, txt_hierarchy, txt_coll_anim_clip, len_anim_clip]