From c009e2e0956ab6c43aebe0ba9275a0dbcc25e9ce Mon Sep 17 00:00:00 2001 From: Sean Dague Date: Fri, 29 Feb 2008 20:36:14 +0000 Subject: [PATCH] From: Mike Pitman 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. --- .../Terrain.BasicTerrain/TerrainEngine.cs | 12 +--- .../libTerrainBSD/Channel/Editing/Raise.cs | 62 +++++++++++++++++++ 2 files changed, 65 insertions(+), 9 deletions(-) diff --git a/OpenSim/Region/Terrain.BasicTerrain/TerrainEngine.cs b/OpenSim/Region/Terrain.BasicTerrain/TerrainEngine.cs index decbb73964..b34ca5e133 100644 --- a/OpenSim/Region/Terrain.BasicTerrain/TerrainEngine.cs +++ b/OpenSim/Region/Terrain.BasicTerrain/TerrainEngine.cs @@ -251,7 +251,6 @@ namespace OpenSim.Region.Terrain //SmoothTerrain(y, x , size, (double)seconds / 5.0); //} //} - SmoothTerrain(west, north, size, (double) seconds/5.0); break; @@ -1331,14 +1330,9 @@ namespace OpenSim.Region.Terrain { lock (heightmap) { - Channel smoothed = heightmap.Copy(); - smoothed.Smooth(amount); - - Channel mask = new Channel(); - mask.Raise(rx, ry, size, amount); - - heightmap.Blend(smoothed, mask); - } + // perform essential computation as a channel method + heightmap.SmoothRegion(rx, ry, size, amount); + } tainted++; } diff --git a/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Editing/Raise.cs b/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Editing/Raise.cs index 523a065c4e..20bca51033 100644 --- a/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Editing/Raise.cs +++ b/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Editing/Raise.cs @@ -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); + } + } + } + } } } \ No newline at end of file