aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/Environment/Modules/World/WorldMap/MapImageModule.cs
diff options
context:
space:
mode:
Diffstat (limited to 'OpenSim/Region/Environment/Modules/World/WorldMap/MapImageModule.cs')
-rw-r--r--OpenSim/Region/Environment/Modules/World/WorldMap/MapImageModule.cs203
1 files changed, 23 insertions, 180 deletions
diff --git a/OpenSim/Region/Environment/Modules/World/WorldMap/MapImageModule.cs b/OpenSim/Region/Environment/Modules/World/WorldMap/MapImageModule.cs
index 38c52f0..2ae4174 100644
--- a/OpenSim/Region/Environment/Modules/World/WorldMap/MapImageModule.cs
+++ b/OpenSim/Region/Environment/Modules/World/WorldMap/MapImageModule.cs
@@ -69,29 +69,47 @@ namespace OpenSim.Region.Environment.Modules.World.WorldMap
69 69
70 private Scene m_scene; 70 private Scene m_scene;
71 private IConfigSource m_config; 71 private IConfigSource m_config;
72 private IMapTileTerrainRenderer terrainRenderer;
72 73
73 #region IMapImageGenerator Members 74 #region IMapImageGenerator Members
74 75
75 public byte[] WriteJpeg2000Image(string gradientmap) 76 public byte[] WriteJpeg2000Image(string gradientmap)
76 { 77 {
77 byte[] imageData = null; 78 byte[] imageData = null;
78 Bitmap mapbmp = new Bitmap(256, 256);
79
80 //Bitmap bmp = TerrainToBitmap(gradientmap);
81 mapbmp = TerrainToBitmap2(m_scene,mapbmp);
82 79
83 bool drawPrimVolume = true; 80 bool drawPrimVolume = true;
81 bool textureTerrain = true;
84 82
85 try 83 try
86 { 84 {
87 IConfig startupConfig = m_config.Configs["Startup"]; 85 IConfig startupConfig = m_config.Configs["Startup"];
88 drawPrimVolume = startupConfig.GetBoolean("DrawPrimOnMapTile", true); 86 drawPrimVolume = startupConfig.GetBoolean("DrawPrimOnMapTile", drawPrimVolume);
87 textureTerrain = startupConfig.GetBoolean("TextureOnMapTile", textureTerrain);
89 } 88 }
90 catch (Exception) 89 catch (Exception)
91 { 90 {
92 m_log.Warn("Failed to load StartupConfig"); 91 m_log.Warn("Failed to load StartupConfig");
93 } 92 }
94 93
94 if (textureTerrain)
95 {
96 terrainRenderer = new TexturedMapTileRenderer();
97 }
98 else
99 {
100 terrainRenderer = new ShadedMapTileRenderer();
101 }
102 terrainRenderer.Initialise(m_scene, m_config);
103
104 Bitmap mapbmp = new Bitmap(256, 256);
105 //long t = System.Environment.TickCount;
106 //for(int i = 0; i < 10; ++i) {
107 terrainRenderer.TerrainToBitmap(mapbmp);
108 //}
109 //t = System.Environment.TickCount - t;
110 //m_log.InfoFormat("[MAPTILE] generation of 10 maptiles needed {0} ms", t);
111
112
95 if (drawPrimVolume) 113 if (drawPrimVolume)
96 { 114 {
97 DrawObjectVolume(m_scene, mapbmp); 115 DrawObjectVolume(m_scene, mapbmp);
@@ -181,181 +199,6 @@ namespace OpenSim.Region.Environment.Modules.World.WorldMap
181// } 199// }
182// } 200// }
183 201
184 private Bitmap TerrainToBitmap2(Scene whichScene, Bitmap mapbmp)
185 {
186 int tc = System.Environment.TickCount;
187 m_log.Info("[MAPTILE]: Generating Maptile Step 1: Terrain");
188
189 double[,] hm = whichScene.Heightmap.GetDoubles();
190 bool ShadowDebugContinue = true;
191
192 bool terraincorruptedwarningsaid = false;
193
194 float low = 255;
195 float high = 0;
196 for (int x = 0; x < 256; x++)
197 {
198 for (int y = 0; y < 256; y++)
199 {
200 float hmval = (float)hm[x, y];
201 if (hmval < low)
202 low = hmval;
203 if (hmval > high)
204 high = hmval;
205 }
206 }
207
208 float mid = (high + low) * 0.5f;
209
210 // temporary initializer
211 float hfvalue = (float)whichScene.RegionInfo.RegionSettings.WaterHeight;
212 float hfvaluecompare = hfvalue;
213 float hfdiff = hfvalue;
214 int hfdiffi = 0;
215
216
217 for (int x = 0; x < 256; x++)
218 {
219 //int tc = System.Environment.TickCount;
220 for (int y = 0; y < 256; y++)
221 {
222 float heightvalue = (float)hm[x, y];
223
224 if (heightvalue > (float)whichScene.RegionInfo.RegionSettings.WaterHeight)
225 {
226 // scale height value
227 heightvalue = low + mid * (heightvalue - low) / mid;
228
229 if (heightvalue > 255)
230 heightvalue = 255;
231
232 if (heightvalue < 0)
233 heightvalue = 0;
234
235 if (Single.IsInfinity(heightvalue) || Single.IsNaN(heightvalue))
236 heightvalue = 0;
237
238 try
239 {
240 Color green = Color.FromArgb((int)heightvalue, 100, (int)heightvalue);
241
242 // Y flip the cordinates
243 mapbmp.SetPixel(x, (256 - y) - 1, green);
244
245 //X
246 // .
247 //
248 // Shade the terrain for shadows
249 if ((x - 1 > 0) && (y - 1 > 0))
250 {
251 hfvalue = (float)hm[x, y];
252 hfvaluecompare = (float)hm[x - 1, y - 1];
253
254 if (Single.IsInfinity(hfvalue) || Single.IsNaN(hfvalue))
255 hfvalue = 0;
256
257 if (Single.IsInfinity(hfvaluecompare) || Single.IsNaN(hfvaluecompare))
258 hfvaluecompare = 0;
259
260 hfdiff = hfvaluecompare - hfvalue;
261
262 if (hfdiff > 0.3f)
263 {
264 }
265 else if (hfdiff < -0.3f)
266 {
267 // We have to desaturate and blacken the land at the same time
268 // we use floats, colors use bytes, so shrink are space down to
269 // 0-255
270
271
272 try
273 {
274 hfdiffi = Math.Abs((int)((hfdiff * 4) + (hfdiff * 0.5))) + 1;
275 if (hfdiff % 1 != 0)
276 {
277 hfdiffi = hfdiffi + Math.Abs((int)(((hfdiff % 1) * 0.5f) * 10f) - 1);
278 }
279 }
280 catch (System.OverflowException)
281 {
282 m_log.Debug("[MAPTILE]: Shadow failed at value: " + hfdiff.ToString());
283 ShadowDebugContinue = false;
284 }
285
286 if (ShadowDebugContinue)
287 {
288 if ((256 - y) - 1 > 0)
289 {
290 Color Shade = mapbmp.GetPixel(x - 1, (256 - y) - 1);
291
292 int r = Shade.R;
293
294 int g = Shade.G;
295 int b = Shade.B;
296 Shade = Color.FromArgb((r - hfdiffi > 0) ? r - hfdiffi : 0, (g - hfdiffi > 0) ? g - hfdiffi : 0, (b - hfdiffi > 0) ? b - hfdiffi : 0);
297 mapbmp.SetPixel(x - 1, (256 - y) - 1, Shade);
298 }
299 }
300 }
301 }
302 }
303 catch (System.ArgumentException)
304 {
305 if (!terraincorruptedwarningsaid)
306 {
307 m_log.WarnFormat("[MAPIMAGE]: Your terrain is corrupted in region {0}, it might take a few minutes to generate the map image depending on the corruption level", whichScene.RegionInfo.RegionName);
308 terraincorruptedwarningsaid = true;
309 }
310 Color black = Color.Black;
311 mapbmp.SetPixel(x, (256 - y) - 1, black);
312 }
313 }
314 else
315 {
316 // We're under the water level with the terrain, so paint water instead of land
317
318 // Y flip the cordinates
319 heightvalue = (float)whichScene.RegionInfo.RegionSettings.WaterHeight - heightvalue;
320 if (heightvalue > 19)
321 heightvalue = 19;
322 if (heightvalue < 0)
323 heightvalue = 0;
324
325 heightvalue = 100 - (heightvalue * 100) / 19;
326
327 if (heightvalue > 255)
328 heightvalue = 255;
329
330 if (heightvalue < 0)
331 heightvalue = 0;
332
333 if (Single.IsInfinity(heightvalue) || Single.IsNaN(heightvalue))
334 heightvalue = 0;
335
336 try
337 {
338 Color water = Color.FromArgb((int)heightvalue, (int)heightvalue, 255);
339 mapbmp.SetPixel(x, (256 - y) - 1, water);
340 }
341 catch (System.ArgumentException)
342 {
343 if (!terraincorruptedwarningsaid)
344 {
345 m_log.WarnFormat("[MAPIMAGE]: Your terrain is corrupted in region {0}, it might take a few minutes to generate the map image depending on the corruption level", whichScene.RegionInfo.RegionName);
346 terraincorruptedwarningsaid = true;
347 }
348 Color black = Color.Black;
349 mapbmp.SetPixel(x, (256 - y) - 1, black);
350 }
351 }
352 }
353 }
354 m_log.Info("[MAPTILE]: Generating Maptile Step 1: Done in " + (System.Environment.TickCount - tc) + " ms");
355
356 return mapbmp;
357 }
358
359 private Bitmap DrawObjectVolume(Scene whichScene, Bitmap mapbmp) 202 private Bitmap DrawObjectVolume(Scene whichScene, Bitmap mapbmp)
360 { 203 {
361 int tc = 0; 204 int tc = 0;