- Home /
Texture breaking along center of mesh
I'm attempting to draw a 2d texture onto a sphere mesh made from a previously normalized cube. Everything works fine except the texture breaks along the center line of each face. The effect becomes even more pronounced when the number of verities is reduced
I'm thinking it might be an issue with the mesh UV, heres how im currently generating it.
public static void CreateUV(Vector3[] vertices, Vector2[] uv)
{
float previousX = 1f;
for (int i = 0; i < vertices.Length; i++)
{
Vector3 v = vertices[i];
if (v.x == previousX)
{
uv[i - 1].x = 1f;
}
previousX = v.x;
Vector2 textureCoordinates;
textureCoordinates.x = Mathf.Atan2(v.x, v.z) / (-2f * Mathf.PI);
if (textureCoordinates.x < 0f)
{
textureCoordinates.x += 1f;
}
textureCoordinates.y = Mathf.Asin(v.y) / Mathf.PI + 0.5f;
uv[i] = textureCoordinates;
}
}
I don't understand how your uv generation works, but my guess is that it's too precise on the Uv Map island borders (and my guess is that there's an uv map island on that problem area and it is almost touching an unwanted portion of the UV map). I would start getting an UV viewer tool like Uvee and take a look at the UV map to see if you can figure out something.
So I did that and it did confirm what i had thought the UV map is misplacing points and moving them to the far left of the image. not sure how to fix this yet
Answer by kilometerbob · Jan 02 at 06:18 AM
it was literally one unnecessary line of code the uv[i - 1].x = 1f;
was causing vertices along the center to have 1 as there x value if you can believe that and the whole thing runs fine without that check