I’m not really sure how this is done… cant find any info on google for some reason so I must be using the wrong term.
If you have a bunch of quads that you are building procedurally and you want to texture them from one big image split up into different textures (so you can have one material), whats the best way? It’s like a sprite atlas but for 3D quads.
I have been editing the mesh UVs directly like so…
public static Vector2[] UV4s(Vector2 TL, Vector2 BR, int rotation) {
Vector2 v1, v2, v3, v4;
v1 = new Vector2(MathF.Round(TL.x / 1024f, 4), 1 - MathF.Round((BR.y / 1024f), 4)); // 0 0
v2 = new Vector2(MathF.Round(TL.x / 1024f, 4), 1 - MathF.Round((TL.y / 1024f), 4)); // 0 1
v3 = new Vector2(MathF.Round(BR.x / 1024f, 4), 1 - MathF.Round((TL.y / 1024f), 4)); // 1 1
v4 = new Vector2(MathF.Round(BR.x / 1024f, 4), 1 - MathF.Round((BR.y / 1024f), 4)); // 1 0
Vector2[] r = new Vector2[] { v1, v2, v3, v4 };
if (rotation == 1) { r = new Vector2[] { v2, v3, v4, v1 }; }
if (rotation == 2) { r = new Vector2[] { v3, v4, v1, v2 }; }
if (rotation == 3) { r = new Vector2[] { v4, v1, v2, v3 }; }
return r;
}
But one thing I’ve noticed is that there are “seams” where the quads bleed through. I’m pretty sure this is because of when you have a large image like 1024 and you set the UV to a certain slice of it you have to divide it and you wind up with a UV float value like 0.625.
But when I use a small 64x64 texture where the UVs can be just whole numbers like (0, 1) the seams dont appear.
So how have you guys tackled this before? I think I’m just going to create a bunch of different 64x64 materials and use that unless there is a better way.