//------------------------------------------------------------------------- public override void Shutdown() { if (null != this.mImage) { this.mImage.Dispose(); } this.mPage = null; }
//------------------------------------------------------------------------- public void ExpirePage(ushort x, ushort y) { // Single page if (x == 0 && y == 0 && null != this.mPage) { this.mPage = null; } }
//------------------------------------------------------------------------- public TerrainZoneRenderable GetTerrainTile(Vector3 pt) { TerrainZonePage tp = GetTerrainZonePage(pt); if (null == tp) { return(null); } else { return(tp.GetTerrainZoneTile(pt)); } }
//------------------------------------------------------------------------- public void AttachPage(ushort pageX, ushort pageZ, TerrainZonePage page) { Debug.Assert(pageX == 0 && pageZ == 0, "Multiple pages not yet supported"); Debug.Assert(this.mTerrainZonePages[pageX][pageZ] == null, "Page at that index not yet expired!"); // Insert page into list this.mTerrainZonePages[pageX][pageZ] = page; // Attach page to terrain root if (page.PageSceneNode.Parent != this.mTerrainRoot) { this.mTerrainRoot.AddChild(page.PageSceneNode); } }
public virtual TerrainZonePage BuildPage(Real[] heightData, Material pMaterial) { string name; // Create a TerrainZone Page var page = new TerrainZonePage((ushort)((this.mPageSize - 1) / (this.mTileSize - 1))); // Create a node for all tiles to be attached to // Note we sequentially name since page can be attached at different points // so page x/z is not appropriate int pageIndex = this.mTerrainZone.PageCount; name = this.mTerrainZone.Name + "_page["; name += pageIndex + "]_Node"; if (this.mTerrainZone.mPCZSM.HasSceneNode(name)) { page.PageSceneNode = this.mTerrainZone.mPCZSM.GetSceneNode(name); // set the home zone of the scene node to the terrainzone ((PCZSceneNode)(page.PageSceneNode)).AnchorToHomeZone(this.mTerrainZone); // EXPERIMENTAL - prevent terrain zone pages from visiting other zones ((PCZSceneNode)(page.PageSceneNode)).AllowToVisit = false; } else { page.PageSceneNode = this.mTerrainZone.TerrainRootNode.CreateChildSceneNode(name); // set the home zone of the scene node to the terrainzone ((PCZSceneNode)(page.PageSceneNode)).AnchorToHomeZone(this.mTerrainZone); // EXPERIMENTAL - prevent terrain zone pages from visiting other zones ((PCZSceneNode)(page.PageSceneNode)).AllowToVisit = false; } int q = 0; for (int j = 0; j < this.mPageSize - 1; j += (this.mTileSize - 1)) { int p = 0; for (int i = 0; i < this.mPageSize - 1; i += (this.mTileSize - 1)) { // Create scene node for the tile and the TerrainZoneRenderable name = this.mTerrainZone.Name + "_tile[" + pageIndex + "][" + p + "," + q + "]_Node"; SceneNode c; if (this.mTerrainZone.mPCZSM.HasSceneNode(name)) { c = this.mTerrainZone.mPCZSM.GetSceneNode(name); if (c.Parent != page.PageSceneNode) { page.PageSceneNode.AddChild(c); } // set the home zone of the scene node to the terrainzone ((PCZSceneNode)c).AnchorToHomeZone(this.mTerrainZone); // EXPERIMENTAL - prevent terrain zone pages from visiting other zones ((PCZSceneNode)c).AllowToVisit = false; } else { c = page.PageSceneNode.CreateChildSceneNode(name); // set the home zone of the scene node to the terrainzone ((PCZSceneNode)c).AnchorToHomeZone(this.mTerrainZone); // EXPERIMENTAL - prevent terrain zone pages from visiting other zones ((PCZSceneNode)c).AllowToVisit = false; } var tile = new TerrainZoneRenderable(name, this.mTerrainZone); // set queue tile.RenderQueueGroup = this.mTerrainZone.mPCZSM.WorldGeometryRenderQueueId; // Initialise the tile tile.Material = pMaterial; tile.Initialize(i, j, heightData); // Attach it to the page page.tiles[p][q] = tile; // Attach it to the node c.AttachObject(tile); p++; } q++; } pageIndex++; // calculate neighbours for page page.LinkNeighbours(); if (this.mTerrainZone.Options.lit) { q = 0; for (int j = 0; j < this.mPageSize - 1; j += (this.mTileSize - 1)) { int p = 0; for (int i = 0; i < this.mPageSize - 1; i += (this.mTileSize - 1)) { page.tiles[p][q].CalculateNormals(); p++; } q++; } } return(page); }
//------------------------------------------------------------------------- public HeightmapTerrainZonePageSource() { this.mIsRaw = false; this.mFlipTerrainZone = false; this.mPage = null; }
//------------------------------------------------------------------------- public override void RequestPage(ushort x, ushort y) { // Only 1 page provided if (x == 0 && y == 0 && this.mPage == null) { // Convert the image data to unscaled floats var totalPageSize = (ulong)(mPageSize * mPageSize); var heightData = new Real[totalPageSize]; byte[] pOrigSrc, pSrc; Real[] pDest = heightData; Real invScale; bool is16bit = false; if (this.mIsRaw) { pOrigSrc = this.mRawData.GetBuffer(); is16bit = (this.mRawBpp == 2); } else { PixelFormat pf = this.mImage.Format; if (pf != PixelFormat.L8 && pf != PixelFormat.L16) { throw new AxiomException("Error: Image is not a grayscale image. HeightmapTerrainZonePageSource.RequestPage"); } pOrigSrc = this.mImage.Data; is16bit = (pf == PixelFormat.L16); } // Determine mapping from fixed to floating ulong rowSize; if (is16bit) { invScale = 1.0f / 65535.0f; rowSize = (ulong)mPageSize * 2; } else { invScale = 1.0f / 255.0f; rowSize = (ulong)mPageSize; } // Read the data pSrc = pOrigSrc; // for ( int j = 0; j < mPageSize; ++j ) // { // if ( mFlipTerrainZone ) // { // //Array al = Array.CreateInstance(typeof(byte), pSrc.Length); // //pSrc.CopyTo(al, 0); // pOrigSrc.CopyTo( pSrc, 0 ); // Array.Reverse( pSrc ); // // Work backwards // // pSrc = pOrigSrc + (rowSize * (mPageSize - j - 1)); // } // for ( int i = 0; i < mPageSize; ++i ) // { // if ( is16bit ) // { //#if OGRE_ENDIAN == OGRE_ENDIAN_BIG // int val = pSrc[ j + i ] << 8; // val += pSrc[ j + i ]; //#else // ushort val = *pSrc++; // val += *pSrc++ << 8; //#endif // pDest[ j + i ] = new Real( val )*invScale; // } // else // { // pDest[ j + i ] = new Real( pSrc[ j + i ] )*invScale; // } // } // } for (ulong i = 0; i < totalPageSize - 1; i++) { float height = pSrc[i] * invScale; pDest[i] = height; } heightData = pDest; // Call listeners OnPageConstructed(0, 0, heightData); // Now turn into TerrainZonePage // Note that we're using a single material for now if (null != mTerrainZone) { this.mPage = BuildPage(heightData, mTerrainZone.Options.terrainMaterial); mTerrainZone.AttachPage(0, 0, this.mPage); } // Free temp store // OGRE_FREE(heightData, MEMCATEGORY_RESOURCE); } }