The Polygon File Format (PLY) is one of the simplest formats to read or write a 3D mesh. It has both ASCII and binary formats, but we look at only the human-readable ASCII format here.
Consider a tetrahedron composed of these 4 points:
1.2 2.9 15.7
132.4 239.4 139.9
152.9 62.9 20.4
81.9 217.7 65.9
The simplest PLY file representing this tetrahedron would be:
ply
format ascii 1.0
element vertex 4
property float x
property float y
property float z
element face 4
property list uchar int vertex_index
end_header
1.2 2.9 15.7
132.4 239.4 139.9
152.9 62.9 20.4
81.9 217.7 65.9
3 0 1 2
3 0 1 3
3 0 2 3
3 1 2 3
It is easy to deduce the file format from the above representation:
The element vertex VERTEXNUM
is used to indicate the number of points.
The number type used for the point coordinates is indicated using the property float x
lines.
The element face FACENUM
is used to indicate the number of polygon faces in the mesh.
The number type used for the number of points in each face and the vertex indices of those points is indicated using property list uchar int vertex_index
. This means that the number of points in each face is of type uchar
and the vertex indices themselves are of type int
.
After the header, are a list of points, much like in the ASC file format.
After the points, are a list of the polygon faces. A line like 3 0 1 2
means that this face has 3 points (hence a triangle) and is composed of the vertices 0, 1 and 2. Note that PLY deals only with polygons (like triangles) and cannot deal with polyhedrons (like tetrahedrons).
PLY files can be opened and rendered in applications like MeshLab. PLY files can have many other features, please refer to the Wikipedia page for those details.