<?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 create texture to used as overlay]]></title>
		<link>https://forum.infinity-code.com/viewtopic.php?id=1547</link>
		<atom:link href="https://forum.infinity-code.com/extern.php?action=feed&amp;tid=1547&amp;type=rss" rel="self" type="application/rss+xml" />
		<description><![CDATA[The most recent posts in How to create texture to used as overlay.]]></description>
		<lastBuildDate>Tue, 30 Jun 2020 23:02:16 +0000</lastBuildDate>
		<generator>PunBB</generator>
		<item>
			<title><![CDATA[Re: How to create texture to used as overlay]]></title>
			<link>https://forum.infinity-code.com/viewtopic.php?pid=6432#p6432</link>
			<description><![CDATA[<div class="quotebox"><cite>Alex Vertax wrote:</cite><blockquote><p>Here is a video of how it works on my side:<br /><a href="https://www.dropbox.com/s/miwprk71uhkhjch/ScreenRecorderProject117.mp4?dl=0">https://www.dropbox.com/s/miwprk71uhkhj … 7.mp4?dl=0</a></p></blockquote></div><p>Thank you for the video.&nbsp; I figured why the script wasn&#039;t working, it&#039;s because I had the size of the tilemap set to 1,1.</p>]]></description>
			<author><![CDATA[null@example.com (lefantan)]]></author>
			<pubDate>Tue, 30 Jun 2020 23:02:16 +0000</pubDate>
			<guid>https://forum.infinity-code.com/viewtopic.php?pid=6432#p6432</guid>
		</item>
		<item>
			<title><![CDATA[Re: How to create texture to used as overlay]]></title>
			<link>https://forum.infinity-code.com/viewtopic.php?pid=6431#p6431</link>
			<description><![CDATA[<p>Here is a video of how it works on my side:<br /><a href="https://www.dropbox.com/s/miwprk71uhkhjch/ScreenRecorderProject117.mp4?dl=0">https://www.dropbox.com/s/miwprk71uhkhj … 7.mp4?dl=0</a></p>]]></description>
			<author><![CDATA[null@example.com (Alex Vertax)]]></author>
			<pubDate>Tue, 30 Jun 2020 18:29:45 +0000</pubDate>
			<guid>https://forum.infinity-code.com/viewtopic.php?pid=6431#p6431</guid>
		</item>
		<item>
			<title><![CDATA[Re: How to create texture to used as overlay]]></title>
			<link>https://forum.infinity-code.com/viewtopic.php?pid=6430#p6430</link>
			<description><![CDATA[<p>Hey, thanks for the quick reply. I&#039;m still getting the same problem with the script. The overlay i used is the same.</p>]]></description>
			<author><![CDATA[null@example.com (lefantan)]]></author>
			<pubDate>Tue, 30 Jun 2020 16:33:54 +0000</pubDate>
			<guid>https://forum.infinity-code.com/viewtopic.php?pid=6430#p6430</guid>
		</item>
		<item>
			<title><![CDATA[Re: How to create texture to used as overlay]]></title>
			<link>https://forum.infinity-code.com/viewtopic.php?pid=6421#p6421</link>
			<description><![CDATA[<p>Thanks for the screenshots.<br />The bug in the example is fixed:<br /></p><div class="codebox"><pre><code>using System;
using UnityEngine;

namespace InfinityCode.OnlineMapsExamples
{
    /// &lt;summary&gt;
    /// Example of how to make the overlay for the tileset.
    /// &lt;/summary&gt;
    [AddComponentMenu(&quot;Infinity Code/Online Maps/Examples (API Usage)/TilesetOverlayExample&quot;)]
    public class TilesetOverlayExample : MonoBehaviour
    {
        // Overlay texture in mercator projection
        public Texture texture;

        // Overlay transparency
        [Range(0, 1)] public float alpha = 1;

        private Mesh overlayMesh;
        private Material material;
        private Collider tilesetCollider;

        private void Start()
        {
            // Create overlay container
            GameObject overlayContainer = new GameObject(&quot;OverlayContainer&quot;);
            overlayContainer.transform.parent = transform;

            // Init overlay material
            MeshRenderer meshRenderer = overlayContainer.AddComponent&lt;MeshRenderer&gt;();
            MeshFilter meshFilter = overlayContainer.AddComponent&lt;MeshFilter&gt;();
            material = new Material(Shader.Find(&quot;Transparent/Diffuse&quot;));
            material.mainTexture = texture;
            meshRenderer.sharedMaterial = material;

            overlayMesh = meshFilter.sharedMesh = new Mesh();
            overlayMesh.name = &quot;Overlay Mesh&quot;;
            overlayMesh.MarkDynamic();
            overlayMesh.vertices = new Vector3[4];

            // Subscribe to events
            OnlineMaps.instance.OnChangePosition += UpdateMesh;
            OnlineMaps.instance.OnChangeZoom += UpdateMesh;

            // Init mesh
            UpdateMesh();
        }

        private void UpdateMesh()
        {
            OnlineMapsTileSetControl control = OnlineMapsTileSetControl.instance;
            if (tilesetCollider == null) tilesetCollider = control.GetComponent&lt;Collider&gt;();
            //Bounds bounds = tilesetCollider.bounds;

            // Clear overlay mesh
            overlayMesh.Clear(true);

            // Init vertices and normals
            Vector2 size = control.sizeInScene;
            Vector3 p1 = new Vector3(-size.x, 0, 0);
            Vector3 p2 = new Vector3(0, 0, size.y);
            float y = 0.5f;
            overlayMesh.vertices = new[]
            {
                new Vector3(p1.x, y, p1.z),
                new Vector3(p1.x, y, p2.z),
                new Vector3(p2.x, y, p2.z),
                new Vector3(p2.x, y, p1.z)
            };

            overlayMesh.normals = new[]
            {
                Vector3.up,
                Vector3.up,
                Vector3.up,
                Vector3.up
            };

            // Init overlay UV
            OnlineMaps map = OnlineMaps.instance;

            double tlx, tly, brx, bry;
            map.GetTileCorners(out tlx, out tly, out brx, out bry);

            int maxTileCount = 1 &lt;&lt; map.zoom;

            float uvX1 = (float)(tlx / maxTileCount);
            float uvX2 = (float)(brx / maxTileCount);

            if (uvX1 &gt; uvX2) uvX2 += 1;

            float uvY1 = (float)(1 - tly / maxTileCount);
            float uvY2 = (float)(1 - bry / maxTileCount);

            overlayMesh.uv = new[]
            {
                new Vector2(uvX2, uvY1),
                new Vector2(uvX2, uvY2),
                new Vector2(uvX1, uvY2),
                new Vector2(uvX1, uvY1)
            };

            // Init triangles
            overlayMesh.SetTriangles(new[]
            {
                0, 1, 2,
                0, 2, 3
            }, 0);

            overlayMesh.RecalculateBounds();
            overlayMesh.RecalculateNormals();
        }

        private void Update()
        {
            if (Math.Abs(material.color.a - alpha) &gt; float.Epsilon)
            {
                Color color = material.color;
                color.a = alpha;
                material.color = color;
            }
        }
    }
}</code></pre></div>]]></description>
			<author><![CDATA[null@example.com (Alex Vertax)]]></author>
			<pubDate>Tue, 30 Jun 2020 09:20:17 +0000</pubDate>
			<guid>https://forum.infinity-code.com/viewtopic.php?pid=6421#p6421</guid>
		</item>
		<item>
			<title><![CDATA[Re: How to create texture to used as overlay]]></title>
			<link>https://forum.infinity-code.com/viewtopic.php?pid=6420#p6420</link>
			<description><![CDATA[<div class="quotebox"><cite>Alex Vertax wrote:</cite><blockquote><p>You mean resolution, right?!<br />The bigger, the better.</p><p>At the beginning of next week (most likely on Monday) I will send you an example.</p><p>I am not a MapTiler specialist, and I don’t know what the problem is. <br />You better ask this question to MapTiler support.</p></blockquote></div><p>Hey sorry, I meant that the aspect ratio of the texture such that when I use TilesetOverlayExample.cs, the texture will be display accurately over the map. </p><p>I tried using an overlay of 1080*1080 (as attached) with the TilesetOverlayExample script, the overlay container is initially offset incorrect in terms of y, after adjusting it( i try setting the overlay container to 0,-0.05,0), I still couldn&#039;t get it to overlay accurately. (Picture 1)</p><p>In the photos (Picture 2), the orange boundaries (using drawing api) are the correct overlay I&#039;m trying to achieve with overlay and the purple one is one created with tilesetexample. </p><p>I hope I explained my problem clearly, thank you Alex for helping up.</p>]]></description>
			<author><![CDATA[null@example.com (lefantan)]]></author>
			<pubDate>Mon, 29 Jun 2020 21:27:58 +0000</pubDate>
			<guid>https://forum.infinity-code.com/viewtopic.php?pid=6420#p6420</guid>
		</item>
		<item>
			<title><![CDATA[Re: How to create texture to used as overlay]]></title>
			<link>https://forum.infinity-code.com/viewtopic.php?pid=6419#p6419</link>
			<description><![CDATA[<p>Something like that:<br /></p><div class="codebox"><pre><code>using System;
using UnityEngine;

public class TilesetOverlayExample2 : MonoBehaviour
{
    // Overlay texture in mercator projection
    public Texture texture;

    /// &lt;summary&gt;
    /// Border coordinates of the overlay
    /// &lt;/summary&gt;
    public double leftLongitude;
    public double topLatitude;
    public double rightLongitude;
    public double bottomLatitude;

    // Overlay transparency
    [Range(0, 1)]
    public float alpha = 1;

    private Mesh overlayMesh;
    private Material material;

    private void Start()
    {
        // Create overlay container
        GameObject overlayContainer = new GameObject(&quot;OverlayContainer&quot;);
        overlayContainer.transform.parent = transform;

        // Init overlay material
        MeshRenderer meshRenderer = overlayContainer.AddComponent&lt;MeshRenderer&gt;();
        MeshFilter meshFilter = overlayContainer.AddComponent&lt;MeshFilter&gt;();
        material = new Material(Shader.Find(&quot;Transparent/Diffuse&quot;));
        material.mainTexture = texture;
        material.renderQueue += 1000;
        meshRenderer.sharedMaterial = material;

        overlayMesh = meshFilter.sharedMesh = new Mesh();
        overlayMesh.name = &quot;Overlay Mesh&quot;;
        overlayMesh.MarkDynamic();
        overlayMesh.vertices = new Vector3[4];

        // Subscribe to events
        OnlineMapsTileSetControl.instance.OnMeshUpdated += UpdateMesh;

        // Init mesh
        UpdateMesh();
    }

    private void UpdateMesh()
    {
        overlayMesh.Clear();
        OnlineMapsTileSetControl control = OnlineMapsTileSetControl.instance;

        Vector3 p1 = control.GetWorldPosition(leftLongitude, topLatitude);
        Vector3 p2 = control.GetWorldPosition(rightLongitude, bottomLatitude);

        Vector2 size = control.sizeInScene;
        size.x *= -1;

        if (p1.x &gt; 0 &amp;&amp; p2.x &gt; 0) return;
        if (p1.x &lt; size.x &amp;&amp; p2.x &lt; size.x) return;
        if (p1.z &lt; 0 &amp;&amp; p2.z &lt; 0) return;
        if (p1.z &gt; size.y &amp;&amp; p2.z &gt; size.y) return;

        Vector2 uv0 = new Vector2(0, 1);
        Vector2 uv1 = new Vector2(1, 0);

        Vector3 v1 = p1;
        Vector3 v2 = p2;

        if (p1.x &gt; 0)
        {
            float m = p1.x / (p1.x - p2.x);
            uv0.x = m;
            v1.x = 0;
        }

        if (p1.z &lt; 0)
        {
            float m = p1.z / (p1.z - p2.z);
            uv0.y = 1 - m;
            v1.z = 0;
        }

        if (p2.x &lt; size.x)
        {
            float m = (p1.x - size.x) / (p1.x - p2.x);
            uv1.x = m;
            v2.x = size.x;
        }

        if (p2.z &gt; size.y)
        {
            float m = (size.y - p2.z) / (p1.z - p2.z);
            uv1.y = m;
            v2.z = size.y;
        }

        overlayMesh.vertices = new[]
        {
            new Vector3(v1.x, 0.1f, v1.z),
            new Vector3(v2.x, 0.1f, v1.z),
            new Vector3(v2.x, 0.1f, v2.z),
            new Vector3(v1.x, 0.1f, v2.z),
        };

        overlayMesh.normals = new[]
        {
            Vector3.up,
            Vector3.up,
            Vector3.up,
            Vector3.up
        };

        overlayMesh.uv = new[]
        {
            uv0,
            new Vector2(uv1.x, uv0.y), 
            uv1, 
            new Vector2(uv0.x, uv1.y), 
        };

        // Init triangles
        overlayMesh.SetTriangles(new[]
        {
            0, 1, 2,
            0, 2, 3
        }, 0);

        overlayMesh.RecalculateBounds();
        overlayMesh.RecalculateNormals();
    }

    private void Update()
    {
        if (Math.Abs(material.color.a - alpha) &gt; float.Epsilon)
        {
            Color color = material.color;
            color.a = alpha;
            material.color = color;
        }
    }
}</code></pre></div>]]></description>
			<author><![CDATA[null@example.com (Alex Vertax)]]></author>
			<pubDate>Mon, 29 Jun 2020 11:21:18 +0000</pubDate>
			<guid>https://forum.infinity-code.com/viewtopic.php?pid=6419#p6419</guid>
		</item>
		<item>
			<title><![CDATA[Re: How to create texture to used as overlay]]></title>
			<link>https://forum.infinity-code.com/viewtopic.php?pid=6411#p6411</link>
			<description><![CDATA[<p>That would be awesome, I would love to understand better how this works</p>]]></description>
			<author><![CDATA[null@example.com (lefantan)]]></author>
			<pubDate>Fri, 26 Jun 2020 22:11:23 +0000</pubDate>
			<guid>https://forum.infinity-code.com/viewtopic.php?pid=6411#p6411</guid>
		</item>
		<item>
			<title><![CDATA[Re: How to create texture to used as overlay]]></title>
			<link>https://forum.infinity-code.com/viewtopic.php?pid=6409#p6409</link>
			<description><![CDATA[<p>You mean resolution, right?!<br />The bigger, the better.</p><p>At the beginning of next week (most likely on Monday) I will send you an example.</p><p>I am not a MapTiler specialist, and I don’t know what the problem is. <br />You better ask this question to MapTiler support.</p>]]></description>
			<author><![CDATA[null@example.com (Alex Vertax)]]></author>
			<pubDate>Fri, 26 Jun 2020 11:03:36 +0000</pubDate>
			<guid>https://forum.infinity-code.com/viewtopic.php?pid=6409#p6409</guid>
		</item>
		<item>
			<title><![CDATA[Re: How to create texture to used as overlay]]></title>
			<link>https://forum.infinity-code.com/viewtopic.php?pid=6408#p6408</link>
			<description><![CDATA[<p>I&#039;ve also tried using maptiler desktop version 10, I imported the geojson file and tried to render but couldn&#039;t get it to export as png. Am i missing something here?</p>]]></description>
			<author><![CDATA[null@example.com (lefantan)]]></author>
			<pubDate>Thu, 25 Jun 2020 23:26:32 +0000</pubDate>
			<guid>https://forum.infinity-code.com/viewtopic.php?pid=6408#p6408</guid>
		</item>
		<item>
			<title><![CDATA[Re: How to create texture to used as overlay]]></title>
			<link>https://forum.infinity-code.com/viewtopic.php?pid=6407#p6407</link>
			<description><![CDATA[<p>I see, for global overlays, what are the dimensions used for the textures to ensure an accurate overlay?</p><p>If you have an example for making an overlay of an area that would be great! Thank you.</p>]]></description>
			<author><![CDATA[null@example.com (lefantan)]]></author>
			<pubDate>Thu, 25 Jun 2020 20:38:55 +0000</pubDate>
			<guid>https://forum.infinity-code.com/viewtopic.php?pid=6407#p6407</guid>
		</item>
		<item>
			<title><![CDATA[Re: How to create texture to used as overlay]]></title>
			<link>https://forum.infinity-code.com/viewtopic.php?pid=6390#p6390</link>
			<description><![CDATA[<p>Hello.</p><p>This example assumes that you are using a global overlay (the whole world).</p><p>You have three ways:<br />1. Combine your overlays and use with this example.<br />2. Combine your overlays, split it into tiles (for example, using MapTiler) and use example:<br /><a href="http://infinity-code.com/atlas/online-maps/pages/TilesetMapTilerOverlayExample.html">http://infinity-code.com/atlas/online-m … ample.html</a><br />3. I can make for you an example of how to use overlay on an area with boundaries. But it will take some time.</p>]]></description>
			<author><![CDATA[null@example.com (Alex Vertax)]]></author>
			<pubDate>Fri, 19 Jun 2020 09:46:37 +0000</pubDate>
			<guid>https://forum.infinity-code.com/viewtopic.php?pid=6390#p6390</guid>
		</item>
		<item>
			<title><![CDATA[How to create texture to used as overlay]]></title>
			<link>https://forum.infinity-code.com/viewtopic.php?pid=6389#p6389</link>
			<description><![CDATA[<p>Hi, I&#039;ve tried following the example here: <a href="http://infinity-code.com/atlas/online-maps/pages/TilesetOverlayExample.html">http://infinity-code.com/atlas/online-m … ample.html</a> but couldn&#039;t get it to work as there are a couple of things in which I&#039;m confused about.</p><p>I would like to overlay many different boundaries (example attached), however I&#039;m not sure how I should approach this. Should I create one large huge overlay texture, if so what should be the width/height of the texture?</p><p>Thank you so much <img src="https://forum.infinity-code.com/img/smilies/smile.png" width="15" height="15" alt="smile" /></p>]]></description>
			<author><![CDATA[null@example.com (lefantan)]]></author>
			<pubDate>Thu, 18 Jun 2020 18:49:42 +0000</pubDate>
			<guid>https://forum.infinity-code.com/viewtopic.php?pid=6389#p6389</guid>
		</item>
	</channel>
</rss>
