Http://wenku.baidu.com/view/a3ab7a26ee06eff9aef8077b.html
[the definition of each triangular patch includes the three-dimensional coordinates of each point of the triangle and the normal vector of triangular patches. It is a vector, a vertical line on a triangular plane]]
Science and Technology Law [E+n][e (representing an exponent) means multiplying the preceding number by the power of N of 10. ]:10 binary 123456789 = 1.23e+7
STL format
The most important feature of STL files is that it is composed of a series of triangular patches that do not reflect the topological relationship between triangular patches.
STL File Rules
(1) Total vertex rule
Each triangular patch must have a total of two vertices adjacent to each patch, i.e. the vertex of a triangular patch cannot fall on the edge of any adjacent triangular patches;
(2) Orientation rules
A single patch normal vector conforms to the right hand rule and its normal vector must point to the outside of the entity;
(3) Full of rules
The small triangular patches must be covered with all the surfaces of the three-dimensional model, without any omission;
(4) Rules for value-taking
The coordinate value for each vertex must be non-negative, i.e. the STL file entity should be in the first quadrant of the coordinate system.
Structure of file formats
The current STL file format includes binary files (binary) and text files (ASCII) for both
ASCII STL an ASCII STL file begins with the Line:solid name wher E name is an optional string (though if name is omitted there must still are a space after solid). The file continueswith any number of triangles, each represented as follows:
Solid filename STL//Custom file header
Facet nor Mal x y z//triangular patch normal vector 3 coordinates
Outer loop
Vertex v1x v1y v1z//triangular patch first vertex coordinates
Vertex v2x v2y v2z//triangular patch second vertex coordinate
V Ertex v3x v3y v3z//triangular patch third vertex coordinate
Endloop
Endfacet//complete a triangular patch definition
where each n or v are a floating point number in Sign-mantissa ' e '-sign-exponent format, e.g., " -2.648000e-002". Thefile concludes With:endsolid name the structure of the format suggests that other possibilities exist (e.g., facets wit H more than one ' loops ', or loops with more than three vertices) but in practice, all facets is simple triangles. White space (spaces, tabs, newlines) is used anywhere in the file except within numbers or words. The spaces between ' facet ' and ' normal ' and between ' outer ' and ' loop ' are required
Binary STL
Because ASCII STL files can become very large, a binary version of the STL exists. A binary STL file have an 80character header (which are generally ignored–but which should never begin with ' solid ' becaus E That'll leads Mostsoftware to assume that's an ASCII STL file). Following the header is a 4 byte unsigned integer indicating the number of triangular facets in the file. Following that's data describing each triangle in turn. The file simply endsafter the last triangle.
Each triangle was described by twelve 32-bit-floating point numbers:three for the normal and then three for the x/y/z coor Dinate of each vertex–just as with the ASCII version of the STL. After the twelve floats there is a and a byteunsigned ' short ' integer that's the ' attribute byte count ' –in the standard F Ormat, this should is zero because Mostsoftware does not understand anything else.
Floating point numbers was represented as IEEE floating point numbers and was assumed to being little endian, Althoughthis is not stated in documentation.
Uint8[80]–header//which is generally ignored–but which should never begin with ' solid ' because Ftware to assume that's an ASCII STL file
Uint32–number of triangles//indicating thenumber of triangular facets in the file.
foreach Triangle
Real32[3]–normal Vector
Real32[3]–vertex 1
Real32[3]–vertex 2
Real32[3]–vertex 3
Uint16–attribute byte Count
End
Color in binary STL
There is at least, variations on the binary, STL format for adding color information:
the Viscam and Solidview software packages use the and the "attribute byte count ' bytes at the end of every triangle to store A-bit RGB color:
bit 0 to 4 is the intensity level for blue (0 to 31)
Bits 5 to 9 is the intensity level for green (0 to 31)
bits to + is the intensity level for red (0 to 31)
bit 1 If the color is valid
bit 0 If the color is not valid (as with normal STL files)
the materialise Magics software does things a little differently. It uses the byte header at the top of the file to represent the overall color of the entire part. If color is used, then somewhere in the header should being the ASCII string "color=" followed by four bytes representing red , green, blue and alpha channel (transparency) in the range 0–255.
The the color of the entire object unless overridden at each facet. Magics also recognizes a material description; A more detailed surface characteristic. Just after "Color=rgba" specification should is another ASCII string ", material=" followed by three colors (3x4 bytes):
First is a color of diffuse reflection,
Second is a color of specular highlight,
And third is a ambient light.
Material settings is preferred over color. The Per-facet color is represented in the "attribute" byte count ' bytes as follows:
bit 0 to 4 is the intensity level for red (0 to 31)
Bits 5 to 9 is the intensity level for green (0 to 31)
bits to + is the intensity level for blue (0 to 31)
bit 0 If this facet have its own unique color
bit 1 If the per-object color is to be used
The red/green/blue ordering within those the bytes is reversed in these
–so While these formatscould easily has been compatible the reversal of the order of the colors means that they is not
–and worse still, ageneric STL file reader cannot automatically distinguish between them. There is also no-the-facets beselectively transparent because there is no Per-facet alpha value
–although in the context of the current rapid prototyping machinery.
Finally paste on, found on GitHub on the STL file parsing class:
Https://github.com/Ultimaker/ruby-admesh/blob/master/ext/admesh/admesh/src/stlinit.c
STL file Format