Download

Questions regarding numbering of vertices and triangles

Hi,

I am trying to generate a mesh from an algorithm and have a question regarding the numbering of vertices and triangles. I am quite new to programming involving 3D objects and have tried searching but maybe i dont know the terminology.

I use an algorithm to generate the vertices first then apply the triangles to those vertices.

  1. Is there a best practice or rule when it comes to numbering the vertices. Given a box mesh with 8 vertices, in what order should they be numbered?

  2. Given a face of the box as shown in the picture below. I know the triangle should be defined in a clockwise manner when facing it. But does it matter if the triangle is numbered as (0, 2, 3), (3, 0, 2) or (2, 3, 0)?

  3. Are there mathematical algorithms that can be applied to generate triangles for a solid mesh given its vertices? (I guess there must be a lot of different ways to do this?)

I would love if someone could point me in the direction of some relevant theory on the subject. Thanks!

BoxFace.png

Before I started using Unreal Engine, I did a game myself on my own engine in OpenGL a few years back, so from what I remember the default way to index vertices (at least in OpenGL) is to do it counterclockwise. It is possible to do it clockwise but then you would have to use front face culling instead of back face culling. So it depends on the way you want to do it, but by default it is counterclockwise. (this is so opengl will know which faces to render, back faces won’t be rendered when using back face culling, and if you were to enable front face culling then it the other way).

http://learnopengl.com/#!Advanced-OpenGL/Face-culling

Then there the issue of duplicated vertices. To draw that square in that pic of yours, there are duplicated vertices, (several of these vertices are shared between triangles). So that where vertex arrays and vertex buffer objects (VBO’s) and etc come into play.

http://www.opengl-tutorial.org/intermediate-tutorials/tutorial-9-vbo-indexing/
http://www.songho.ca/opengl/gl_vertexarray.html

By using indices for your vertices you would reduce redundant vertices and opengl function calls. There a bunch of theory on those but hopefully this will help a bit :slight_smile:

In this video, the guy uses clockwise ordering and works well: Unreal Engine 4 Guide - Mesh generation - YouTube