Hey
I was wondering how it would be possible to convert a low resolution height map to a high resolution one. I currently have a height map with a resolution of 513x513 but I’d like to scale it up to 2049x2049 to work on further details. But if I change the resolution in the terrain field, I actually use all the heights and so on which I changed earlier.
So I guess that I need to that through script but I couldn’t figure out a good way to do that yet. Anybody an idea how to that?
This is a tricky one.
If what you want is to “add” more terrain, I would do something like this:
void ChangeTerrainResolution (int newResolution)
{
Terrain t = Terrain.activeTerrain;
TerrainData d = t.terrainData;
float[,] heights = d.GetHeights(0, 0, d.heightmapWidth, d.heightmapHeight);
int previousResolution = d.heightmapResolution;
d.heightmapResolution = newResolution;
float[,] newHeights = new float[newResolution,newResolution];
for(int x = 0; x < previousResolution; x++)
{
for(int y = 0; y < previousResolution; y++)
{
newHeights[x,y] = heights[x,y];
}
}
d.SetHeights(0, 0, newHeights);
}
If you want to actually be able to “fill in the gaps”, you will need to interpolate new height values and it will be somewhat more complex.
Yeah I want to “fill the gaps” and that’s actually where I’m struggling