The easiest solution I can think of is to create a CustomTerrain
class by copying the Terrain
class, and slightly change the way it reads from heightmap image data.
If you look at the source code for Terrain
class, luckily, the height data is already stored as float
/// Height data.
SharedArrayPtr<float> heightData_;
/// Source height data for smoothing.
SharedArrayPtr<float> sourceHeightData_;
So the only thing you need to change is around line 940-1000 in Terrain.cpp
// Reading single channel image data.
float newHeight = (float)src[imgRow * (numVertices_.y_ - 1 - z) + x] * spacing_.y_;
...
// Reading multiple channels data (R and G).
float newHeight = ((float)src[imgRow * (numVertices_.y_ - 1 - z) + imgComps * x] +
(float)src[imgRow * (numVertices_.y_ - 1 - z) + imgComps * x + 1] / 256.0f) * spacing_.y_;
where the src
is the source image data you can read whatever you want, e.g. tiff (You can find other library from DEM to read it).