Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
5fe0678
update polygon and height mods to support buildings with holes
brnkhy Apr 18, 2017
9812657
add tile to modifier run parameters
brnkhy Apr 19, 2017
f74b0b9
add smooth line modifier
brnkhy Apr 21, 2017
0502b75
fix line mesh modifier for new mesh factory refactoring
brnkhy Apr 21, 2017
e9e05e5
fix a height modifier bug where side wall triangulation was wrong and…
brnkhy Apr 22, 2017
4b1a879
fix a height modifier bug where it connects side walls of separate fe…
brnkhy Apr 23, 2017
3eb8b9e
introduce edge list to mesh data containing outer edges of building/r…
brnkhy Apr 25, 2017
208dde8
fix height modifier bugs where min_height wasn't used properly
brnkhy Apr 26, 2017
a8a10f8
add a new line mesh modifier using clipper offsetting
brnkhy Apr 27, 2017
c041cb8
Merge branch 'develop' into cuttingHoles
brnkhy May 5, 2017
967554c
change PolygonMeshModifier to use new parameter order of vertex class
brnkhy May 5, 2017
fcbb0ea
bumping submodules
May 8, 2017
7c4f789
fix a bug where y coordinate is lost and not used in polygon modifier
brnkhy May 15, 2017
d345ef7
fix snap y axis to 0 function
brnkhy May 16, 2017
d811402
submodule update
May 16, 2017
315ca86
roll back submodule
May 16, 2017
dbbfbb2
add empty constructor to VectorFeatureUnity
brnkhy May 16, 2017
524b14f
update scene and some asset files
brnkhy May 16, 2017
e8b9ada
Merge branch 'cuttingHoles' of https://github.com/mapbox/mapbox-unity…
brnkhy May 16, 2017
3406c85
Merge branch 'develop' into cuttingHoles
brnkhy May 16, 2017
9fe30f4
fix branch for latest static field removal
brnkhy May 16, 2017
4309095
fix broken using statement path
brnkhy May 16, 2017
48b99c7
point to proper triangle branch
May 16, 2017
575b328
Merge branch 'cuttingHoles' of github.com:mapbox/mapbox-unity-sdk int…
May 16, 2017
9792343
update cs module
May 16, 2017
28ae04b
bump vector module
May 16, 2017
660c7cb
fix using statement after submodule update
brnkhy May 16, 2017
baac819
Smaller map for building to mobile
May 16, 2017
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion dependencies/mapbox-sdk-cs
2 changes: 1 addition & 1 deletion dependencies/triangle.net-uwp
Submodule triangle.net-uwp updated 97 files
+9 −37 Triangle.NET/Triangle/Behavior.cs
+0 −421 Triangle.NET/Triangle/Carver.cs
+44 −0 Triangle.NET/Triangle/Configuration.cs
+0 −484 Triangle.NET/Triangle/Data/Otri.cs
+8 −18 Triangle.NET/Triangle/Enums.cs
+0 −129 Triangle.NET/Triangle/Geometry/BoundingBox.cs
+246 −0 Triangle.NET/Triangle/Geometry/Contour.cs
+4 −10 Triangle.NET/Triangle/Geometry/Edge.cs
+143 −0 Triangle.NET/Triangle/Geometry/ExtensionMethods.cs
+29 −0 Triangle.NET/Triangle/Geometry/IEdge.cs
+93 −0 Triangle.NET/Triangle/Geometry/IPolygon.cs
+4 −25 Triangle.NET/Triangle/Geometry/ISegment.cs
+29 −43 Triangle.NET/Triangle/Geometry/ITriangle.cs
+0 −206 Triangle.NET/Triangle/Geometry/InputGeometry.cs
+32 −18 Triangle.NET/Triangle/Geometry/Point.cs
+183 −0 Triangle.NET/Triangle/Geometry/Polygon.cs
+189 −0 Triangle.NET/Triangle/Geometry/Rectangle.cs
+30 −0 Triangle.NET/Triangle/Geometry/RegionPointer.cs
+92 −0 Triangle.NET/Triangle/Geometry/Segment.cs
+26 −14 Triangle.NET/Triangle/Geometry/Vertex.cs
+256 −235 Triangle.NET/Triangle/IO/DebugWriter.cs
+126 −0 Triangle.NET/Triangle/IO/FileProcessor.cs
+0 −611 Triangle.NET/Triangle/IO/FileReader.cs
+0 −497 Triangle.NET/Triangle/IO/FileWriter.cs
+13 −0 Triangle.NET/Triangle/IO/IFileFormat.cs
+0 −27 Triangle.NET/Triangle/IO/IGeometryFormat.cs
+14 −10 Triangle.NET/Triangle/IO/IMeshFormat.cs
+38 −0 Triangle.NET/Triangle/IO/IPolygonFormat.cs
+18 −51 Triangle.NET/Triangle/IO/InputTriangle.cs
+44 −19 Triangle.NET/Triangle/IO/TriangleFormat.cs
+741 −0 Triangle.NET/Triangle/IO/TriangleReader.cs
+459 −0 Triangle.NET/Triangle/IO/TriangleWriter.cs
+22 −0 Triangle.NET/Triangle/IPredicates.cs
+19 −16 Triangle.NET/Triangle/Log.cs
+1 −4 Triangle.NET/Triangle/Logging/ILog.cs
+1 −4 Triangle.NET/Triangle/Logging/ILogItem.cs
+4 −7 Triangle.NET/Triangle/Logging/LogItem.cs
+327 −1,327 Triangle.NET/Triangle/Mesh.cs
+215 −0 Triangle.NET/Triangle/MeshValidator.cs
+121 −327 Triangle.NET/Triangle/Meshing/Algorithm/Dwyer.cs
+71 −61 Triangle.NET/Triangle/Meshing/Algorithm/Incremental.cs
+263 −259 Triangle.NET/Triangle/Meshing/Algorithm/SweepLine.cs
+1,225 −0 Triangle.NET/Triangle/Meshing/ConstraintMesher.cs
+40 −0 Triangle.NET/Triangle/Meshing/ConstraintOptions.cs
+269 −104 Triangle.NET/Triangle/Meshing/Converter.cs
+8 −17 Triangle.NET/Triangle/Meshing/Data/BadSubseg.cs
+14 −16 Triangle.NET/Triangle/Meshing/Data/BadTriQueue.cs
+7 −15 Triangle.NET/Triangle/Meshing/Data/BadTriangle.cs
+233 −0 Triangle.NET/Triangle/Meshing/GenericMesher.cs
+26 −0 Triangle.NET/Triangle/Meshing/IConstraintMesher.cs
+57 −0 Triangle.NET/Triangle/Meshing/IMesh.cs
+28 −0 Triangle.NET/Triangle/Meshing/IQualityMesher.cs
+10 −6 Triangle.NET/Triangle/Meshing/ITriangulator.cs
+12 −14 Triangle.NET/Triangle/Meshing/Iterators/EdgeIterator.cs
+135 −0 Triangle.NET/Triangle/Meshing/Iterators/RegionIterator.cs
+100 −0 Triangle.NET/Triangle/Meshing/Iterators/VertexCirculator.cs
+133 −241 Triangle.NET/Triangle/Meshing/QualityMesher.cs
+55 −0 Triangle.NET/Triangle/Meshing/QualityOptions.cs
+84 −102 Triangle.NET/Triangle/NewLocation.cs
+0 −488 Triangle.NET/Triangle/Primitives.cs
+1,346 −0 Triangle.NET/Triangle/RobustPredicates.cs
+0 −111 Triangle.NET/Triangle/Sampler.cs
+3 −5 Triangle.NET/Triangle/Smoothing/ISmoother.cs
+116 −48 Triangle.NET/Triangle/Smoothing/SimpleSmoother.cs
+201 −0 Triangle.NET/Triangle/Smoothing/VoronoiFactory.cs
+105 −224 Triangle.NET/Triangle/Tools/AdjacencyMatrix.cs
+121 −95 Triangle.NET/Triangle/Tools/CuthillMcKee.cs
+105 −0 Triangle.NET/Triangle/Tools/Interpolation.cs
+194 −0 Triangle.NET/Triangle/Tools/IntersectionHelper.cs
+245 −0 Triangle.NET/Triangle/Tools/PolygonValidator.cs
+0 −423 Triangle.NET/Triangle/Tools/QuadTree.cs
+2 −2 Triangle.NET/Triangle/Tools/QualityMeasure.cs
+0 −139 Triangle.NET/Triangle/Tools/RegionIterator.cs
+10 −82 Triangle.NET/Triangle/Tools/Statistic.cs
+426 −0 Triangle.NET/Triangle/Tools/TriangleQuadTree.cs
+371 −0 Triangle.NET/Triangle/Tools/VertexSorter.cs
+269 −0 Triangle.NET/Triangle/Topology/DCEL/DcelMesh.cs
+112 −0 Triangle.NET/Triangle/Topology/DCEL/Face.cs
+101 −0 Triangle.NET/Triangle/Topology/DCEL/HalfEdge.cs
+68 −0 Triangle.NET/Triangle/Topology/DCEL/Vertex.cs
+74 −73 Triangle.NET/Triangle/Topology/Osub.cs
+481 −0 Triangle.NET/Triangle/Topology/Otri.cs
+11 −23 Triangle.NET/Triangle/Topology/SubSegment.cs
+32 −89 Triangle.NET/Triangle/Topology/Triangle.cs
+78 −48 Triangle.NET/Triangle/Triangle.csproj
+63 −39 Triangle.NET/Triangle/TriangleLocator.cs
+305 −0 Triangle.NET/Triangle/TrianglePool.cs
+85 −0 Triangle.NET/Triangle/TriangleSampler.cs
+182 −0 Triangle.NET/Triangle/Voronoi/BoundedVoronoi.cs
+35 −0 Triangle.NET/Triangle/Voronoi/DefaultVoronoiFactory.cs
+18 −0 Triangle.NET/Triangle/Voronoi/IVoronoiFactory.cs
+166 −130 Triangle.NET/Triangle/Voronoi/Legacy/BoundedVoronoiLegacy.cs
+8 −3 Triangle.NET/Triangle/Voronoi/Legacy/IVoronoi.cs
+119 −73 Triangle.NET/Triangle/Voronoi/Legacy/SimpleVoronoi.cs
+34 −5 Triangle.NET/Triangle/Voronoi/Legacy/VoronoiRegion.cs
+66 −0 Triangle.NET/Triangle/Voronoi/StandardVoronoi.cs
+291 −0 Triangle.NET/Triangle/Voronoi/VoronoiBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,19 @@ public class FeatureBehaviour : MonoBehaviour
[Multiline(10)]
public string DataString;

[Multiline(10)]
public string Points;

public void Init(VectorFeatureUnity feature)
{
Transform = transform;
Data = feature;
DataString = string.Join(" \r\n ", Data.Properties.Select(x => x.Key + " - " + x.Value.ToString()).ToArray());
foreach (var item in feature.Points)
{
Points += string.Join(",", item.Select(x => x.x + "-" + x.z).ToArray());
Points += "\r\n ";
}
}
}
}
51 changes: 28 additions & 23 deletions sdkproject/Assets/Mapbox/Core/Unity/MeshGeneration/Data/MeshData.cs
Original file line number Diff line number Diff line change
@@ -1,25 +1,30 @@
namespace Mapbox.Unity.MeshGeneration.Data
{
using System.Collections.Generic;
using UnityEngine;
using Utils;

public class MeshData
{
public Vector2 MercatorCenter { get; set; }
public RectD TileRect { get; set; }
namespace Mapbox.Unity.MeshGeneration.Data
{
using System.Collections.Generic;
using TriangleNet.Geometry;
using TriangleNet.Meshing;
using UnityEngine;
using Utils;

public class MeshData
{
public List<int> Edges { get; set; }
public IMesh PolygonMesh { get; set; }
public Vector2 MercatorCenter { get; set; }
public RectD TileRect { get; set; }
public List<Vector3> Vertices { get; set; }
public List<Vector3> Normals { get; set; }
public List<List<int>> Triangles { get; set; }
public List<List<Vector2>> UV { get; set; }

public MeshData()
{
Vertices = new List<Vector3>();
Normals = new List<Vector3>();
Triangles = new List<List<int>>();
UV = new List<List<Vector2>>();
UV.Add(new List<Vector2>());
}
}
}
public List<List<int>> Triangles { get; set; }
public List<List<Vector2>> UV { get; set; }

public MeshData()
{
Edges = new List<int>();
Vertices = new List<Vector3>();
Normals = new List<Vector3>();
Triangles = new List<List<int>>();
UV = new List<List<Vector2>>();
UV.Add(new List<Vector2>());
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@ public class VectorFeatureUnity
public Dictionary<string, object> Properties { get; set; }
public List<List<Vector3>> Points;

public VectorFeatureUnity()
{
Points = new List<List<Vector3>>();
}

public VectorFeatureUnity(VectorTileFeature feature, UnityTile tile, float layerExtent)
{
Data = feature;
Expand All @@ -25,7 +30,7 @@ public VectorFeatureUnity(VectorTileFeature feature, UnityTile tile, float layer
for (int j = 0; j < geom[i].Count; j++)
{
var point = geom[i][j];
nl.Add(new Vector3((float)(point.X / layerExtent * tile.Rect.Size.x - (tile.Rect.Size.x/2)), 0, (float)((layerExtent - point.Y) / layerExtent * tile.Rect.Size.y - (tile.Rect.Size.y / 2))));
nl.Add(new Vector3((float)(point.X / layerExtent * tile.Rect.Size.x - (tile.Rect.Size.x / 2)), 0, (float)((layerExtent - point.Y) / layerExtent * tile.Rect.Size.y - (tile.Rect.Size.y / 2))));
}
Points.Add(nl);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,18 +39,21 @@ public void Query(List<Transform> waypoints)
void HandleDirectionsResponse(DirectionsResponse response)
{
var meshData = new MeshData();

var dat = new List<Vector3>();
foreach (var leg in response.Routes[0].Legs)
{
foreach (var point in response.Routes[0].Geometry)
{
meshData.Vertices.Add(Conversions.GeoToWorldPosition(point.x, point.y, Parameters.ReferenceTileRect.Center, Parameters.WorldScaleFactor).ToVector3xz());
dat.Add(Conversions.GeoToWorldPosition(point.x, point.y, Parameters.ReferenceTileRect.Center, Parameters.WorldScaleFactor).ToVector3xz());
}
}

var feat = new VectorFeatureUnity();
feat.Points.Add(dat);

foreach (MeshModifier mod in MeshModifiers.Where(x => x.Active))
{
mod.Run(null, meshData);
mod.Run(feat, meshData);
}

CreateGameObject(meshData);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,102 +109,65 @@ public override void Create(VectorTileLayer layer, UnityTile tile)
/// <param name="feature"></param>
/// <param name="tile"></param>
/// <param name="parent"></param>
private void Build(VectorFeatureUnity feature, UnityTile tile, GameObject parent)
private bool IsFeatureValid(VectorFeatureUnity feature)
{
if (feature.Properties.ContainsKey("extrude") && !bool.Parse(feature.Properties["extrude"].ToString()))
return;
return false;

//we're not cutting out the holes yet
foreach (var geometry in feature.Points)
{
var meshData = new MeshData();
meshData.TileRect = tile.Rect;
if (feature.Points.Count < 1)
return false;

if (geometry.Count <= 1)
continue;
return true;
}

//this will be improved in next version and will probably be replaced by filters
string styleSelectorKey = "";
if (string.IsNullOrEmpty(_classificationKey))
{
if (feature.Properties.ContainsKey("type"))
{
styleSelectorKey = feature.Properties["type"].ToString().ToLowerInvariant();
}
else if (feature.Properties.ContainsKey("class"))
{
styleSelectorKey = feature.Properties["class"].ToString().ToLowerInvariant();
}
}
else if (feature.Properties.ContainsKey(_classificationKey))
{
if (feature.Properties.ContainsKey(_classificationKey))
{
styleSelectorKey = feature.Properties[_classificationKey].ToString().ToLowerInvariant();
}
}
private void Build(VectorFeatureUnity feature, UnityTile tile, GameObject parent)
{
if (!IsFeatureValid(feature))
return;

//we'll run all visualizers on MeshData here
var list = geometry;
//.Select(x => Conversions.GeoToWorldPosition(x.Lat, x.Lng, tile.Rect.Center).ToVector3xz()).ToList();
//this will be improved in next version and will probably be replaced by filters
var styleSelectorKey = FindSelectorKey(feature);

//long straight edges looks bad on bumpy terrain
if (_subdivideLongEdges)
{
var verts = new List<Vector3>();
if (list.Count > 1)
{
for (int i = 0; i < list.Count - 1; i++)
{
verts.Add(list[i]);
var dist = Vector3.Distance(list[i], list[i + 1]);
var step = Math.Min(_maxEdgeSectionCount, dist / _preferredEdgeSectionLength);
if (step > 1)
{
var counter = 1;
while (counter < step)
{
var nv = Vector3.Lerp(list[i], list[i + 1], Mathf.Min(1, counter / step));
verts.Add(nv);
counter++;
}
}
}
}
verts.Add(list.Last());
list = verts;
}
var meshData = new MeshData();
meshData.TileRect = tile.Rect;

//and finally, running the modifier stack on the feature
var mod = Stacks.FirstOrDefault(x => x.Type.Contains(styleSelectorKey));
GameObject go;
if (mod != null)
{
go = mod.Stack.Execute(tile, feature, meshData, parent, mod.Type);
}
else
{
if (_defaultStack != null)
go = _defaultStack.Execute(tile, feature, meshData, parent, _key);
}
//go.layer = LayerMask.NameToLayer(_key);
}

//adding terrain & building min_height to vertices
//we may move this into height modifier in the future
meshData.Vertices = list.Select(vertex =>
private string FindSelectorKey(VectorFeatureUnity feature)
{
if (string.IsNullOrEmpty(_classificationKey))
{
if (feature.Properties.ContainsKey("type"))
{
var h = tile.QueryHeightData((float)((vertex.x + tile.Rect.Size.x / 2) / tile.Rect.Size.x), (float)((vertex.z + tile.Rect.Size.y / 2) / tile.Rect.Size.y));
vertex += new Vector3(0, h, 0);

if (feature.Properties.ContainsKey("min_height"))
{
var min_height = Convert.ToSingle(feature.Properties["min_height"]);
vertex += new Vector3(0, min_height, 0);
}

return vertex;
}).ToList();

//and finally, running the modifier stack on the feature
var mod = Stacks.FirstOrDefault(x => x.Type.Contains(styleSelectorKey));
GameObject go;
if (mod != null)
return feature.Properties["type"].ToString().ToLowerInvariant();
}
else if (feature.Properties.ContainsKey("class"))
{
go = mod.Stack.Execute(tile, feature, meshData, parent, mod.Type);
return feature.Properties["class"].ToString().ToLowerInvariant();
}
else
}
else if (feature.Properties.ContainsKey(_classificationKey))
{
if (feature.Properties.ContainsKey(_classificationKey))
{
if (_defaultStack != null)
go = _defaultStack.Execute(tile, feature, meshData, parent, _key);
return feature.Properties[_classificationKey].ToString().ToLowerInvariant();
}
//go.layer = LayerMask.NameToLayer(_key);
}

return "";
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -67,18 +67,11 @@ public void Start()
/// <summary>
/// Pulls the root world object to origin for ease of use/view
/// </summary>
public void Update()
private void SnapZero(UnityTile s, object e)
{
if (_snapYToZero)
{
var ray = new Ray(new Vector3(0, 1000, 0), Vector3.down);
RaycastHit rayhit;
if (Physics.Raycast(ray, out rayhit))
{
Root.transform.position = new Vector3(0, -rayhit.point.y, 0);
_snapYToZero = false;
}
}
var h = Conversions.GetRelativeHeightFromColor(s.HeightData.GetPixel(127, 127), s.RelativeScale);
Root.transform.position = new Vector3(0, -h * WorldParameters.WorldScaleFactor, 0);
s.HeightDataChanged -= SnapZero;
}

public void Execute()
Expand Down Expand Up @@ -109,6 +102,11 @@ public void Execute(double lat, double lng, int zoom, Vector4 frame)
tile.transform.position = new Vector3((float)(tile.Rect.Center.x - WorldParameters.ReferenceTileRect.Center.x), 0, (float)(tile.Rect.Center.y - WorldParameters.ReferenceTileRect.Center.y));
tile.transform.SetParent(Root.transform, false);
MapVisualization.ShowTile(tile);

if (_snapYToZero && j == _refTile.y && i == _refTile.x)
{
tile.HeightDataChanged += SnapZero;
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ public class MergedModifierStack : ModifierStackBase

public override GameObject Execute(UnityTile tile, VectorFeatureUnity feature, MeshData meshData, GameObject parent = null, string type = "")
{
base.Execute(tile, feature, meshData, parent, type);

if (!_cacheVertexCount.ContainsKey(tile))
{
_cacheVertexCount.Add(tile, 0);
Expand All @@ -37,7 +39,7 @@ public override GameObject Execute(UnityTile tile, VectorFeatureUnity feature, M
_buildingCount[tile]++;
foreach (MeshModifier mod in MeshModifiers.Where(x => x.Active))
{
mod.Run(feature, meshData);
mod.Run(feature, meshData, tile);
}

GameObject go = null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public class MeshModifier : ModifierBase
{
public virtual ModifierType Type { get { return ModifierType.Preprocess; } }

public virtual void Run(VectorFeatureUnity feature, MeshData md)
public virtual void Run(VectorFeatureUnity feature, MeshData md, UnityTile tile = null)
{

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public class ChamferModifier : MeshModifier
[SerializeField]
private float _size;

public override void Run(VectorFeatureUnity feature, MeshData md)
public override void Run(VectorFeatureUnity feature, MeshData md, UnityTile tile = null)
{
if (md.Vertices.Count == 0)
return;
Expand Down
Loading