<?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 — Add texture at specific location]]></title>
		<link>https://forum.infinity-code.com/viewtopic.php?id=2391</link>
		<atom:link href="https://forum.infinity-code.com/extern.php?action=feed&amp;tid=2391&amp;type=rss" rel="self" type="application/rss+xml" />
		<description><![CDATA[The most recent posts in Add texture at specific location.]]></description>
		<lastBuildDate>Thu, 09 Oct 2025 13:16:18 +0000</lastBuildDate>
		<generator>PunBB</generator>
		<item>
			<title><![CDATA[Re: Add texture at specific location]]></title>
			<link>https://forum.infinity-code.com/viewtopic.php?pid=9900#p9900</link>
			<description><![CDATA[<p>Hello.</p><p>Example:<br /></p><div class="codebox"><pre><code>/*         INFINITY CODE         */
/*   https://infinity-code.com   */

using System;
using OnlineMaps;
using UnityEngine;

namespace OnlineMapsExamples
{
    /// &lt;summary&gt;
    /// Example of how to make the overlay for the tileset.
    /// &lt;/summary&gt;
    [AddComponentMenu(Utils.ExampleMenuPath + &quot;TilesetOverlayExample&quot;)]
    public class TilesetOverlayExample : MonoBehaviour
    {
        /// &lt;summary&gt;
        /// Reference to the tileset control. If not specified, the current instance will be used.
        /// &lt;/summary&gt;
        public TileSetControl control;
        
        /// &lt;summary&gt;
        /// Overlay material.
        /// If missed, a new material with Transparent/Diffuse shader will be used.
        /// If present, the texture field will be ignored and you must specify the texture directly in the material.
        /// &lt;/summary&gt;
        [Tooltip(&quot;If missed, a new material with Transparent/Diffuse shader will be used. If present, the texture field will be ignored and you must specify the texture directly in the material.&quot;)]
        public Material material;

        /// &lt;summary&gt;
        /// Shader for overlay material.
        /// If material is specified, this field will be ignored.
        /// If material is not specified and shader is missed, a default shader for the current render pipeline will be used.
        /// &lt;/summary&gt;
        [Tooltip(&quot;If material is specified, this field will be ignored. If material is not specified and shader is missed, a default shader for the current render pipeline will be used.&quot;)]
        public Shader shader;
        
        /// &lt;summary&gt;
        /// Overlay texture in mercator projection
        /// &lt;/summary&gt;
        [Tooltip(&quot;If material is specified, this field will be ignored and you must specify the texture directly in the material.&quot;)]
        public Texture texture;
        
        /// &lt;summary&gt;
        /// Border coordinates of the overlay
        /// &lt;/summary&gt;
        public double leftLongitude = -180;
        public double topLatitude = 90;
        public double rightLongitude = 180;
        public double bottomLatitude = -90;
        
        /// &lt;summary&gt;
        /// Overlay transparency
        /// &lt;/summary&gt;
        [Range(0, 1)] 
        public float alpha = 1;
        
        private Mesh overlayMesh;
        private Map map;

        private void Start()
        {
            // If the control is not specified, get the current instance.
            if (!control &amp;&amp; !(control = GetComponent&lt;TileSetControl&gt;()))
            {
                Debug.LogError(&quot;TileSetControl not found&quot;);
                return;
            }
            
            // 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;();
            if (!material)
            {
                if (!shader) shader = RenderPipelineHelper.GetTransparentShader();
                material = new Material(shader);
                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
            map = control.map;
            map.OnLocationChanged += UpdateMesh;
            map.OnZoomChanged += UpdateMesh;

            // Init mesh
            UpdateMesh();
        }

        private void UpdateMesh()
        {
            // Clear overlay mesh
            overlayMesh.Clear(true);
            
            Vector3 p1 = control.transform.worldToLocalMatrix * control.LocationToWorld(leftLongitude, topLatitude);
            Vector3 p2 = control.transform.worldToLocalMatrix * control.LocationToWorld(rightLongitude, bottomLatitude);

            // Init vertices and normals
            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>Thu, 09 Oct 2025 13:16:18 +0000</pubDate>
			<guid>https://forum.infinity-code.com/viewtopic.php?pid=9900#p9900</guid>
		</item>
		<item>
			<title><![CDATA[Add texture at specific location]]></title>
			<link>https://forum.infinity-code.com/viewtopic.php?pid=9899#p9899</link>
			<description><![CDATA[<p>Hello, <br />I need to add texture at a specific location on the map, overlaid on top of the map. There would be several textures that I can hide and show in different locations, and they need to zoom with the map, not maintain size like markers, so I can overlay a specific part of the map.<br />How can I do that? I am a new user. Is there an example for something like this?</p>]]></description>
			<author><![CDATA[null@example.com (tomislav.stefan)]]></author>
			<pubDate>Thu, 09 Oct 2025 12:10:04 +0000</pubDate>
			<guid>https://forum.infinity-code.com/viewtopic.php?pid=9899#p9899</guid>
		</item>
	</channel>
</rss>
