Hi everyone, I am trying to generate a terrain base on a height map. And I have an issue with the last "column" and last "row" of the map. (see the attached screenshot) some of the heights have a value of 0. I think I have offsetting every variable possible, hoping it would solve the problem, but for now nothing works ... Does anybody have an idea about what I am doing wrong ? Code (CSharp): public void LoadHeightMap(string aFileName, TerrainData aTerrain) { int res = aTerrain.heightmapResolution; int h = aTerrain.heightmapResolution-1; int w = aTerrain.heightmapResolution-1; Debug.Log(aTerrain.heightmapResolution + ":::::::::::::::::::::::::::::"); float[,] data = new float[w, h]; using (var file = System.IO.File.OpenRead(aFileName)) using (var reader = new System.IO.BinaryReader(file)) { for (int y = 0; y < h; y++) { for (int x = 0; x < h; x++) { float v = (float)reader.ReadUInt16() / 0xFFFF; data[y, x] = v; //data[y, x] = (float)x / (float)h; } progress = (float)y / (float)h; EditorUtility.DisplayProgressBar("Loading Height Map", "", progress); } } aTerrain.SetHeights(0, 0, data);
My first guess would be because you set w and h to one less than resolution. I suppose that you do this because otherwise you're out of range in your data source. Suggest you reduce the height map resolution to that of your data.
I don't know anything anymore ... I might have to start from scratch, but I am really afraid to hit the same wall ... I guess it would be really nice to have builtin function to load Height maps in unity ( i.e the one used in standard terrain script)
You need to add one more row and column to your height map data, like this: float[,] data = new float[w+1, h+1];