# Convert an array of points into a mesh (generate triangles)

In my code, I have a 2d array of Vector3s that define the points I need for a mesh. none of the points are above one another; they form a sheet. I can pass those into a mesh just fine, but i need to generate the list of triangles for the mesh. I’m not sure how to do that. any ideas? C# would be best. oh, the array could be 1d instead of 2d, to make passing it to the mesh faster

http://www.studentgamedev.org/2013/08/unity-voxel-tutorial-part-1-generating.html

do these tutorials, they’re quick, it took me only a couple hours to get to the point of making 3D minecraft style terrain.

It starts off real simple with exactly what you’re asking for.

took me a while to get back here, but I solved it myself. Thanks for the answers anyway.
here’s my code snippet, can anyone tell me if I did it right? it seems to work fine.

``````		lrLengthx = (int)((xmax-xmin)/xres+1);//how many points in the x direction
lrLengthz = (int)((zmax-zmin)/zres+1);//how many points needed in z direction
points = new Vector3[lrLengthx*lrLengthz];
uvs = new Vector2[lrLengthx*lrLengthz];
triangles = new int[points.Length*6];
//generate triangles
int index = 0;
for(int z = 0; z<lrLengthz-1;z++){
for(int x = 0; x<lrLengthx-1;x++){
uvs[x+z*lrLengthx] = new Vector2(x/(lrLengthx-1.0f),z/(lrLengthz-1.0f));
triangles[index+2]   = x+z*lrLengthx;
triangles[index+1] = x+1+z*lrLengthx;
triangles[index+0] = x+z*lrLengthx+lrLengthx;

triangles[index+3] = x+z*lrLengthx+lrLengthx;
triangles[index+4] = x+1+z*lrLengthx+lrLengthx;
triangles[index+5] = x+1+z*lrLengthx;
index+=6;
}
}
``````