1 (edited by vai.rg321mh 2017-09-01 10:27:12)

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)

Post's attachments

Attachment icon holomaps_thumb.jpg 69.7 kb, 81 downloads since 2017-09-01 

Re: Round 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.

Post's attachments

Attachment icon img1.png 480.71 kb, 73 downloads since 2017-09-02 

Kind Regards,
Infinity Code Team.

Boost your productivity a lot and immediately using Ultimate Editor Enhancer. Trial and non-commerce versions available.