View Full Version : OBJ Parser with GL_TRIANGLE_STRIP

renzyortega

07-22-2015, 08:42 PM

Hi. I know OBJ files behaves as TRIANGLES but is there any way to load OBJ files and render it using GL_TRIANGLE_STRIP? I have an OBJ parser which works with GL_TRIANGLES but I wanna load it and use GL_TRIANGLE_STRIP instead. Hope you can help me :)

GClements

07-23-2015, 02:56 AM

Hi. I know OBJ files behaves as TRIANGLES but is there any way to load OBJ files and render it using GL_TRIANGLE_STRIP?

If you can find a set of triangles which have the same topology as a triangle strip, you can render it as a triangle strip. Two triangles which share a common edge can always be rendered as a triangle strip. Beyond that, converting a set of triangles to the minimum number of triangle strips is a hard problem. And unless you use primitive restarting (which requires OpenGL 3.1 or later), rendering multiple triangle strips requires multiple draw calls, while any number of individual triangles can be rendered in a single draw call.

Any algorithm for generating triangle strips boils down to choosing a triangle, then keep adding adjacent triangles so long as you can satisfy the topology. When you can't add any more triangles, choose another triangle and repeat the process (ignoring triangles which have already been added to a previous strip).

For the first triangle, there are 6 permutations of the 3 vertices, but only 3 which maintain the original orientation (clockwise or counter-clockwise). After that, there are no choices; if there exists a triangle which contains the last two vertices and which hasn't already been incorporated into a strip (either the current strip or a previous strip), you can add it, otherwise you're done and need to move onto the next strip.

So the choices involved are which triangle to choose for the first triangle and the order of the vertices. After which, finding the limits of how far the strip can be extended in either direction is deterministic.

The initial choices can be made randomly or using heuristics (e.g. preferring triangles at a corner or an edge rather than cutting the mesh in half with a strip through the middle). Or you could start by identifying all possible strips which can be made from the complete mesh, ignoring duplicates (when a strip forms a loop, you can form the same strip starting at any triangle in the loop), identifying which pairs of strips are mutually exclusive, and preferring long strips which exclude relatively few other strips. If the total number of triangles involved is reasonably low, you could treat it as an exact cover problem (https://en.wikipedia.org/wiki/Exact_cover) to be solved using Algorithm X (https://en.wikipedia.org/wiki/Algorithm_X) or similar, but for large meshes this is likely to be infeasible.

Carmine

07-23-2015, 12:23 PM

I know OBJ files behaves as TRIANGLES ... The OBJ format is not limited to triangles. It can handle polygons with many sides. Not sure what the maximum is. If you are only seeing triangles in the OBJ files you are working with, it's because whatever software generated those files is doing it that way, or perhaps the model was created that way. Some modeling or CAD software will take n-sided polygons, break them down into triangles, and write the OBJ out that way.

is there any way to load OBJ files and render it using GL_TRIANGLE_STRIP? You can't use GL_TRIANGLE_STRIP on an arbitrary set of polygons. They have to share edges. This is typically not the way a model is created or written out.

Powered by vBulletin® Version 4.2.3 Copyright © 2018 vBulletin Solutions, Inc. All rights reserved.