一、ply文件简介
ply文件是一种用于描述图形结构的文件。一般包括:头部、顶点列表、面片列表、其他元素列表等。
例如下面这个ply文件描述了一个cube。
ply format ascii 1.0 comment made by anonymous comment this file is a cube element vertex 8 property float32 x property float32 y property float32 z element face 12 property list uint8 int32 vertex_index end_header 0 0 0 0 0 0.01 0 0.01 0.01 0 0.01 0 0.01 0 0 0.01 0 0.01 0.01 0.01 0.01 0.01 0.01 0 3 0 1 2 3 0 3 2 3 7 9 5 3 7 4 5 3 0 4 5 3 0 1 5 3 1 5 6 3 1 2 6 3 2 6 7 3 2 3 7 3 1 7 4 3 3 0 4
二、ply文件的解析及用openGL显示
ply的文件格式比较简单,我们只需要对其中的信息进行提取,在调用openGL中相应的函数就可以实现显示ply模型了。
代码:
1 #ifndef PLYREADER_H_ 2 #define PLYREADER_H_ 3 4 #include <GL/glut.h> 5 #include <GL/glu.h> 6 #include <GL/gl.h> 7 #include <vector> 8 using namespace std; 9 10 struct SModelData 11 { 12 vector <float> vecFaceTriangles; // = face * 9 13 vector <float> vecFaceTriangleColors; // = face * 9 14 int iTotalConnectedTriangles; 15 }; 16 17 class CPLYLoader 18 { 19 public: 20 CPLYLoader(); 21 bool LoadModel(char * filename); 22 void Draw(); 23 private: 24 float * mp_vertexXYZ; 25 float * mp_vertexRGB; 26 in