User Tools

Site Tools


tutorials:opengl_ply_mesh

Stanford Polygon (PLY) Format

In class, we talked about meshes. Meshes are continuous surfaces that are approximated as a series of connected polygons. These polygons are usually either triangles or quads.
For your projects, you'll be using PLY files, also known as Stanford Polygon files. The PLY file can be generalized as consisting of two sections: the header and the body. The header describes the format of the contents of the body. Below is an example header from the cow model we worked with in class.

ply
format ascii 1.0
comment Created by Blender 2.79
element vertex 2154
property float x
property float y
property float z
property float nx
property float ny
property float nz
property float s
property float t
element face 718
property list uchar uint vertex_indices
end_header

The header always begins with the line “ply” and ends with the line “end_header”. Everything after the “end_header” line is the body. The second line specifies the file format. Notice that comments can also be inserted into the header. Probably the most important parts of the header are the element lines. The first element line in the header typically describes the “vertex” section of the body. A number is provided at the end of this line. This specifies the total number of vertices stored in the body. The vertex section of the file contains the <x,y,z> coordinates of a vertex, at a minimum. Usually, an <x,y,z> normal is also provided, but it can also have things like colors and texture coordinates. The property lines following the element line specify the datatype and kind of data stored in each line. The second element line describes number of faces in the model. The face lines in the body consist of at least three integers. The first integer tells how many remaining integers are on the line. The remaining integers indicate the indices of the vertices that compose a given face. Once you have the vertex indices, you can reference the vertices stored at these indices to specify a polygon representing a given face.

tutorials/opengl_ply_mesh.txt · Last modified: 2021/08/01 00:52 by jones