public IEnumerator ApplyBingHeightmapV2(WWW metaReq, string key) { MetadataObject metadata = JsonConvert.DeserializeObject <MetadataObject>(metaReq.text); List <double> bbox = metadata.resourceSets[0].resources[0].bbox; firstBbox = bbox; string url = "http://dev.virtualearth.net/REST/v1/Elevation/Bounds?bounds="; url += bbox[0] + "," + bbox[1] + "," + bbox[2] + "," + bbox[3]; int rows = 32; url += "&rows=" + rows + "&cols=" + rows + "&heights=sealevel&key=" + key; //max height point retrievable = 1024 = 32 * 32 WWW elevReq = new WWW(url); yield return(elevReq); ElevDataObject elevData = JsonConvert.DeserializeObject <ElevDataObject> (elevReq.text); List <int> elevations = elevData.resourceSets[0].resources[0].elevations; //elevations at sea level in meters //TerrainData terrain = GetComponent<Terrain> ().terrainData; int width = 512 * 3; float[,] heightmapData = new float[width, width]; //terrain.GetHeights(0, 0, width, width); if (width % rows == 0) { heightmapData = ApplyElevationsToHeightmap(elevations, heightmapData, width); heightmapData = Smooth(heightmapData, smoothings, neighbors, width); float[] coordinates = new float[2]; coordinates[0] = float.Parse(metadata.resourceSets[0].resources[0].mapCenter.coordinates[0]); coordinates[1] = float.Parse(metadata.resourceSets[0].resources[0].mapCenter.coordinates[1]); GameControl.control.SetCurrentHeightmapData(heightmapData, centerLocation.zoom, coordinates); GameControl.control.SaveAsCurrent(); } else { Debug.Log("Something went wrong: size of terrain is not processable for heightmap generation"); } }
public IEnumerator saveCachedHeighmaps(Vector3 cellSize, Vector3 center) { for (int i = 0; i < 9; i++) { cachedHeightmaps.Add(GetCachedHMIndex(center, cellSize, i), new float[size, size]); } Debug.Log("started"); string url; if (firstRequest) { url = GetUrlMetadata(); } else { url = GetBaseImageryUrl(); url += imSet + "?"; url += "mapArea=" + GetBBoxString(cellSize, center); url += "&mapSize=" + size + "," + size; url += "&mapMetadata=1&key=" + key; } WWW metaReq = new WWW(url); yield return(metaReq); MetadataObject metadata = JsonConvert.DeserializeObject <MetadataObject>(metaReq.text); if (firstRequest) { firstRequest = false; firstSpawnPoint = new Vector3(center.x + cellSize.x, center.y, center.z + cellSize.z); firstBbox = metadata.resourceSets[0].resources[0].bbox; realGPSSize = firstBbox[3] - firstBbox[1]; //east - west } List <double> bbox = metadata.resourceSets[0].resources[0].bbox; url = "http://dev.virtualearth.net/REST/v1/Elevation/Bounds?bounds="; url += bbox[0] + "," + bbox[1] + "," + bbox[2] + "," + bbox[3]; int rows = 32; url += "&rows=" + rows + "&cols=" + rows + "&heights=sealevel&key=" + key; //max height point retrievable = 1024 = 32 * 32 WWW elevReq = new WWW(url); yield return(elevReq); ElevDataObject elevData = JsonConvert.DeserializeObject <ElevDataObject> (elevReq.text); List <int> elevations = elevData.resourceSets[0].resources[0].elevations; //elevations at sea level in meters //TerrainData terrain = GetComponent<Terrain> ().terrainData; int width = 512 * 3; float[,] heightmapData = new float[width, width]; //terrain.GetHeights(0, 0, width, width); if (width % rows == 0) { heightmapData = ApplyElevationsToHeightmap(elevations, heightmapData, width); heightmapData = Smooth(heightmapData, smoothings, neighbors, width); for (int i = 0; i < 9; i++) { cachedHeightmaps.Add(GetCachedHMIndex(center, cellSize, i), GetHeightmapForChunk(heightmapData, i)); } } else { Debug.Log("Something went wrong: size of terrain is not processable for heightmap generation"); } keepGoing = false; Debug.Log("finished"); Debug.Log(cachedHeightmaps.Count); }