1

我正在编写一个代码来读取和绘制 opengl (c++) 中的 ply 文件格式。我将glVertex3d函数用于顶点元素。现在我不明白element faceply 文件中的内容是什么?这是为了颜色吗?任何想法?

4

3 回答 3

3

面是多边形。读取顶点后开始读取面。每条面线都以多边形中的顶点数开始。然后跟随该数量的 0 偏移多边形顶点索引。

假设您将顶点读入具有 x、y、z 成员的结构向量(例如)。还将面部索引读入结构。

for (int f = 0; f < num_faces; ++f)
{
    glBegin(GL_POLYGON);
      for (int i = 0; i < face[f].num_vertices; ++i)
      {
        glVertex3f(face[f].vertex[i].x,face[f].vertex[i].y, face[f].vertex[i].z);
      }
    glEnd();
}
于 2013-01-24T19:54:21.083 回答
2

元素面描述了所有层文件中有多少面(多边形)。

ply
format ascii 1.0           { ascii/binary, format version number }
comment made by Greg Turk  { comments keyword specified, like all lines }
comment this file is a cube
element vertex 8           { define "vertex" element, 8 of them in file }
property float x           { vertex contains float "x" coordinate }
property float y           { y coordinate is also a vertex property }
property float z           { z coordinate, too }
element face 6             { there are 6 "face" elements in the file }
property list uchar int vertex_index { "vertex_indices" is a list of ints }
end_header                 { delimits the end of the header }
0 0 0                      { start of vertex list }
0 0 1
0 1 1
0 1 0
1 0 0
1 0 1
1 1 1
1 1 0
4 0 1 2 3                  { start of face list }
4 7 6 5 4
4 0 4 5 1
4 1 5 6 2
4 2 6 7 3
4 3 7 4 0

如果你看一下人脸列表从哪里开始数到最后,那么你应该数 6。元素 faces 也说 6 来确认它。


上面的 ply 文件可耻地从http://paulbourke.net/dataformats/ply/被盗

于 2013-01-24T19:31:59.063 回答
0

element 是一个三角形索引,因为上面的例子在meshlab EOF中不起作用,这里是另一个例子:

ply
format ascii 1.0
comment VCGLIB generated
element vertex 8
property float x
property float y
property float z
property float nx
property float ny
property float nz
element face 12
property list uchar int vertex_indices
end_header
-1 24 4.5 -1.570796 1.570796 1.570796 
0 21 4.5 1.570796 -1.570796 1.570796 
0 24 4.5 1.570796 1.570796 1.570796 
-1 21 4.5 -1.570796 -1.570796 1.570796 
-1 21 2.5 -1.570796 -1.570796 -1.570796 
0 24 2.5 1.570796 1.570796 -1.570796 
0 21 2.5 1.570796 -1.570796 -1.570796 
-1 24 2.5 -1.570796 1.570796 -1.570796 
3 0 1 2 
3 1 0 3 
3 4 5 6 
3 5 4 7 
3 4 1 3 
3 1 4 6 
3 1 5 2 
3 5 1 6 
3 5 0 2 
3 0 5 7 
3 4 0 7 
3 0 4 3 
于 2017-01-18T09:58:58.427 回答