Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by SkandYxyz · Jun 05, 2021 at 03:42 PM · terrainmerge

Is there a script to merge terrain tiles into one terrain?

Hi,

is there a script to merge terrain tiles into one terrain? No stitching needed, just reconfigure tiling.

Kind Regards, Skandy

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

1 Reply

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by SkandYxyz · Jun 19, 2021 at 06:18 PM

Here a script i wrote to merge the heightmaps of 256 terrains into a single terrain heightmap. using System.Collections; using System.Collections.Generic; using System.IO; using UnityEngine; using UnityEditor;

 [ExecuteInEditMode]
 public class CreateBigTerrain : MonoBehaviour
 {
     
     public Terrain _bigTerrain;
     public Terrain _tiles;
     public TerrainData tData;
     public RenderTexture tileHeightmap;
     public RenderTexture newHeightmap;
     public bool active=true;
     private int progressId;
     
     IEnumerator Start()
     {
         if(active)
         {
             // Create a new progress indicator
             progressId = Progress.Start("Merging Terrain");
             
             yield return StartCoroutine("Calculate");
 
             // The task is finished. Remove the associated progress indicator.
             Progress.Remove(progressId);
             active=false;    
             StopAllCoroutines();
         }
         DestroyImmediate(this);
 
     }
 
     IEnumerator Calculate()
     {
         TerrainData terrainData; 
         string path; 
         bool flipVertical=false;
         Vector2 inputLevelsRange;
         
         //_bigTerrain = GameObject.Find("bigTerrain").GetComponent<Terrain>();
         
         int heightmapWidth = 1024;
         int heightmapHeight = 1024;
 
         float normalize = (1 << 16);
         byte[] data = new byte[4096 * 4096 * 2];
         
         for(int y=0; y<16; y++)
         {
             for(int x=0; x<16; x++)
             {
                 _tiles = GameObject.Find("Terrain_"+x+"_"+y+"-20210513 - 125829").GetComponent<Terrain>();
                         
                 tData = _tiles.terrainData;
 
                 float[,] heights = tData.GetHeights(0, 0, 1024, 1024);
 
 
                 for (int ty = 0; ty < 256; ++ty)
                 {
                     for (int tx = 0; tx < 256; ++tx)
                     {
                         int index = (x*256+tx)+(y*256+ty)*4096; //tx*4 + ty*4 * 1024;
                         //int srcY = flipVertical ? 1024 - 1 - y : y;
 
                         float remappedHeight = heights[ty*4, tx*4];// * (inputLevelsRange.y - inputLevelsRange.x) + inputLevelsRange.x;
 
                         int height = Mathf.RoundToInt(remappedHeight * normalize);
                         ushort compressedHeight = (ushort)Mathf.Clamp(height, 0, ushort.MaxValue);
 
                         byte[] byteData = System.BitConverter.GetBytes(compressedHeight);
 
                         data[index * 2 + 0] = byteData[0];
                         data[index * 2 + 1] = byteData[1];
                     }
                 }                
                 
                 
                 yield return new WaitForSeconds(0.1f);
 
                     
                 Progress.Report(progressId, x+16*y, 256,"Heightmap of Terrain_"+x+"_"+y+"-20210513 - 125829");
             }            
         }
         
 
 
         path="Assets/Heightmaps/bigTerrain";
         
 
         FileStream fs = new FileStream((path + ".raw"), FileMode.Create);
         fs.Write(data, 0, data.Length);
         fs.Close();
 
         yield return null;
     }
 
     // Update is called once per frame
     void Update()
     {
 
     }
 
 }
Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

145 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Make a simple tree 1 Answer

Chopping down trees painted onto the terrain 2 Answers

Lights attached to objects turning off over terrain 2 Answers

Splitting map for multiplayer? 1 Answer

Update terrain alphamap at runtime makes my game crawling 3 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges