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. Dismiss Notice

Question Importing with a script a raw file on a terrain

Discussion in 'Scripting' started by k1k3sigo, Jun 22, 2023.

  1. k1k3sigo

    k1k3sigo

    Joined:
    Jun 22, 2023
    Posts:
    1
    I'm trying to import a raw file into Unity on a terrain using a C# script, but I can't find any functionality that does the same as what is done from the Unity interface of the raw import button. Is there something specific that fulfills this function? Or how could I solve this problem by another solution?
    I have seen other posts from several years ago and none have helped me to solve it.

    Thank you on advance
    upload_2023-6-22_21-53-6.png
     
  2. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    36,563
    Bunny83 likes this.
  3. Bunny83

    Bunny83

    Joined:
    Oct 18, 2010
    Posts:
    3,495
    Right, I'm also quite certain that they didn't include that functionality in the scripting API. Especially it requires a lot of manual settings which actual format the raw data is in. So in the end it's just about interpreting the raw data the way it actually is. Since raw files just contain raw data without any kind of header or metadata you have to know and specify all those "parameters" yourself. So in the end it's "just" a simple for loop which may swap bytes (depending on endian-ness) and normalizing the samples. Of course you have to know the exact width and height beforehand.

    ps: that idea of modifying the terrain to match placed colliders is really quite ingenious. Most people always try to do it the other way round :) A bit of parameterized smoothing at the edges and you can sell it :D
     
    Kurt-Dekker likes this.