Beispiel #1
0
def update_mesh_data(mesh: bpy.types.Mesh):
    global mario_geo
    vcol = mesh.vertex_colors.active
    for i in range(mario_geo.numTrianglesUsed):
        mesh.vertices[3 * i +
                      0].co.x = mario_geo.position_data[9 * i +
                                                        0] / SM64_SCALE_FACTOR
        mesh.vertices[3 * i +
                      0].co.z = mario_geo.position_data[9 * i +
                                                        1] / SM64_SCALE_FACTOR
        mesh.vertices[
            3 * i +
            0].co.y = -mario_geo.position_data[9 * i + 2] / SM64_SCALE_FACTOR
        mesh.vertices[3 * i +
                      1].co.x = mario_geo.position_data[9 * i +
                                                        3] / SM64_SCALE_FACTOR
        mesh.vertices[3 * i +
                      1].co.z = mario_geo.position_data[9 * i +
                                                        4] / SM64_SCALE_FACTOR
        mesh.vertices[
            3 * i +
            1].co.y = -mario_geo.position_data[9 * i + 5] / SM64_SCALE_FACTOR
        mesh.vertices[3 * i +
                      2].co.x = mario_geo.position_data[9 * i +
                                                        6] / SM64_SCALE_FACTOR
        mesh.vertices[3 * i +
                      2].co.z = mario_geo.position_data[9 * i +
                                                        7] / SM64_SCALE_FACTOR
        mesh.vertices[
            3 * i +
            2].co.y = -mario_geo.position_data[9 * i + 8] / SM64_SCALE_FACTOR
        mesh.uv_layers.active.data[mesh.loops[3 * i + 0].index].uv = (
            mario_geo.uv_data[6 * i + 0], mario_geo.uv_data[6 * i + 1])
        mesh.uv_layers.active.data[mesh.loops[3 * i + 1].index].uv = (
            mario_geo.uv_data[6 * i + 2], mario_geo.uv_data[6 * i + 3])
        mesh.uv_layers.active.data[mesh.loops[3 * i + 2].index].uv = (
            mario_geo.uv_data[6 * i + 4], mario_geo.uv_data[6 * i + 5])
        vcol.data[3 * i + 0].color = (mario_geo.color_data[9 * i + 0],
                                      mario_geo.color_data[9 * i + 1],
                                      mario_geo.color_data[9 * i + 2], 1.0)
        vcol.data[3 * i + 1].color = (mario_geo.color_data[9 * i + 3],
                                      mario_geo.color_data[9 * i + 4],
                                      mario_geo.color_data[9 * i + 5], 1.0)
        vcol.data[3 * i + 2].color = (mario_geo.color_data[9 * i + 6],
                                      mario_geo.color_data[9 * i + 7],
                                      mario_geo.color_data[9 * i + 8], 1.0)
    mesh.update()
Beispiel #2
0
    def export_mesh(self, mesh: bpy.types.Mesh, vertex_groups: List[bpy.types.VertexGroup], bone_names: List[str])->MeshStore:

        def get_texture_layer(layers):
            for l in layers:
                if l.active:
                    return l

        mesh.update(calc_tessface=True)
        uv_texture_faces = get_texture_layer(mesh.tessface_uv_textures)
        store = MeshStore(mesh.name, mesh.vertices,
                          mesh.materials, vertex_groups, bone_names)
        for i, face in enumerate(mesh.tessfaces):
            submesh = store.get_or_create_submesh(face.material_index)
            for triangle in store.add_face(face, uv_texture_faces.data[i] if uv_texture_faces else None):
                for fv in triangle:
                    submesh.indices.append(fv)

        self.mesh_stores.append(store)
        return store