Topic: How to add sides to the map?

I would like to add four sides to a 3D map with elevation data but I'm not sure how to proceed.
I'm assuming I could create four planes and put them up against the map mesh but the elevation values make this more complicated. Is is possible to use a cube instead of the plains?
Can you recommend an approach? I attached an example of what I'm looking to do. Thank you!

Re: How to add sides to the map?

Hello

I've marked your question.
After the weekend I will make for you an example.

Kind Regards,
Infinity Code Team.

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

Re: How to add sides to the map?

Hello.

Example below, the screenshot attached.
Requires Online Maps v2.4.0.61+.
If you do not have it, just update Online Maps through the built-in update system.

using System.Collections.Generic;
using System.Linq;
using UnityEngine;

public class MapSides:MonoBehaviour
{
    public Material sideMaterial;

    private OnlineMapsTileSetControl control;
    private Mesh mesh;
    private Mesh mapMesh;

    private void ClearSides()
    {
        mesh.Clear();
    }

    private void OnMeshUpdated()
    {
        if (control.useElevation && control.elevationZoomRange.InRange(OnlineMaps.instance.zoom)) UpdateSides();
        else ClearSides();
    }

    private void Start()
    {
        control = OnlineMapsTileSetControl.instance;
        control.OnMeshUpdated += OnMeshUpdated;

        GameObject sidesContainer = new GameObject("Sides");
        sidesContainer.transform.parent = control.transform;
        sidesContainer.transform.localPosition = Vector3.zero;
        sidesContainer.transform.localScale = Vector3.one;
        sidesContainer.transform.localRotation = Quaternion.Euler(Vector3.zero);
        MeshFilter meshFilter = sidesContainer.AddComponent<MeshFilter>();
        MeshRenderer meshRenderer = sidesContainer.AddComponent<MeshRenderer>();
        meshRenderer.sharedMaterial = sideMaterial;
        mesh = new Mesh();
        mesh.MarkDynamic();
        meshFilter.sharedMesh = mesh;
        meshRenderer.material = sideMaterial;
    }

    private void UpdateSides()
    {
        mesh.Clear();

        if (mapMesh == null) mapMesh = control.GetComponent<MeshFilter>().sharedMesh;
        Vector3[] mapVertices = mapMesh.vertices;

        List<Vector3> left = new List<Vector3>();
        List<Vector3> right = new List<Vector3>();
        List<Vector3> top = new List<Vector3>();
        List<Vector3> bottom = new List<Vector3>();

        for (int i = 0; i < mapVertices.Length; i++)
        {
            Vector3 v = mapVertices[i];
            if (Mathf.Abs(v.x) <= 0.01f) left.Add(v);
            if (Mathf.Abs(v.x + OnlineMaps.instance.tilesetSize.x) <= 0.01f) right.Add(v);
            if (Mathf.Abs(v.z) <= 0.01f) top.Add(v);
            if (Mathf.Abs(v.z - OnlineMaps.instance.tilesetSize.y) <= 0.01f) bottom.Add(v);
        }

        left = left.Distinct().OrderBy(v => v.z).ToList();
        right = right.Distinct().OrderBy(v => v.z).Reverse().ToList();
        top = top.Distinct().OrderBy(v => v.x).ToList();
        bottom = bottom.Distinct().OrderBy(v => v.x).Reverse().ToList();

        List<Vector3> vertices = new List<Vector3>();
        List<Vector2> uv = new List<Vector2>();
        List<Vector3> normals = new List<Vector3>();
        List<int> triangles = new List<int>();

        UpdateSide(left, vertices, uv, normals, triangles, Vector3.left);
        UpdateSide(top, vertices, uv, normals, triangles, Vector3.forward);
        UpdateSide(right, vertices, uv, normals, triangles, Vector3.right);
        UpdateSide(bottom, vertices, uv, normals, triangles, Vector3.back);

        mesh.vertices = vertices.ToArray();
        mesh.uv = uv.ToArray();
        mesh.normals = normals.ToArray();
        mesh.SetTriangles(triangles.ToArray(), 0);
    }

    private static void UpdateSide(List<Vector3> side, List<Vector3> vertices, List<Vector2> uv, List<Vector3> normals, List<int> triangles, Vector3 normal)
    {
        for (int i = 0; i < side.Count - 1; i++)
        {
            int cv = vertices.Count;

            Vector3 p1 = side[i];
            Vector3 p2 = side[i + 1];
            vertices.Add(p1);
            vertices.Add(p2);
            vertices.Add(new Vector3(p2.x, 0, p2.z));
            vertices.Add(new Vector3(p1.x, 0, p1.z));

            uv.Add(new Vector2(0, 1));
            uv.Add(new Vector2(1, 1));
            uv.Add(new Vector2(1, 0));
            uv.Add(new Vector2(0, 0));

            normals.Add(normal);
            normals.Add(normal);
            normals.Add(normal);
            normals.Add(normal);

            triangles.Add(cv);
            triangles.Add(cv + 1);
            triangles.Add(cv + 2);
            triangles.Add(cv);
            triangles.Add(cv + 2);
            triangles.Add(cv + 3);
        }
    }
}
Post's attachments

Attachment icon img1.png 620.88 kb, 271 downloads since 2016-08-08 

Kind Regards,
Infinity Code Team.

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

Re: How to add sides to the map?

That's exactly what I was looking for. Thank you!