In this example, the plane mesh displays a total of 9 vertices and 8 triangles, composing a total of 4 quads.
So my question here is simply this: How would you calculate the most optimal index buffer for this?
Keep in mind that the actual number of X and Y vertices may vary, but the overall mesh will still be a series of quads.
Bonus Question:
What is the default flag (triangle fan, triangle strip, etc) that UE4 uses while rendering, and what is the default vertex winding order?
This is a bit old, but since nobody has answered this yet, I’ll just go ahead and add this, since I was trying to figure this out myself and others might benefit from it.
You would probably be interested in the following function which should do what you ask to:
From KismetProceduralMeshLibrary.h (part of the ProceduralMeshComponent plugin)
/**
* Generate an index buffer for a grid of quads.
* @param NumX Number of vertices in X direction (must be >= 2)
* @param NumY Number of vertices in y direction (must be >= 2)
* @param bWinding Reverses winding of indices generated for each quad
* @out Triangles Output index buffer
*/
UFUNCTION(BlueprintCallable, Category = "Components|ProceduralMesh")
static void CreateGridMeshTriangles(int32 NumX, int32 NumY, bool bWinding, TArray<int32>& Triangles);
So all you need is to know how many vertices you have in x and y direction on your grid.
You can probably also look at the source code of the function if you want to know how it’s done exactly.
Also, even though this says BluePrintCallable, you can easily access these functions in C++:
First you’ll have to add the ProceduralMeshComponent Module to your Build.cs file.
For Example:
I am using Procedural Mesh Component in a C++ class and I wonder how to use this CreateGridMeshTriangles method. I’ve added #include "KismetProceduralMeshLibrary.h" to my cpp file, and have added
to a method, but I am not sure how this is going to produce a mesh… any tips or examples of actual usage would be greatly appreciate, I’m also new to C++, although familiar with other programming languages.