public void GenerateMesh() { //Create an initial array for verticies and triangles generated so that if we wish to apply changes later it will not effect the stored members of class. Vector3[] initialVerticies = new Vector3[m_resolution * m_resolution]; int[] initialTris = new int[(m_resolution - 1) * (m_resolution - 1) * 6]; //Initial Verticies of Face int triIndex = 0; for (int i = 0, y = 0; y < m_resolution; y++) { for (int x = 0; x < m_resolution; x++) { //Calculate the point in space of this vertex on a spheracal plane. Vector2 percent = new Vector2(x, y) / (m_resolution - 1); Vector3 pointOnCubeFace = m_localUp + (percent.x - 0.5f) * 2 * m_axisA + (percent.y - 0.5f) * 2 * m_axisB; Vector3 pointOnSphere = pointOnCubeFace.normalized; //Apply perlin Noise to add variation to the cubesphere face. initialVerticies[i] = m_faceProperties.GeneratePointOnShape(pointOnSphere); //Calculate Faces on the Face of Cubesphere. //Check to make sure triangle won't extend over edge of face. if (x != m_resolution - 1 && y != m_resolution - 1) { initialTris[triIndex] = i; initialTris[triIndex + 1] = i + m_resolution + 1; initialTris[triIndex + 2] = i + m_resolution; initialTris[triIndex + 3] = i; initialTris[triIndex + 4] = i + 1; initialTris[triIndex + 5] = i + m_resolution + 1; triIndex += 6; } i++; } } //Set the faces variables now they have been calculated. m_vertices = initialVerticies; m_triangles = initialTris; UpdateMesh(); }