Greg G
Greg G

Reputation: 697

Mesh Triangulation: Seperate vs Nested loop Complexity

I wrote a collada loader for my model viewer.

Write now it loops through all the vertices and indices and creates and index and vertice buffer so I can render the mesh.

If the model is not triangulated I have two options. I can either traingulate the indices as they are written to my buffer (ie calculate and add more indices to create triangules).

Or I can trinagulate the entire mesh before I write my buffers and leave my buffer system as is (it will assume that the mesh is triangulated before hand).

In order to trangulate the model before hand I would need to load the entire thing into a linked list loop through the list and insert new indices to hack up the 4+ polygons into tirangles.

If I triangulated as I wrote the mesh I would need to dely the writing of 4+ polygons, put them into a seperate buffer, then when that buffer had the entire 4+ polygon in it, triangulate it and write the new indices.

This would essentially add another for loop that would only be triggered each time it encountered a 4+ triangle.

This is by far the most complex thing i've written so far so and i'm having a really hard time wrapping my head around which direction will be more effecient.

One involves double the ammount of memory I am using by duplicating the entire mesh so I can procces it, the other involves a nested for loop that is only triggered when it encounters 4+ polygons.

Can anyone offer any advice as to how I might gauge the complexity of the two options without acutally writing and testing both?

Upvotes: 0

Views: 263

Answers (1)

comingstorm
comingstorm

Reputation: 26117

Adding an inner loop to handle an occasional condition is fine. If I understand your problem correctly, you will need to test for polygons and triangulate them as necessary one way or another; a conditionally executed inner loop is appropriate reflection of this.

If you think the inner loop will make your function too long/ugly/difficult-to-read, you can write a separate "triangulate_polygon()" function containing the inner loop, and call it conditionally.

Upvotes: 1

Related Questions