我正在编写一个代码来读取和绘制opengl(c ++)中的ply文件格式。
我使用glVertex3d
函数作为顶点元素。现在我无法理解ply文件中的element face
是什么?这是为了颜色吗?任何想法?
答案 0 :(得分: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();
}
答案 1 :(得分: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.然后元素面也会显示6以确认它。
答案 2 :(得分:0)
元素是一个三角形索引,因为上面的例子在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