diff options
author | Sean Dague | 2008-02-29 20:36:14 +0000 |
---|---|---|
committer | Sean Dague | 2008-02-29 20:36:14 +0000 |
commit | c009e2e0956ab6c43aebe0ba9275a0dbcc25e9ce (patch) | |
tree | b69db77d795779b03e90b29a327f9d5613c06a06 | |
parent | More compiler warning cleanup. (diff) | |
download | opensim-SC-c009e2e0956ab6c43aebe0ba9275a0dbcc25e9ce.zip opensim-SC-c009e2e0956ab6c43aebe0ba9275a0dbcc25e9ce.tar.gz opensim-SC-c009e2e0956ab6c43aebe0ba9275a0dbcc25e9ce.tar.bz2 opensim-SC-c009e2e0956ab6c43aebe0ba9275a0dbcc25e9ce.tar.xz |
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.
-rw-r--r-- | OpenSim/Region/Terrain.BasicTerrain/TerrainEngine.cs | 12 | ||||
-rw-r--r-- | OpenSim/Region/Terrain.BasicTerrain/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 decbb73..b34ca5e 100644 --- a/OpenSim/Region/Terrain.BasicTerrain/TerrainEngine.cs +++ b/OpenSim/Region/Terrain.BasicTerrain/TerrainEngine.cs | |||
@@ -251,7 +251,6 @@ namespace OpenSim.Region.Terrain | |||
251 | //SmoothTerrain(y, x , size, (double)seconds / 5.0); | 251 | //SmoothTerrain(y, x , size, (double)seconds / 5.0); |
252 | //} | 252 | //} |
253 | //} | 253 | //} |
254 | |||
255 | SmoothTerrain(west, north, size, (double) seconds/5.0); | 254 | SmoothTerrain(west, north, size, (double) seconds/5.0); |
256 | 255 | ||
257 | break; | 256 | break; |
@@ -1331,14 +1330,9 @@ namespace OpenSim.Region.Terrain | |||
1331 | { | 1330 | { |
1332 | lock (heightmap) | 1331 | lock (heightmap) |
1333 | { | 1332 | { |
1334 | Channel smoothed = heightmap.Copy(); | 1333 | // perform essential computation as a channel method |
1335 | smoothed.Smooth(amount); | 1334 | heightmap.SmoothRegion(rx, ry, size, amount); |
1336 | 1335 | } | |
1337 | Channel mask = new Channel(); | ||
1338 | mask.Raise(rx, ry, size, amount); | ||
1339 | |||
1340 | heightmap.Blend(smoothed, mask); | ||
1341 | } | ||
1342 | 1336 | ||
1343 | tainted++; | 1337 | tainted++; |
1344 | } | 1338 | } |
diff --git a/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Editing/Raise.cs b/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Editing/Raise.cs index 523a065..20bca51 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 | |||
127 | } | 127 | } |
128 | } | 128 | } |
129 | } | 129 | } |
130 | |||
131 | public double SphericalFactor(double x, double y, double rx, double ry, double size) | ||
132 | { | ||
133 | double z = size * size - ((x - rx) * (x - rx) + (y - ry) * (y - ry)); | ||
134 | return z; | ||
135 | } | ||
136 | |||
137 | public void SmoothRegion(double rx, double ry, double size, double amount) | ||
138 | { | ||
139 | int x, y; | ||
140 | double[,] tweak = new double[w, h]; | ||
141 | |||
142 | double n, l; | ||
143 | double area = size; | ||
144 | double step = size / 4.0; | ||
145 | |||
146 | // compute delta map | ||
147 | for (x = 0; x < w; x++) | ||
148 | { | ||
149 | for (y = 0; y < h; y++) | ||
150 | { | ||
151 | double z = SphericalFactor(x, y, rx, ry, size); | ||
152 | |||
153 | if (z > 0) // add in non-zero amount | ||
154 | { | ||
155 | double average = 0.0; | ||
156 | int avgsteps = 0; | ||
157 | |||
158 | for (n = 0.0 - area; n < area; n += step) | ||
159 | { | ||
160 | for (l = 0.0 - area; l < area; l += step) | ||
161 | { | ||
162 | avgsteps++; | ||
163 | average += GetBilinearInterpolate(x + n, y + l); | ||
164 | } | ||
165 | } | ||
166 | tweak[x, y] = average / avgsteps; | ||
167 | //if (x == rx && y == ry) | ||
168 | // Console.WriteLine("tweak[ " + x + " , " + y + " ] = " + tweak[x, y]); | ||
169 | } | ||
170 | } | ||
171 | } | ||
172 | // blend in map | ||
173 | for (x = 0; x < w; x++) | ||
174 | { | ||
175 | for (y = 0; y < h; y++) | ||
176 | { | ||
177 | double z = SphericalFactor(x, y, rx, ry, size); | ||
178 | |||
179 | if (z > 0) // add in non-zero amount | ||
180 | { | ||
181 | double da = z * amount; | ||
182 | double a = (map[x, y] - tweak[x, y]) * da; | ||
183 | double newz = map[x, y] - a; | ||
184 | //if (rx == x || ry == y) | ||
185 | // Console.WriteLine("map[ " + x + " , " + y + " ] = " + map[x, y] + " tweak, a , da, z, size, amount = " + tweak[x, y] + " " + a + " " + da + " " + z + " " + size + " " + amount); | ||
186 | if (newz > 0.0) | ||
187 | Set(x, y, newz); | ||
188 | } | ||
189 | } | ||
190 | } | ||
191 | } | ||
130 | } | 192 | } |
131 | } \ No newline at end of file | 193 | } \ No newline at end of file |