【发布时间】:2017-01-18 17:58:58
【问题描述】:
我正在编写代码以在 opengl (c++) 中读取和绘制 ply 文件格式。
我使用glVertex3d 函数作为顶点元素。现在我不明白 ply 文件中的element face 是什么?这是为了颜色吗?有什么想法吗?
【问题讨论】:
我正在编写代码以在 opengl (c++) 中读取和绘制 ply 文件格式。
我使用glVertex3d 函数作为顶点元素。现在我不明白 ply 文件中的element face 是什么?这是为了颜色吗?有什么想法吗?
【问题讨论】:
面是多边形。读取顶点后开始读取面。每条面线都以多边形中的顶点数开始。然后是 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();
}
【讨论】:
glVertex3f 来绘制顶点。好的。我正在寻找像glVertex3f 这样的opengl 函数来绘制人脸。非常感谢
元素 faces 描述了所有 ply 文件中有多少个面(多边形)。
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。元素面也说6来确认。
上面的 ply 文件被 http://paulbourke.net/dataformats/ply/ 偷来的可耻
【讨论】:
glVertex3d 用于顶点元素,但对于我不知道的面元素
{ foo bar } 不是 PLY 格式的一部分。因此,如果这些描述被删除,文件可以在 MeshLab 中打开。
元素是一个三角形索引,因为上面的例子在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
【讨论】: