in a wavefront object file (.obj) how am i supposed to render faces with more than 4 vertices in opengl?

后端 未结 3 972
别跟我提以往
别跟我提以往 2021-01-12 16:27

So using a Wavefront object file how am i supposed to render faces that have more than 4 vertices in OpenGL?

I understand that if it has 3 vertices I use GL_TR

3条回答
  •  一向
    一向 (楼主)
    2021-01-12 17:14

    In practice, most wavefront-obj faces are coplanar and convex, but I can't find anything in the original OBJ specification saying this is guaranteed.

    If the face is coplanar and convex, you can either use GL_TRIANGLE_FAN, or you can use GL_TRIANGLE and manually evaluate the fan yourself. A fan has all triangles share the first vertex. Like this:

    // manually generate a triangle-fan
    for (int x = 1; x < (faceIndicies.Length-1); x++) {
        renderIndicies.Add(faceIndicies[0]);
        renderIndicies.Add(faceIndicies[x]);
        renderIndicies.Add(faceIndicies[x+1]);
    }
    

    If the number of vertices in an n-gon is large, using GL_TRIANGLE_STRIP, or manually forming your own triangle strips, can produce better visual results. But this is very uncommon in wavefront OBJ files.

    If the face is co-planar but concave, then you need to triangulate the face using an algorithm, such as the Ear-Clipping Method..

    http://en.wikipedia.org/wiki/Polygon_triangulation#Ear_clipping_method

    If the verticies are not-coplanar, you are screwed, because OBJ doesn't preserve enough information to know what shape tessellation was intended.

提交回复
热议问题