def write_off(file_path: str, vertices: np.ndarray, faces: np.ndarray,
              colors_vertex: np.ndarray = np.array([]), colors_face: np.ndarray = np.array([])) -> None:
    """
    Write mesh as .off file.
    :param file_path:
    :param vertices:
    :param faces:
    :param colors_vertex:
    :param colors_face:
    :return:
    """
    
    if len(vertices) == 0:
        return

    file_utils.make_dir_for_file(file_path)
    
    with open(file_path, 'w') as fp:  
        
        # write header
        if colors_face.size == 0 and colors_vertex.size == 0:
            fp.write("OFF\n")
        else:
            fp.write("COFF\n")
        
        # convert 2d vertices to 3d
        if len(vertices[0]) == 2:
            vertices_2p5d = np.zeros((len(vertices), 3))
            vertices_2p5d[:, :2] = vertices
            vertices_2p5d[:, 2] = 0.0
            vertices = vertices_2p5d

        # write number of elements
        fp.write(str(len(vertices)) + " " + str(len(faces)) + " 0\n")  # 0 for optional #edges
        
        # write vertices
        if colors_vertex.size == 0:
            for v in vertices:
                fp.write(str(v[0]) + " " + str(v[1]) + " " + str(v[2]) + "\n")
        else:
            color_channels = colors_vertex.shape[1]
            for vi, v in enumerate(vertices):
                line_vertex = str(v[0]) + " " + str(v[1]) + " " + str(v[2]) + " "
                # line_vertex = line_vertex + str(color_channels) + " "
                for c in range(color_channels):
                    line_vertex += str(colors_vertex[vi][c]) + " "
                fp.write(line_vertex + "\n")

        # write faces
        if colors_face.size == 0:
            for f in faces:
                fp.write(str(len(f)) + " " + str(f[0]) + " " + str(f[1]) + " " + str(f[2]) + "\n")
        else:
            color_channels = colors_face.shape[1]
            for fi, f in enumerate(faces):
                line_face = str(len(f)) + " " + str(f[0]) + " " + str(f[1]) + " " + str(f[2]) + " "
                # line_face = line_face + str(color_channels) + " " # not for meshlab
                for c in range(color_channels):
                    line_face += str(colors_face[fi][c]) + " "
                fp.write(line_face + "\n")

    Write mesh as .off file.
    :param file_path:
    :param vertices:
    :param faces:
    :param colors_vertex:
    :param colors_face:
    :return:
    
source/base/mesh_io.py