public override TerrainDescriptor GetTerrainDescriptor() { TerrainDescriptor td = new TerrainDescriptor(); td.heightMap = terrain.terrainData.heightmapTexture; td.normalMap = terrain.normalmapTexture; if (perPixelNormal != null) { td.normalMap = perPixelNormal; } td.heightMapScale = terrain.terrainData.heightmapScale; return(td); }
public virtual short[,] FetchTerrain(PointF startingLongLat, Rectangle regionInPixels) { TerrainDescriptor desc = new TerrainDescriptor() { longLat = startingLongLat, regionInPixels = regionInPixels }; if (TerrainMemory.Contains(desc)) return TerrainMemory.Get(desc); Point location = CalculatePixelLocationInCombinedFileMap(startingLongLat); location = Point.Add(location, new Size(regionInPixels.Left, -regionInPixels.Top)); location = Point.Subtract(location, new Size(regionInPixels.Width / 2, regionInPixels.Height / 2)); regionInPixels = new Rectangle(location, regionInPixels.Size); //Console.WriteLine("region: " + regionInPixels); coarseRegion = CalculateCoarseRegion(regionInPixels); //Console.WriteLine("regionPixels: " + regionInPixels+", coarseRegion: "+coarseRegion); sizeInPixels = regionInPixels.Size; short[,] array = new short[sizeInPixels.Height, sizeInPixels.Width]; Point arrayOffset = new Point(); Rectangle subregionInPixels = new Rectangle(); for (int y = 0; y <= coarseRegion.Height; y += LatDiffBetweenFiles) { arrayOffset.X = 0; for (int x = 0; x <= coarseRegion.Width; x += LongDiffBetweenFiles) { Point cp = UpdateCoarsePoint(y, x); Point coarsePoint = CalculatePixelLocationInCombinedFileMap(cp); string filename = GetFilenameFromLongLat(cp.X, cp.Y); subregionInPixels = CalculateRegionInFile(regionInPixels, CalculatePixelLocationInCombinedFileMap(cp)); //Console.WriteLine("cp: "+cp+", coarsePoint: " + coarsePoint + ", filename: " + filename + ", subregion: " + subregionInPixels); ReadHgtFile(array, filename, arrayOffset, subregionInPixels); arrayOffset.X += subregionInPixels.Width; } arrayOffset.Y += subregionInPixels.Height; } TerrainMemory.Add(desc, array); return array; }