protected void InitLineMesh(IEnumerable points, OnlineMapsTileSetControl control, ref List <Vector3> vertices, ref List <Vector3> normals, ref List <int> triangles, ref List <Vector2> uv, float width, bool closed = false, bool optimize = true) { map.buffer.GetCorners(out tlx, out tly, out brx, out bry); if (brx < tlx) { brx += 360; } float zoomCoof = map.zoomCoof; List <Vector2> localPoints = GetLocalPoints(points, closed, optimize); List <Vector2> activePoints = new List <Vector2>(localPoints.Count); int maxX = 1 << map.zoom; float maxSize = maxX * OnlineMapsUtils.tileSize * control.sizeInScene.x / map.width; float halfSize = maxSize / 2; float lastPointX = 0; float lastPointY = 0; float sizeX = control.sizeInScene.x / zoomCoof; float sizeY = control.sizeInScene.y / zoomCoof; bestElevationYScale = OnlineMapsElevationManagerBase.GetBestElevationYScale(tlx, tly, brx, bry); if (vertices == null) { vertices = new List <Vector3>(Mathf.Max(Mathf.NextPowerOfTwo(localPoints.Count * 4), 32)); } else { vertices.Clear(); } if (normals == null) { normals = new List <Vector3>(vertices.Capacity); } else { normals.Clear(); } if (triangles == null) { triangles = new List <int>(Mathf.Max(Mathf.NextPowerOfTwo(localPoints.Count * 6), 32)); } else { triangles.Clear(); } if (uv == null) { uv = new List <Vector2>(vertices.Capacity); } else { uv.Clear(); } Vector2[] intersections = new Vector2[4]; bool needExtraPoint = false; float extraX = 0, extraY = 0; for (int i = 0; i < localPoints.Count; i++) { Vector2 p = localPoints[i]; float px = p.x; float py = p.y; if (needExtraPoint) { activePoints.Add(new Vector2(extraX, extraY)); float ox = extraX - lastPointX; if (ox > halfSize) { lastPointX += maxSize; } else if (ox < -halfSize) { lastPointX -= maxSize; } activePoints.Add(new Vector2(lastPointX, lastPointY)); needExtraPoint = false; } if (i > 0 && checkMapBoundaries) { int countIntersections = 0; float ox = px - lastPointX; while (Math.Abs(ox) > halfSize) { if (ox < 0) { px += maxSize; ox += maxSize; } else if (ox > 0) { px -= maxSize; ox -= maxSize; } } float crossTopX, crossTopY, crossLeftX, crossLeftY, crossBottomX, crossBottomY, crossRightX, crossRightY; bool hasCrossTop = OnlineMapsUtils.LineIntersection(lastPointX, lastPointY, px, py, 0, 0, sizeX, 0, out crossTopX, out crossTopY); bool hasCrossBottom = OnlineMapsUtils.LineIntersection(lastPointX, lastPointY, px, py, 0, sizeY, sizeX, sizeY, out crossBottomX, out crossBottomY); bool hasCrossLeft = OnlineMapsUtils.LineIntersection(lastPointX, lastPointY, px, py, 0, 0, 0, sizeY, out crossLeftX, out crossLeftY); bool hasCrossRight = OnlineMapsUtils.LineIntersection(lastPointX, lastPointY, px, py, sizeX, 0, sizeX, sizeY, out crossRightX, out crossRightY); if (hasCrossTop) { intersections[0] = new Vector2(crossTopX, crossTopY); countIntersections++; } if (hasCrossBottom) { intersections[countIntersections] = new Vector2(crossBottomX, crossBottomY); countIntersections++; } if (hasCrossLeft) { intersections[countIntersections] = new Vector2(crossLeftX, crossLeftY); countIntersections++; } if (hasCrossRight) { intersections[countIntersections] = new Vector2(crossRightX, crossRightY); countIntersections++; } if (countIntersections == 1) { activePoints.Add(intersections[0]); } else if (countIntersections == 2) { Vector2 lastPoint = new Vector2(lastPointX, lastPointY); int minIndex = (lastPoint - intersections[0]).sqrMagnitude < (lastPoint - intersections[1]).sqrMagnitude? 0: 1; activePoints.Add(intersections[minIndex]); activePoints.Add(intersections[1 - minIndex]); } if (hasCrossLeft) { needExtraPoint = OnlineMapsUtils.LineIntersection(lastPointX + maxSize, lastPointY, px + maxSize, py, sizeX, 0, sizeX, sizeY, out extraX, out extraY); } else if (hasCrossRight) { needExtraPoint = OnlineMapsUtils.LineIntersection(lastPointX - maxSize, lastPointY, px - maxSize, py, 0, 0, 0, sizeY, out extraX, out extraY); } } if (!checkMapBoundaries || px >= 0 && py >= 0 && px <= sizeX && py <= sizeY) { activePoints.Add(new Vector2(px, py)); } else if (activePoints.Count > 0) { DrawActivePoints(control, ref activePoints, ref vertices, ref normals, ref triangles, ref uv, width); } lastPointX = px; lastPointY = py; } if (needExtraPoint) { activePoints.Add(new Vector2(extraX, extraY)); float ox = extraX - lastPointX; if (ox > halfSize) { lastPointX += maxSize; } else if (ox < -halfSize) { lastPointX -= maxSize; } activePoints.Add(new Vector2(lastPointX, lastPointY)); } if (activePoints.Count > 0) { DrawActivePoints(control, ref activePoints, ref vertices, ref normals, ref triangles, ref uv, width); } }
protected void InitLineMesh(IEnumerable points, OnlineMapsTileSetControl control, ref List <Vector3> vertices, ref List <Vector3> normals, ref List <int> triangles, ref List <Vector2> uv, float width, bool closed = false, bool optimize = true) { api.buffer.GetCorners(out tlx, out tly, out brx, out bry); if (brx < tlx) { brx += 360; } List <Vector2> localPoints = GetLocalPoints(points, closed, optimize); List <Vector2> activePoints = new List <Vector2>(localPoints.Count); float lastPointX = 0; float lastPointY = 0; float sizeX = api.tilesetSize.x; float sizeY = api.tilesetSize.y; bestElevationYScale = control.GetBestElevationYScale(tlx, tly, brx, bry); if (vertices == null) { vertices = new List <Vector3>(Mathf.Max(Mathf.NextPowerOfTwo(localPoints.Count * 4), 32)); } else { vertices.Clear(); } if (normals == null) { normals = new List <Vector3>(vertices.Capacity); } else { normals.Clear(); } if (triangles == null) { triangles = new List <int>(Mathf.Max(Mathf.NextPowerOfTwo(localPoints.Count * 6), 32)); } else { triangles.Clear(); } if (uv == null) { uv = new List <Vector2>(triangles.Capacity); } else { uv.Clear(); } Vector2[] intersections = new Vector2[4]; for (int i = 0; i < localPoints.Count; i++) { Vector2 p = localPoints[i]; float px = p.x; float py = p.y; int countIntersections = 0; if (i > 0 && checkMapBoundaries) { float crossTopX, crossTopY, crossLeftX, crossLeftY, crossBottomX, crossBottomY, crossRightX, crossRightY; bool hasCrossTop = OnlineMapsUtils.LineIntersection(lastPointX, lastPointY, px, py, 0, 0, sizeX, 0, out crossTopX, out crossTopY); bool hasCrossBottom = OnlineMapsUtils.LineIntersection(lastPointX, lastPointY, px, py, 0, sizeY, sizeX, sizeY, out crossBottomX, out crossBottomY); bool hasCrossLeft = OnlineMapsUtils.LineIntersection(lastPointX, lastPointY, px, py, 0, 0, 0, sizeY, out crossLeftX, out crossLeftY); bool hasCrossRight = OnlineMapsUtils.LineIntersection(lastPointX, lastPointY, px, py, sizeX, 0, sizeX, sizeY, out crossRightX, out crossRightY); if (hasCrossTop) { intersections[0] = new Vector2(crossTopX, crossTopY); countIntersections++; } if (hasCrossBottom) { intersections[countIntersections] = new Vector2(crossBottomX, crossBottomY); countIntersections++; } if (hasCrossLeft) { intersections[countIntersections] = new Vector2(crossLeftX, crossLeftY); countIntersections++; } if (hasCrossRight) { intersections[countIntersections] = new Vector2(crossRightX, crossRightY); countIntersections++; } if (countIntersections == 1) { activePoints.Add(intersections[0]); } else if (countIntersections == 2) { Vector2 lastPoint = new Vector2(lastPointX, lastPointY); int minIndex = (lastPoint - intersections[0]).sqrMagnitude < (lastPoint - intersections[1]).sqrMagnitude? 0: 1; activePoints.Add(intersections[minIndex]); activePoints.Add(intersections[1 - minIndex]); } } if (!checkMapBoundaries || px >= 0 && py >= 0 && px <= sizeX && py <= sizeY) { activePoints.Add(p); } else if (activePoints.Count > 0) { DrawActivePoints(control, ref activePoints, ref vertices, ref normals, ref triangles, ref uv, width); } lastPointX = px; lastPointY = py; } if (activePoints.Count > 0) { DrawActivePoints(control, ref activePoints, ref vertices, ref normals, ref triangles, ref uv, width); } }
protected void InitLineMesh(List <Vector2> points, OnlineMapsTileSetControl control, out List <Vector3> verticles, out List <Vector3> normals, out List <int> triangles, out List <Vector2> uv, float weight, bool closed = false) { api.GetTopLeftPosition(out tlx, out tly); api.GetBottomRightPosition(out brx, out bry); if (brx < tlx) { brx += 360; } List <Vector2> localPoints = GetLocalPoints(points, closed); List <Vector2> activePoints = new List <Vector2>(); Rect mapRect = new Rect(0, 0, api.tilesetSize.x, api.tilesetSize.y); Vector2 lastPoint = Vector2.zero; Vector2 rightTop = new Vector2(api.tilesetSize.x, 0); Vector2 rightBottom = new Vector2(api.tilesetSize.x, api.tilesetSize.y); Vector2 leftBottom = new Vector2(0, api.tilesetSize.y); bestElevationYScale = control.GetBestElevationYScale(tlx, tly, brx, bry); verticles = new List <Vector3>(); normals = new List <Vector3>(); triangles = new List <int>(); uv = new List <Vector2>(); for (int i = 0; i < localPoints.Count; i++) { Vector2 p = localPoints[i]; if (lastPoint != Vector2.zero) { Vector2 crossTop, crossLeft, crossBottom, crossRight; bool hasCrossTop = OnlineMapsUtils.LineIntersection(lastPoint, p, Vector2.zero, rightTop, out crossTop); bool hasCrossBottom = OnlineMapsUtils.LineIntersection(lastPoint, p, leftBottom, rightBottom, out crossBottom); bool hasCrossLeft = OnlineMapsUtils.LineIntersection(lastPoint, p, Vector2.zero, leftBottom, out crossLeft); bool hasCrossRight = OnlineMapsUtils.LineIntersection(lastPoint, p, rightTop, rightBottom, out crossRight); List <Vector2> intersections = new List <Vector2>(); if (hasCrossTop) { intersections.Add(crossTop); } if (hasCrossBottom) { intersections.Add(crossBottom); } if (hasCrossLeft) { intersections.Add(crossLeft); } if (hasCrossRight) { intersections.Add(crossRight); } if (intersections.Count == 1) { activePoints.Add(intersections[0]); } else if (intersections.Count == 2) { int minIndex = ((lastPoint - intersections[0]).magnitude < (lastPoint - intersections[1]).magnitude)? 0: 1; activePoints.Add(intersections[minIndex]); activePoints.Add(intersections[1 - minIndex]); } } if (mapRect.Contains(p)) { activePoints.Add(p); } else if (activePoints.Count > 0) { DrawActivePoints(control, ref activePoints, ref verticles, ref normals, ref triangles, ref uv, weight); } lastPoint = p; } if (activePoints.Count > 0) { DrawActivePoints(control, ref activePoints, ref verticles, ref normals, ref triangles, ref uv, weight); } }
protected void InitLineMesh(IEnumerable points, OnlineMapsTileSetControl control, out List <Vector3> verticles, out List <Vector3> normals, out List <int> triangles, out List <Vector2> uv, float weight, bool closed = false) { api.GetCorners(out tlx, out tly, out brx, out bry); if (brx < tlx) { brx += 360; } List <Vector2> localPoints = GetLocalPoints(points, closed); List <Vector2> activePoints = new List <Vector2>(localPoints.Count); float lastPointX = 0; float lastPointY = 0; float sizeX = api.tilesetSize.x; float sizeY = api.tilesetSize.y; bestElevationYScale = control.GetBestElevationYScale(tlx, tly, brx, bry); verticles = new List <Vector3>(localPoints.Count * 4); normals = new List <Vector3>(localPoints.Count * 4); triangles = new List <int>(localPoints.Count * 6); uv = new List <Vector2>(localPoints.Count * 6); Vector2[] intersections = new Vector2[4]; for (int i = 0; i < localPoints.Count; i++) { Vector2 p = localPoints[i]; float px = p.x; float py = p.y; int countIntersections = 0; if (i > 0) { float crossTopX, crossTopY, crossLeftX, crossLeftY, crossBottomX, crossBottomY, crossRightX, crossRightY; bool hasCrossTop = OnlineMapsUtils.LineIntersection(lastPointX, lastPointY, px, py, 0, 0, sizeX, 0, out crossTopX, out crossTopY); bool hasCrossBottom = OnlineMapsUtils.LineIntersection(lastPointX, lastPointY, px, py, 0, sizeY, sizeX, sizeY, out crossBottomX, out crossBottomY); bool hasCrossLeft = OnlineMapsUtils.LineIntersection(lastPointX, lastPointY, px, py, 0, 0, 0, sizeY, out crossLeftX, out crossLeftY); bool hasCrossRight = OnlineMapsUtils.LineIntersection(lastPointX, lastPointY, px, py, sizeX, 0, sizeX, sizeY, out crossRightX, out crossRightY); if (hasCrossTop) { intersections[0] = new Vector2(crossTopX, crossTopY); countIntersections++; } if (hasCrossBottom) { intersections[countIntersections] = new Vector2(crossBottomX, crossBottomY); countIntersections++; } if (hasCrossLeft) { intersections[countIntersections] = new Vector2(crossLeftX, crossLeftY); countIntersections++; } if (hasCrossRight) { intersections[countIntersections] = new Vector2(crossRightX, crossRightY); countIntersections++; } if (countIntersections == 1) { activePoints.Add(intersections[0]); } else if (countIntersections == 2) { Vector2 lastPoint = new Vector2(lastPointX, lastPointY); int minIndex = (lastPoint - intersections[0]).magnitude < (lastPoint - intersections[1]).magnitude? 0: 1; activePoints.Add(intersections[minIndex]); activePoints.Add(intersections[1 - minIndex]); } } if (px >= 0 && py >= 0 && px <= sizeX && py <= sizeY) { activePoints.Add(p); } else if (activePoints.Count > 0) { DrawActivePoints(control, ref activePoints, ref verticles, ref normals, ref triangles, ref uv, weight); } lastPointX = px; lastPointY = py; } if (activePoints.Count > 0) { DrawActivePoints(control, ref activePoints, ref verticles, ref normals, ref triangles, ref uv, weight); } }