2
\$\begingroup\$

I have a 3D .OBJ model file that is loaded in my OpenGL ES 2 Android application using ASSIMP library. All the faces are triangulated.

I want to draw the wireframe for my mesh. In OpenGL we have something called glPolygonMode that enables wireframe drawing just in one line.

Is there a function I can use to convert those triangulated faces into a pair of Line segments and then draw these line segments using GL_LINES?

Any better approach to draw wireframe for 3D mesh in OpenGL ES 2 would be appreciated. Maybe something based on GLSL shader.

\$\endgroup\$

2 Answers 2

2
\$\begingroup\$

A (triangular) face is created using tree or more vertices. An aiModel contains a list of all vertices in the model and a list of faces. Each aiFace contains the indices to vertices that make up this (triangle) face. An index is the position in the list of vertices where the vertex we want is.

Here is some pseudo code that retrieves the thee vertices of the first face.

vertex0 = aiMesh.mVertices[aiMesh.mFaces[0].mIndices[0]];
vertex1 = aiMesh.mVertices[aiMesh.mFaces[0].mIndices[1]];
vertex2 = aiMesh.mVertices[aiMesh.mFaces[0].mIndices[2]];

You can now draw lines between vertex0-vertex1, vertex1-vertex2, vertex2-vertex0 to accomplish wireframe rendering.

Note that an aiMesh can have 0 or more vertices, 0 or more faces, and an aiFace can have 0 or more vertices.

For more information see: http://assimp.sourceforge.net/lib_html/structai_mesh.html

\$\endgroup\$
1
\$\begingroup\$

There are two possibilities, as far as I know:

  1. Draw your geometry using one of the GL_LINE* topologies: GL_LINE_STRIP, GL_LINE_LOOP, GL_LINES.

  2. Use a fragment shader and some math to define the wireframe on-the-fly, without changing the topology. See this very nice example using WebGL: Wireframe display with barycentric coordinates.

\$\endgroup\$
1
  • \$\begingroup\$ Drawing with GL_LINE* topologies does not render correct wireframe. I'll look into Baycentric Coordinates later, sounds complicated to me. \$\endgroup\$ Commented Oct 11, 2014 at 20:10

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .