Search Unity

From large image to map / terrain / texture

Discussion in 'General Graphics' started by JuZ-index, Feb 13, 2021.

  1. JuZ-index

    JuZ-index

    Joined:
    Feb 2, 2021
    Posts:
    10
    Hi,

    I'd like to generate map from a large image file (9650*12573).
    I already have a tile/image pieces generator but it generates 1900 images 256*256, and it seems hard to create a map by hand like this (and I have more then one large image to process...).

    These image pieces are sorted like this :

    x/y.png


    Where x starts from left to right and y from top to bottom.

    As MelvMay suggests me here, I should use textures to achieve that, but how?

    Do you have any idea of how to achieve that programmatically? Or may be with an existing bundle?

    Thanks a lot!

    Julien
     
  2. JuZ-index

    JuZ-index

    Joined:
    Feb 2, 2021
    Posts:
    10
    As a workaround, I tried this but really don't know how to implement it...

    Code (CSharp):
    1. public class TexGenerator : MonoBehaviour {
    2.    
    3.     private Renderer m_Renderer;
    4.     private Texture2D m_MainTexture;
    5.  
    6.     // Use this for initialization
    7.     void Start () {
    8.  
    9.         //Fetch the Renderer from the GameObject
    10.         m_Renderer = GetComponent<Renderer> ();
    11.         m_MainTexture = LoadPNG("Assets/Tiles/Ressources/Map/0/3.png");
    12.         m_Renderer.material.mainTexture = m_MainTexture;
    13.        
    14.     }
    15.  
    16.     private Texture2D LoadPNG(string filePath) {
    17.         Texture2D tex = null;
    18.         byte[] fileData;
    19.    
    20.         if (File.Exists(filePath))     {
    21.             UnityEngine.Debug.Log(filePath);
    22.             fileData = File.ReadAllBytes(filePath);
    23.             tex = new Texture2D(2, 2);
    24.             tex.LoadImage(fileData); //..this will auto-resize the texture dimensions.
    25.         }
    26.  
    27.         return tex;
    28.  
    29.     }
    30.  
    31. }