Download

Procedural Mesh >> UVs not working?

Hey everyone,

I am trying to generate a mesh using the ProceduralMeshComponent class. I am able to create the mesh, however the UVs do not seem work properly unless the mesh has only 2 triangles. What I am doing wrong here?

If I set xSize and zSize to 1, I see the default checkboard pattern, otherwise I don’t (only a uniform gray color).



void AProceduralMesh::CreateShape()
{
    int xSize = 20;
    int zSize = 20;

    TArray<FVector> vertices;
    vertices.Reserve((xSize + 1) * (zSize + 1));

    TArray<int32> triangles;
    triangles.Reserve(xSize * zSize * 6);

    TArray<FVector> normals;
    TArray<FVector2D> UV0;
    TArray<FProcMeshTangent> tangents;
    TArray<FLinearColor> vertexColors;

    for (int z = 0; z <= zSize; z++)
    {
        for (int x = 0; x <= xSize; x++)
        {
            vertices.Add(FVector(x * 100, z * 100, 0));
        }
    }

    int vert = 0;
    for (int z = 0; z < zSize; z++)
    {
        for (int x = 0; x < xSize; x++)
        {
            triangles.Add(vert);// 0
            triangles.Add(vert + xSize + 1); // 1
            triangles.Add(vert + 1);//2
            triangles.Add(vert + xSize + 2);//3
            triangles.Add(vert + 1);//2
            triangles.Add(vert + xSize + 1);//1

            UV0.Add(FVector2D(0, 0));
            UV0.Add(FVector2D(1, 0));
            UV0.Add(FVector2D(0, 1));
            UV0.Add(FVector2D(1, 1));

            vert++;
        }
        vert++;
    }

    Mesh->CreateMeshSection_LinearColor(0, vertices, triangles, normals, UV0, vertexColors, tangents, true);
    Mesh->ContainsPhysicsTriMeshData(true);
}


Thank you