stl文件格式
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文件格式的更多相关文章
- stl文件格式解析代码--java版
代码是参考three.js中的stlLoader.js写的. 需要注意的地方,java中byte取值-128~127 package test_stl.test_entry; import java. ...
- Open Cascade Data Exchange STL
Open Cascade Data Exchange STL eryar@163.com 摘要Abstract:介绍了三维数据交换格式STL的组成,以及Open Cascade中对STL的读写.并将O ...
- C++ STL自学总结,仅供参考
本文内容,为博主在网上看到资料总结整合而来 一.stl格式简介 .stl文件是在计算机图形应用系统,来表示封闭的面或者体,用来表示三角形网格的一种文件格式.为STereo Lithography的缩写 ...
- 从STL文件到网格拓扑
原文链接 STL文件是什么 STL文件是网格文件的一种格式,分为二进制和文本两种类型.具体来讲,它定义了一群三角面片,比如下面是一个文本的STL示例: solid geometryplusplus f ...
- Delaunay Triangulation in OpenCascade
Delaunay Triangulation in OpenCascade eryar@163.com 摘要:本文简要介绍了Delaunay三角剖分的基础理论,并使用OpenCascade的三角剖分算 ...
- 免费开源3D模型设计软件汇总
免费开源3D模型设计软件汇总 3D 打印需要先通过计算机辅助设计(CAD)进行建模,再将建好的3D模型“分割”成逐层的截面,从而指导3D打印机进行逐层打印.因此用于3D打印的3D模 型大都储存或输出成 ...
- 使用WebGL实现一个Viewer来显示STL文件
关键字:WebGL,STL,ThreeJS,Chrome,Viewer,Python3.4, HTML5,Canvas. OS:Windows 10. 本文介绍如何使用ThreeJS来实现一个WebG ...
- Assimp场景模型输出Collada,STL,3DPDF
本文介绍开源库模型的几种输出格式:DAE,STL,3DPDF. Assimp是C++写的,AssimpNet是C#重构其中主要数据结构,并开通Assimp中重要方法的调用接口,为不熟悉C++的码农带来 ...
- Three.js 3D打印数据模型文件(.STL)载入中
3DPrint是现在和未来10年度科技产品的主流之中.广泛的. 对于电子商务类3D打印网站.一个主要功能就是商品3D呈现的方式,那是,3D数据可视化技术. HTML5(WebGL)它可以用于构建3D查 ...
随机推荐
- [译]Android调整图像大小的一些方法
翻译自 某大神在Stack Overflow里的自问自答 (一般我们将Bitmap翻译为位图,但为了更好理解,在本文中我将它翻译成图像): 我们在开发的时候,经常需要从服务器中加载图像到客户端中,但有 ...
- bootstrap使用心得及css模块化的初步尝试
第一次用bootstrap到实战项目,是一个企业门户站,可以说是强行拿bootstrap上来练手,感觉并不适合. 我是用的less编译bootstrap文件,直接改less变量.然后把不可重用的部分, ...
- C++虚函数浅探
C++中和虚函数(Virtual Function)密切相关的概念是"动态绑定"(Dynamic Binding),与之相对的概念是"静态绑定"(Static ...
- js遮罩效果
function ShowLoadingMaskLayer(text) { var htmlContent = '<div id=\"masklayer\">' + ' ...
- js实现四舍六入 奇进偶舍
function PointFloat(src, pos) { return Math.round(src * Math.pow(10, pos)) / Math.pow(10, pos); } // ...
- 初学Redis(1)——认识Redis
Redis官网对Redis的定义是:“Redis is an open source, BSD licensed, advanced key-value cache and store”,可以看出,R ...
- JS中多种方式创建对象
1.内置对象创建 var girl=new Object(); girl.name='hxl'; console.log(typeof girl); 2.工厂模式,寄生构造函数模式 function ...
- PHP表单与验证
一.Header()函数 标头 (header) 是服务器以 HTTP 协议传 HTML 资料到浏览器前所送出的字符串,在标头与 HTML 文件之间尚需空一行分隔. /*一.Header()函数 */ ...
- Java基本数据类型与位运算
>>赋值运算符 赋值使用操作符“=”.它的意思是“取右边的值(即右值),把它复制给左边(即左值)”.右值可以是任何 常数.变量或者表达式 (只要它能 生成 一个值就行).但左值必须是一个明 ...
- sybase 收集常用sql语句
-------创建sybase设备 语句--------- disk init name="DEV_DB_CLIENT_DAT26", physname="F:\syba ...