Skip to content Skip to sidebar Skip to footer

.OFF Files On Python

I've been practicing with Python and PyOpenGL, but I can't seem to open .OFF files (Object File Format) with Python. If you're wondering, .OFF files are files that contain position

Solution 1:

No idea on what the last field in the second line means. The rest can be deduced easily:

def read_off(file):
    if 'OFF' != file.readline().strip():
        raise('Not a valid OFF header')
    n_verts, n_faces, n_dontknow = tuple([int(s) for s in file.readline().strip().split(' ')])
    verts = [[float(s) for s in file.readline().strip().split(' ')] for i_vert in range(n_verts)]
    faces = [[int(s) for s in file.readline().strip().split(' ')][1:] for i_face in range(n_faces)]
    return verts, faces

Post a Comment for ".OFF Files On Python"