hello
I’m using a script that automatically generates UVs
However, only one part of the cylinder is formed by putting it together.
In my opinion, it seems that the UV was created repeatedly in that small part.
I’m not sure how to solve it.
Is there any way to solve this?
-My Result-
- MYCode-
public void PlayAutoUV()
{
Mesh mesh = GetComponent<MeshFilter>().mesh;
if (mesh != null)
{
// Check if the mesh already has UVs
if (mesh.uv.Length == 0)
{
// Generate cylinder UVs
Vector2[] uvs = new Vector2[mesh.vertices.Length];
for (int i = 0; i < mesh.vertices.Length; i++)
{
Vector3 vertexPos = mesh.vertices[i];
Vector3 normalizedPos = new Vector3(vertexPos.x, 0f, vertexPos.z).normalized;
//float angle = Mathf.Atan2(vertexPos.z, vertexPos.x);
float u = Mathf.Atan2(normalizedPos.x, normalizedPos.z) / (2f * Mathf.PI) + 0.5f;//angle / (2 * Mathf.PI) + 0f;
//float v = vertexPos.y / mesh.bounds.size.y;
float v = (vertexPos.y - mesh.bounds.min.y) / mesh.bounds.size.y;
uvs[i] = new Vector2(u, v);
}
// Assign the new UVs to the mesh
mesh.uv = uvs;
}
}
}
