I am trying to fill in a plane of vertices with triangles but the triangles do not show on my mesh. Is there anything I am doing wrong? Here is the code that does that:
private void Generate()
{
for (int z = 0; z < chunkWidth; z++)
{
for (int x = 0; x < chunkWidth; x++)
{
float simplex1 = noise.GetSimplex(x * 0.8f, z * 0.8f) * 10;
float simplex2 = noise.GetSimplex(x * 3f, z * 3f) * 10 * (noise.GetSimplex(x * 0.3f, z * 0.3f) + 0.5f);
float y = simplex1 + simplex2;
// Instantiate(cube, new Vector3(x, y, z), Quaternion.identity);
verts.Add(new Vector3(x, 0, z));
}
}
int v = 0;
int t = 0;
for (int z = 0; z < chunkWidth; z++)
{
for (int x = 0; x < chunkWidth; x++)
{
tris.Add(v + 0);
tris.Add(v + chunkWidth + 1);
tris.Add(v + 1);
tris.Add(v + 1);
tris.Add(v + chunkWidth + 1);
tris.Add(v + chunkWidth + 2);
v++;
t += 6;
}
v++;
}
UpdateMesh();
}
private void UpdateMesh()
{
mesh.vertices = verts.ToArray();
mesh.triangles = tris.ToArray();
mesh.RecalculateNormals();
MeshFilter filter = GetComponent<MeshFilter>();
filter.mesh = mesh;
}