- Home /
Controlling height when importing heightmaps
I'm working on a scene and want accurate control over the various measurements. I imported the terrain just nice, but I just found out that it's slightly higher then it should be. However, I only know the max height (set at resolutions) but not the actual height that is imported.
So my question here is: how does Unity convert the color information from the raw file into height information and is there a way for me to check the height at whatever point to ensure the terrain is accurate? I made the map with true colours ranging from [39,39,39] to [252,252,252].
Thanks for the help!
To give some more specific details about the project I'm working on:
I started on an AutoCAD dwg, where I gave the various contour lines colours in the above range. I exported to Illustrator to fill the areas between the lines with the colour of the specific height en then exported to photoshop as tga so I could rasterize it and export as raw to use in Unity. Before importing into Unity I did have to decrease the size to 1024 x 1024 pixels, but I already had the image put on a square image (just added black lines around it) so that it would not be distorted. I checked the regions below for their actual pixel colour in the smaller version and it was as I expected it to be.
In Unity I have several test boxes which I give different heights to check how high my terrain is at several points. The height of the area with the colour [43,43,43] is 14,3, the height of the area with colour [99,99,99] is 36,8 and the height of the area with colour [252,252,252] is 119,38. When putting it into the actual height of the terrain in meters, I would expect the respective areas to have a height of 101m, 129,5m and 206m. Ins$$anonymous$$d (when adding 86 to the above measured values [ie. raising the lot]) I get 100,3m, 122,8m and 205,38m. The first and last are ok (and easily fully rectified) but the middle value is 7m short.
$$anonymous$$morrow I'll test the terrain at other points to see if I can find other areas that don't fit in with the current 'best' resolution (which, for these measurements was set with a max height of 122). But I'm really wondering how these differences came into the scene and how I can check en correct this more easily.
I hope this might help someone to help me out here :)
Answer by Roelof · Aug 16, 2013 at 10:16 AM
After lots of measuring I came up with the following table where 'Real Height' is the height the specific measuring point has in the real world and 'Measured Height' is the height measured in Unity units. For this I used a maximum height in the terrain resolution of 100. For this entire model I've simply viewed Unity units as being in meters.
Real Height /-/ Measured Height
101.5m /-/ 11.73
129.5m /-/ 30.09
153m /-/ 48.81
180m /-/ 72.67
196m /-/ 88.67
206m /-/ 97.88
The main problem was that there was no maximum height setting in which the differences between the various real heights equal the differences between the measured points in Unity. As the area between 180m and 196m is the most important in my project, I chose for this setting where the difference between the two real heights equals the difference in Unity in units (=16). However, in this model, it means a difference of almost 10 meters at the lowest level (real height: 129.5m - 101.5m = 28m; measured height: 30.09 - 11.73 = 18.36; 28 - 18.36 = 9.64!).
For now I'll just leave it at this as I have no idea how this difference came into being, I've checked and rechecked the original files in photoshop and I found the colours as I would expect them. If someone should read this and know why these values are so strange, please do respond, I hope to not have this kind of trouble with all my following models. If this still is not enough information for anyone to answer, then I hope someone can respond to tell me what is required still.