On the first look it works quite well to generate the mesh from scratch. Just tested it with 10000 tiles and only one material.
The time needed for that is about zero. While I would need to do several more conditionals and so on for more complex stuff and several materials I guess it would be fine even if it took 10 times longer then. The only obstacle here is that a mesh can’t have more than 65k vertices, but that equals more than 100x100 tiles per mesh and should work fine.
So thanks to all for your help!
For those finding this thread and looking for more information - I got the info about these mechanics by the following links:
and
and the function I built for a simple test (straight line of 10000 tiles):
void Start()
{
GetComponent<MeshFilter>().mesh = CreateTonsPlaneMesh();
}
Mesh CreateTonsPlaneMesh()
{
int counter=10000;
Mesh mesh = new Mesh();
Vector3[] vertices = new Vector3[counter*4];
for (int i = 0; i < counter; i++)
{
vertices[i*4] =new Vector3(1+i*2 ,0, 1);
vertices[i*4+1] =new Vector3(1+i*2 ,0,-1);
vertices[i*4+2] =new Vector3(-1+i*2 ,0, 1);
vertices[i*4+3] =new Vector3(-1+i*2 ,0,-1);
}
/*
Vector3[] vertices = new Vector3[]
{
new Vector3( 1, 0, 1),
new Vector3( 1, 0, -1),
new Vector3(-1, 0, 1),
new Vector3(-1, 0, -1),
new Vector3( 3, 0, 1), /2nd run
new Vector3( 3, 0, -1), /2nd run
new Vector3( 1, 0, 1), /2nd run
new Vector3( 1, 0, -1), /2nd run
};
*/
Vector2[] uv = new Vector2[counter*4];
for (int i = 0; i < counter; i++)
{
uv[i*4] =new Vector2(1,1);
uv[i*4+1] =new Vector2(1,0);
uv[i*4+2] =new Vector2(0,1);
uv[i*4+3] =new Vector2(0,0);
}
/*
Vector2[] uv = new Vector2[]
{
new Vector2(1, 1),
new Vector2(1, 0),
new Vector2(0, 1),
new Vector2(0, 0),
new Vector2(1, 1), /2nd run
new Vector2(1, 0), /2nd run
new Vector2(0, 1), /2nd run
new Vector2(0, 0), /2nd run
};*/
int[] triangles= new int[counter*6];
for (int i = 0; i < counter; i++)
{
triangles[i*6] =0+i*4;
triangles[i*6+1] =1+i*4;
triangles[i*6+2] =2+i*4;
triangles[i*6+3] =2+i*4;
triangles[i*6+4] =1+i*4;
triangles[i*6+5] =3+i*4;
}
/*
int[] triangles = new int[]
{
0, 1, 2,
2, 1, 3,
4, 5, 6, /2nd run
6, 5, 7, /2nd run
};*/
mesh.vertices = vertices;
mesh.uv = uv;
mesh.triangles = triangles;
return mesh;
}