CreateMeshSection without having the triangles

I’m following the article Procedural Mesh Component in C++:Getting Started because I want to create a polygon.

My problem is that I have N unordered vertices and I don’t know how to generate the triangles needed by the method


CreateMeshSection(1, vertices, Triangles, normals, UV0, vertexColors, tangents, false);

How can I obtain the triangles vertices from an unordered array of vertices?

Without the triangles information, you just have a pile of points in space. You need to provide a series of sets of 3 ordered vertex indexes to describe the surface geometry.


0==1
|  |
2==3

With this array of verts, you could make a quad out of two triangles by setting triangles to [0,2,1,2,3,1]

Yes, but there is some method, class, function in Unreal to order the vertices and calculate the triangles or I have to do it by myself?

You need to do it yourself, there’s no way for the engine to know what geometry you want to create. I think there are some functions knocking around still in the KismetProceduralMeshLibary for making boxes/quads.

There is definitely a procedure in there that will generate normals and tangents for you…but you must provide the Vertices and Triangles.

Ok, great answer. Thanks!