I am trying to create a Plane using custom mesh.
I have applied the same material to a Unity Default plane and another plane is generated using code.
But the material looks different on both the mesh.
Mesh detail:
Left Mesh-> Unity Default plane
Right Mesh → Mesh Generated Using Code.
// assigning vertices, traingles, and UVs
mesh.vertices = vertices.ToArray();
mesh.triangles = triangles.ToArray();
mesh.uv = GetUVs(mesh.vertices);
mesh.RecalculateNormals();
mesh.RecalculateBounds();
mesh.RecalculateTangents();
// Generating UVs for custom plane
Vector2[] GetUVs(Vector3[] verticesList)
{
Vector2[] uvs = new Vector2[verticesList.Length];
for (int i = 0; i < uvs.Length; i++)
{
uvs[i] = new Vector2(verticesList[i].x, verticesList[i].y);
}
return uvs;
}
I have to generate a plane manually because it is a wall and I am placing an opened door and window between the wall, so the mesh needs to be cut, that’s why I am generating mesh manually.
Need help fixing the tiling issue, I didn’t need tiling when I passed 1,1 tiling in the material.
I may be wrong, but it looks like this means that the x and y coordinates of each vertex are integers from 0 to 10, according to their index in the array. Therefore, each quad of the plane covers the UV space between these integers (effectively the 0-1 space), and thus the entire texture, which is why it tiles like this. So, what I would try is dividing the x and y coordinates by the width and height in quads (10, in this case), so that the coordinates are in the 0-1 range.