private void CreateTileBase(UnityTile tile) { var mesh = new Mesh(); var verts = new List <Vector3>(); verts.Add((tile.Rect.min - tile.Rect.center).ToVector3xz()); verts.Add(new Vector3(tile.Rect.xMax - tile.Rect.center.x, 0, tile.Rect.yMin - tile.Rect.center.y)); verts.Add(new Vector3(tile.Rect.xMin - tile.Rect.center.x, 0, tile.Rect.yMax - tile.Rect.center.y)); verts.Add((tile.Rect.max - tile.Rect.center).ToVector3xz()); mesh.SetVertices(verts); var trilist = new List <int>() { 0, 1, 2, 1, 3, 2 }; mesh.SetTriangles(trilist, 0); var uvlist = new List <Vector2>() { new Vector2(0, 1), new Vector2(1, 1), new Vector2(0, 0), new Vector2(1, 0) }; mesh.SetUVs(0, uvlist); mesh.RecalculateNormals(); tile.GetComponent <MeshFilter>().sharedMesh = mesh; tile.GetComponent <MeshRenderer>().material = _flatTileMaterial; tile.gameObject.AddComponent <MeshCollider>(); }
private void Run(UnityTile tile) { if (!string.IsNullOrEmpty(_mapId)) { var parameters = new Tile.Parameters(); parameters.Fs = this.FileSource; parameters.Id = new CanonicalTileId(tile.Zoom, (int)tile.TileCoordinate.x, (int)tile.TileCoordinate.y); parameters.MapId = _mapId; tile.ImageDataState = TilePropertyState.Loading; var rasterTile = parameters.MapId.StartsWith("mapbox://") ? new RasterTile() : new ClassicRasterTile(); rasterTile.Initialize(parameters, (Action)(() => { if (rasterTile.Error != null) { tile.ImageDataState = TilePropertyState.Error; return; } var rend = tile.GetComponent <MeshRenderer>(); rend.material = _baseMaterial; tile.ImageData = new Texture2D(256, 256, TextureFormat.RGB24, false); tile.ImageData.wrapMode = TextureWrapMode.Clamp; tile.ImageData.LoadImage(rasterTile.Data); rend.material.mainTexture = tile.ImageData; tile.ImageDataState = TilePropertyState.Loaded; })); } else { var rend = tile.GetComponent <MeshRenderer>(); rend.material = _baseMaterial; } }
//BRNKHY there has to be a better way to do this private void FixStitches(UnityTile tile) { var tmesh = tile.GetComponent <MeshFilter>().mesh; var left = new Vector2(tile.TileCoordinate.x - 1, tile.TileCoordinate.y); int depth_sampleCount = (int)(sampleCount / (Mathf.Pow(2, Config.maxTreeDepth - tile.depth))); if (_tiles.ContainsKey(left) && _tiles[left].HeightData != null) { var t2mesh = _tiles[left].GetComponent <MeshFilter>().mesh; var verts = tmesh.vertices; for (int i = 0; i < depth_sampleCount; i++) { verts[i].Set(verts[i].x, t2mesh.vertices[verts.Length - depth_sampleCount + i].y, verts[i].z); } tmesh.vertices = verts; } var right = new Vector2(tile.TileCoordinate.x + 1, tile.TileCoordinate.y); if (_tiles.ContainsKey(right) && _tiles[right].HeightData != null) { var t2mesh = _tiles[right].GetComponent <MeshFilter>().mesh; var verts = tmesh.vertices; for (int i = 0; i < depth_sampleCount; i++) { verts[verts.Length - depth_sampleCount + i].Set(verts[verts.Length - depth_sampleCount + i].x, t2mesh.vertices[i].y, verts[verts.Length - depth_sampleCount + i].z); } tmesh.vertices = verts; } var up = new Vector2(tile.TileCoordinate.x, tile.TileCoordinate.y - 1); if (_tiles.ContainsKey(up) && _tiles[up].HeightData != null) { var t2mesh = _tiles[up].GetComponent <MeshFilter>().mesh; var verts = tmesh.vertices; for (int i = 0; i < depth_sampleCount; i++) { verts[i * depth_sampleCount].Set(verts[i * depth_sampleCount].x, t2mesh.vertices[i * depth_sampleCount + depth_sampleCount - 1].y, verts[i * depth_sampleCount].z); } tmesh.vertices = verts; } var down = new Vector2(tile.TileCoordinate.x, tile.TileCoordinate.y + 1); if (_tiles.ContainsKey(down) && _tiles[down].HeightData != null) { var t2mesh = _tiles[down].GetComponent <MeshFilter>().mesh; var verts = tmesh.vertices; for (int i = 0; i < depth_sampleCount; i++) { verts[i * depth_sampleCount + depth_sampleCount - 1].Set(verts[i * depth_sampleCount + depth_sampleCount - 1].x, t2mesh.vertices[i * depth_sampleCount].y, verts[i * depth_sampleCount + depth_sampleCount - 1].z); } tmesh.vertices = verts; } tmesh.RecalculateNormals(); }