Download

How to texture a procedural mesh?

I have a question about the procedural Mesh Creation.
I can easily import a Cube from Blender and transform it to a procedural mesh.
The Problem that I have is about the UVs. According to this Post, the Vertices array must match the vertex data, meaning one UV value for each vertex.
I don’t understand two things here:

  1. How can more complicated UVs be created if that statements correct?
    Lets say with vertices and coordinates like this:

    v -22.510305 -21.476305 23.214086
    v 22.510305 -21.476305 23.214086
    v -22.510305 23.544305 23.214086
    v 22.510305 23.544305 23.214086
    v -22.510305 23.544305 -21.806524
    v 22.510305 23.544305 -21.806524
    v -22.510305 -21.476305 -21.806524
    v 22.510305 -21.476305 -21.806524

    vt 0.001891 0.668525
    vt 0.331370 0.668525
    vt 0.001891 0.998004
    vt 0.331370 0.998004
    vt 0.338706 0.668529
    vt 0.668185 0.668529
    vt 0.338706 0.998008
    vt 0.668185 0.998008
    vt 0.338706 0.001992
    vt 0.668185 0.001992
    vt 0.338706 0.331471
    vt 0.668185 0.331471
    vt 0.282362 0.335259
    vt 0.611841 0.335259
    vt 0.282362 0.664738
    vt 0.611841 0.664738
    vt 0.001891 0.001992
    vt 0.331370 0.001992
    vt 0.001891 0.331471
    vt 0.331370 0.331471
    vt 0.617664 0.335261
    vt 0.947143 0.335261
    vt 0.617664 0.664740
    vt 0.947143 0.664740

  2. How can I keep the material clean for different shapes of the procedural mesh. Lets say if I move one vertex?
    How can I avoid distortion?

Thank you.

Hi @Phoenix100
i am not an expert but i would consider using world aligned texturing,
if i remember correctly you can use this sistem to avoid uv .
for some thing is good even with some distorsions

1 Like

Shouldn’t this already be handled with CopyProceduralMeshFromStaticMesh? If not:

CreateMeshSection gives you up to four UV sets. However, GetSectionFromStaticMesh only has one UV array, so I’m assuming all UV sections are combined into that one array. You can check this by getting the length of the array.
For your example, you have 8 vertices and 24 coordinates. 24/8=3, so you have 3 UV sets: the first 8 coordinates are the first set, the second 8 coordinates are the second set, and the third 8 coordinates are the third set (8+8+8=24).
So for a static mesh, you would loop through each section and put the UVs into the appropriate slot & index. To get the slot, do slot = floor(coordinateIndex/vertexCount), and to get the index, do index = mod(coordinateIndex, vertexCount) (this should be equal to the index of the vertex it’s assigned to).

1 Like