public static void Generate(int detailLevel) { //Get Number of Cells int cellNr = 20; if (detailLevel > 0) { for (int i = 0; i <= detailLevel; i++) { cellNr = cellNr * 4; } } // Instanciate Clean Arrays World.Cells = new Cell[cellNr]; World.CellPoints = new CellPoint[cellNr * 3]; World.CellColor = new Color[cellNr]; World.CellTecID = new UInt16[cellNr]; World.Height = new float[cellNr]; cellList = new List <Cell>(); points = new List <CellPoint>(); Icosahedron(); for (var i = 0; i < detailLevel; i++) { Subdivide(true); } /// normalize vectors to "inflate" the icosahedron into a sphere. for (var i = 0; i < vectors.Count; i++) { vectors[i] = Vector3.Normalize(vectors[i]); points.Add(new CellPoint(vectors[i])); } //Generate Cells int id = 0; for (int i = 0; i < indices.Count; i++) { if (i % 3 == 0) { id = i / 3; cellList.Add(new Cell((uint)id)); //Debug.Log("Cell " + id + " added"); } cellList[id].Vertexes.Add((uint)indices[i]); points[indices[i]].Cells.Add((uint)id); } // Center Cells foreach (Cell c in cellList) { Vector3 vec = Vector3.zero; foreach (int nr in c.Vertexes) { vec += points[nr].Vector; } c.Location = vec / 3; //Debug.Log("Cell ID " + c.Id + " centered at " + (vec / 3).ToString()); } World.Cells = cellList.ToArray(); World.CellPoints = points.ToArray(); CheckConnections(); TextureBuilder.NewTextures(); //Set Scale SetWorldScale(); }