Skip to content

Commit

Permalink
add "just draw everything fam" option
Browse files Browse the repository at this point in the history
to draw everything regardless of settings/filtering. useful if you havent memorized all types & enums.
  • Loading branch information
brnkhy committed Oct 4, 2016
1 parent 122f338 commit f7b198b
Show file tree
Hide file tree
Showing 3 changed files with 96 additions and 94 deletions.
1 change: 1 addition & 0 deletions Assets/MapzenGo/Models/Factories/Factory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<JSONObject, bool> Query { get; set; }
Expand Down
73 changes: 37 additions & 36 deletions Assets/MapzenGo/Models/Factories/LanduseFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,55 +22,56 @@ public override void Start()
protected override IEnumerable<MonoBehaviour> Create(Vector2d tileMercPos, JSONObject geo)
{
var kind = geo["properties"]["kind"].str.ConvertToEnum<LanduseKind>();
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<Landuse>();
var md = new MeshData();
var mesh = landuse.GetComponent<MeshFilter>().mesh;
var landuse = new GameObject("Landuse").AddComponent<Landuse>();
var md = new MeshData();
var mesh = landuse.GetComponent<MeshFilter>().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<JSONObject> items)
{
var main = new GameObject("Landuse Layer");

var _meshes = new Dictionary<LanduseKind, MeshData>();
foreach (var geo in items.Where(x => Query(x)))
{
var kind = geo["properties"]["kind"].str.ConvertToEnum<LanduseKind>();
if (!_settings.HasSettingsFor(kind))
if (!_settings.HasSettingsFor(kind) && JustDrawEverythingFam)
continue;

var typeSettings = _settings.GetSettingsFor(kind);
Expand All @@ -80,7 +81,7 @@ protected override GameObject CreateLayer(Vector2d tileMercPos, List<JSONObject>
//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;
Expand Down Expand Up @@ -113,7 +114,7 @@ protected override GameObject CreateLayer(Vector2d tileMercPos, List<JSONObject>

return main;
}

private Vector3 ChangeToRelativePositions(List<Vector3> landuseCorners)
{
var landuseCenter = landuseCorners.Aggregate((acc, cur) => acc + cur) / landuseCorners.Count;
Expand Down
116 changes: 58 additions & 58 deletions Assets/MapzenGo/Models/Factories/RoadFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,78 +22,78 @@ public override void Start()
protected override IEnumerable<MonoBehaviour> Create(Vector2d tileMercPos, JSONObject geo)
{
var kind = geo["properties"]["kind"].str.ConvertToEnum<RoadType>();
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<Road>();
var mesh = road.GetComponent<MeshFilter>().mesh;
var roadEnds = new List<Vector3>();
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<MeshRenderer>().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<Road>();
var road = new GameObject("Roads").AddComponent<Road>();
var mesh = road.GetComponent<MeshFilter>().mesh;
var roadEnds = new List<Vector3>();
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<MeshRenderer>().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<Road>();
var mesh = road.GetComponent<MeshFilter>().mesh;
var roadEnds = new List<Vector3>();
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<MeshRenderer>().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<MeshRenderer>().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;
}
}
}
Expand All @@ -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;
}
Expand Down Expand Up @@ -131,7 +131,7 @@ private void GetVertices(Vector2d tileMercPos, List<JSONObject> geoList, MeshDat
foreach (var geo in geoList.Where(x => Query(x)))
{
var kind = geo["properties"]["kind"].str.ConvertToEnum<RoadType>();
if (!_settings.HasSettingsFor(kind))
if (!_settings.HasSettingsFor(kind) && JustDrawEverythingFam)
continue;

var settings = _settings.GetSettingsFor(kind);
Expand Down Expand Up @@ -204,17 +204,17 @@ private void CreateMesh(List<Vector3> 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);
Expand Down

0 comments on commit f7b198b

Please sign in to comment.