Hello all,
using WM 1.25 Standard Edition, I’m currently trying to load files that are created by the File Output device into Terragen.
Using Terragens own file format *.ter, this generally works very well, except for the fact that it gets the terrains heights (altitudes) incorrectly scaled.
In World-Machine, I’ve set a world size of 1024*1024 pixels, scaled to 10.86 km^2. The “Terrain Height Scale” is set to 2040m.
(However, the actual elevation data that I eventually feed to the File Output device ranges only from about 80m to 500m.)
Then I started to examine the .ter file that the File Output device generated by hand:
It seems to get all chunks right, except for the beginning of the ALTW chunk (see http://www.planetside.co.uk/terragen/dev/tgterrain.html for details):
The ALTW chunk header is followed by the hex byte sequence 80 01 00 00 77 89 (signed, 2-byte ints in Intel byte order), which translates to
HeightScale = 384,
BaseHeight = 0,
Elevation of first point = -30345.
Now, when I put these numbers into the equation BaseHeight + Elevation * HeightScale / 65536 as given by the spec, I obtain in fact and as expected the same numbers that I see in Terragen in the Landscape View.
(0 + -30345*384/65536 = -177.803, and taking this from pixels to meters yields -177.803 * 10860 / 1024 = -1885.7, the result that I can also read in the Terragen Landscape View.)
So it seems that Terragen is correctly reading the file, while it has been incorrectly created by World-Machine.
Here is what I had expected WM to put into the .ter file:
First, determine the min. terrain elevation at 80m, the max. elevation at 500m.
The difference is 420m, the average height is at 290m.
These two numbers must be taken from the real world units “meters” to per-pixel units. As we have 10.86 km per 1024 pixels, we get 420m / 10860m * 1024 pixels = 39.6 pixels, and 290m / 10860m * 1024 pixels = 27.3 pixels.
Reasonably rounding these numbers to integers (always(??) upwards, ceil()), we find the complete equation that translates a ALTW height value to meters as
(28 + 40*x/65536 ) * 10860/1024 = h. (h is the height in meters.)
That is, WM should have set HeightScale to 40, BaseHeight to 28, and find the height values by solving the above equation for x… (which must expect 16-bit integer overflows as a consequence from the previous rounding step, I didn’t fully think this out…)
:arrow: A bug?? Or did I overlook something?
I’d be very happy for any help here, as it is very important for me to get these things correctly loaded into Terragen…
Oh, and this issue could easily be worked-around if WM showed the true min/max elevation heights (I’ve just “guessed” the above 80 and 500m from my knowledge about how the terrain was built…).
Thank you very much in advance!!