x


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

more ▼

asked Aug 11 '10 at 07:29 AM

Will 10 gravatar image

Will 10
12 3 3 5

Unless you know what file format the source is, it'd be impossible for you to do that.

Aug 11 '10 at 08:23 AM qJake
(comments are locked)
10|3000 characters needed characters left

1 answer: sort voted first

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 ;-)

more ▼

answered Aug 11 '10 at 10:47 AM

Wolfram gravatar image

Wolfram
9k 8 20 52

(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x1673
x972
x82

asked: Aug 11 '10 at 07:29 AM

Seen: 1699 times

Last Updated: Aug 11 '10 at 07:29 AM