def generate_mesh(self, data): if "error" in data: print(data["error"]) return Mesh() meshes = [] for i in range(len(data["mesh_informations"])): mesh_data = {} mesh_infos = {} indi_clip = (data["mesh_informations"][i]["first_triangle"] * IQM_TRIANGLE_SIZE, (data["mesh_informations"][i]["first_triangle"] + data["mesh_informations"][i]["num_triangle"]) * IQM_TRIANGLE_SIZE) used_indices = data["indices"][indi_clip[0]:indi_clip[1]] mesh_infos["num_triangles"] = data["mesh_informations"][i][ "num_triangle"] mesh_infos["num_vertices"] = data["mesh_informations"][i][ "num_vertices"] mesh_infos["num_bones"] = 0 if "animation_data" in data: mesh_infos["num_bones"] = len(data["animation_data"]["joints"]) for j in range(len(data["buffers"])): name = "str_" + str(j) buf = data["buffers"][j] type = buf["data_type"][1] buf_data = buf["data"] mesh_data[name] = {} mesh_data[name]["type"] = GL_ARRAY_BUFFER mesh_data[name]["size"] = ctypes.sizeof(type * len(buf_data)) mesh_data[name]["data"] = (type * len(buf_data))(*buf_data) mesh_data[name]["attributes"] = [{}] mesh_data[name]["attributes"][0]["size"] = buf["size"] mesh_data[name]["attributes"][0]["normalized"] = buf[ "normalized"] mesh_data[name]["attributes"][0]["type"] = buf["data_type"][0] mesh_data[name]["attributes"][0]["stride"] = 0 mesh_data[name]["attributes"][0]["offset"] = 0 mesh_data["ibo"] = {} mesh_data["ibo"]["type"] = GL_ELEMENT_ARRAY_BUFFER mesh_data["ibo"]["size"] = ctypes.sizeof(GLuint * len(used_indices)) mesh_data["ibo"]["data"] = (GLuint * len(used_indices))(*used_indices) mesh = Mesh(data["mesh_informations"][i]["str_name"]) mesh.get_buffer().prepare_buffer(GL_TRIANGLES, len(used_indices), GL_UNSIGNED_INT, mesh_data) mesh.get_buffer().create_buffer() mesh.set_aabb(data["bboxes"][0]) mesh.assign_default_material( data["mesh_informations"][i]["material_obj"]) mesh.assign_mesh_data(data) mesh.set_informations(mesh_infos) if "animation_data" in data: mesh.set_animation_player_class(IQMMeshAnimationPlayer) meshes.append(mesh) return meshes
def generate_mesh(self, data): meshes = [] for i in range(len(data)): c_data = data[i] mesh_data = {} mesh_infos = {} mesh_infos["num_triangles"] = len(c_data["indices"]) / 3 mesh_infos["num_vertices"] = len(c_data["vertices"]) mesh_infos["num_bones"] = 0 #objs doesnt have any bones mesh_infos["center_of_mass"] = c_data["center_of_mass"] mesh_data["vbo"] = {} mesh_data["vbo"]["type"] = GL_ARRAY_BUFFER mesh_data["vbo"]["size"] = ctypes.sizeof(GLfloat * len(c_data["vertices"])) mesh_data["vbo"]["data"] = (GLfloat * len(c_data["vertices"])) (*c_data["vertices"]) mesh_data["vbo"]["attributes"] = [] mesh_data["vbo"]["attributes"].append({}) mesh_data["vbo"]["attributes"][0]["size"] = 3 mesh_data["vbo"]["attributes"][0]["type"] = GL_FLOAT mesh_data["vbo"]["attributes"][0]["stride"] = 8 * ctypes.sizeof(GLfloat)#every 6 byte defines the next start_position of an vertex mesh_data["vbo"]["attributes"][0]["offset"] = 0 mesh_data["vbo"]["attributes"][0]["normalized"] = GL_FALSE mesh_data["vbo"]["attributes"].append({}) mesh_data["vbo"]["attributes"][1]["size"] = 3 mesh_data["vbo"]["attributes"][1]["type"] = GL_FLOAT mesh_data["vbo"]["attributes"][1]["stride"] = 8 * ctypes.sizeof(GLfloat)#start_pos mesh_data["vbo"]["attributes"][1]["offset"] = 3 * ctypes.sizeof(GLfloat)#start_pos + offset mesh_data["vbo"]["attributes"][1]["normalized"] = GL_FALSE mesh_data["vbo"]["attributes"].append({}) mesh_data["vbo"]["attributes"][2]["size"] = 2 mesh_data["vbo"]["attributes"][2]["type"] = GL_FLOAT mesh_data["vbo"]["attributes"][2]["stride"] = 8 * ctypes.sizeof(GLfloat)#start_pos mesh_data["vbo"]["attributes"][2]["offset"] = 6 * ctypes.sizeof(GLfloat)#start_pos + offset mesh_data["vbo"]["attributes"][2]["normalized"] = GL_FALSE mesh_data["ibo"] = {} mesh_data["ibo"]["type"] = GL_ELEMENT_ARRAY_BUFFER mesh_data["ibo"]["size"] = ctypes.sizeof(GLuint * len(c_data["indices"]) ) mesh_data["ibo"]["data"] = (GLuint * len(c_data["indices"])) (*c_data["indices"]) c_data["aabb"].calculate_base_knots() mesh = Mesh(c_data["name"]) mesh.get_buffer().prepare_buffer(c_data["type"][0], len(c_data["indices"]),GL_UNSIGNED_INT, mesh_data) mesh.get_buffer().create_buffer() mesh.set_informations(mesh_infos) mesh.set_aabb(c_data["aabb"]) mesh.assign_default_material( c_data["material"] ) meshes.append(mesh) return meshes