Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ namespace Mapbox.Unity.MeshGeneration.Data

public class VectorFeatureUnity
{
public string Id;
public VectorTileFeature Data;
public Dictionary<string, object> Properties;
public List<List<Vector3>> Points = new List<List<Vector3>>();
Expand All @@ -29,10 +30,21 @@ public VectorFeatureUnity(VectorTileFeature feature, UnityTile tile, float layer
Properties = Data.GetProperties();
Points.Clear();

//this is a temp hack until we figure out how streets ids works
if (feature.Id > 10000) //ids from building dataset is big ulongs
{
Id = feature.Id.ToString();
_geom = feature.Geometry<float>(); //and we're not clipping by passing no parameters
}
else //streets ids, will require clipping
{
Id = string.Empty;
_geom = feature.Geometry<float>(0); //passing zero means clip at tile edge
}

_rectSizex = tile.Rect.Size.x;
_rectSizey = tile.Rect.Size.y;

_geom = feature.Geometry<float>(0);

_geomCount = _geom.Count;
for (int i = 0; i < _geomCount; i++)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,11 +75,16 @@ public override string Key
private int _entityPerCoroutine = 20;
private int _entityInCurrentCoroutine = 0;

private HashSet<string> _activeIds;
private Dictionary<UnityTile, List<string>> _idPool; //necessary to keep _activeIds list up to date when unloading tiles

public override void Initialize()
{
base.Initialize();
_entityInCurrentCoroutine = 0;
_activeCoroutines = new Dictionary<UnityTile, List<int>>();
_activeIds = new HashSet<string>();
_idPool = new Dictionary<UnityTile, List<string>>();

foreach (var filter in Filters)
{
Expand Down Expand Up @@ -127,7 +132,26 @@ private IEnumerator ProcessLayer(VectorTileLayer layer, UnityTile tile, Action c
for (int i = 0; i < fc; i++)
{
filterOut = false;
var feature = new VectorFeatureUnity(layer.GetFeature(i, 0), tile, layer.Extent);
var feature = new VectorFeatureUnity(layer.GetFeature(i), tile, layer.Extent);

//skip existing features, only works on tilesets with unique ids
if (!string.IsNullOrEmpty(feature.Id) && _activeIds.Contains(feature.Id))
{
continue;
}
else
{
_activeIds.Add(feature.Id);
if (!_idPool.ContainsKey(tile))
{
_idPool.Add(tile, new List<string>());
}
else
{
_idPool[tile].Add(feature.Id);
}
}

foreach (var filter in Filters)
{
if (!string.IsNullOrEmpty(filter.Key) && !feature.Properties.ContainsKey(filter.Key))
Expand Down Expand Up @@ -272,12 +296,25 @@ public override void OnUnregisterTile(UnityTile tile)
}

if (_defaultStack != null)
{
_defaultStack.UnregisterTile(tile);
}

foreach (var val in Stacks)
{
if (val != null && val.Stack != null)
val.Stack.UnregisterTile(tile);
}

//removing ids from activeIds list so they'll be recreated next time tile loads (necessary when you're unloading/loading tiles)
if (_idPool.ContainsKey(tile))
{
foreach (var item in _idPool[tile])
{
_activeIds.Remove(item);
}
_idPool[tile].Clear();
}
}
}
}