public static Mesh IcosahedronMesh (double lengthDouble = 2d) { Mesh mesh = new Mesh(); float length = (float)lengthDouble; float phiLength = (float)PhiDouble(lengthDouble); List rawVerts = new List(); List meshVerts = new List(); List meshNormals = new List(); List meshUVs = new List(); List meshTris = new List(); rawVerts.AddRange(new Vector3[] { new Vector3(0f, phiLength, length), new Vector3(0f, phiLength, -length), new Vector3(0f, -phiLength, length), new Vector3(0f, -phiLength, -length), new Vector3(length, 0f, phiLength), new Vector3(length, 0f, -phiLength), new Vector3(-length, 0f, phiLength), new Vector3(-length, 0f, -phiLength), new Vector3(phiLength, length, 0f), new Vector3(phiLength, -length, 0f), new Vector3(-phiLength, length, 0f), new Vector3(-phiLength, -length, 0f) }); meshVerts.AddRange(new Vector3[] { // North rawVerts[0], rawVerts[6], rawVerts[4], rawVerts[0], rawVerts[10], rawVerts[6], rawVerts[0], rawVerts[1], rawVerts[10], rawVerts[0], rawVerts[8], rawVerts[1], rawVerts[0], rawVerts[4], rawVerts[8], // North-Equator rawVerts[2], rawVerts[4], rawVerts[6], rawVerts[11], rawVerts[6], rawVerts[10], rawVerts[7], rawVerts[10], rawVerts[1], rawVerts[5], rawVerts[1], rawVerts[8], rawVerts[9], rawVerts[8], rawVerts[4], // South-Equator rawVerts[6], rawVerts[11], rawVerts[2], rawVerts[10], rawVerts[7], rawVerts[11], rawVerts[1], rawVerts[5], rawVerts[7], rawVerts[8], rawVerts[9], rawVerts[5], rawVerts[4], rawVerts[2], rawVerts[9], // South rawVerts[3], rawVerts[2], rawVerts[11], rawVerts[3], rawVerts[11], rawVerts[7], rawVerts[3], rawVerts[7], rawVerts[5], rawVerts[3], rawVerts[5], rawVerts[9], rawVerts[3], rawVerts[9], rawVerts[2] }); meshTris.AddRange(new int[] { 0,1,2, 3,4,5, 6,7,8, 9,10,11, 12,13,14, // North 15,16,17, 18,19,20, 21,22,23, 24,25,26, 27,28,29, // North-Equator 30,31,32, 33,34,35, 36,37,38, 39,40,41, 42,43,44, // South-Equator 45,46,47, 48,49,50, 51,52,53, 54,55,56, 57,58,59 // South }); // new Vector2(0.5f, 1f), new Vector2(1f, 0f), new Vector2(0f, 0f) meshUVs.AddRange(new Vector2[] { // North (Tri 0-4) new Vector2(.455f, .992f), new Vector2(.542f, .671f), new Vector2(.367f, .671f), new Vector2(.273f, .992f), new Vector2(.360f, .671f), new Vector2(.185f, .671f), new Vector2(.091f, .992f), new Vector2(.178f, .671f), new Vector2(.003f, .671f), new Vector2(.818f, .992f), new Vector2(.906f, .671f), new Vector2(.731f, .671f), new Vector2(.636f, .992f), new Vector2(.724f, .671f), new Vector2(.549f, .671f), new Vector2(.455f, .342f), new Vector2(.367f, .662f), new Vector2(.542f, .662f), new Vector2(.273f, .992f), new Vector2(.360f, .671f), new Vector2(.185f, .671f), new Vector2(.091f, .992f), new Vector2(.178f, .671f), new Vector2(.003f, .671f), new Vector2(.818f, .992f), new Vector2(.906f, .671f), new Vector2(.731f, .671f), new Vector2(.636f, .992f), new Vector2(.724f, .671f), new Vector2(.549f, .671f), new Vector2(.455f, .992f), new Vector2(.542f, .671f), new Vector2(.367f, .671f), new Vector2(.273f, .992f), new Vector2(.360f, .671f), new Vector2(.185f, .671f), new Vector2(.091f, .992f), new Vector2(.178f, .671f), new Vector2(.003f, .671f), new Vector2(.818f, .992f), new Vector2(.906f, .671f), new Vector2(.731f, .671f), new Vector2(.636f, .992f), new Vector2(.724f, .671f), new Vector2(.549f, .671f), new Vector2(.455f, .992f), new Vector2(.542f, .671f), new Vector2(.367f, .671f), new Vector2(.273f, .992f), new Vector2(.360f, .671f), new Vector2(.185f, .671f), new Vector2(.091f, .992f), new Vector2(.178f, .671f), new Vector2(.003f, .671f), new Vector2(.818f, .992f), new Vector2(.906f, .671f), new Vector2(.731f, .671f), new Vector2(.636f, .992f), new Vector2(.724f, .671f), new Vector2(.549f, .671f) }); /* meshUVs.AddRange(new int[] { 0,4,6, 0,6,10, 0,10,1, 0,1,8, 0,8,4, // North 2,6,4, 11,10,6, 7,1,10, 5,8,1, 9,4,8, // North-Equator 6,2,11, 10,11,7, 1,7,5, 8,5,9, 4,9,2, // South-Equator 3,11,2, 3,7,11, 3,5,7, 3,9,5, 3,2,9 // South }); */ mesh.vertices = meshVerts.ToArray(); mesh.triangles = meshTris.ToArray(); mesh.normals = meshVerts.ToArray(); mesh.uv = meshUVs.ToArray(); return (mesh); } public static Mesh IcosphereMesh (int subdivisions = 1, double lengthDouble = 2d) { int triLength = (int)Mathf.Pow(2, subdivisions); double icoLength = lengthDouble * (double)triLength; double icoPhiLength = PhiDouble(lengthDouble) * (double)triLength; Mesh mesh = IcosahedronMesh(icoLength); List oldVerts = new List(); List oldTris = new List(); List meshVerts = new List(); List meshTris = new List(); meshVerts.AddRange(mesh.vertices); meshTris.AddRange(mesh.triangles); List meshNormals = new List(); List meshUVs = new List(); float radius = meshVerts[0].magnitude; int triCount; int triID; Vector3 vertA = new Vector3(); Vector3 vertB = new Vector3(); Vector3 vertC = new Vector3(); Vector3 vertAB = new Vector3(); Vector3 vertBC = new Vector3(); Vector3 vertCA = new Vector3(); // For each level of Subdivision... for (int s=1; s<=subdivisions; s++) { Debug.Log ("Subdivision #" + s + "/" + subdivisions); oldVerts.Clear(); oldVerts.AddRange(meshVerts); oldTris.Clear(); oldTris.AddRange(meshTris); meshVerts.Clear(); meshTris.Clear(); meshUVs.Clear(); meshNormals.Clear(); // For each triangle in the last dataset... triCount = oldTris.Count / 3; //Debug.Log ("Tricount: " + triCount); for (int t=0; t