Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice

Question Magician needed for texturing from csv data values

Discussion in 'World Building' started by esdcpl, Aug 15, 2022.

  1. esdcpl

    esdcpl

    Joined:
    Aug 13, 2022
    Posts:
    1
    Hi, I'm struggling with a problem and I don't know how to remedy it, I've tried many reverse engineering methods but I'm not able to remedy it. It puts a big wall in front of me that is impossible to get around.... so I turn to you.
    In order not to complicate things for a potential wizard who will solve my problem with the snap of a finger, I will provide the most important information.
    I have a 2048x2048 terrain generated from a RAW map, and texture record. The problem is precisely in what format I have the locations of the various textures represented. I know that for this map the list of them looks like this:

    Size: 2048
    Texture
    #0 Earth.tga
    #1 Rock.tga
    #2 jungle_Grass.tga
    #3 Road.tga
    #4 Ground.tga
    #5 Earthdirty.tga
    #6 Earth_Root.tga


    And then we have the notation itself where the texture is. From what I understand it is a text expressing a two-dimensional array that has 2048 columns and rows. An example of a small fragment.



    How do I superimpose the corresponding texture values from a two-dimensional array onto the terrain?
    Thanks!
     
  2. kris007_iron

    kris007_iron

    Joined:
    Oct 5, 2020
    Posts:
    3
    This solution is written in raw C# .NET6 simply it converts csv to bmp by creating 2D array but for purposes of example i simply used colors instead of materials

    Code (CSharp):
    1. using System.Drawing;
    2.  
    3. string filePath = @"C:\Users\Maria\Desktop\22.csv";
    4. StreamReader sr = new StreamReader(filePath);
    5. var lines = new List<string[]>();
    6. int Row = 0;
    7. while (!sr.EndOfStream)
    8. {
    9.     string[] Line = sr.ReadLine().Split(';');
    10.     lines.Add(Line);
    11.     Row++;  
    12. }
    13.  
    14. string[][] data = lines.ToArray();
    15. foreach (string cell in data[0])
    16. {
    17. Console.Write(cell + "\n");
    18. }
    19.  
    20. Bitmap image;
    21. image = new Bitmap(1025,1025,System.Drawing.Imaging.PixelFormat.Format32bppArgb);
    22.  
    23. for (int i = 0; i < image.Width; i++)
    24. {
    25.     for (int j = 0; j < image.Height; j++)
    26.     {      
    27.         switch (data[i][j])
    28.         {
    29.             case "0":
    30.                 {
    31.                     image.SetPixel(i, j, Color.Black);
    32.                     break;
    33.                 }
    34.             case "1":
    35.                 {
    36.                     image.SetPixel(i, j, Color.Red);
    37.                     break;
    38.                 }
    39.             case "2":
    40.                 {
    41.                     image.SetPixel(i, j, Color.Blue);
    42.                     break;
    43.                 }
    44.             case "3":
    45.                 {
    46.                     image.SetPixel(i, j, Color.Yellow);
    47.                     break;
    48.                 }
    49.             case "4":
    50.                 {
    51.                     image.SetPixel(i, j, Color.Magenta);
    52.                     break;
    53.                 }
    54.             case "5":
    55.                 {
    56.                     image.SetPixel(i, j, Color.Cyan);
    57.                     break;
    58.                 }
    59.             case "6":
    60.                 {
    61.                     image.SetPixel(i, j, Color.White);
    62.                     break;
    63.                 }
    64.         }      
    65.     }
    66. }
    67. image.Save(@"C:\Users\Maria\Desktop\22.bmp");