Hi,
I’m trying to create a simple plane with 32x32 tiles using the Mesh-class
It works like a charm although I would like to share vertices between tiles.
How can I do this, anyone have a simple algorithm to share or recommend?
Right now I’m doing this, but as I said, it creates 4 vertices/tile…
var mesh : Mesh = new Mesh();
mesh.Clear();
var vertices = new Array();
var triangles = new Array();
vertices.length = tiles.length * 4;
i = 0;
for (var tile : Vector3 in tiles) {
vertIndex = i * 4;
vertices[vertIndex] = Vector3(tile.x, 0, tile.z);
vertices[vertIndex + 1] = Vector3(tile.x+1, 0, tile.z);
vertices[vertIndex + 2] = Vector3(tile.x, 0, tile.z+1);
vertices[vertIndex + 3] = Vector3(tile.x+1, 0, tile.z+1);
i++;
}
triangles.length = tiles.length * 6;
i = 0;
for (var tile : Vector3 in tiles) {
triIndex = i * 6;
vertIndex = i * 4;
triangles[triIndex] = vertIndex + 3;
triangles[triIndex + 1] = vertIndex + 1;
triangles[triIndex + 2] = vertIndex + 2;
triangles[triIndex + 3] = vertIndex + 2;
triangles[triIndex + 4] = vertIndex + 1;
triangles[triIndex + 5] = vertIndex;
i++;
}
mesh.vertices = vertices;
mesh.triangles = triangles;
tiles is an array with Vector3 objects…
Any suggestions? I can’t seem to wrap my head around this