c# - Getting vertices and indices from a List<Vector3> -


i trying achieve drawing triangles list of vector3 elements.

previously have used heightmap create vertices , indices worked out because rectangle in 2d array not list.

how go (or modify) existing code deal list instead of 2d array.

my existing code vertices:

public vertexpositionnormaltexture[] getverticies(float[,] heightdata)     {         vertexpositionnormaltexture[] vertices = new vertexpositionnormaltexture[terrainlength * terrainwidth];          (int y = 0; y < terrainlength; y++)         {             (int x = 0; x < terrainwidth; x++)             {                  // position vertices heightfield centered                 // around x=0,z=0                 vertices[x + y * terrainwidth].position.x = terrainscale * (x - ((terrainwidth - 1) / 2.0f));                 vertices[x + y * terrainwidth].position.z = terrainscale * (y - ((terrainlength - 1) / 2.0f));                  vertices[x + y * terrainwidth].position.y = (heightdata[x, y] - 1);                  vertices[x + y * terrainwidth].texturecoordinate.x = (float)x / terrainscale;                 vertices[x + y * terrainwidth].texturecoordinate.y = (float)y / terrainscale;             }         }          return vertices;     } 

here code indices:

public int[] getindicies()     {         int counter = 0;         int [] indices = new int[(terrainwidth - 1) * (terrainlength - 1) * 6];          (int y = 0; y < terrainlength - 1; y++)         {             (int x = 0; x < terrainwidth - 1; x++)             {                 int lowerleft = x + y * terrainwidth;                 int lowerright = (x + 1) + y * terrainwidth;                 int topleft = x + (y + 1) * terrainwidth;                 int topright = (x + 1) + (y + 1) * terrainwidth;                  indices[counter++] = topleft;                 indices[counter++] = lowerright;                 indices[counter++] = lowerleft;                  indices[counter++] = topleft;                 indices[counter++] = topright;                 indices[counter++] = lowerright;             }         }          return indices;     } 

you'd looking @ list<list<float> or whichever type you're working here.

syntax might change slightly.


Comments