Calculation of procedural mesh indices (C++)

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. :slight_smile:

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:

PublicDependencyModuleNames.AddRange(new string[] { "Core", "CoreUObject", "Engine", "InputCore", "ProceduralMeshComponent" });

Then you can just include the header file as you would normally:

#include "ProceduralMeshComponent.h"
#include "KismetProceduralMeshLibrary.h"

Just beware that this functionality is still marked as experimental.