private IEnumerator updateAllMeshesCoroutine()
    {
        for (int i = 0; i < planetInfo.chunksAmmount; i++)
        {
            Vector3 xyz   = planetInfo.calculateXYZ(i);
            float   xDisp = -radius + interval2 + (interval2 * 2 * xyz.x);
            float   yDisp = -radius + interval2 + (interval2 * 2 * xyz.y);
            updateMesh(i, (int)xyz.z, planetInfo.chunkObject[i], planetInfo.chunkArray[i], LOD, planetInfo.mfChunkArray [i], xDisp, yDisp, interval2, false);

            if (objPlacerObj != null)
            {
                ObjectPlacer tp1 = planetInfo.chunkObject [i].AddComponent(typeof(ObjectPlacer)) as ObjectPlacer;
                objPlacerObj.copyTo(tp1);
                tp1.Initialize(planetInfo.colorArray [i]);
                tp1.calculateObjectID();
                planetInfo.objPlacer [i] = tp1;
                if (psh != null)
                {
                    if (psh.availableSpawns == null)
                    {
                        psh.availableSpawns = new List <SpawningInfo> ();
                    }
                    psh.availableSpawns.AddRange(tp1.getSpawningInfo());
                }
            }
            yield return(null);
        }

        if (objPlacerObj != null)
        {
            spawnAllObjects();
            hasTrees = true;
        }
        planetInfo.finishedCreating = true;
        setAllLOD(awayLOD, false);
    }
    public void GenerateMap(bool putTrees = false)
    {
        if (objPlacerObj != null)
        {
            objPlacerObj.treeScale = radius / 200;
        }
        if (planet)
        {
            sphere = true;
        }
        else
        {
            sphere = false;
        }
        meshHeightMultiplier = radius * heightMuliplier / 1000;

        int count = gameObject.transform.childCount;

        for (int i = 0; i < count; i++)
        {
            GameObject.DestroyImmediate(gameObject.transform.GetChild(0).gameObject);
        }

        if (planet)
        {
            planetInfo = new PlanetInfo(subCount, radius);

            if (gameObject.GetComponent <MeshFilter>() != null)
            {
                GameObject.DestroyImmediate(gameObject.GetComponent <MeshFilter> ());
            }
            if (gameObject.GetComponent <MeshRenderer>() != null)
            {
                GameObject.DestroyImmediate(gameObject.GetComponent <MeshRenderer> ());
            }

            interval2 = radius / planetInfo.squareSectionAmmount;
            createNewChildren(/*putTrees*/);
            if (player != null && dynamicUpdate && putTrees)
            {
                threadInitializer();
            }
        }
        else
        {
            float[,] noiseMap = Noise.GenerateNoiseMap(textQual, textQual, seed, noiseScale, octaves, persistance, lacunarity, new Vector2(0, 0), Noise.NormalizeMode.Global);
            Color[] colourMap = generateColorAndFalloff(noiseMap, textQual, useFalloff, false);

            GameObject gO = gameObject;
            MeshFilter mf;
            //Add MeshRenderer and MeshFilter
            if (gameObject.GetComponent <MeshFilter> () != null)
            {
                mf = gameObject.GetComponent <MeshFilter> ();
            }
            else
            {
                mf = gameObject.AddComponent <MeshFilter>();
            }

            if (gameObject.GetComponent <MeshRenderer> () == null)
            {
                gameObject.AddComponent <MeshRenderer>();
            }

            gO.layer = gameObject.layer;
            //gO.tag = gameObject.tag;

            updateMesh(LOD, mf, noiseMap, radius);

            Texture2D texture = new Texture2D(textQual, textQual);
            texture.filterMode = FilterMode.Point;
            texture.wrapMode   = TextureWrapMode.Clamp;
            texture.SetPixels(colourMap);
            texture.Apply();

            if (objPlacerObj != null)
            {
                ObjectPlacer tp1 = this.GetComponent <ObjectPlacer>();
                tp1.Initialize(colourMap);
                //objPlacerObj.copyTo (tp1);
                bool localTree = tp1.doTrees;
                if (!putTrees && !tp1.areChildren)
                {
                    objPlacerObj.doTrees = false;
                }
                //planetInfo.objPlacer [i] = tp1;
                tp1.spawnObjects(true);
                objPlacerObj.doTrees = localTree;
                //if (psh != null) {
                //	psh.availableSpawns = new List<SpawningInfo> ();
                //	SpawningInfo[] availableChunkSpawns = tp1.getSpawningInfo ();
                //	psh.availableSpawns.AddRange (availableChunkSpawns);
                //}
            }


            gO.GetComponent <Renderer> ().sharedMaterial             = new Material(Shader.Find("Diffuse"));
            gO.GetComponent <Renderer> ().sharedMaterial.mainTexture = texture;
        }
        Resources.UnloadUnusedAssets();
    }