<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
	<channel>
		<title><![CDATA[Infinity Code Forum — How to add sides to the map?]]></title>
		<link>https://forum.infinity-code.com/viewtopic.php?id=235</link>
		<atom:link href="https://forum.infinity-code.com/extern.php?action=feed&amp;tid=235&amp;type=rss" rel="self" type="application/rss+xml" />
		<description><![CDATA[The most recent posts in How to add sides to the map?.]]></description>
		<lastBuildDate>Tue, 09 Aug 2016 18:04:01 +0000</lastBuildDate>
		<generator>PunBB</generator>
		<item>
			<title><![CDATA[Re: How to add sides to the map?]]></title>
			<link>https://forum.infinity-code.com/viewtopic.php?pid=1072#p1072</link>
			<description><![CDATA[<p>That&#039;s exactly what I was looking for. Thank you!</p>]]></description>
			<author><![CDATA[null@example.com (kalaki)]]></author>
			<pubDate>Tue, 09 Aug 2016 18:04:01 +0000</pubDate>
			<guid>https://forum.infinity-code.com/viewtopic.php?pid=1072#p1072</guid>
		</item>
		<item>
			<title><![CDATA[Re: How to add sides to the map?]]></title>
			<link>https://forum.infinity-code.com/viewtopic.php?pid=1066#p1066</link>
			<description><![CDATA[<p>Hello.</p><p>Example below, the screenshot attached.<br />Requires Online Maps v2.4.0.61+.<br />If you do not have it, just update Online Maps through the built-in update system.</p><div class="codebox"><pre><code>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 &amp;&amp; control.elevationZoomRange.InRange(OnlineMaps.instance.zoom)) UpdateSides();
        else ClearSides();
    }

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

        GameObject sidesContainer = new GameObject(&quot;Sides&quot;);
        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&lt;MeshFilter&gt;();
        MeshRenderer meshRenderer = sidesContainer.AddComponent&lt;MeshRenderer&gt;();
        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&lt;MeshFilter&gt;().sharedMesh;
        Vector3[] mapVertices = mapMesh.vertices;

        List&lt;Vector3&gt; left = new List&lt;Vector3&gt;();
        List&lt;Vector3&gt; right = new List&lt;Vector3&gt;();
        List&lt;Vector3&gt; top = new List&lt;Vector3&gt;();
        List&lt;Vector3&gt; bottom = new List&lt;Vector3&gt;();

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

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

        List&lt;Vector3&gt; vertices = new List&lt;Vector3&gt;();
        List&lt;Vector2&gt; uv = new List&lt;Vector2&gt;();
        List&lt;Vector3&gt; normals = new List&lt;Vector3&gt;();
        List&lt;int&gt; triangles = new List&lt;int&gt;();

        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&lt;Vector3&gt; side, List&lt;Vector3&gt; vertices, List&lt;Vector2&gt; uv, List&lt;Vector3&gt; normals, List&lt;int&gt; triangles, Vector3 normal)
    {
        for (int i = 0; i &lt; 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);
        }
    }
}</code></pre></div>]]></description>
			<author><![CDATA[null@example.com (Alex Vertax)]]></author>
			<pubDate>Mon, 08 Aug 2016 20:54:46 +0000</pubDate>
			<guid>https://forum.infinity-code.com/viewtopic.php?pid=1066#p1066</guid>
		</item>
		<item>
			<title><![CDATA[Re: How to add sides to the map?]]></title>
			<link>https://forum.infinity-code.com/viewtopic.php?pid=1056#p1056</link>
			<description><![CDATA[<p>Hello</p><p>I&#039;ve marked your question.<br />After the weekend I will make for you an example.</p>]]></description>
			<author><![CDATA[null@example.com (Alex Vertax)]]></author>
			<pubDate>Fri, 05 Aug 2016 21:16:52 +0000</pubDate>
			<guid>https://forum.infinity-code.com/viewtopic.php?pid=1056#p1056</guid>
		</item>
		<item>
			<title><![CDATA[How to add sides to the map?]]></title>
			<link>https://forum.infinity-code.com/viewtopic.php?pid=1053#p1053</link>
			<description><![CDATA[<p>I would like to add four sides to a 3D map with elevation data but I&#039;m not sure how to proceed.<br />I&#039;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? <br />Can you recommend an approach? I attached an example of what I&#039;m looking to do. Thank you!</p>]]></description>
			<author><![CDATA[null@example.com (kalaki)]]></author>
			<pubDate>Fri, 05 Aug 2016 16:55:22 +0000</pubDate>
			<guid>https://forum.infinity-code.com/viewtopic.php?pid=1053#p1053</guid>
		</item>
	</channel>
</rss>
