The binary format uses the IEEE integer and floating point numerical representation.
Binary (.STL) files are organized as an 84 byte header followed by 50-byte
records each of which describes one triangle facet:
| # of bytes | description |
|---|---|
| 80 | Any text such as the creator's name |
| 4 | int equal to the number of facets in file |
| facet 1 | |
| 4 4 4 4 4 4 4 4 4 4 4 4 2 |
float normal x float normal y float normal z float vertex1 x float vertex1 y float vertex1 z float vertex2 x float vertex2 y float vertex2 z float vertex3 x float vertex3 y float vertex3 z unused (padding to make 50-bytes) |
| facet 2 | |
| 4 4 4 4 4 4 4 4 4 4 4 4 2 |
float normal x float normal y float normal z float vertex1 x float vertex1 y float vertex1 z float vertex2 x float vertex2 y float vertex2 z float vertex3 x float vertex3 y float vertex3 z unused (padding to make 50-bytes) |
| facet 3 | |
| ... |
A facet entry begins with the x,y,z components of the triangle's face normal vector. The normal vector points in a direction away from the surface and it should be normalized to unit length. The x,y,z coordinates of the triangle's three vertices come next. They are stored in CCW order when viewing the facet from outside the surface. The direction of the normal vector follows the "right-hand-rule" when traversing the triangle vertices from 1 to 3, i.e., with the fingers of your right hand curled in the direction of vertex 1 to 2 to 3, your thumb points in the direction of the surface normal.
Notice that each facet entry is 50 bytes. So adding the 84 bytes in the header space, a binary file should have a size in bytes = 84 + (number of facets) * 50. Notice the 2 extra bytes thrown in at the end of each entry to make it a nice even 50. 50 is a nice number for people, but not for most 32-bit computers because they store values on 4-byte boundaries. Therefore, when writing programs to read and write .STL files the programmer has to take care to design data structures that accommodate this problem.
The recent introduction of colour RP introduced the need for a 'colour STL' extension. One of these proposed extension make use of the 2 padding bytes to store the RGB data. Click here to see the definition of the extension.
To read an .stl file into a 'big-endian' machine, one would use an 'inverse'
of the write operation, first reading the header, fishing out the number of
facets from the header (byte swapping the value), and then reading
Facet structures plus their 2-byte padding to make up 50-byte records.
Part of this introduction is an excerpt from technical documentation of Ennex Corporation and other sources.
For more detail or full version of the Ennex document, contact www.Ennex.com