diff --git a/Assets/MapzenGo/Models/Factories/Factory.cs b/Assets/MapzenGo/Models/Factories/Factory.cs index 6202818..5de3c61 100644 --- a/Assets/MapzenGo/Models/Factories/Factory.cs +++ b/Assets/MapzenGo/Models/Factories/Factory.cs @@ -9,6 +9,7 @@ namespace MapzenGo.Models.Factories public class Factory : Plugin { public bool MergeMeshes; + public bool JustDrawEverythingFam = false; public float Order = 1; public virtual string XmlTag {get { return ""; } } public virtual Func Query { get; set; } diff --git a/Assets/MapzenGo/Models/Factories/LanduseFactory.cs b/Assets/MapzenGo/Models/Factories/LanduseFactory.cs index a7ccf8f..d49d85b 100644 --- a/Assets/MapzenGo/Models/Factories/LanduseFactory.cs +++ b/Assets/MapzenGo/Models/Factories/LanduseFactory.cs @@ -22,55 +22,56 @@ public override void Start() protected override IEnumerable Create(Vector2d tileMercPos, JSONObject geo) { var kind = geo["properties"]["kind"].str.ConvertToEnum(); - if (kind != LanduseKind.Unknown && _settings.HasSettingsFor(kind)) - { - var bb = geo["geometry"]["coordinates"].list[0]; //this is wrong but cant fix it now - if (bb == null || bb.list == null) - yield break; - var count = bb.list.Count - 1; - if (count < 3) - yield break; + if (!_settings.HasSettingsFor(kind) && !JustDrawEverythingFam) + yield break; - var inp = new InputGeometry(count); - for (var i = 0; i < count; i++) - { - var c = bb.list[i]; - var dotMerc = GM.LatLonToMeters(c[1].f, c[0].f); - var localMercPos = dotMerc - tileMercPos; - inp.AddPoint(localMercPos.x, localMercPos.y); - inp.AddSegment(i, (i + 1) % count); - } + var bb = geo["geometry"]["coordinates"].list[0]; //this is wrong but cant fix it now + if (bb == null || bb.list == null) + yield break; + + var count = bb.list.Count - 1; + if (count < 3) + yield break; + + var inp = new InputGeometry(count); + for (var i = 0; i < count; i++) + { + var c = bb.list[i]; + var dotMerc = GM.LatLonToMeters(c[1].f, c[0].f); + var localMercPos = dotMerc - tileMercPos; + inp.AddPoint(localMercPos.x, localMercPos.y); + inp.AddSegment(i, (i + 1) % count); + } - var landuse = new GameObject("Landuse").AddComponent(); - var md = new MeshData(); - var mesh = landuse.GetComponent().mesh; + var landuse = new GameObject("Landuse").AddComponent(); + var md = new MeshData(); + var mesh = landuse.GetComponent().mesh; - SetProperties(geo, landuse, kind); - CreateMesh(inp, md); + SetProperties(geo, landuse, kind); + CreateMesh(inp, md); - //I want object center to be in the middle of object, not at the corner of the tile - var landuseCenter = ChangeToRelativePositions(md.Vertices); - landuse.transform.localPosition = landuseCenter; - - mesh.vertices = md.Vertices.ToArray(); - mesh.triangles = md.Indices.ToArray(); - mesh.SetUVs(0, md.UV); - mesh.RecalculateNormals(); + //I want object center to be in the middle of object, not at the corner of the tile + var landuseCenter = ChangeToRelativePositions(md.Vertices); + landuse.transform.localPosition = landuseCenter; - yield return landuse; - } + mesh.vertices = md.Vertices.ToArray(); + mesh.triangles = md.Indices.ToArray(); + mesh.SetUVs(0, md.UV); + mesh.RecalculateNormals(); + + yield return landuse; } protected override GameObject CreateLayer(Vector2d tileMercPos, List items) { var main = new GameObject("Landuse Layer"); - + var _meshes = new Dictionary(); foreach (var geo in items.Where(x => Query(x))) { var kind = geo["properties"]["kind"].str.ConvertToEnum(); - if (!_settings.HasSettingsFor(kind)) + if (!_settings.HasSettingsFor(kind) && JustDrawEverythingFam) continue; var typeSettings = _settings.GetSettingsFor(kind); @@ -80,7 +81,7 @@ protected override GameObject CreateLayer(Vector2d tileMercPos, List //foreach (var bb in geo["geometry"]["coordinates"].list) //{ var bb = geo["geometry"]["coordinates"].list[0]; //this is wrong but cant fix it now - var count = bb.list.Count -1; + var count = bb.list.Count - 1; if (count < 3) continue; @@ -113,7 +114,7 @@ protected override GameObject CreateLayer(Vector2d tileMercPos, List return main; } - + private Vector3 ChangeToRelativePositions(List landuseCorners) { var landuseCenter = landuseCorners.Aggregate((acc, cur) => acc + cur) / landuseCorners.Count; diff --git a/Assets/MapzenGo/Models/Factories/RoadFactory.cs b/Assets/MapzenGo/Models/Factories/RoadFactory.cs index fb4e5ba..2767ccd 100644 --- a/Assets/MapzenGo/Models/Factories/RoadFactory.cs +++ b/Assets/MapzenGo/Models/Factories/RoadFactory.cs @@ -22,78 +22,78 @@ public override void Start() protected override IEnumerable Create(Vector2d tileMercPos, JSONObject geo) { var kind = geo["properties"]["kind"].str.ConvertToEnum(); - if (_settings.HasSettingsFor(kind)) + if (!_settings.HasSettingsFor(kind) && !JustDrawEverythingFam) + yield break; + + var typeSettings = _settings.GetSettingsFor(kind); + + if (geo["geometry"]["type"].str == "LineString") { - var typeSettings = _settings.GetSettingsFor(kind); + var road = new GameObject("road").AddComponent(); + var mesh = road.GetComponent().mesh; + var roadEnds = new List(); + var md = new MeshData(); - if (geo["geometry"]["type"].str == "LineString") + for (var i = 0; i < geo["geometry"]["coordinates"].list.Count; i++) + { + var c = geo["geometry"]["coordinates"][i]; + var dotMerc = GM.LatLonToMeters(c[1].f, c[0].f); + var localMercPos = dotMerc - tileMercPos; + roadEnds.Add(localMercPos.ToVector3()); + } + + CreateMesh(roadEnds, typeSettings, md); + + mesh.vertices = md.Vertices.ToArray(); + mesh.triangles = md.Indices.ToArray(); + mesh.SetUVs(0, md.UV); + mesh.RecalculateNormals(); + + road.GetComponent().material = typeSettings.Material; + + road.Id = geo["properties"]["id"].ToString(); + road.Type = geo["type"].str; + road.Kind = geo["properties"]["kind"].str; + road.SortKey = (int)geo["properties"]["sort_key"].f; + if (geo["properties"].HasField("name")) + road.Name = geo["properties"]["name"].str; + + road.transform.position += Vector3.up * road.SortKey / 100; + yield return road; + } + else if (geo["geometry"]["type"].str == "MultiLineString") + { + for (var i = 0; i < geo["geometry"]["coordinates"].list.Count; i++) { - var road = new GameObject("road").AddComponent(); + var road = new GameObject("Roads").AddComponent(); var mesh = road.GetComponent().mesh; var roadEnds = new List(); var md = new MeshData(); - for (var i = 0; i < geo["geometry"]["coordinates"].list.Count; i++) + roadEnds.Clear(); + var c = geo["geometry"]["coordinates"][i]; + for (var j = 0; j < c.list.Count; j++) { - var c = geo["geometry"]["coordinates"][i]; - var dotMerc = GM.LatLonToMeters(c[1].f, c[0].f); + var seg = c[j]; + var dotMerc = GM.LatLonToMeters(seg[1].f, seg[0].f); var localMercPos = dotMerc - tileMercPos; roadEnds.Add(localMercPos.ToVector3()); } - CreateMesh(roadEnds, typeSettings, md); + SetProperties(geo, road); + CreateMesh(roadEnds, typeSettings, md); mesh.vertices = md.Vertices.ToArray(); mesh.triangles = md.Indices.ToArray(); mesh.SetUVs(0, md.UV); mesh.RecalculateNormals(); - - road.GetComponent().material = typeSettings.Material; - - road.Id = geo["properties"]["id"].ToString(); - road.Type = geo["type"].str; - road.Kind = geo["properties"]["kind"].str; - road.SortKey = (int)geo["properties"]["sort_key"].f; - if (geo["properties"].HasField("name")) - road.Name = geo["properties"]["name"].str; - - road.transform.position += Vector3.up*road.SortKey/100; - yield return road; - } - else if (geo["geometry"]["type"].str == "MultiLineString") - { - for (var i = 0; i < geo["geometry"]["coordinates"].list.Count; i++) - { - var road = new GameObject("Roads").AddComponent(); - var mesh = road.GetComponent().mesh; - var roadEnds = new List(); - var md = new MeshData(); - - roadEnds.Clear(); - var c = geo["geometry"]["coordinates"][i]; - for (var j = 0; j < c.list.Count; j++) - { - var seg = c[j]; - var dotMerc = GM.LatLonToMeters(seg[1].f, seg[0].f); - var localMercPos = dotMerc - tileMercPos; - roadEnds.Add(localMercPos.ToVector3()); - } - SetProperties(geo, road); + road.GetComponent().material = typeSettings.Material; - CreateMesh(roadEnds, typeSettings, md); - mesh.vertices = md.Vertices.ToArray(); - mesh.triangles = md.Indices.ToArray(); - mesh.SetUVs(0, md.UV); - mesh.RecalculateNormals(); - - road.GetComponent().material = typeSettings.Material; - - road.transform.position += Vector3.up*road.SortKey/100; - yield return road; - } + road.transform.position += Vector3.up * road.SortKey / 100; + yield return road; } } } @@ -103,7 +103,7 @@ private static void SetProperties(JSONObject geo, Road road) road.Id = geo["properties"]["id"].ToString(); road.Type = geo["type"].str; road.Kind = geo["properties"]["kind"].str; - road.SortKey = (int) geo["properties"]["sort_key"].f; + road.SortKey = (int)geo["properties"]["sort_key"].f; if (geo["properties"].HasField("name")) road.Name = geo["properties"]["name"].str; } @@ -131,7 +131,7 @@ private void GetVertices(Vector2d tileMercPos, List geoList, MeshDat foreach (var geo in geoList.Where(x => Query(x))) { var kind = geo["properties"]["kind"].str.ConvertToEnum(); - if (!_settings.HasSettingsFor(kind)) + if (!_settings.HasSettingsFor(kind) && JustDrawEverythingFam) continue; var settings = _settings.GetSettingsFor(kind); @@ -204,17 +204,17 @@ private void CreateMesh(List list, SettingsLayers.RoadSettings settings md.Indices.Add(j); md.Indices.Add(j + 2); md.Indices.Add(j + 1); - + md.Indices.Add(j + 1); md.Indices.Add(j + 2); md.Indices.Add(j + 3); - } - else - { + } + else + { md.Indices.Add(j + 1); md.Indices.Add(j + 2); md.Indices.Add(j); - + md.Indices.Add(j + 3); md.Indices.Add(j + 2); md.Indices.Add(j + 1);