private TriangleList GenerateVertexAndIndices() { var vertices = new List <VertexPositionNormalColored>(); var indices = new List <int>(); for (int My = 0; My < 16; My++) { for (int Mx = 0; Mx < 16; Mx++) { MCNK lMCNK = MCNKArray[Mx, My]; var HolesMap = new bool[4, 4]; if (lMCNK.holes > 0) { HolesMap = lMCNK.GetHolesMap(); } #region indexing for (int row = 0; row < 8; row++) { for (int col = 0; col < 8; col++) { if (!HolesMap[row / 2, col / 2]) { /* The order metter*/ /*This 3 index add the up triangle * * 0--1--2 *| /| / *|/ |/ * 9 10 11 */ indices.Add(vertices.Count + ((row + 1) * (8 + 1) + col)); //9 ... 10 indices.Add(vertices.Count + (row * (8 + 1) + col)); //0 ... 1 indices.Add(vertices.Count + (row * (8 + 1) + col + 1)); //1 ... 2 /*This 3 index add the low triangle * * 0 1 2 * /| /| * / | / | * 9--10--11 */ indices.Add(vertices.Count + ((row + 1) * (8 + 1) + col + 1)); indices.Add(vertices.Count + ((row + 1) * (8 + 1) + col)); indices.Add(vertices.Count + (row * (8 + 1) + col + 1)); } #endregion } } //this.Indices.AddRange(triangleListIndices); const float offset_x = (533.33333f / 16) / 8; const float offset_z = (533.33333f / 16) / 8; var LowResMap = lMCNK._MCVT.GetLowResMapMatrix(); var LowResNormal = lMCNK._MCNR.GetLowResNormalMatrix(); for (int r = 0; r < 9; r++) { for (int c = 0; c < 9; c++) { float x_pos = lMCNK.x - (c * offset_x); float z_pos = lMCNK.z - (r * offset_z); float y_pos = LowResMap[r, c] + lMCNK.y; var normal = LowResNormal[r, c]; float cosAngle = Vector3.Dot(Vector3.Up, normal); float angle = MathHelper.ToDegrees((float)Math.Acos(cosAngle)); var position = new Vector3(x_pos, y_pos, z_pos); vertices.Add(new VertexPositionNormalColored(position, angle > 50.0 ? Color.Brown : Color.Green, normal)); } } } } return(new TriangleList(indices, vertices)); }