A Generated Mesh

So to generate all of the vertices and triangles for this mesh, begin with an empty vertex array and an empty triangle array.

for r = 0 to n − 1
  for c = 0 to n − 1
    Add a new vertex $[x, y, z]$ at row r column c.
for r = 0 to n − 2
  for c = 0 to n − 2
    Add a new triangle $[i_0, i_1, i_2]$ at row r column c.
    Add a new triangle $[i_2, i_1, i_3]$ at row r column c.