From: Mike Pitman <pitman@us.ibm.com>

Below is a patch for the smooth tool. 

I factored out the essential computations and placed it in a 
channel method to work similar to raise and lower. 
It now performs about the same rate as raise and lower.
0.6.0-stable
Sean Dague 2008-02-29 20:36:14 +00:00
parent 6d774339d9
commit c009e2e095
2 changed files with 65 additions and 9 deletions

View File

@ -251,7 +251,6 @@ namespace OpenSim.Region.Terrain
//SmoothTerrain(y, x , size, (double)seconds / 5.0); //SmoothTerrain(y, x , size, (double)seconds / 5.0);
//} //}
//} //}
SmoothTerrain(west, north, size, (double) seconds/5.0); SmoothTerrain(west, north, size, (double) seconds/5.0);
break; break;
@ -1331,13 +1330,8 @@ namespace OpenSim.Region.Terrain
{ {
lock (heightmap) lock (heightmap)
{ {
Channel smoothed = heightmap.Copy(); // perform essential computation as a channel method
smoothed.Smooth(amount); heightmap.SmoothRegion(rx, ry, size, amount);
Channel mask = new Channel();
mask.Raise(rx, ry, size, amount);
heightmap.Blend(smoothed, mask);
} }
tainted++; tainted++;

View File

@ -127,5 +127,67 @@ namespace libTerrain
} }
} }
} }
public double SphericalFactor(double x, double y, double rx, double ry, double size)
{
double z = size * size - ((x - rx) * (x - rx) + (y - ry) * (y - ry));
return z;
}
public void SmoothRegion(double rx, double ry, double size, double amount)
{
int x, y;
double[,] tweak = new double[w, h];
double n, l;
double area = size;
double step = size / 4.0;
// compute delta map
for (x = 0; x < w; x++)
{
for (y = 0; y < h; y++)
{
double z = SphericalFactor(x, y, rx, ry, size);
if (z > 0) // add in non-zero amount
{
double average = 0.0;
int avgsteps = 0;
for (n = 0.0 - area; n < area; n += step)
{
for (l = 0.0 - area; l < area; l += step)
{
avgsteps++;
average += GetBilinearInterpolate(x + n, y + l);
}
}
tweak[x, y] = average / avgsteps;
//if (x == rx && y == ry)
// Console.WriteLine("tweak[ " + x + " , " + y + " ] = " + tweak[x, y]);
}
}
}
// blend in map
for (x = 0; x < w; x++)
{
for (y = 0; y < h; y++)
{
double z = SphericalFactor(x, y, rx, ry, size);
if (z > 0) // add in non-zero amount
{
double da = z * amount;
double a = (map[x, y] - tweak[x, y]) * da;
double newz = map[x, y] - a;
//if (rx == x || ry == y)
// Console.WriteLine("map[ " + x + " , " + y + " ] = " + map[x, y] + " tweak, a , da, z, size, amount = " + tweak[x, y] + " " + a + " " + da + " " + z + " " + size + " " + amount);
if (newz > 0.0)
Set(x, y, newz);
}
}
}
}
} }
} }