Topic: Round Map
Hi all
I would like to make round map like attached image.
(I know Online Maps can't make building textures.
I want to make just round shape map)
You are not logged in. Please login or register.
Infinity Code Forum → Online Maps Help → Round Map
Hi all
I would like to make round map like attached image.
(I know Online Maps can't make building textures.
I want to make just round shape map)
Hello.
Something like that:
using System.Collections.Generic;
using UnityEngine;
public class RoundMap:MonoBehaviour
{
public float radius = 512;
private OnlineMaps map;
private OnlineMapsTileSetControl control;
private MeshFilter meshFilter;
private OnlineMapsBuildings buildings;
private float sqrRadius;
private Vector3 mapCenter;
private void Start()
{
map = OnlineMaps.instance;
control = OnlineMapsTileSetControl.instance;
buildings = OnlineMapsBuildings.instance;
meshFilter = control.GetComponent<MeshFilter>();
sqrRadius = radius * radius;
mapCenter = new Vector3(map.tilesetSize.x / -2, 0, map.tilesetSize.y / 2);
map.OnMapUpdated += OnMapUpdated;
control.OnMeshUpdated += OnMeshUpdated;
buildings.OnShowBuilding += OnShowBuilding;
}
private bool OnShowBuilding(OnlineMapsBuildingBase building)
{
return (building.gameObject.transform.localPosition - mapCenter).sqrMagnitude < sqrRadius;
}
private void OnMapUpdated()
{
foreach (KeyValuePair<string, OnlineMapsBuildingBase> pair in buildings.buildings)
{
Vector3 worldPosition = pair.Value.transform.localPosition - mapCenter;
pair.Value.gameObject.SetActive(worldPosition.sqrMagnitude < sqrRadius);
}
}
private void OnMeshUpdated()
{
Mesh mesh = meshFilter.sharedMesh;
Vector3[] vertices = mesh.vertices;
Vector2[] uvs = mesh.uv;
float halfWidth = map.tilesetSize.x / -2;
float halfHeight = map.tilesetSize.y / 2;
double tlx, tly, brx, bry;
map.GetCorners(out tlx, out tly, out brx, out bry);
float elevationScale = control.GetBestElevationYScale(tlx, tly, brx, bry);
for (int i = 0; i < vertices.Length; i++)
{
Vector3 v = vertices[i];
Vector2 nv = new Vector2(v.x - halfWidth, v.z - halfHeight);
if (nv.sqrMagnitude > sqrRadius)
{
float m = nv.magnitude;
Vector2 nn = nv.normalized;
nv = nn * radius;
nv.x += halfWidth;
nv.y += halfHeight;
vertices[i] = new Vector3(nv.x, control.GetElevationValue(nv.x, nv.y, elevationScale, tlx, tly, brx, bry), nv.y);
Vector2 uv = uvs[i];
uv.x = Mathf.Clamp01(uv.x + nn.x * (1 - radius / m));
uv.y = Mathf.Clamp01(uv.y + nn.y * (1 - radius / m));
uvs[i] = uv;
}
}
mesh.vertices = vertices;
mesh.uv = uvs;
}
}
Note:
This script has a bug with UV (fisheye), but when using elevations, it's not visible. If this is critical for your application, I'll try to find a way around this.
Note for other users who are reading this thread:
This method can only be used if you want to have a cylindrical map that should be fully visible. In other cases it is better to use Camera - Clipping Planes.
Infinity Code Forum → Online Maps Help → Round Map
Powered by PunBB, supported by Informer Technologies, Inc.