Convert the Tiles to a Mesh

This section covers how to convert the tiles produced in the previous section to a mesh and render it in the scene.

1. Generate the Mesh Data

The first step is to convert the tiles to vertices and triangles. It can be done using the following code:

BlueprintsC++
TArray<FVector> Vertices;
TArray<int32> Faces;
TArray<FColor> Colors;
TArray<FVector> Normals;
TArray<FProcMeshTangent> Tangents;
TArray<FVector2D> UV0;
FHexaSphereLib::TilesToMesh(Tiles, Vertices, Faces, Colors, true);

2. Create a Procedural Mesh Component

To use the mesh data, we need a Procedural Mesh Component. It can be added to any actor as shown below:

Add a component button

Search for procedural and add a Procedural Mesh component.

Add a component button

Now that we have the Procedural Mesh Component, we can create a section with the data:

BlueprintsC++
#include "ProceduralMeshComponent.h"
#include "HexaSphere/HexaSphereLib.h"
#include "HexaSphere/HexaTile.h"
// ...
TArray<FVector> Vertices;
TArray<int32> Faces;
TArray<FColor> Colors;
TArray<FVector> Normals;
TArray<FProcMeshTangent> Tangents;
TArray<FVector2D> UV0;
FHexaSphereLib::TilesToMesh(Tiles, Vertices, Faces, Colors, true);
ProceduralMesh->CreateMeshSection(0, Vertices, Faces, Normals, UV0, Colors, Tangents, false);