Hello. Working a bit on procedural meshes, I get hits and misses on coloring the vertices. I made a nice voxel model in full color in another part of my code. Then I try to create some additional meshes and get only grey instead of red.
Sometimes, it’s about changing the section index from 0 to 1. But that doesn’t always work.
Below is a simple square mesh that I am trying to color. It was tested on the Basic Code template for C++. Can anyone see what’s wrong ?
ProceduralMeshComponent module is set in the build.cs file.
Mesh object is set in .h file like so:
UPROPERTY(VisibleAnywhere, Category = ProcMesh)
UProceduralMeshComponent* mesh;
Constructor in .cpp goes like this:
AMyActor::AMyActor()
{
mesh = CreateDefaultSubobject<UProceduralMeshComponent>(TEXT("GeneratedMesh"));
RootComponent = mesh;
TArray<FVector> vertices;
TArray<int32> triangles;
TArray<FVector> normals;
TArray<FLinearColor> colors;
vertices.Add(FVector(0.f, 0.f, 0.f));
vertices.Add(FVector(0.f, 100.f, 0.f));
vertices.Add(FVector(100.f, 0.f, 0.f));
vertices.Add(FVector(100.f, 100.f, 0.f));
triangles.Add(0);
triangles.Add(1);
triangles.Add(2);
triangles.Add(3);
triangles.Add(2);
triangles.Add(1);
for (int32 i = 0; i < vertices.Num(); i++)
{
normals.Add(FVector(0.f, 0.f, 1.f));
colors.Add(FLinearColor::Red);
}
// Optional arrays
TArray<FVector2D> UV0;
TArray<FProcMeshTangent> tangents;
mesh->CreateMeshSection_LinearColor(0, vertices, triangles, normals, UV0, colors, tangents, true);
}