Hello.
After a couple of days of testing and debuggins, I think I have found a bug in your code: specifically with the method CoordinatesToTile.
Let me explain:
I made a class that makes a request for a specific city (I'm using the city of Catania for the test).
The request returns a list of points (lat and lon).
I then took the points, and applied different implementation of Triangulate, to get this result
Link img1: https://photos.app.goo.gl/zRzLYizXEVozZJUV8
As you can see, the mesh is correctly filled, but it's position does not match the map tile, since we have not remapped the coordinates to the map space.
At this point, after looking into the plugin's code, I found the method CoordinatesToTile.
So I tried using this method to remap the list of coordinates, and this is the result:
Link img2: https://photos.app.goo.gl/La6xqo71YHAKcvSE8
As you can see, it seems that I get the same result as your code.
After the conversion, it seems like the vertices are not connected anymore: they don't form a continuous line.
This is the reason why the triangulation does not appear to fill the poly shape.
Link img3: https://photos.app.goo.gl/fYrPoNNRJEF362957
I am attaching to this post the code that I used.
Please advise on how to fix this problem.
Thanks
Claudio
public void Recalculate(Vector2[] coordinates) //each element contains lat and lon of the boundary
{
List<Vector2> list_point_tile = null;
foreach (var item in coordinates)
{
double tx1, ty1;
OnlineMaps map = OnlineMaps.instance;
map.projection.CoordinatesToTile(item.x, item.y, map.zoom, out tx1, out ty1);
Vector2 tile_point = new Vector2((float)tx1, (float)ty1);
list_point_tile.Add(tile_point);
}
var vertices2D = list_point_tile.ToArray();
var vertices3D = System.Array.ConvertAll<Vector2, Vector3>(vertices2D, v => v);
// Use the triangulator to get indices for creating triangles
var triangulator = new Triangulator(vertices2D);
var indices = triangulator.Triangulate();
// Generate a color for each vertex
var colors = Enumerable.Range(0, vertices3D.Length)
.Select(i => Random.ColorHSV())
.ToArray();
// Create the mesh
var mesh = new Mesh
{
vertices = vertices3D,
triangles = indices,
colors = colors
};
mesh.RecalculateNormals();
mesh.RecalculateBounds();
// Set up game object with mesh;
var meshRenderer = gameObject.AddOrGetComponent<MeshRenderer>();
meshRenderer.material = new Material(Shader.Find("Sprites/Default"));
var filter = gameObject.AddOrGetComponent<MeshFilter>();
filter.mesh = mesh;
mesh.triangles = mesh.triangles.Reverse().ToArray();
}