I am trying to load ply format which looks like this:
0.000000 0.000000 -1.543509 0.000000 0.000000 -1.000000 0.838731 0.300864 106 34 22
vertex pos/ normal dir/texture coords/ vertex color
and the face defines like this:
3 0 1 2
how much vertices per face/ which vertex for x/ which vertex for y/which vertex for z/
then I read them in to a vertex array,and a face array, draw them like this:
//bind buffer first of course)
glDrawElements(GL_TRIANGLE_FAN,vert_amount,GL_UNSIGNED_INT,faces);
I am using opengles 1.1 so I am stuck with TRIANGLE_FAN I guess,the result is messed up,so I guess the default ply face definition is not suitable for opengl right? how to reorganize faces if I want to use glDrawElements ?
here is the simple cube of ply model file:
1.000000 1.000000 -1.000000 0.000000 0.000000 -1.000000
1.000000 -1.000000 -1.000000 0.000000 0.000000 -1.000000
-1.000000 -1.000000 -1.000000 0.000000 0.000000 -1.000000
1.000000 0.999999 1.000000 -0.000000 0.000000 1.000000
-1.000000 1.000000 1.000000 -0.000000 0.000000 1.000000
-1.000000 -1.000000 1.000000 -0.000000 0.000000 1.000000
1.000000 1.000000 -1.000000 1.000000 -0.000001 -0.000000
1.000000 0.999999 1.000000 1.000000 -0.000001 -0.000000
0.999999 -1.000001 1.000000 1.000000 -0.000001 -0.000000
1.000000 -1.000000 -1.000000 -0.000000 -1.000000 -0.000000
0.999999 -1.000001 1.000000 -0.000000 -1.000000 -0.000000
-1.000000 -1.000000 1.000000 -0.000000 -1.000000 -0.000000
-1.000000 -1.000000 -1.000000 -1.000000 0.000000 -0.000000
-1.000000 -1.000000 1.000000 -1.000000 0.000000 -0.000000
-1.000000 1.000000 1.000000 -1.000000 0.000000 -0.000000
1.000000 0.999999 1.000000 0.000000 1.000000 0.000000
1.000000 1.000000 -1.000000 0.000000 1.000000 0.000000
-1.000000 1.000000 -1.000000 0.000000 1.000000 0.000000
-1.000000 1.000000 -1.000000 0.000000 0.000000 -1.000000
0.999999 -1.000001 1.000000 -0.000000 0.000000 1.000000
1.000000 -1.000000 -1.000000 1.000000 0.000000 0.000000
1.000000 1.000000 -1.000000 1.000000 0.000000 0.000000
0.999999 -1.000001 1.000000 1.000000 0.000000 0.000000
-1.000000 -1.000000 -1.000000 -0.000000 -1.000000 0.000000
-1.000000 1.000000 -1.000000 -1.000000 0.000000 -0.000000
-1.000000 1.000000 1.000000 0.000000 1.000000 0.000000
3 0 1 2
3 3 4 5
3 6 7 8
3 9 10 11
3 12 13 14
3 15 16 17
3 18 0 2
3 19 3 5
3 20 21 22
3 23 9 11
3 24 12 14
3 25 15 17
GL_TRIANGLE_FAN is the wrong primitive here - a triangle fan has one fixed vertex shared by all the triangles. If you only have triangles, GL_TRIANGLES is the better choice. If not, consider triangulating, or otherwise build triangle strips instead.