First off, i’m not talking about UV wrapping/unwrapping.
I’m making a procedurally generated map and am trying to put the image of the map onto the editable mesh, which is the big plane you see. (2D map visible in top-left corner)
However the problem is that at the top and right of the map , it seems as though the UV map wraps back around. At the top, the little lighter bar fades in from the bottom and the same thing is visible to the right, just that it’s a little harder to see in the picture. So it looks like the UV map thinks its one continuous image and goes from the top back to the bottom.
In the code that generates the UVs, settings.ChunkLength
is the amount of vertices the map has on its side, so if settings.ChunkLength
is 4, then the map is 4x4. settings.ChunkPointGap
is the distance between two neighbouring vertices on the map.
The resolution of the map at the top left and the amount of vertices on the actual map are equal.
local uvIds: {number} = editable:GetUVs()
local k = 1
for x = 1, settings.ChunkLength do
for y = 1, settings.ChunkLength do
local vId: number = editable:GetVerticesWithAttribute(uvIds[k])[1]
local vPos: Vector3 = editable:GetPosition(vId) -- ty roblox for almost making this make sense <3
editable:SetUV(uvIds[k], Vector2.new(vPos.Z + settings.ChunkPointGap, settings.ChunkLength * settings.ChunkPointGap - settings.ChunkPointGap - vPos.X) / settings.ChunkPointGap / settings.ChunkLength)
-- Why not just
-- editable:SetUV(uvIds[k], Vector2.new(vPos.X, vPos.Z) / settings.ChunkPointGap / settings.ChunkLength)?
-- Because what I do above also rotates the map. F=Essentially functions the same tho, but with this option that is commented out, the wrapping appears at the left and top not at the right and top.
k += 1
end
end
...
MeshPart.TextureContent = Content.fromObject(texture) -- Apply the EditableImage of the 2D map to the 3D one
The way that the UVs are being set might seem a bit weird, but apparently, when creating vertices for the mesh, the UVs that are made for the vertices at the same time aren’t ordered the same way as the vertices, so I have to get the vertex id from the uv id and then get the position of the vertex so that I could change UV to be at the correct position.
If anyone knows how to prevent the UV from wrapping around like that, then that’d be awesome!
Another example
It’s quite a bit past midnight when writing this, so I’m sorry if this causes brain damage to read.