http://wenku.baidu.com/view/a3ab7a26ee06eff9aef8077b.html

[每个三角形面片的定义包括三角形各个定点的三维坐标及三角形面片的法矢量[三角形的法线。它是一个向量,是三角形平面上的一条垂线]]
科学技术法[e+n][E(代表指数)表示将前面的数字乘以 10 的 n 次幂。]:10进制123456789 = 1.23e+7

stl格式
STL文件的最大特点也是其主要问题是,它是由一系列的三角形面片无序排列组合在一起的,没有反映三角形面片之间的拓扑关系

STL文件规则
(1)共顶点规则
每一个三角面片必须与其相邻的每一个面片共两个顶点 ,即一个三角面片的顶点不能落在相邻的任何三角面片的边上;

(2)取向规则
单个面片法向量符合右手法则且其法向量必须指向实体外面;

(3)充满规则
小三角面片必须布满三维模型的所有表面,不得有任何遗漏;

(4)取值规则
每个顶点的坐标值必须为非负 ,即 STL 文件的实体应该在坐标系的第一象限.

文件格式的结构
目前的STL文件格式包括二进制文件(BINARY)和文本文件(ASCII)两种
ASCII STL An ASCII STL file begins with the line:solid name where name is an optional string (though if name is omitted there must still be a space after solid). The file continueswith any number of triangles, each represented as follows:
solid filename stl //自定义文件头
facet normal x y z //三角面片法向量的3个坐标
outer loop
vertex v1x v1y v1z //三角面片第一个顶点坐标
vertex v2x v2y v2z //三角面片第二个顶点坐标
vertex v3x v3y v3z //三角面片第三个顶点坐标
endloop
endfacet //完成一个三角面片定义

where each n or v is 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 with more than one 'loop', or loops with more than three vertices) but in practice, all facets are simple triangles. White space (spaces, tabs, newlines) may be 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 STL exists. A binary STL file has an 80character header (which is generally ignored – but which should never begin with 'solid' because that will lead mostsoftware to assume that this is an ASCII STL file). Following the header is a 4 byte unsigned integer indicating the number of triangular facets in the file. Following that is data describing each triangle in turn. The file simply endsafter the last triangle.
Each triangle is described by twelve 32-bit-floating point numbers: three for the normal and then three for the X/Y/Z coordinate of each vertex – just as with the ASCII version of STL. After the twelve floats there is a two byteunsigned 'short' integer that is the 'attribute byte count' – in the standard format, this should be zero because mostsoftware does not understand anything else.
Floating point numbers are represented as IEEE floating point numbers and are assumed to be little endian, althoughthis is not stated in documentation.

UINT8[80] – Header //which is generally ignored – but which should never begin with 'solid' because that will lead most software to assume that this is 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 are at least two variations on the binary STL format for adding color information:
•The VisCAM and SolidView software packages use the two 'attribute byte count' bytes at the end of every triangle to store a 15 bit RGB color:
•bit 0 to 4 are the intensity level for blue (0 to 31)
•bits 5 to 9 are the intensity level for green (0 to 31)
•bits 10 to 14 are the intensity level for red (0 to 31)
•bit 15 is 1 if the color is valid
•bit 15 is 0 if the color is not valid (as with normal STL files)
•The Materialise Magics software does things a little differently. It uses the 80 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 be the ASCII string "COLOR=" followed by four bytes representing red, green, blue and alpha channel (transparency) in the range 0–255. 
This is 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 be another ASCII string ",MATERIAL=" followed by three colors (3 × 4 bytes): 
first is a color of diffuse reflection,
second is a color of specular highlight, 
and third is an ambient light.
Material settings are preferred over color.The per-facet color is represented in the two 'attribute byte count' bytes as follows:
•bit 0 to 4 are the intensity level for red (0 to 31)
•bits 5 to 9 are the intensity level for green (0 to 31)
•bits 10 to 14 are the intensity level for blue (0 to 31)
•bit 15 is 0 if this facet has its own unique color
•bit 15 is 1 if the per-object color is to be used
The red/green/blue ordering within those two bytes is reversed in these two approaches
– so while these formatscould easily have been compatible the reversal of the order of the colors means that they are not 
– and worse still, ageneric STL file reader cannot automatically distinguish between them. There is also no way to have facets beselectively transparent because there is no per-facet alpha value 
– although in the context of current rapid prototyping machinery, this is not important.

最后粘贴上,在github上找到的stl文件解析类:

https://github.com/Ultimaker/ruby-admesh/blob/master/ext/admesh/admesh/src/stlinit.c

stl文件格式的更多相关文章

  1. stl文件格式解析代码--java版

    代码是参考three.js中的stlLoader.js写的. 需要注意的地方,java中byte取值-128~127 package test_stl.test_entry; import java. ...

  2. Open Cascade Data Exchange STL

    Open Cascade Data Exchange STL eryar@163.com 摘要Abstract:介绍了三维数据交换格式STL的组成,以及Open Cascade中对STL的读写.并将O ...

  3. C++ STL自学总结,仅供参考

    本文内容,为博主在网上看到资料总结整合而来 一.stl格式简介 .stl文件是在计算机图形应用系统,来表示封闭的面或者体,用来表示三角形网格的一种文件格式.为STereo Lithography的缩写 ...

  4. 从STL文件到网格拓扑

    原文链接 STL文件是什么 STL文件是网格文件的一种格式,分为二进制和文本两种类型.具体来讲,它定义了一群三角面片,比如下面是一个文本的STL示例: solid geometryplusplus f ...

  5. Delaunay Triangulation in OpenCascade

    Delaunay Triangulation in OpenCascade eryar@163.com 摘要:本文简要介绍了Delaunay三角剖分的基础理论,并使用OpenCascade的三角剖分算 ...

  6. 免费开源3D模型设计软件汇总

    免费开源3D模型设计软件汇总 3D 打印需要先通过计算机辅助设计(CAD)进行建模,再将建好的3D模型“分割”成逐层的截面,从而指导3D打印机进行逐层打印.因此用于3D打印的3D模 型大都储存或输出成 ...

  7. 使用WebGL实现一个Viewer来显示STL文件

    关键字:WebGL,STL,ThreeJS,Chrome,Viewer,Python3.4, HTML5,Canvas. OS:Windows 10. 本文介绍如何使用ThreeJS来实现一个WebG ...

  8. Assimp场景模型输出Collada,STL,3DPDF

    本文介绍开源库模型的几种输出格式:DAE,STL,3DPDF. Assimp是C++写的,AssimpNet是C#重构其中主要数据结构,并开通Assimp中重要方法的调用接口,为不熟悉C++的码农带来 ...

  9. Three.js 3D打印数据模型文件(.STL)载入中

    3DPrint是现在和未来10年度科技产品的主流之中.广泛的. 对于电子商务类3D打印网站.一个主要功能就是商品3D呈现的方式,那是,3D数据可视化技术. HTML5(WebGL)它可以用于构建3D查 ...

随机推荐

  1. 关闭Linux防火墙(iptables) 及 SELinux

    一.关闭防火墙 1.重启后永久性生效: 开启:chkconfig iptables on 关闭:chkconfig iptables off 2.即时生效,重启后失效: 开启:service ipta ...

  2. 【Alpha版本】冲刺-Day10

    队伍:606notconnected 会议时间:11月18日 会议总结 张斯巍(433) 今天安排:完成剩余界面的设计,小修小补 完成度:100% 遇到的问题:无 感想:因为自己是负责界面美工部分的, ...

  3. jquery.validate.js插件使用

    jQuery验证控件jquery.validate.js使用说明+中文API 官网地址:http://bassistance.de/jquery-plugins/jquery-plugin-valid ...

  4. 关于CDN的认识

    传统的未加缓存服务的访问过程: 用户提交域名→浏览器对域名进行解释→得到目的主机的IP地址→根据IP地址访问发出请求→得到请求数据并回复 由上可见,用户访问未使用CDN缓存网站的过程为: 1).用户向 ...

  5. Proj.4库的编译及使用

    Proj.4库的编译及使用 Proj.4是开源GIS最著名的地图投影库,GRASS GIS, MapServer, PostGIS, Thuban, OGDI, Mapnik, TopoCad, GD ...

  6. %格式化和format格式化--python

    格式符 %[(name)][floags][width].[precision]typecode (name) 可选,用于选择指定的key flags 可选,可提供的值有: · + 右对齐,整数前加正 ...

  7. 安装第三方模块方法和requests

    如何安装第三方模块 pip3         pip3 install xxxx          源码         下载,解压         进入目录 python setup.py inst ...

  8. [k]优雅的css

    1.图片文字列表 (2016-01-25) 1.1 实现效果图如下: 1.2 代码: html:( 代码十分优雅哦! ) <ul> <li class="step1&quo ...

  9. sharepoint OWA问题解决

    请检查DNS   检查域名解析   cmd----nslookup---输入IP或者域名(计算机名)可以看到

  10. Magento 新增字段的值读写丢失原因

    某实体新增字段handreturn_status,欲操作之: $order_info = Mage::getModel('sales/order')->load($order_id); //se ...