Every PLY file starts with a text header, whatever the encoding of its data. The header names the encoding, then declares each kind of element the file holds, how many there are, and the properties each one carries. A reader needs nothing else to find its way through the data that follows.
Header lines
The header is a series of lines of ASCII text, each starting with a keyword. Keywords
and type names are lower case. Words on a line are separated by spaces. Greg Turk’s
description calls the lines “carriage-return terminated”; in practice files end each
line with a line feed (0A), and some readers, RPly for one, also accept a
carriage return and line feed when the first line is written that way.
| Line | Where | Meaning |
|---|---|---|
ply | First line, exactly | The magic number: the bytes 70 6C 79 and the line end |
format encoding version | Second line | How the data after the header is written |
comment text | Any line after the first | A comment; the rest of the line is free text |
obj_info text | Any line after the first | Information about the object as a whole, as free text |
element name count | Any number, in data order | Starts the declaration of one kind of element, and how many items of it follow |
property type name | After an element line | One scalar value that each item of that element carries |
property list count-type item-type name | After an element line | A variable-length list that each item carries |
end_header | Last line | Ends the header; the data starts on the next byte |
format – Data encoding
The format line names one of three encodings and the version of the format. The only
version ever defined is 1.0. Turk’s reader does not check it: it converts
the word to a number and carries on, and it refuses the file only for a format name
other than the three below or a format line that does not have exactly three words.
| Encoding | Data |
|---|---|
ascii | Numbers written as text, separated by white space |
binary_little_endian | Packed binary values, least significant byte first |
binary_big_endian | Packed binary values, most significant byte first |
The header is the same text in all three. Data encodings describes each one.
comment and obj_info
A comment line holds any text, which readers ignore. Turk’s examples use
them for the author and the object’s name. His library drops the spaces and tabs
after the word comment and keeps the rest of the line (ply.c,
add_comment).
An obj_info line holds information about the object as a whole, also as
free text. It is not in Turk’s description (PLY_FILES.txt), but his
library reads and writes it the same way as a comment, and so do libraries such as
RPly; the Stanford range scans use it for the grid size and the scanner’s settings.
Both kinds of line are optional, and their order relative to each other does not
matter. A line that begins with any other word is skipped by Turk’s reader, which
looks only for the words it knows.
element – Declaring elements
An element line gives a name and a count. Every property line
after it, up to the next element line or end_header, belongs
to that element. The data holds the elements in the same order as the header, all the
items of the first element, then all the items of the second, and so on.
Element and property names are chosen by the writer. A reader looks for the names it knows and skips the rest, which it can do because the header gives the size and type of everything. Turk’s description asks writers to reuse the usual elements and property names below, rather than invent new ones, so that other programs can read the data.
Scalar types
Each property has a type. Two sets of names are in use: the sized names
(int8 to float64), which are the names in Turk’s description
and the ones ply.c writes, and the older C-style names (char
to double), which ply.c lists as “old names of types for
backward compatibility” and which many programs still write. Readers should accept
both, and Turk’s does. The sizes must not vary between implementations, so that files
stay portable.
| Name | Also written | Size | Meaning |
|---|---|---|---|
char | int8 | 1 | Signed integer |
uchar | uint8 | 1 | Unsigned integer |
short | int16 | 2 | Signed integer |
ushort | uint16 | 2 | Unsigned integer |
int | int32 | 4 | Signed integer |
uint | uint32 | 4 | Unsigned integer |
float | float32 | 4 | IEEE 754 single-precision floating point |
double | float64 | 8 | IEEE 754 double-precision floating point |
Signed integers are two’s complement.
Turk’s description says a property can be a scalar, a string or a list, and his
library reads and writes property string name, though the
description gives no example. In ASCII the value is a word or text in double quotes
(the library writes the quotes and reads up to the closing quote, so the text may hold
spaces); in binary it is a four-byte integer holding the length, counting the zero
byte, then the characters, then the zero byte. Turk’s ply.c does no byte
swapping anywhere: it writes the length with fwrite of a C int,
so the length is in the byte order of the machine that wrote the file, which is not
necessarily the one the format line declares (the library names the
format after that machine, so for files it wrote the two agree). The explorer reads
the length in the declared order. Most other readers do not know the type and refuse
the file.
property list – Lists
A list property carries a variable number of values. Its declaration gives two types: the type of the count, then the type of each item. In the data, each list is its count followed by that many items.
element face 2
property list uchar int vertex_index
end_header
3 0 1 2
4 0 2 3 4
The count type must be an integer type; uchar is usual, which limits a
list to 255 items. Vertex numbers in a face count from 0, in the order the vertices
appear in the data. Paul Bourke’s copy of Turk’s description states that a face’s
vertices make a triangle fan, not a triangle strip: a face with vertices
a b c d is the triangles a b c and a c d. The sentence
is not in the 2020 PLY_FILES.txt of the Georgia Tech distribution, and the
file format itself stores only the polygon; how a program cuts a polygon into triangles
is its own choice (the explorer fans a convex one and cuts a concave one into ears).
The usual elements
These elements and properties appear in Turk’s description and its examples.
| Element | Property | Type in the examples | Meaning |
|---|---|---|---|
vertex | x, y, z | float | Position |
vertex | red, green, blue | uchar | Colour, 0 to 255 |
face | vertex_index | list uchar int | The face’s vertex numbers |
edge | vertex1, vertex2 | int | The vertex numbers at the two ends |
edge | red, green, blue | uchar | Colour of the edge |
material | ambient_red, ambient_green, ambient_blue | uchar | Ambient colour |
material | ambient_coeff | float | Ambient coefficient |
material | diffuse_red, diffuse_green, diffuse_blue | uchar | Diffuse colour |
material | diffuse_coeff | float | Diffuse coefficient |
material | specular_red, specular_green, specular_blue | uchar | Specular colour |
material | specular_coeff | float | Specular coefficient |
material | specular_power | float | Specular exponent |
Many programs write the face list as vertex_indices instead of
vertex_index, so readers usually accept both. Other names are conventions
of later programs rather than part of the description: for example nx,
ny and nz for a vertex normal, alpha for opacity,
and s and t or u and v for texture
coordinates. A point cloud is simply a file with a vertex element and no
face element.
Names later programs use
The description leaves a great deal to convention, and the conventions below come
from the programs that read and write PLY today. Each line says where it was read:
Turk’s own library and description (ply.h, ply.c and
PLY_FILES.txt, the 2020 Georgia Tech copy), the source of MeshLab’s
reader and writer (vcglib import_ply.h and export_ply.h),
PCL (ply_io.cpp), CloudCompare (PlyFilter.cpp), Assimp,
CGAL, Blender’s importer, Open3D’s reader or the 3D Gaussian Splatting training code,
and the files the Stanford 3D Scanning Repository, MeshLab, VCGlib, Assimp, CGAL and
PCL publish. Where a name means something only to the program that wrote the file
(a scanner’s intensity, a program’s own quality or
flags), the explorer shows the value as written and says in the tree
that its meaning is the writer’s; the layouts of range_grid,
camera, texcoord and TextureFile are set out
under Range grids, cameras and textures.
| Element | Property | Meaning | Source |
|---|---|---|---|
vertex | x y z | Position; any number type | Turk; Blender, Open3D read them as required |
vertex | nx ny nz | Normal, which should be of length 1 | Blender, Open3D, 3D Gaussian Splatting (written as zeros) |
vertex | red green blue, alpha | Colour and opacity. uchar is usual, 0 to 255; some writers use float 0 to 1 (or 0 to 255). MeshLab also reads diffuse_red, diffuse_green, diffuse_blue, diffuse_alpha | Turk’s second example (red green blue); Blender (reads alpha too), Open3D, MeshLab (float colours 0 to 1), PCL |
vertex | s t | Texture coordinates | Turk’s obj2ply and sphereply write them; Blender, MeshLab, Assimp |
vertex | u v, texture_u texture_v, texture_s texture_t | Other spellings of the same. Assimp also takes tx ty | MeshLab reads texture_u texture_v; Assimp reads u v and texture_u texture_v. texture_s texture_t is read by the explorer only, and no source read for this reference uses it |
vertex | material_index | Number of an item of the material element | Turk (the material example in PLY_FILES.txt) |
vertex | confidence | The scanner’s confidence in the sample, in the Stanford zipper output (0 to 1). A quality value, whose meaning is the scanner software’s | MeshLab reads it as the vertex quality; Stanford bunny reconstruction files |
vertex | intensity | Strength of the scanner’s return, usually 0 to 1. With no colour in the file, MeshLab shows it as a grey; PCL keeps it as a field and CloudCompare as a scalar field | MeshLab (import_ply.h calls it “a strange way to code single channel color … in rangemap”); Stanford bunny reconstruction files |
vertex | quality, flags, radius | A per-vertex quality number, flag bits and a point radius; their meaning is the writing program’s | MeshLab |
face | vertex_indices, vertex_index | The vertex numbers; both spellings are in use, and a face element with a single list property is read as that. Turk’s description and example use vertex_index, his programs vertex_indices | Turk; Blender, Open3D, MeshLab (both) |
face | red green blue, alpha | Colour of the whole face | MeshLab; CGAL’s sample colored_tetra.ply |
face | texcoord | property list uchar float texcoord: two numbers (u, v) for each corner of the face, in the order of the vertex list, so a list of 2 × corners numbers. A face whose count differs is refused by MeshLab; CloudCompare accepts 6 or 8 numbers | MeshLab; CloudCompare; sample files TextureDouble.ply, uccello200.ply |
face | texnumber | property int texnumber: which TextureFile comment the face’s coordinates refer to, counting from 0. Absent: the first | MeshLab; CloudCompare; TextureDouble.ply |
face | flags, quality, nx ny nz, material_index | Face flag bits, a face quality, a face normal; material_index is a number into the material element | MeshLab; Turk |
edge | vertex1 vertex2 | The vertex numbers at the two ends | Turk; Open3D |
edge | red green blue | Colour of the edge. Turk’s second example writes it | Turk (PLY_FILES.txt); CGAL’s colored_tetra.ply has an edge confidence instead |
tristrips | vertex_indices (a list) | One item holding every strip: vertex numbers, with -1 between strips. Triangle k of a strip takes the three numbers ending at k, every other one turned over so that all face the same way; a triangle with a repeated number is dropped | Blender’s importer |
range_grid | property list uchar int vertex_indices | The scanner’s grid: one item for each cell of the scan, in rows, holding the one vertex seen there or no number at all where the scanner saw nothing. Layout below | PCL; Stanford’s range scans (10 files read); not in Turk’s library or description |
camera | twenty-three properties, view_px to k4 | Where a scan or a photograph was taken from and with what lens. Layout below | MeshLab (reads and writes); PCL (reads some); faccia000.ply; not in Turk’s library or description |
material | ambient_red … specular_power | Colours and coefficients, as in the table above; a face’s or vertex’s material_index picks an item | Turk |
Comments follow the same habit: comment TextureFile name
names the texture image for the texture coordinates (a MeshLab convention, read
from vcglib; details below), and comment
lines at the top often name the program that wrote the file. Gaussian splat scenes
use the vertex element with their
own property names; they have their own pages:
3D Gaussian Splatting PLY,
2D Gaussian Splatting PLY and
PlayCanvas compressed PLY.
Turk’s description itself contains slips: the vertex colour lines of its second
example (property red uint8) and every line of its material example
(property ambient_red uint8) put the name before the type, where the rule
in the same text and all the other lines (and the reader in his ply.c,
whose add_property takes the type from the first word) put the type
first. Read as written, those lines are not valid.
Range grids, cameras and textures
These four conventions are not in Turk’s library or in his description (the files
ply.h, ply.c and PLY_FILES.txt of the Georgia
Tech distribution were read for this; none of the four words is in them). They were
read from the sources of the programs that write and read them, and checked against
real files: ten Stanford range scans of the bunny, the MeshLab range map
faccia000.ply, and MeshLab’s texture samples
TextureDouble.ply, TextureSingle.ply and
uccello200.ply. A program reading a PLY file is free to ignore any of
them: they only say what the values mean when the program that wrote them is the
one that reads them.
range_grid
A scanner takes a grid of samples, a cell for each row and column of its sensor. A
PLY file from a scanner keeps the samples in the vertex element
(the cells that saw something, in cell order) and the grid in a
range_grid element with one item for each cell. An item is a list of
vertex numbers: one number for a cell that has a sample, and none for a cell where
the scanner saw nothing. The header of a Stanford scan (bun000.ply,
ASCII, from 1996):
ply
format ascii 1.0
obj_info is_cyberware_data 1
obj_info is_mesh 0
obj_info num_cols 512
obj_info num_rows 400
element vertex 40256
property float x
property float y
property float z
element range_grid 204800
property list uchar int vertex_indices
end_header
obj_info
lines about the scanner’s optics, echo_rgb_* and
echo_lgincr). After 40,256 lines of three numbers come 204,800 lines of
the grid: 0 for an empty cell, 1 7 for a cell holding
vertex 7.| Part | What it is | Checked in |
|---|---|---|
obj_info num_cols, num_rows | The grid’s width and height. The element’s item count is their product (512 × 400 = 204,800) | all ten Stanford scans |
| Cell number | Item i is the cell in column i mod num_cols and row i div num_cols: the file goes along a row, then to the next. Measured over each scan: the next cell along a row holds a vertex 0.7 to 0.9 mm away on average, the cell a row on 1.0 to 1.3 mm, and a cell 400 places on 58 to 68 mm (the scans are in metres), so the grid is laid out 512 across and 400 down | all ten Stanford scans (a script of mine in Research/Specs/ply) |
| The list | A count (uchar, 0 or 1) and the vertex number (int). The numbers rise from cell to cell, and every vertex is in exactly one cell | all ten |
obj_info is_mesh 0 | The file has no faces: the grid is how the samples are neighbours. Joining neighbours into triangles is a step for the program (Stanford’s tools did it), and the file does not say which neighbours to join | the Stanford scans (the word is the scanner software’s; the file does not define it) |
| PCL | Reads a range_grid as an organised cloud: one point for each cell, the cell’s vertex or, for an empty list, a point whose coordinates are NaN. The width and height come from the camera element’s viewportx and viewporty | PCL ply_io.cpp |
The other obj_info lines of the Stanford scans (is_cyberware_data,
is_warped, is_interlaced, echo_rgb_offset_x and
so on) are the scanner software’s own: the file defines none of them, so the explorer
shows them as written.
camera
MeshLab writes one camera element of one item when a model has a
shot (a camera position it was taken from), and PCL reads the position, the axes and
the size of the image. The properties, in the order MeshLab writes them (binary
little-endian offsets, as in faccia000.ply, which holds exactly this and
nothing else before its vertex element: 92 bytes):
| Offset | Property | Type | Meaning |
|---|---|---|---|
| 0 | view_px view_py view_pz | float × 3 | The camera’s position, in the model’s coordinates |
| 12 | x_axisx x_axisy x_axisz | float × 3 | First row of the 3 × 3 rotation matrix |
| 24 | y_axisx y_axisy y_axisz | float × 3 | Second row |
| 36 | z_axisx z_axisy z_axisz | float × 3 | Third row, the direction the camera looks along: in faccia000.ply the model is on this side (the camera is at (0, 0, 21.6), looks along (0, 0, −1), and the model’s middle is 800 units away along it) |
| 48 | focal | float | Distance from the focal centre to the image plane, in the unit of the pixel size (millimetres: 14.38 in the sample) |
| 52 | scalex scaley | float × 2 | Width and height of one pixel (0.0074 and 0.0074) |
| 60 | centerx centery | float × 2 | Where the focal centre projects onto the image, in pixels (320, 240) |
| 68 | viewportx viewporty | int × 2 | Size of the image in pixels (640 × 480) |
| 76 | k1 k2 k3 k4 | float × 4 | Radial lens distortion; MeshLab writes zeros |
The vertical field of view of the picture is then 2 · atan(viewporty ·
scaley / 2 / focal) (14.08° in the sample): that is worked
out by the explorer from the table above, and is not written in the file. Other
programs write a camera element with other properties; the explorer lists
those as they are, and the meaning is the writer’s.
TextureFile, texcoord and texnumber
A header comment comment TextureFile name names a picture
file; there may be several. MeshLab and CloudCompare write and read it;
CloudCompare looks for the picture in the folder of the PLY file, and MeshLab’s reader
keeps the name and leaves finding the picture to the program. MeshLab reads the keyword exactly as
written and takes the name from the character after it, throwing away spaces and any
character outside 33 to 124; CloudCompare compares the keyword without regard to
case and trims the name. MeshLab replaces <this> in the name with the
PLY file’s own name without folder and without .ply, so the pictures follow
a renamed model. The textured faces carry two properties:
ply
format ascii 1.0
comment VCGLIB generated
comment TextureFile <this>_A.png
comment TextureFile <this>_B.png
element vertex 8
property float x
property float y
property float z
element face 4
property list uchar int vertex_indices
property list uchar float texcoord
property int texnumber
end_header
0 0 0
…
3 0 1 2 6 0 0 1 0 1 1 0
3 0 2 3 6 0 0 1 1 0 1 0
3 4 5 6 6 0 0 1 0 1 1 1
TextureDouble.ply (the first face’s line:
three vertices 0 1 2, then six numbers, the texture coordinates
(0, 0) (1, 0) (1, 1), then texture 0). Beside TextureDouble.ply are
TextureDouble_A.png and TextureDouble_B.png.texcoord:property list uchar float texcoord, two numbers (u, then v) for each corner of the face in the order of the face’s vertex list, so 2 × the vertex count numbers. MeshLab refuses a face with another count; CloudCompare accepts 6 or 8 numbers (three or four corners). v grows upwards: the bottom edge of the picture is v = 0 (inTextureDouble_A.pngthe labels (0,0) and (1,1) sit at the bottom left and top right where the coordinates put them).texnumber:property int texnumber, the number of theTextureFilecomment, from 0, that the face’s coordinates refer to. A file with one picture may leave it out. Coordinates beyond 0 to 1 repeat the picture (TextureSingle.plyuses 0 to 2).- Vertex texture coordinates (
s tand the other spellings above) may be used instead of the face list; the picture is then named the same way. - A face’s own
colorlist (property list uchar float color, three numbers a corner) is MeshLab’s per-corner colour; MeshLab refuses a face whose count is not three times the corners.
Header faults
| Fault | What readers do; what the explorer does |
|---|---|
No end_header, no format line, an unknown format name | Refused. The explorer shows the header lines and the bytes after as unread |
A type that is not one of the sixteen names (int64, half, bool, a misspelling) | Refused, naming the type |
A version other than 1.0 | Python’s plyfile refuses it; Turk’s ply.c does not look at it; the explorer reads on and notes it |
| A blank line, an unknown keyword | plyfile skips blank lines; others refuse unknown keywords. The explorer notes both and reads on |
| A float as the list count type | Noted; the count is still read as the type says |
| The same element or property name twice | Noted. Only one of them is found by name, which is the source of many wrong colours |
| An element with no properties | Its items take no bytes; noted |
| A header that never ends (over 4 MB) | The explorer stops looking and refuses the file |
| CR LF or CR alone as line ends | Accepted in the header. The data starts after the line end of end_header |
A text file named .ply | Not PLY: the first line must be ply by itself. The explorer turns it down |
A complete header
ply
format ascii 1.0
comment author: Greg Turk
comment object: another cube
element vertex 8
property float x
property float y
property float z
property uchar red
property uchar green
property uchar blue
element face 7
property list uchar int vertex_index
element edge 5
property int vertex1
property int vertex2
property uchar red
property uchar green
property uchar blue
end_header