How do you triangulate faces?

Started by
3 comments, last by Chris528 10 years, 8 months ago
Alright, after quite a bit of work I've been able to calculate all the points for all brushes from a source engine .vmf. For each face I have a set of verts but I'm not sure how to load this into a vbo.

If I'm not mistaken I should create a function that takes in the points of a face and outputs a list of triangles? Also I need this to work with cylinders, as my test map has a cylinder with 32 sides, which means both the top and bottom face each have 32 verts.

How would I go about doing that? I've messed around with quite a few opengl 3.3+ tutorials, but never worked on something this involved before.

Thanks, Chris528
Advertisement

If all faces are convex (they usually are), just turn them into the equivalent of triangle fans, i.e. the first triangle is vertices 0-1-2, the next is 0-2-3, the next 0-3-4, then 0-4-5, and so on.

Alternatively, just import it into an editor and make it triangulate the faces for you =P

Don't pay much attention to "the hedgehog" in my nick, it's just because "Sik" was already taken =/ By the way, Sik is pronounced like seek, not like sick.

I was typing a reply at the same time as Sik, so I'll delete what I was saying and just post the diagram that goes with his explanation of the fans ;)

8l4C4yv.png

Also, vmf files are not meant to be rendered directly (except in the editor). In Valve's engine/tools, the "brushes" from the map files are fed into a CSG algorithm, which produces the final geometry data.

Also, vmf files are not meant to be rendered directly (except in the editor). In Valve's engine/tools, the "brushes" from the map files are fed into a CSG algorithm, which produces the final geometry data.


My immediate goal is to make a simple vmf viewer. In my first post I said I'd already parsed the vmf and calculated all the points from the planes. I'm just looking to split all the faces up into triangles.

If all faces are convex (they usually are), just turn them into the equivalent of triangle fans, i.e. the first triangle is vertices 0-1-2, the next is 0-2-3, the next 0-3-4, then 0-4-5, and so on.


Hey, thanks for your help.

I was thinking of doing the exact same thing before I asked here but couldn't figure it out, even after working on it for hours.

After messing around with the code a bit this morning I used your suggestion, and finally got a working loop that calculates all the triangles.(even for 32 sided cylinders)

This topic is closed to new replies.

Advertisement