Right am new to this whole mesh generation thing, i got it down but am having issues with UVs and well its not tiling… should also point out am using a texture atlas Heres and Example
// Create the mesh
GameObject NewChunk = new GameObject();
NewChunk.transform.name = "Chunk " + ChunkNumber;
NewChunk.transform.position = Pos;
Mesh msh = new Mesh();
msh.vertices = Points.ToArray();
List<int> Tris = new List<int>();
for (int i = 0; i < Points.Count; i++)
{
List<int> SetTris1 = new List<int>();
List<int> SetTris2 = new List<int>();
SetTris1.Add(GetPointIndexAt(Points[i], Points));
SetTris1.Add(GetPointIndexAt(Points[i] + new Vector3(0, 0, 1), Points));
SetTris1.Add(GetPointIndexAt(Points[i] + new Vector3(1, 0, 0), Points));
if (!SetTris1.Contains(-1))
{
Tris.AddRange(SetTris1);
}
SetTris2.Add(GetPointIndexAt(Points[i] + new Vector3(1, 0, 0), Points));
SetTris2.Add(GetPointIndexAt(Points[i] + new Vector3(0, 0, 1), Points));
SetTris2.Add(GetPointIndexAt(Points[i] + new Vector3(1, 0, 1), Points));
if (!SetTris2.Contains(-1))
{
Tris.AddRange(SetTris2);
}
}
msh.triangles = Tris.ToArray();
Vector2[] Uvs = new Vector2[Points.Count]; // Create array with the same element count
for (var i = 0; i < Points.Count; i++)
{
//Uvs[i] = new Vector2(Points[i].x, Points[i].y);
List<int> UVPoints = new List<int>();
UVPoints.Add(GetPointIndexAt(Points[i], Points));
UVPoints.Add(GetPointIndexAt(Points[i] + new Vector3(0, 0, 1), Points));
UVPoints.Add(GetPointIndexAt(Points[i] + new Vector3(1, 0, 1), Points));
UVPoints.Add(GetPointIndexAt(Points[i] + new Vector3(1, 0, 0), Points));
if (!UVPoints.Contains(-1))
{
Uvs[UVPoints[0]] = UVMap.GetUVMap("cobblestone_mossy").UV_Map[1];
Uvs[UVPoints[1]] = UVMap.GetUVMap("cobblestone_mossy").UV_Map[3];
Uvs[UVPoints[2]] = UVMap.GetUVMap("cobblestone_mossy").UV_Map[2];
Uvs[UVPoints[3]] = UVMap.GetUVMap("cobblestone_mossy").UV_Map[0];
}
}
msh.uv = Uvs;
msh.RecalculateNormals();
msh.RecalculateBounds();
NewChunk.AddComponent(typeof(MeshRenderer));
NewChunk.GetComponent<Renderer>().material.SetTexture("_MainTex", ChunkAtlas);
MeshFilter filter = NewChunk.AddComponent(typeof(MeshFilter)) as MeshFilter;
filter.mesh = msh;
Not sure what the issue is.