Vulkan

PLY文件格式

一、PLY简介

        PLY文件格式是Stanford大学开发的一套三维mesh模型数据格式,图形学领域内很多著名的模型数据,比如Stanford的三维扫描数据库(其中包括很多文章中会见到的Happy Buddha, Dragon, Bunny兔子),Geogia Tech的大型几何模型库,北卡(UNC)的电厂模型等,最初的模型都是基于这个格式的。

        PLY多边形文件格式的开发目标是建立一套针对多边形模型的,结构简单但是能够满足大多数图形应用需要的模型格式,而且它允许以ASCII码格式或二进制形式存储文件。PLY的开发者希望,这样一套既简单又灵活的文件格式,能够帮助开发人员避免重复开发文件格式的问题。然而由于各种各样的原因,在工业领域内,新的文件格式仍然在不断的出现,但是在图形学的研究领域中,PLY还是种常用且重要的文件格式。

        PLY作为一种多边形模型数据格式,不同于三维引擎中常用的场景图文件格式和脚本文件,每个PLY文件只用于描述一个多边形模型对象(Object),该模型对象可以通过诸如顶点、面等数据进行描述,每一类这样的数据被称作一种元素(Element)。相比于现代的三维引擎中所用到的各种复杂格式,PLY实在是种简单的不能再简单的文件格式,但是如果仔细研究就会发现,就像设计者所说的,这对于绝大多数的图形应用来说已经是足够用了。 

二、PLY结构

        PLY的文件结构简单:文件头加上元素数据列表。其中文件头中以行为单位描述文件类型、格式与版本、元素类型、元素的属性等,然后就根据在文件头中所列出元素类型的顺序及其属性,依次记录各个元素的属性数据。

        典型的PLY文件结构: 

        头部 
        顶点列表 
        面片列表 
      (其他元素列表)


         头部是一系列以回车结尾的文本行,用来描述文件的剩余部分。头部包含一个对每个元素类型的描述,包括元素名(如“边”),这个元素在工程里有多少,以及一个与这个元素关联的不同属性的列表。头部还说明这个文件是二进制的或者是ASCII的。头部后面的是一个每个元素类型的元素列表,按照在头部中描述的顺序出现。

        下面是一个立方体的完整ASCII描述大括号中的注释不是文件的一部分,它们是这个例子的注解。文件中的注释一般在   “comment”开始的关键词定义行里。

  1. <span style="font-size:16px;">ply   
  2. format   ascii   1.0   {   ascii/二进制,格式版本数   }   
  3. comment   made   by   anonymous   {   注释关键词说明,像其他行一样   }   
  4. comment   this   file   is   a   cube   
  5. element   vertex   8   {   定义“vertex”(顶点)元素,在文件中有8个   }   
  6. property   float32   x   {   顶点包含浮点坐标“x”}   
  7. property   float32   y   {   y   坐标同样是一个顶点属性   }   
  8. property   float32   z   {   z   也是坐标   }   
  9. element   face   6   {   在文件里有6个“face”(面片)   }   
  10. property   list   uint8   int32   vertex_index   {   “vertex_indices”(顶点素引)是一列整数   }   
  11. end_header   {   划定头部结尾   }   
  12. 0   0   0   {   顶点列表的开始   }   
  13. 0   0   1   
  14. 0   1   1   
  15. 0   1   0   
  16. 1   0   0   
  17. 1   0   1   
  18. 1   1   1   
  19. 1   1   0   
  20. 4   0   1   2   3   {   面片列表开始   }   
  21. 4   7   6   5   4   
  22. 4   0   4   5   1   
  23. 4   1   5   6   2   
  24. 4   2   6   7   3   
  25. 4   3   7   4   0 </span>  

        这个例子说明头部的基本组成。头部的每个部分都是一个以关键词开头,以回车结尾的ASCII串。"ply"是文件的头四个字符。

        跟在文件头部开头之后的,是关键词“format”和一个特定的ASCII或者二进制的格式,接下来是一个版本号。

        再下面是多边形文件中每个元素的描述,在每个元素里还有多属性的说明。一般元素以下面的格式描述:
        element   <元素名>   <在文件中的个数> 
        property   <数据类型>   <属性名-1> 
        property   <数据类型>   <属性名-2> 
        property   <数据类型>   <属性名-3>

        属性罗列在“element”(元素)行后面定义,既包含属性的数据类型,也包含属性在每个元素中出现的次序。一个属性可以有三种数据类型:标量,字符串和列表。属性可能具有的标量数据类型列表如下:

        名称      类型           字节数 
         ------------------------------- 
         int8        字符                    1 
         uint8      非负字符           1 
         int16      短整型               2 
         uint16    非负短整型       2 
         int32      整型                   4 
         uint32    非负整型           4 
         float32   单精度浮点数   4 
         float64   双精度浮点数   8

         这些字节计数很重要,而且在实现过程中不能修改以使这些文件可移植。

         使用列表数据类型的属性定义有一种特殊的格式:property   list   <数值类型>   <数值类型>   <属性名> ,这种格式,一个非负字符表示在属性里包含多少索引,接下来是一个列表包含许多整数。在这个边长列表里的每个整数都是一个顶点的索引。 

        另外一个立方体定义:

  1. ply   
  2. format   ascii   1.0   
  3. comment   author:   anonymous   
  4. comment   object:   another   cube   
  5. element   vertex   8   
  6. property   float32   x   
  7. property   float32   y   
  8. property   float32   z   
  9. property   red   uint8   {   顶点颜色开始   }   
  10. property   green   uint8   
  11. property   blue   uint8   
  12. element   face   7   
  13. property   list   uint8   int32   vertex_index   {   每个面片的顶点个数   }   
  14. element   edge   5   {   物体里有5条边   }   
  15. property   int32   vertex1   {   边的第一个顶点的索引   }   
  16. property   int32   vertex2   {   第二个顶点的索引   }   
  17. property   uint8   red   {   边颜色开始   }   
  18. property   uint8   green   
  19. property   uint8   blue   
  20. end_header   
  21. 0   0   0   255   0   0   {   顶点列表开始   }   
  22. 0   0   1   255   0   0   
  23. 0   1   1   255   0   0   
  24. 0   1   0   255   0   0   
  25. 1   0   0   0   0   255   
  26. 1   0   1   0   0   255   
  27. 1   1   1   0   0   255   
  28. 1   1   0   0   0   255   
  29. 3   0   1   2   {   面片列表开始,从一个三角形开始   }   
  30. 3   0   2   3   {   另一个三角形   }   
  31. 4   7   6   5   4   {   现在是一些四边形   }   
  32. 4   0   4   5   1   
  33. 4   1   5   6   2   
  34. 4   2   6   7   3   
  35. 4   3   7   4   0   
  36. 0   1   255   255   255   {   边列表开始,从白边开始   }   
  37. 1   2   255   255   255   
  38. 2   3   255   255   255   
  39. 3   0   255   255   255   
  40. 2   0   0   0   0   {   以一个黑线结束   }   

         这个文件为每个顶点指定一个红、绿、蓝值。

       为了说明变长vertex_index(顶点索引)的能力,物体的头两个面片是两个三角形而不是一个四边形。这意味着物体的面片数是7。这个物体还包括一个边列表。每条边包括两个指向说明边的顶点的指针。每条边也有一种颜色。上面定义的五条边指定了颜色,使文件里的两个三角形高亮。前四条边白色,它们包围两个三角形。最后一条边是黑的,他是分割三角形的边。


三、用户定义元素

        上面的例子显示了顶点、面片和边三种元素的用法。PLY   格式同样允许用户定义它们自己的元素。定义新元素的格式于顶点、面片和边相同。这是头部定义材料属性的部分:

  1. element   material   6   
  2. property   ambient_red   uint8   {   环绕颜色   }   
  3. property   ambient_green   uint8   
  4. property   ambient_blue   uint8   
  5. property   ambient_coeff   float32   
  6. property   diffuse_red   uint8   {   扩散(diffuse)颜色   }   
  7. property   diffuse_green   uint8   
  8. property   diffuse_blue   uint8   
  9. property   diffuse_coeff   float32   
  10. property   specular_red   uint8   {   镜面(specular)颜色   }   
  11. property   specular_green   uint8   
  12. property   specular_blue   uint8   
  13. property   specular_coeff   float32   
  14. property   specular_power   float32   {   Phong   指数   }   

        这些行应该在头部顶点、面片和边的说明后直接出现。如果我们希望每个顶点有一个材质说明,我们可以将这行加在顶点属性末尾:property   material_index   int32

       这个整数现在是一个到文件内包含的材质列表的索引。这可能诱使一个新应用的作者编制一些信的元素保存在PLY文件中。

 

 

转载自:http://blog.csdn.net/lxfyzx/article/details/4997627

                http://blog.csdn.net/lxfyzx/article/details/4997780


以下是常用的elements 和 properties 原地址 http://www.mathworks.com/matlabcentral/fx_files/5459/1/content/ply.htm

Common Elements and Properties

While the PLY format has the flexibility to define many types of elements and properities, a common set of elements are understood between programs to communicate common 3D data types. Turk suggests elements and property names that programs should try to make standard.

 
Element Property Data Type Property Description
vertex x
y
z
float
float
float
x,y,z coordinates
  nx
ny
nz
float
float
float
x,y,z components of normal
  red
green
blue
alpha
uchar
uchar
uchar
uchar
vertex color


amount of transparency
  material_index int index to list of materials
face vertex_indices list of int indices to vertices
  back_red
back_green
back_blue
uchar
uchar
uchar
backside color
edge vertex1
vertex2
int
int
index to vertex
index to other vertex
  crease_tag uchar crease in subdivision surface
material red
green
blue
alpha
uchar
uchar
uchar
uchar
material color


amount of transparency
  reflect_coeff
refract_coeff
refract_index
extinct_coeff
float
float
float
float
amount of light reflected
amount of light transmitted
index of refraction
extinction coefficient
 
* - required "core" properties in red

For most applications, the minimum necessary information is vertex and face data. To make it easier for programs to interpret PLY files, the element properties listed in red should always be included. If there is no face data (as in the case of point-cloud data) the face element could be defined with an element count of zero. The other elements and properties are suggested names for often used information like material parameters and edge information.


posted on 2014-10-08 16:57  Vulkan  阅读(1644)  评论(0编辑  收藏  举报

导航