Skip to content
Closed
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
14 changes: 2 additions & 12 deletions Assets/Mapzen/Unity/Earcut.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,20 +20,15 @@ public class Earcut
private static extern uint ReleaseTesselationContext(uint context);

[DllImport(LibraryName, EntryPoint = "TesselatePolygon")]
private static extern void TesselatePolygon(uint context, IntPtr points, IntPtr rings, int nRings, out int nIndices, out int nVertices);
private static extern void TesselatePolygon(uint context, IntPtr points, IntPtr rings, int nRings, out int nIndices);

[DllImport(LibraryName, EntryPoint = "GetIndices")]
private static extern void GetIndices(uint context, IntPtr indices);

[DllImport(LibraryName, EntryPoint = "GetVertices")]
private static extern void GetVertices(uint context, IntPtr vertices);

private uint contextId;

public int[] Indices { get; internal set; }

public float[] Vertices { get; internal set; }

public Earcut()
{
contextId = CreateTesselationContext();
Expand All @@ -42,28 +37,23 @@ public Earcut()

public void Tesselate(float[] points, int[] rings)
{
int nVertices = 0;
int nIndices = 0;

GCHandle pointsBufferHandle = GCHandle.Alloc(points, GCHandleType.Pinned);
GCHandle ringsBufferHandle = GCHandle.Alloc(rings, GCHandleType.Pinned);

TesselatePolygon(contextId, pointsBufferHandle.AddrOfPinnedObject(), ringsBufferHandle.AddrOfPinnedObject(), rings.Length, out nIndices, out nVertices);
TesselatePolygon(contextId, pointsBufferHandle.AddrOfPinnedObject(), ringsBufferHandle.AddrOfPinnedObject(), rings.Length, out nIndices);

pointsBufferHandle.Free();
ringsBufferHandle.Free();

Indices = new int[nIndices];
Vertices = new float[nVertices * 2];

GCHandle indicesBufferHandle = GCHandle.Alloc(Indices, GCHandleType.Pinned);
GCHandle verticesBufferHandle = GCHandle.Alloc(Vertices, GCHandleType.Pinned);

GetIndices(contextId, indicesBufferHandle.AddrOfPinnedObject());
GetVertices(contextId, verticesBufferHandle.AddrOfPinnedObject());

indicesBufferHandle.Free();
verticesBufferHandle.Free();
}

public void Release()
Expand Down
2 changes: 1 addition & 1 deletion Assets/Mapzen/Unity/IO.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public IEnumerator FetchNetworkData(Uri uri, IORequestCallback callback)
yield return request.Send();
string requestError = null;

if (request.isError)
if (request.isNetworkError)
{
// only handles system errors
requestError = request.error;
Expand Down
8 changes: 4 additions & 4 deletions Assets/Mapzen/Unity/PolygonBuilder.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Collections.Generic;
using System.Linq;
using Mapzen.VectorData;
using UnityEngine;
using System;
Expand Down Expand Up @@ -120,12 +121,11 @@ public void OnEndPolygon()
var earcut = new Earcut();

earcut.Tesselate(coordinates.ToArray(), rings.ToArray());
var vertices = new List<Vector3>(coordinates.Count / 2);

var vertices = new List<Vector3>(earcut.Vertices.Length / 2);

for (int i = 0; i < earcut.Vertices.Length; i += 2)
for (int i = 0; i < coordinates.Count; i += 2)
{
var v = new Vector3(earcut.Vertices[i], options.MaxHeight, earcut.Vertices[i + 1]);
var v = new Vector3(coordinates[i], options.MaxHeight, coordinates[i + 1]);

v = this.transform.MultiplyPoint(v);

Expand Down
Binary file modified Assets/Plugins/OSX/Earcut.bundle/Contents/MacOS/Earcut
Binary file not shown.
Loading