public void SplitMainTerrainPlanet(Terrain terrain)
        {
            int size = (Planet.PlanetRes - 1) / 2 + 1;

            int td = -1;
            terrain.loadChildBorders(this.GetNeighbour(location, this.parent), td);
            terrain.PostNormalize();

            for (int x = 0; x < BlockRes; x++)
                for (int y = 0; y < BlockRes; y++)
                {
                    this.terrain[x, y] = new Terrain(terrain.CellSize, terrain.Height, terrain.TextureTiling, size,
                                            new Vector3(terrain.Position.X, terrain.Position.Y, terrain.Position.Z),
                                            effect, terrain.baseTexture, terrain.type, this.depth);
                }

            float[,][,] heights = new float[BlockRes, BlockRes][,];
            VertexPositionNormalTexture[,][] subCopy = new VertexPositionNormalTexture[BlockRes, BlockRes][];

            for (int x = 0; x < BlockRes; x++)
                for (int y = 0; y < BlockRes; y++)
                {
                    heights[x, y] = new float[size, size];
                    subCopy[x, y] = new VertexPositionNormalTexture[size * size];

                    for (int x1 = 0; x1 < size; x1++)
                        for (int y1 = 0; y1 < size; y1++)
                        {
                            int a = x1 + (size - 1) * x;
                            int b = y1 + (size - 1) * y;
                            subCopy[x, y][convertFromXY(x1, y1, size) ] = terrain.vertices[convertFromXY(a, b, terrain.Size)];
                            heights[x, y][x1, y1] = terrain.heightMaps[a, b];
                        }
                }

            for (int x = 0; x < BlockRes; x++)
                for (int y = 0; y < BlockRes; y++)
                {
                    this.terrain[x, y].CopyCustom(subCopy[x, y], heights[x, y]);
                    this.terrain[x, y].GlobalRot = terrain.GlobalRot;
                }
        }
        public Planet(GraphicsDevice GraphicsDevice, ContentManager Content)
        {
            this.isWater = false;
            Effect effect = Content.Load<Effect>(@"effects/PPModel");
            Texture2D texture = Content.Load<Texture2D>(@"textures/base");

            Vector3 pos = Vector3.Zero;
            top = new Terrain(4096, HeightMag, 1f, PlanetRes, pos, effect, texture, Terrain.Type.CubeFace);
            top.GenerateFractual();

            float[][] borders = new float[4][];
            borders[2] = top.MyHeightBorders[0].ToArray();

            left = new Terrain(4096, HeightMag, 1f, PlanetRes, pos, effect, texture, Terrain.Type.CubeFace);
            left.GenerateFractualSlice(new Vector3(0, 0, 90), borders, Fractal.BorderType.Right);

            borders = new float[4][];
            borders[0] = top.MyHeightBorders[2].ToArray();

            right = new Terrain(4096, HeightMag, 1f, PlanetRes, pos, effect, texture, Terrain.Type.CubeFace);
            right.GenerateFractualSlice(new Vector3(0, 0, -90), borders, Fractal.BorderType.Left);

            borders = new float[4][];
            borders[0] = left.MyHeightBorders[3].ToArray();
            borders[1] = top.MyHeightBorders[3].ToArray();
            borders[2] = right.MyHeightBorders[3].ToArray();

            Array.Reverse(borders[0]);

            front = new Terrain(4096, HeightMag, 1f, PlanetRes, pos, effect, texture, Terrain.Type.CubeFace);
            front.GenerateFractualSlice(new Vector3(90, 0, 0), borders, Fractal.BorderType.Left | Fractal.BorderType.Top | Fractal.BorderType.Right);

            borders = new float[4][];
            borders[0] = left.MyHeightBorders[1].ToArray();
            borders[2] = right.MyHeightBorders[1].ToArray();
            borders[3] = top.MyHeightBorders[1].ToArray();

            Array.Reverse(borders[2]);

            back = new Terrain(4096, HeightMag, 1f, PlanetRes, pos, effect, texture, Terrain.Type.CubeFace);
            back.GenerateFractualSlice(new Vector3(-90, 0, 0), borders, Fractal.BorderType.Left | Fractal.BorderType.Bottom | Fractal.BorderType.Right);

            borders = new float[4][];
            borders[0] = left.MyHeightBorders[0].ToArray();
            borders[1] = front.MyHeightBorders[3].ToArray();
            borders[2] = right.MyHeightBorders[2].ToArray();
            borders[3] = back.MyHeightBorders[1].ToArray();

            Array.Reverse(borders[0]);
            Array.Reverse(borders[2]);

            bottom = new Terrain(4096, HeightMag, 1f, PlanetRes, pos, effect, texture, Terrain.Type.CubeFace);
            bottom.GenerateFractualSlice(new Vector3(180, 0, 0), borders, Fractal.BorderType.All);

            ///////////////////
            top.loadPosBorders(left.MyRawHeightBorders[2], Fractal.BorderType.Left, false);
            top.loadPosBorders(right.MyRawHeightBorders[0], Fractal.BorderType.Right, false);
            top.loadPosBorders(front.MyRawHeightBorders[1], Fractal.BorderType.Bottom, false);
            top.loadPosBorders(back.MyRawHeightBorders[3], Fractal.BorderType.Top, false);
            top.PostNormalize();

            left.loadPosBorders(top.MyRawHeightBorders[0], Fractal.BorderType.Right, false);
            left.loadPosBorders(front.MyRawHeightBorders[0], Fractal.BorderType.Bottom, true);
            left.loadPosBorders(back.MyRawHeightBorders[0], Fractal.BorderType.Top, false);
            left.loadPosBorders(bottom.MyRawHeightBorders[0], Fractal.BorderType.Left, true);
            left.PostNormalize();

            right.loadPosBorders(top.MyRawHeightBorders[2], Fractal.BorderType.Left, false);
            right.loadPosBorders(front.MyRawHeightBorders[2], Fractal.BorderType.Bottom, false);
            right.loadPosBorders(back.MyRawHeightBorders[2], Fractal.BorderType.Top, true);
            right.loadPosBorders(bottom.MyRawHeightBorders[2], Fractal.BorderType.Right, true);
            right.PostNormalize();

            front.loadPosBorders(top.MyRawHeightBorders[3], Fractal.BorderType.Top, false);
            front.loadPosBorders(left.MyRawHeightBorders[3], Fractal.BorderType.Left, true);
            front.loadPosBorders(right.MyRawHeightBorders[3], Fractal.BorderType.Right, false);
            front.loadPosBorders(bottom.MyRawHeightBorders[1], Fractal.BorderType.Bottom, false);
            front.PostNormalize();

            back.loadPosBorders(top.MyRawHeightBorders[1], Fractal.BorderType.Bottom, false);
            back.loadPosBorders(right.MyRawHeightBorders[1], Fractal.BorderType.Right, true);
            back.loadPosBorders(left.MyRawHeightBorders[1], Fractal.BorderType.Left, false);
            back.loadPosBorders(bottom.MyRawHeightBorders[3], Fractal.BorderType.Top, false);
            back.PostNormalize();

            bottom.loadPosBorders(left.MyRawHeightBorders[0], Fractal.BorderType.Left, true);
            bottom.loadPosBorders(front.MyRawHeightBorders[3], Fractal.BorderType.Top, false);
            bottom.loadPosBorders(right.MyRawHeightBorders[2], Fractal.BorderType.Right, true);
            bottom.loadPosBorders(back.MyRawHeightBorders[1], Fractal.BorderType.Bottom, false);
            bottom.PostNormalize();

            topBlock = new TerrainBlock(top, 0, GraphicsDevice, effect, TerrainBlock.PlanetBlock.Top, this.GetNeighbourTerrain, new Point(), null);
            leftBlock = new TerrainBlock(left, 0, GraphicsDevice, effect, TerrainBlock.PlanetBlock.Left, this.GetNeighbourTerrain, new Point(), null);
            rightBlock = new TerrainBlock(right, 0, GraphicsDevice, effect, TerrainBlock.PlanetBlock.Right, this.GetNeighbourTerrain, new Point(), null);
            frontBlock = new TerrainBlock(front, 0, GraphicsDevice, effect, TerrainBlock.PlanetBlock.Front, this.GetNeighbourTerrain, new Point(), null);
            backBlock = new TerrainBlock(back, 0, GraphicsDevice, effect, TerrainBlock.PlanetBlock.Back, this.GetNeighbourTerrain, new Point(), null);
            bottomBlock = new TerrainBlock(bottom, 0, GraphicsDevice, effect, TerrainBlock.PlanetBlock.Bottom, this.GetNeighbourTerrain, new Point(), null);

            topBlock.GetNeighbour = this.GetNeighbourTerrain;
            leftBlock.GetNeighbour = this.GetNeighbourTerrain;
            rightBlock.GetNeighbour = this.GetNeighbourTerrain;
            frontBlock.GetNeighbour = this.GetNeighbourTerrain;
            backBlock.GetNeighbour = this.GetNeighbourTerrain;
            bottomBlock.GetNeighbour = this.GetNeighbourTerrain;

            water = new Planet(GraphicsDevice, Content, true);
        }