Creating a procedural cube with texture

I want to use the ProceduralMeshComponent for creating a box with texture. Something like this:

This cube has 8 vertices and 12 faces. The texture’s coordinates are 4.

The problem is that the ProceduralMeshComponent wants the uvs per vertex, so each vertex must have only one uv, while in my case each vertex should have 3, since each vertex belongs to 3 faces.

The only solution I can think of is to split the vertices, so that each face uses unique vertices. This is the trick done by UKismetProceduralMeshLibrary::GenerateBoxMesh, which creates the box using 8 * 3 = 24 vertices.

My question is: is there a better way to handle this? Is there a way to use just 8 vertices and somehow tell Unreal that the vertices may have multiple texture coordinates?

I do not think so. Splitting the verts is actually what is happening under the hood any time you have UV discontinuities.

You could procedurally map the texture instead using the local position of the mesh, and then you wouldn’t need UVs except for tangent basis.

edit, you could remove some of the duplication by using an alternating flipping pattern, so the texture would mirror at each corner. Then maybe you could counteract that by setting the texture mode to be mirrored which might work but I haven’t tried. The top face wouldn’t be able to do that for all edges (doing so would describe a hypercube of some kind:)

Oh, didn’t know that.

Thanks a lot for the explanation! I think I’ll just duplicate the vertices for now :smiley: