- Home /
Importing heightmap with c# code..
Hi all,
Does anyone have any hints/ideas/code for importing a heightmap from a binary raw file to a TerrainData object?
I've tried opening a stream and using BinaryReader to read in the file, but I'm getting strange results..
Unless you know what file format the source is, it'd be impossible for you to do that.
Answer by Wolfram · Aug 11, 2010 at 10:47 AM
A pure raw file generally does not have a header, so it does not contain any information about its resolution, bit depth, or byte arrangement. If you do know these, you can parse the file, which should have a size of exactly (xRes*yRes*bitDepth) bytes.
If the bit depth is 2 bytes (16bit), you need to figure out the endianness (whether the most significant byte is the first or the second one). If your endianness is wrong, the imported map will jsut look like gibberish, and often resemble random noise.
You also need to figure out whether the pixel rows are ascending (0->(ymax-1)) or descending ((ymax-1)->0), which might cause a vertical flip of the map.
You should be able to figure out these settings by trial and error ;-)
Your answer
Follow this Question
Related Questions
Heightmaps not importing properly 0 Answers
Animation Inspector is suddenly Unbearably Laggy 1 Answer
Custom Export and Import FBX Data 1 Answer
Updating UV in imported mesh without having to re-material 0 Answers
Monobehaviours & Editors with Inheritance across DLL boundaries don't load into Unity 2 Answers