Hi,
I am trying to convert the shape of a mesh to the terrain object. First I tried exporting a greyscale map from my modelling program but found that the surface gets distorted to much. Using the smooth height tool results in loss of detail.
So I thought of manipulating the terrain height directly in unity using terrain.SetHeights and Physics.Raycast on the modeled surface.
The terrain and the modeled surface on top of eachother

for (var i : float = 0; i < terrain.heightmapHeight; i++) {
for (var j : float = 0; j < terrain.heightmapWidth; j++) {
//for (i = 0; i < terrain.heightmapHeight; i++) {
// for (j = 0; j < terrain.heightmapWidth; j++) {
var pos : Vector3 = Vector3(0,0,0);
pos.x = (j / terrain.heightmapWidth) * terrain.size.x;
pos.z = (i / terrain.heightmapHeight) * terrain.size.z;
h = GetRaycast(pos);
tData[i,j] = h;
str += pos.x + " - " + pos.z + " - " + j + " - " + i + " - " + h + " - " + tData[i,j] + "\n";
}
}
terrain.SetHeights(0, 0, tData);
Write (str);
The result of this code

The log file does show accurate information about all the scanned coordinates, the height of the modeled terrain at each position and the height stored in tData. Yet the height of most of the terrain is set to the maximum Terrain height and some parts it is set to 0.
Any ideas what goes wrong here?
Thanks,
Raoul