public void ConstructMesh() { var vertices = new Vector3[resolution * resolution]; var triangles = new int[((resolution - 1) * (resolution - 1)) * 6]; var triIndex = 0; for (int y = 0; y < resolution; y++) { for (int x = 0; x < resolution; x++) { var i = x + y * resolution; var precent = new Vector2(x, y) / (resolution - 1); var pointOnUnitCube = localUp + (precent.x - .5f) * 2 * axisA + (precent.y - .5f) * 2 * axisB; var pointOnUnitSphere = pointOnUnitCube.normalized; vertices[i] = shapeGenerator.CalculatePointOnSphere(pointOnUnitSphere); if (x != resolution - 1 && y != resolution - 1) { triangles[triIndex] = i; triangles[triIndex + 1] = i + resolution + 1; triangles[triIndex + 2] = i + resolution; triangles[triIndex + 3] = i; triangles[triIndex + 4] = i + 1; triangles[triIndex + 5] = i + resolution + 1; triIndex += 6; } } } mesh.Clear(); mesh.vertices = vertices; mesh.triangles = triangles; mesh.RecalculateNormals(); }