I’ve written a simple function that generates a cube with 3 mesh sections. Is there a built in function in the runtime mesh plugin that calculates tangents? If so, how do I call it?
void ARuntimeMeshActor::GenerateCube(UPARAM() FVector size, UPARAM() FVector offset, UPARAM() bool createCollision, UPARAM() UMaterialInstance* mat, UPARAM() FLinearColor vertexColor, EUnitsType eType, float UVScale)
{
SetScale(eType);
MeshComponent->ClearAllMeshSections();
FVector sizeMod = size * sMod;
float UVX = size.X * UVScale;
float UVY = size.Y * UVScale;
float UVZ = size.Z * UVScale;
Vertices.SetNum(8);
Vertices[0].Position = FVector(0.0f, 0.0f, 0.0f);
Vertices[1].Position = FVector(sizeMod.X, 0.0f, 0.0f);
Vertices[2].Position = FVector(0.0f, sizeMod.Y, 0.0f);
Vertices[3].Position = FVector(sizeMod.X, sizeMod.Y, 0.0f);
Vertices[4].Position = FVector(0.0f, 0.0f, sizeMod.Z);
Vertices[5].Position = FVector(sizeMod.X, 0.0f, sizeMod.Z);
Vertices[6].Position = FVector(0.0f, sizeMod.Y, sizeMod.Z);
Vertices[7].Position = FVector(sizeMod.X, sizeMod.Y, sizeMod.Z);
Vertices[0].UV0 = FVector2D(UVX, 0.0f);
Vertices[1].UV0 = FVector2D(0.0f, 0.0f);
Vertices[2].UV0 = FVector2D(UVX, UVY);
Vertices[3].UV0 = FVector2D(0.0f, UVY);
Vertices[4].UV0 = FVector2D(0.0f, 0.0f);
Vertices[5].UV0 = FVector2D(UVX, 0.0f);
Vertices[6].UV0 = FVector2D(0.0f, UVY);
Vertices[7].UV0 = FVector2D(UVX, UVY);
CalculateOffset(Vertices, offset);
Triangles.SetNum(12);
//Bottom
Triangles[0] = 0;
Triangles[1] = 1;
Triangles[2] = 2;
Triangles[3] = 2;
Triangles[4] = 1;
Triangles[5] = 3;
//Top
Triangles[6] = 6;
Triangles[7] = 5;
Triangles[8] = 4;
Triangles[9] = 7;
Triangles[10] = 5;
Triangles[11] = 6;
GenerateMeshSection(0, vColor, Vertices, Triangles);
Vertices[0].UV0 = FVector2D(0.0f, UVZ);
Vertices[1].UV0 = FVector2D(UVY, UVZ);
Vertices[2].UV0 = FVector2D(UVY, UVZ);
Vertices[3].UV0 = FVector2D(0.0f, UVZ);
Vertices[4].UV0 = FVector2D(0.0f, 0.0f);
Vertices[5].UV0 = FVector2D(UVY, 0.0f);
Vertices[6].UV0 = FVector2D(UVY, 0.0f);
Vertices[7].UV0 = FVector2D(0.0f, 0.0f);
//Left
Triangles[0] = 6;
Triangles[1] = 0;
Triangles[2] = 2;
Triangles[3] = 4;
Triangles[4] = 0;
Triangles[5] = 6;
//Right
Triangles[6] = 5;
Triangles[7] = 3;
Triangles[8] = 1;
Triangles[9] = 7;
Triangles[10] = 3;
Triangles[11] = 5;
GenerateMeshSection(1, vColor, Vertices, Triangles);
Vertices[0].UV0 = FVector2D(UVX, UVZ);
Vertices[1].UV0 = FVector2D(0.0f, UVZ);
Vertices[2].UV0 = FVector2D(0.0f, UVZ);
Vertices[3].UV0 = FVector2D(UVX, UVZ);
Vertices[4].UV0 = FVector2D(UVX, 0.0f);
Vertices[5].UV0 = FVector2D(0.0f, 0.0f);
Vertices[6].UV0 = FVector2D(0.0f, 0.0f);
Vertices[7].UV0 = FVector2D(UVX, 0.0f);
//Back
Triangles[0] = 4;
Triangles[1] = 1;
Triangles[2] = 0;
Triangles[3] = 5;
Triangles[4] = 1;
Triangles[5] = 4;
//Front
Triangles[6] = 2;
Triangles[7] = 3;
Triangles[8] = 6;
Triangles[9] = 6;
Triangles[10] = 3;
Triangles[11] = 7;
GenerateMeshSection(2, vColor, Vertices, Triangles);
}
Edit:
Figured it out
URuntimeMeshLibrary::CalculateTangentsForMesh(InVertices, InTriangles);
MeshComponent->CreateMeshSection(sectionID, Vertices, Triangles, true, EUpdateFrequency::Infrequent);