Hello i am not sure if this forum section is the right place for my question.
So basicly i have this procedural generated mesh and i want to add uv to the Mesh Component via meshcomponent.uv = myVector2Array. Unfortuanetly i don´t know what values i have to add to that Array.
I have another array that is holding the vectors for the mesh, do i have to use those (represented as the blue dots on the pic).
UVs are an attribute of a vector, so you will need to pass an array of Vector2s(plural?) equal to the size of the vertex array.
Here is how UVs work in OpenGL(texture coordinates).
What you’ve shown in picture 2 is achieved by setting your left UVs X to 0, your right UVs X to 1, bottom UVs Y to 0 and top UVs Y to 1.
If i want to always have same uv on the texture, is there a default value i can use. I think you described that BakeMyCake but i don´t understand it right.
Can you explain please, what you mean by left Uvs x and so on.
See the attachment picture of how UV coordinates would look like for the image you posted. You’ll have to figure out how to code an algorithm that would issue correct UVs to your mesh. Most implementations I’ve seen hold a point path and generate geometry based on the points.
Does the geometry have unique vertices per triangle, or are they shared? If they’re shared then the example @BakeMyCake gave you won’t really work since you can’t set unique UVs per triangle, only per vertex. But that’s okay, you can just use UVs that are outside that 0.0 to 1.0 range. Starting from the bottom, the next quad would simply use a UV range of 1.0 to 2.0 for the y, the next would use the range of 2.0 to 3.0 for y, etc. If the texture applied is set to wrap mode repeat, it’ll simply repeat the texture as if the UV value being passed in was in that 0.0 to 1.0 range.
(Negative values are totally fine too.)
Now, if you want the texture to appear exactly as you showed in your original #2 image where each “smiley face” is undistorted, neither @BakeMyCake nor my modification for use with shared vertices will produce that. The textures will be stretched in odd ways since that’s what the UVs are doing. There are multiple solutions to this, but the easiest one is to actually have unique vertices, at least per “quad”. Then you’d need to set the UVs to whatever is required to keep the texture centered and undistorted, like this:
Now, if the geometry 3D and not just on a flat 2D plane, you may have to choose some kind of projection direction to determine the 2D UVs. And if the mesh is moving and distorting after it is initially created, any vertex movement will cause the textures to distort again. So you either just need to live with the fact the textures will distort, or update the UVs every time the vertices change.