- Home /
Question by
UnityGISTech · Apr 11, 2019 at 08:44 AM ·
terrainterrain generationsetneighbors
Blend edges between multi terrains
i spent alot of time to get my dynamic terrain works bet every time i have spaces between terrains tiles any one can help me please :
my code : note that map size is the number of col and row
public float[,] _floatheightData; // Here where i have all elevation data stored from parsing elevation file
[code=CSharp]where i have all elevation data stored from parsing elevation file Code (CSharp):
/ Im using terrain.SetNeighbors but it not work correctly
Any errors on my code ?!
public float[,] GetTileHeightMap(TerrainPrefs prefs,TerrainData tdata)
{
if (_floatheightData.Length > 0)
{
float[,] m_TileHeightMap = new float[tdata.heightmapWidth, tdata.heightmapHeight];
float elevationRange = MaxElevation - MinElevation;
float thx = tdata.heightmapWidth - 1;
float thy = tdata.heightmapHeight - 1;
var y_Terrain_Col_num = (mapSize_row_x);
var x_Terrain_row_num = (mapSize_col_y);
// heightmap rotation
int tw = tdata.heightmapWidth - 1;
int th = tdata.heightmapHeight - 1;
float wRatio = (y_Terrain_Col_num ) / (tw);
float hRatio = (x_Terrain_row_num ) / (th);
for (int y = 0; y < tw; y++)
{
for (int x = 0; x < th; x++)
{
var elevation = (_floatheightData[(int)((y) * hRatio), (int)(x * wRatio)]);
float v = ((elevation - MinElevation) / elevationRange);
m_TileHeightMap[x, y] = v;
}
}
return m_TileHeightMap;
}
else return new float[0, 0];
}
terrains.jpg
(509.8 kB)
Comment