<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
	<title type="html"><![CDATA[Infinity Code Forum — A new way to capture terrains ?]]></title>
	<link rel="self" href="https://forum.infinity-code.com/extern.php?action=feed&amp;tid=1434&amp;type=atom" />
	<updated>2020-02-07T15:09:56Z</updated>
	<generator>PunBB</generator>
	<id>https://forum.infinity-code.com/viewtopic.php?id=1434</id>
		<entry>
			<title type="html"><![CDATA[Re: A new way to capture terrains ?]]></title>
			<link rel="alternate" href="https://forum.infinity-code.com/viewtopic.php?pid=5963#p5963" />
			<content type="html"><![CDATA[<p>You are right, I tested in another project and it works fine ! Awesome !<br />Thanks Alex !</p>]]></content>
			<author>
				<name><![CDATA[philzmz]]></name>
				<uri>https://forum.infinity-code.com/profile.php?id=606</uri>
			</author>
			<updated>2020-02-07T15:09:56Z</updated>
			<id>https://forum.infinity-code.com/viewtopic.php?pid=5963#p5963</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: A new way to capture terrains ?]]></title>
			<link rel="alternate" href="https://forum.infinity-code.com/viewtopic.php?pid=5937#p5937" />
			<content type="html"><![CDATA[<p>I tested this with the settings above for several terrains.<br />Yes, please send a video.</p>]]></content>
			<author>
				<name><![CDATA[Alex Vertax]]></name>
				<uri>https://forum.infinity-code.com/profile.php?id=2</uri>
			</author>
			<updated>2020-01-30T19:26:51Z</updated>
			<id>https://forum.infinity-code.com/viewtopic.php?pid=5937#p5937</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: A new way to capture terrains ?]]></title>
			<link rel="alternate" href="https://forum.infinity-code.com/viewtopic.php?pid=5936#p5936" />
			<content type="html"><![CDATA[<p>Excellent ! Great improvement ! But I have an issue : it works fine with 1 tile, but if I have several tiles in 1 line or several lines each with several (or only one) tile, it seems that only 1 tile is downloaded ?<br />I can send a video if you want.<br />Thanks a lot !</p>]]></content>
			<author>
				<name><![CDATA[philzmz]]></name>
				<uri>https://forum.infinity-code.com/profile.php?id=606</uri>
			</author>
			<updated>2020-01-30T19:23:41Z</updated>
			<id>https://forum.infinity-code.com/viewtopic.php?pid=5936#p5936</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: A new way to capture terrains ?]]></title>
			<link rel="alternate" href="https://forum.infinity-code.com/viewtopic.php?pid=5913#p5913" />
			<content type="html"><![CDATA[<p>Something like that:<br /><span class="postimg"><img src="https://i.ibb.co/TKDsWDr/img1.png" alt="https://i.ibb.co/TKDsWDr/img1.png" /></span></p><p>Place the script in the Editor folder, and run Menu / RWT / Automator.<br /></p><div class="codebox"><pre><code>using System;
using System.Collections.Generic;
using InfinityCode.RealWorldTerrain;
using InfinityCode.RealWorldTerrain.Windows;
using UnityEditor;
using UnityEngine;

public class AutomatorExample : EditorWindow
{
    private RealWorldTerrainContainer container;
    private List&lt;Rule&gt; rules = new List&lt;Rule&gt;();
    private Vector2 scrollPosition;
    private int status = 0; // 0 - idle, 1 - execute, 2 - finalize
    private int executeIndex = -1;
    private bool finished = false;

    private void Execute()
    {
        if (container == null) return;
        if (container.terrains == null) return;
        if (rules.Count == 0) return;

        status = 1;
        executeIndex = -1;
        ExecuteNextTerrain();
    }

    private void ExecuteNextTerrain()
    {
        int ruleIndex = -1;
        Rule activeRule = null;
        RealWorldTerrainItem item = null;

        do
        {
            executeIndex++;
            if (executeIndex == container.terrainCount)
            {
                status = 2;
                Repaint();
                return;
            }

            item = container.terrains[executeIndex];

            for (int i = 0; i &lt; rules.Count; i++)
            {
                Rule rule = rules[i];
                if (rule.Contains(item) &amp;&amp; rule.textureResolution != item.prefs.textureSize.x)
                {
                    activeRule = rule;
                    ruleIndex = i;
                    break;
                }
            }
        } while (activeRule == null);

        finished = false;

        Debug.Log(item + &quot;, Rule - &quot; + ruleIndex);

        RealWorldTerrainWindow.OpenWindow(RealWorldTerrainGenerateType.texture, item);

        RealWorldTerrainWindow.prefs.textureSize = new RealWorldTerrainVector2i(activeRule.textureResolution, activeRule.textureResolution);
        RealWorldTerrainWindow.OnCaptureCompleted += OnCaptureCompleted;
        RealWorldTerrainWindow.OnCaptureCanceled += OnCaptureCanceled;

        RealWorldTerrainWindow.StartCapture();
    }

    private void OnCaptureCanceled()
    {
        UnsubscribeFromEvents();

        status = 2;
    }

    private void OnCaptureCompleted()
    {
        UnsubscribeFromEvents();

        finished = true;
        Repaint();
    }

    private void OnGUI()
    {
        if (status == 0) OnIdleGUI();
        else if (status == 1) OnWaitGUI();
        else if (Event.current.type == EventType.Repaint)
        {
            status = 0;
            Repaint();
        }
    }

    private void OnIdleGUI()
    {
        int rulesCount = rules.Count;
        int moveUp = -1;
        int moveDown = -1;

        container = EditorGUILayout.ObjectField(&quot;RWT Container&quot;, container, typeof(RealWorldTerrainContainer), true) as RealWorldTerrainContainer;

        try
        {
            scrollPosition = EditorGUILayout.BeginScrollView(scrollPosition);
        }
        catch (Exception e)
        {
            Debug.Log(Event.current.type);
        }
        

        for (int i = 0; i &lt; rulesCount; i++)
        {
            Rule rule = rules[i];

            EditorGUILayout.BeginHorizontal();

            EditorGUILayout.LabelField(&quot;From X&quot;, GUILayout.Width(50));
            rule.fromX = EditorGUILayout.IntField(rule.fromX);
            EditorGUILayout.LabelField(&quot;Y&quot;, GUILayout.Width(20));
            rule.fromY = EditorGUILayout.IntField(rule.fromY);

            EditorGUILayout.LabelField(&quot; To X&quot;, GUILayout.Width(40));
            rule.toX = EditorGUILayout.IntField(rule.toX);
            EditorGUILayout.LabelField(&quot;Y&quot;, GUILayout.Width(20));
            rule.toY = EditorGUILayout.IntField(rule.toY);

            EditorGUILayout.LabelField(&quot; Resolution&quot;, GUILayout.Width(80));
            rule.textureResolution = EditorGUILayout.IntField(rule.textureResolution);

            if (GUILayout.Button(&quot;Up&quot;, GUILayout.ExpandWidth(false))) moveUp = i;
            if (GUILayout.Button(&quot;Down&quot;, GUILayout.ExpandWidth(false))) moveDown = i;
            if (GUILayout.Button(&quot;X&quot;, GUILayout.ExpandWidth(false)))
            {
                rules.RemoveAt(i);
                rulesCount--;
            }

            EditorGUILayout.EndHorizontal();
        }

        EditorGUILayout.EndScrollView();

        if (moveUp &gt; 0)
        {
            Rule t = rules[moveUp - 1];
            rules[moveUp - 1] = rules[moveUp];
            rules[moveUp] = t;
        }

        if (moveDown != -1 &amp;&amp; moveDown &lt; rulesCount - 1)
        {
            Rule t = rules[moveDown + 1];
            rules[moveDown + 1] = rules[moveDown];
            rules[moveDown] = t;
        }

        if (GUILayout.Button(&quot;Add&quot;)) rules.Add(new Rule());
        if (GUILayout.Button(&quot;Execute&quot;)) Execute();
    }

    private void OnWaitGUI()
    {
        if (finished) ExecuteNextTerrain();

        Rect rect = GUILayoutUtility.GetRect(GUIContent.none, GUI.skin.box, GUILayout.Height(20), GUILayout.ExpandWidth(true));
        float progress = (float)executeIndex / (container.terrainCount - 1);
        EditorGUI.ProgressBar(rect, progress, Mathf.FloorToInt(progress * 100) + &quot; %&quot;);

        if (GUILayout.Button(&quot;Cancel&quot;))
        {
            status = 2;
            RealWorldTerrainWindow.CancelCapture();
        }
    }

    [MenuItem(&quot;RWT/Automator&quot;)]
    private static void OpenWindow()
    {
        GetWindow&lt;AutomatorExample&gt;();
    }

    private void UnsubscribeFromEvents()
    {
        RealWorldTerrainWindow.OnCaptureCompleted -= OnCaptureCompleted;
        RealWorldTerrainWindow.OnCaptureCanceled -= OnCaptureCanceled;
    }

    internal class Rule
    {
        public int fromX;
        public int fromY;
        public int toX;
        public int toY;
        public int textureResolution = 256;

        public bool Contains(RealWorldTerrainItem item)
        {
            return fromX &lt;= item.x &amp;&amp; toX &gt;= item.x &amp;&amp; fromY &lt;= item.y &amp;&amp; toY &gt;= item.y;
        }
    }
}</code></pre></div>]]></content>
			<author>
				<name><![CDATA[Alex Vertax]]></name>
				<uri>https://forum.infinity-code.com/profile.php?id=2</uri>
			</author>
			<updated>2020-01-28T00:20:34Z</updated>
			<id>https://forum.infinity-code.com/viewtopic.php?pid=5913#p5913</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: A new way to capture terrains ?]]></title>
			<link rel="alternate" href="https://forum.infinity-code.com/viewtopic.php?pid=5906#p5906" />
			<content type="html"><![CDATA[<p>Thanks Alex, keep me informed ! Best regards !</p>]]></content>
			<author>
				<name><![CDATA[philzmz]]></name>
				<uri>https://forum.infinity-code.com/profile.php?id=606</uri>
			</author>
			<updated>2020-01-27T15:36:14Z</updated>
			<id>https://forum.infinity-code.com/viewtopic.php?pid=5906#p5906</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: A new way to capture terrains ?]]></title>
			<link rel="alternate" href="https://forum.infinity-code.com/viewtopic.php?pid=5894#p5894" />
			<content type="html"><![CDATA[<p>Hello.</p><p>Thanks for the suggestions.</p><p>The suggestion for unique settings for each tile I marked in work.<br />But it will not be implemented in RWT 4x. Only in RWT 5.<br />Currently, this can be automated using RWT API.<br />Please give me 3-5 days and I will give you an example of how to do this.</p><p>The infinite horizon suggestion cannot be implemented, simply because there can be nothing infinite in Unity.<br />In addition, Unity has many bugs, when something have a large sizes or positions in the scene.</p>]]></content>
			<author>
				<name><![CDATA[Alex Vertax]]></name>
				<uri>https://forum.infinity-code.com/profile.php?id=2</uri>
			</author>
			<updated>2020-01-21T09:06:03Z</updated>
			<id>https://forum.infinity-code.com/viewtopic.php?pid=5894#p5894</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[A new way to capture terrains ?]]></title>
			<link rel="alternate" href="https://forum.infinity-code.com/viewtopic.php?pid=5890#p5890" />
			<content type="html"><![CDATA[<p>Hi Alex,</p><p>The anchor you added in 4.4.0.1 is a great feature. You could add a checkbox “center anchor” and then calculate the center coordinates.</p><p>I would like to suggest another way to capture a terrain than selecting its boundaries, which is not always, to me, the most convenient. </p><p>The main problem is that if you want to get a nice horizon aspect (as if the terrain would be limitless) you need to capture a very large terrain.</p><p>I am using terrains within oculus Quest, so memory optimisation is very important.</p><p>My actual process is as follow (tell me what you think, maybe I am wrong…) :</p><p>I capture the terrain that I need with a high resolution. I prefer to capture large tiles (8192x8192) to avoid the meshes junction issues that may happen between the tiles.<br />I capture a larger terrain (5x the 1st terrain size) with a lower resolution.<br />I place the 1st terrain above the second one</p><p>As I use invisible fences around the high res terrain, the result is correct, but this process could be easier : it would be great if the resolution of the surrounding tiles could be automatically adjusted.</p><p>When I want to capture a terrain, I know 2 things :<br />the center of this terrain<br />the (approximative) area that I need in high resolution that could be adjusted to match the tiles.</p><p>The rest of the process could be automated, capturing all the needed tiles automatically, in the desired resolution, as shown on the picture below.</p><p><a href="https://ibb.co/cwYK3YY"><span class="postimg"><img src="https://i.ibb.co/cwYK3YY/terrain-resolution.png" alt="https://i.ibb.co/cwYK3YY/terrain-resolution.png" /></span></a></p><p>Another idea to improve the “infinite” horizon aspect could be to raise the mesh boudaries of the “external” terrains in order that they match the horizon line, I don’t know if this is possible.<br />Best regards, </p><p>Philippe</p>]]></content>
			<author>
				<name><![CDATA[philzmz]]></name>
				<uri>https://forum.infinity-code.com/profile.php?id=606</uri>
			</author>
			<updated>2020-01-20T07:10:30Z</updated>
			<id>https://forum.infinity-code.com/viewtopic.php?pid=5890#p5890</id>
		</entry>
</feed>
