FDynamicMesh3 Vertex Colors not working in UE 5.3

Hi, I upgraded from 5.1 to 5.3 and noticed that the vertex colors are not working anymore.

Here is how I build the mesh:

FDynamicMesh3* Mesh = DynamicMeshComponent->GetMesh();
Mesh->Clear();
Mesh->EnableVertexColors(FVector3f());
Mesh->EnableVertexNormals(FVector3f(0, 1, 0));

TArray<int> Indices;

for (int i = 0; i < MeshData.Vertices.Num(); i++)
{
	int Id = Mesh->AppendVertex(MeshData.Vertices[i]);
	Mesh->SetVertexNormal(Id, FVector3f(MeshData.Normals[i]));
	Mesh->SetVertexColor(Id, FVector3f(MeshData.Colors[i]));
	Indices.Add(Id);
}

for (int i = 0; i < MeshData.Triangles.Num(); i += 3)
{
	const int T0 = Indices[MeshData.Triangles[i]];
	const int T1 = Indices[MeshData.Triangles[i + 1]];
	const int T2 = Indices[MeshData.Triangles[i + 2]];
	Mesh->AppendTriangle(T0, T1, T2);
}

DynamicMeshComponent->NotifyMeshUpdated();

Any idea?

I got it to work by setting the primary color attributes.
Here is the updated code:

Mesh->EnableVertexNormals(FVector3f());
Mesh->EnableVertexColors(FVector4f());

Mesh->EnableAttributes();
Mesh->Attributes()->EnablePrimaryColors();
const auto ColorOverlay = Mesh->Attributes()->PrimaryColors();

for (int i = 0; i < MeshData.Vertices.Num(); i++)
{
    int Id = Mesh->AppendVertex(MeshData.Vertices[i]);
    Indices.Add(Id);
    Mesh->SetVertexNormal(Id, FVector3f(MeshData.Normals[i]));
    Mesh->SetVertexColor(Id, FVector4f(MeshData.Colors[i]));
    ColorOverlay->AppendElement(FVector4f(MeshData.Colors[i]));
}

for (int i = 0; i < MeshData.Triangles.Num(); i += 3)
{
    const int T0 = Indices[MeshData.Triangles[i]];
    const int T1 = Indices[MeshData.Triangles[i + 1]];
    const int T2 = Indices[MeshData.Triangles[i + 2]];
    const int Id = Mesh->AppendTriangle(T0, T1, T2);
    ColorOverlay->SetTriangle(Id, UE::Geometry::FIndex3i(T0, T1, T2));
}

MeshComponent->NotifyMeshUpdated();
3 Likes

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.