Exemple #1
0
        internal void TBuild(int gridSize, int chunkSize, float medianHeight,
                             float variance, int polySize, int tilingIterations, float borderSize,
                             int smoothPasses, int seed, int erosionIterations,
                             float rainFall, float solubility, float evaporation, int threads)
        {
            mFracFact = new FractalFactory(variance, medianHeight, gridSize + 1, gridSize + 1);

            mNumStreamThreads = threads;

            float   [,] fract = mFracFact.CreateFractal(seed);

            for (int i = 0; i < smoothPasses; i++)
            {
                FractalFactory.SmoothPass(fract);
            }

            for (int i = 0; i < tilingIterations; i++)
            {
                float borderSlice = borderSize / tilingIterations;

                FractalFactory.MakeTiled(fract, borderSlice * (i + 1));
            }

            if (erosionIterations > 0)
            {
                int realIterations = FractalFactory.Erode(fract, mRand,
                                                          erosionIterations, rainFall, solubility, evaporation);

                //redo tiling if eroded
                for (int i = 0; i < tilingIterations; i++)
                {
                    float borderSlice = borderSize / tilingIterations;

                    FractalFactory.MakeTiled(fract, borderSlice * (i + 1));
                }
            }

            Vector3 [,] norms = mFracFact.BuildNormals(fract, polySize);

            if (mTModel != null)
            {
                mTModel.FreeAll();
            }
            mTModel = new TerrainModel(fract, polySize, gridSize);

            mCellGridMax = gridSize / chunkSize;

            List <HeightMap.TexData> tdata = new List <HeightMap.TexData>();

            float transHeight = 0f;

            if (mTerrain != null)
            {
                //grab a copy of the old texture data if any
                List <HeightMap.TexData> texOld = mTerrain.GetTextureData(out transHeight);

                //clone it because it is about to all get nuked
                foreach (HeightMap.TexData td in texOld)
                {
                    HeightMap.TexData td2 = new HeightMap.TexData(td);
                    tdata.Add(td2);
                }
                mTerrain.FreeAll();
            }
            mTerrain = new Terrain(fract, norms, polySize, chunkSize, mCellGridMax);

            mTerrain.SetTextureData(tdata, transHeight);

            mBoundary = chunkSize * polySize;

            WrapGridCoordinates();

            mTerrain.SetCellCoord(mGridCoordinate);

            mTerrain.BuildGrid(mGD, mChunkRange, mNumStreamThreads);

            mPos.Y = mTModel.GetHeight(mPos) + 200f;

            mTerrain.UpdatePosition(mPos, mTerMats);

            //clamp box heights
            mTModel.FixBoxHeights();

            //clear existing
            if (mQTreeBoxes != null)
            {
                mQTreeBoxes.Free();
            }

            //turn on to debug quadtree
            //careful about big map sizes
//			List<BoundingBox>	boxes	=mTModel.GetAllBoxes();
//			mQTreeBoxes	=PrimFactory.CreateCubes(mGD.GD, boxes);
        }