/// <summary> /// /// </summary> /// <param name="geom"></param> /// <param name="bounds"></param> public TreeLoader2D(PagedGeometry geom, TBounds bounds) { //Calculate grid size mGeom = geom; mPageSize = mGeom.PageSize; //Reset height function mHeightFunction = null; mHeightFunctionUserData = null; //Make sure the bounds are aligned with PagedGeometry's grid, so the TreeLoader's grid tiles will have a 1:1 relationship mActualBounds = bounds; mGridBounds = bounds; mGridBounds.Left = (float)(mPageSize * System.Math.Floor((mGridBounds.Left - mGeom.Bounds.Left) / mPageSize) + mGeom.Bounds.Left); mGridBounds.Top = (float)(mPageSize * System.Math.Floor((mGridBounds.Top - mGeom.Bounds.Top) / mPageSize) + mGeom.Bounds.Top); mGridBounds.Right = (float)(mPageSize * System.Math.Ceiling((mGridBounds.Right - mGeom.Bounds.Left) / mPageSize) + mGeom.Bounds.Left); mGridBounds.Bottom = (float)(mPageSize * System.Math.Ceiling((mGridBounds.Bottom - mGeom.Bounds.Top) / mPageSize) + mGeom.Bounds.Top); //Calculate page grid size mPageGridX = (int)(System.Math.Ceiling(mGridBounds.Width / mPageSize) + 1); mPageGridZ = (int)(System.Math.Ceiling(mGridBounds.Height / mPageSize) + 1); //Reset color map mColorMap = null; mColorMapFilter = MapFilter.None; //Default scale range mMaximumScale = 2.0f; mMinimumScale = 0.0f; }
/// <summary> /// /// </summary> public void SetInfinite() { if (mMangerList.Count > 0) { throw new Exception("PagedGeometry::setPageSize() cannot be called after detail levels have been added. Call removeDetailLevels() first."); } mBounds = new TBounds(0, 0, 0, 0); }
/// <summary> /// /// </summary> /// <param name="point"></param> internal void ReloadGeometryPages(TBounds area) { //Determine which grid block contains the top-left corner int x1 = (int)System.Math.Floor(mGeomGridX * (area.Left - mGridBounds.Left) / mGridBounds.Width); int z1 = (int)System.Math.Floor(mGeomGridZ * (area.Top - mGridBounds.Top) / mGridBounds.Height); if (x1 < 0) { x1 = 0; } else if (x1 > mGeomGridX) { x1 = mGeomGridX; } if (z1 < 0) { z1 = 0; } else if (z1 > mGeomGridZ) { z1 = mGeomGridZ; } //...and the bottom right int x2 = (int)System.Math.Floor(mGeomGridX * (area.Right - mGridBounds.Left) / mGridBounds.Width); int z2 = (int)System.Math.Floor(mGeomGridZ * (area.Bottom - mGridBounds.Top) / mGridBounds.Height); if (x2 < 0) { x2 = 0; } else if (x2 > mGeomGridX) { x2 = mGeomGridX; } if (z2 < 0) { z2 = 0; } else if (z2 > mGeomGridZ) { z2 = mGeomGridZ; } for (int x = x1; x <= x2; ++x) { for (int z = z1; z <= z2; ++z) { GeometryPage page = GetGridPage(x, z); if (page.IsLoaded) { UnLoadPage(page); mLoadedList.Remove(page); } } } }
/// <summary> /// /// </summary> /// <param name="mainGeom"></param> public GeometryPageManager(PagedGeometry mainGeom) { mMainGeom = mainGeom; mCacheTimer = 0; mScrollBuffer = null; mGeomGrid = null; SetCacheSpeed(200, 2000); Transition = 0; mGridBounds = new TBounds(0, 0, 0, 0); }
/// <summary> /// /// </summary> /// <param name="area"></param> public void ReloadGeometryPages(TBounds area) { if (mPageLoader == null) { return; } foreach (GeometryPageManager mgr in mMangerList) { mgr.ReloadGeometryPages(area); } }
/// <summary> /// /// </summary> /// <param name="cam"></param> /// <param name="pageSize"></param> public PagedGeometry(Camera cam, float pageSize) { if (cam != null) { mSceneCam = cam; mSceneMgr = mSceneCam.SceneManager; mOldCamPos = mSceneCam.DerivedPosition; mRootNode = mSceneMgr.RootSceneNode; } else { mSceneCam = null; mSceneMgr = null; mOldCamPos = Vector3.Zero; } mTimer = Root.Singleton.Timer; mTimer.Reset(); mLastTime = 0; PageSize = pageSize; mBounds = new TBounds(0, 0, 0, 0); mPageLoader = null; }
/// <summary> /// /// </summary> /// <param name="area"></param> /// <param name="type"></param> /// <returns></returns> public List <object> DeleteTrees(TBounds area, Entity type) { throw new NotImplementedException(); }
/// <summary> /// /// </summary> /// <param name="area"></param> /// <returns></returns> public List <object> DeleteTrees(TBounds area) { return(DeleteTrees(area, null)); }
/// <summary> /// /// </summary> /// <param name="point"></param> /// <param name="radius"></param> internal void ReloadGeometryPages(Vector3 center, float radius) { //First calculate a square boundary to eliminate the search space TBounds area = new TBounds(center.x - radius, center.z - radius, center.x + radius, center.z + radius); //Determine which grid block contains the top-left corner int x1 = (int)System.Math.Floor(mGeomGridX * (area.Left - mGridBounds.Left) / mGridBounds.Width); int z1 = (int)System.Math.Floor(mGeomGridZ * (area.Top - mGridBounds.Top) / mGridBounds.Height); if (x1 < 0) { x1 = 0; } else if (x1 > mGeomGridX) { x1 = mGeomGridX; } if (z1 < 0) { z1 = 0; } else if (z1 > mGeomGridZ) { z1 = mGeomGridZ; } //...and the bottom right int x2 = (int)System.Math.Floor(mGeomGridX * (area.Right - mGridBounds.Left) / mGridBounds.Width); int z2 = (int)System.Math.Floor(mGeomGridZ * (area.Bottom - mGridBounds.Top) / mGridBounds.Height); if (x2 < 0) { x2 = 0; } else if (x2 > mGeomGridX) { x2 = mGeomGridX; } if (z2 < 0) { z2 = 0; } else if (z2 > mGeomGridZ) { z2 = mGeomGridZ; } //Scan all the grid blocks in the region float radiusSq = radius * radius; for (int x = x1; x <= x2; ++x) { for (int z = z1; z <= z2; ++z) { GeometryPage page = GetGridPage(x, z); if (page.IsLoaded) { Vector3 pos = page.CenterPoint; Real distX = (pos.x - center.x), distZ = (pos.z - center.z); Real distSq = distX * distX + distZ * distZ; if (distSq <= radius) { UnLoadPage(page); mLoadedList.Remove(page); } } } } }
/// <summary> /// /// </summary> /// <param name="bounds"></param> /// <returns></returns> internal void InitPages <T>(TBounds bounds) { // Calculate grid size, if left is Real minimum, it means that bounds are infinite // scrollBuffer is used as a flag. If it is allocated than infinite bounds are used // !!! Two cases are required because of the way scrolling is implemented // if it is redesigned it would allow to use the same functionality. if (bounds.Width < 0.00001f) { // In case of infinite bounds bounding rect needs to be calculated in a different manner, since // it represents local bounds, which are shifted along with the player's movements around the world. mGeomGridX = (int)((2 * mFarTransDist / mMainGeom.PageSize) + 4); mGridBounds.Top = 0; mGridBounds.Left = 0; mGridBounds.Right = mGeomGridX * mMainGeom.PageSize; mGridBounds.Bottom = mGeomGridX * mMainGeom.PageSize; // Allocate scroll buffer (used in scrolling the grid) mScrollBuffer = new GeometryPage[mGeomGridX]; //Note: All this padding and transition preparation is performed because even in infinite //mode, a local grid size must be chosen. Unfortunately, this also means that view ranges //and transition lengths cannot be exceeded dynamically with set functions. } else { //Bounded mode mGridBounds = bounds; // In case the devision does not give the round number use the next largest integer mGeomGridX = (int)System.Math.Ceiling(mGridBounds.Width / mMainGeom.PageSize); } mGeomGridZ = mGeomGridX;//Note: geomGridX == geomGridZ; Need to merge. //Allocate grid array mGeomGrid = new GeometryPage[mGeomGridX * mGeomGridZ]; for (int x = 0; x < mGeomGridX; ++x) { for (int z = 0; z < mGeomGridZ; ++z) { GeometryPage p = null; Type t = typeof(T); switch (t.Name) { case "GrassPage": p = new GrassPage(); break; case "BatchPage": p = new BatchPage(); break; case "ImpostorPage": p = new ImpostorPage(); break; default: throw new Exception("This GeometryPage is Unkown!,GeometryPageManager.Update!"); break; } p.Init(mMainGeom); float cx = 0, cy = 0, cz = 0; // 0,0 page is located at (gridBounds.left,gridBounds.top) corner of the bounds cx = ((x + 0.5f) * mMainGeom.PageSize) + mGridBounds.Left; cz = ((z + 0.5f) * mMainGeom.PageSize) + mGridBounds.Top; cy = 0.0f; p.CenterPoint = new Vector3(cx, cy, cz); p.mXIndex = x; p.mZIndex = z; p.mInactiveTime = 0; p.mIsLoaded = false; p.mNeedsUnload = false; p.mIsPending = false; p.mIsVisible = false; p.mUserData = null; p.ClearBoundingBox(); SetGridPage(x, z, p); } } }