diff options
Diffstat (limited to '')
3 files changed, 452 insertions, 347 deletions
diff --git a/OpenSim/Region/CoreModules/World/LegacyMap/MapImageModule.cs b/OpenSim/Region/CoreModules/World/LegacyMap/MapImageModule.cs index 8a422b0..796a15f 100644 --- a/OpenSim/Region/CoreModules/World/LegacyMap/MapImageModule.cs +++ b/OpenSim/Region/CoreModules/World/LegacyMap/MapImageModule.cs | |||
@@ -55,7 +55,7 @@ namespace OpenSim.Region.CoreModules.World.LegacyMap | |||
55 | public struct DrawStruct | 55 | public struct DrawStruct |
56 | { | 56 | { |
57 | public DrawRoutine dr; | 57 | public DrawRoutine dr; |
58 | public Rectangle rect; | 58 | // public Rectangle rect; |
59 | public SolidBrush brush; | 59 | public SolidBrush brush; |
60 | public face[] trns; | 60 | public face[] trns; |
61 | } | 61 | } |
@@ -77,40 +77,71 @@ namespace OpenSim.Region.CoreModules.World.LegacyMap | |||
77 | { | 77 | { |
78 | bool drawPrimVolume = true; | 78 | bool drawPrimVolume = true; |
79 | bool textureTerrain = false; | 79 | bool textureTerrain = false; |
80 | bool generateMaptiles = true; | ||
81 | Bitmap mapbmp; | ||
80 | 82 | ||
81 | try | 83 | string[] configSections = new string[] { "Map", "Startup" }; |
82 | { | ||
83 | IConfig startupConfig = m_config.Configs["Startup"]; | ||
84 | drawPrimVolume = startupConfig.GetBoolean("DrawPrimOnMapTile", drawPrimVolume); | ||
85 | textureTerrain = startupConfig.GetBoolean("TextureOnMapTile", textureTerrain); | ||
86 | } | ||
87 | catch | ||
88 | { | ||
89 | m_log.Warn("[MAPTILE]: Failed to load StartupConfig"); | ||
90 | } | ||
91 | 84 | ||
92 | if (textureTerrain) | 85 | drawPrimVolume |
93 | { | 86 | = Util.GetConfigVarFromSections<bool>(m_config, "DrawPrimOnMapTile", configSections, drawPrimVolume); |
94 | terrainRenderer = new TexturedMapTileRenderer(); | 87 | textureTerrain |
95 | } | 88 | = Util.GetConfigVarFromSections<bool>(m_config, "TextureOnMapTile", configSections, textureTerrain); |
96 | else | 89 | generateMaptiles |
90 | = Util.GetConfigVarFromSections<bool>(m_config, "GenerateMaptiles", configSections, generateMaptiles); | ||
91 | |||
92 | if (generateMaptiles) | ||
97 | { | 93 | { |
98 | terrainRenderer = new ShadedMapTileRenderer(); | 94 | if (String.IsNullOrEmpty(m_scene.RegionInfo.MaptileStaticFile)) |
99 | } | 95 | { |
100 | terrainRenderer.Initialise(m_scene, m_config); | 96 | if (textureTerrain) |
97 | { | ||
98 | terrainRenderer = new TexturedMapTileRenderer(); | ||
99 | } | ||
100 | else | ||
101 | { | ||
102 | terrainRenderer = new ShadedMapTileRenderer(); | ||
103 | } | ||
104 | |||
105 | terrainRenderer.Initialise(m_scene, m_config); | ||
101 | 106 | ||
102 | Bitmap mapbmp = new Bitmap((int)Constants.RegionSize, (int)Constants.RegionSize, System.Drawing.Imaging.PixelFormat.Format24bppRgb); | 107 | mapbmp = new Bitmap((int)m_scene.Heightmap.Width, (int)m_scene.Heightmap.Height, |
103 | //long t = System.Environment.TickCount; | 108 | System.Drawing.Imaging.PixelFormat.Format24bppRgb); |
104 | //for (int i = 0; i < 10; ++i) { | 109 | //long t = System.Environment.TickCount; |
105 | terrainRenderer.TerrainToBitmap(mapbmp); | 110 | //for (int i = 0; i < 10; ++i) { |
106 | //} | 111 | terrainRenderer.TerrainToBitmap(mapbmp); |
107 | //t = System.Environment.TickCount - t; | 112 | //} |
108 | //m_log.InfoFormat("[MAPTILE] generation of 10 maptiles needed {0} ms", t); | 113 | //t = System.Environment.TickCount - t; |
114 | //m_log.InfoFormat("[MAPTILE] generation of 10 maptiles needed {0} ms", t); | ||
109 | 115 | ||
116 | if (drawPrimVolume) | ||
117 | { | ||
118 | DrawObjectVolume(m_scene, mapbmp); | ||
119 | } | ||
120 | } | ||
121 | else | ||
122 | { | ||
123 | try | ||
124 | { | ||
125 | mapbmp = new Bitmap(m_scene.RegionInfo.MaptileStaticFile); | ||
126 | } | ||
127 | catch (Exception) | ||
128 | { | ||
129 | m_log.ErrorFormat( | ||
130 | "[MAPTILE]: Failed to load Static map image texture file: {0} for {1}", | ||
131 | m_scene.RegionInfo.MaptileStaticFile, m_scene.Name); | ||
132 | //mapbmp = new Bitmap((int)m_scene.Heightmap.Width, (int)m_scene.Heightmap.Height, System.Drawing.Imaging.PixelFormat.Format24bppRgb); | ||
133 | mapbmp = null; | ||
134 | } | ||
110 | 135 | ||
111 | if (drawPrimVolume) | 136 | if (mapbmp != null) |
137 | m_log.DebugFormat( | ||
138 | "[MAPTILE]: Static map image texture file {0} found for {1}", | ||
139 | m_scene.RegionInfo.MaptileStaticFile, m_scene.Name); | ||
140 | } | ||
141 | } | ||
142 | else | ||
112 | { | 143 | { |
113 | DrawObjectVolume(m_scene, mapbmp); | 144 | mapbmp = FetchTexture(m_scene.RegionInfo.RegionSettings.TerrainImageID); |
114 | } | 145 | } |
115 | 146 | ||
116 | return mapbmp; | 147 | return mapbmp; |
@@ -121,7 +152,10 @@ namespace OpenSim.Region.CoreModules.World.LegacyMap | |||
121 | try | 152 | try |
122 | { | 153 | { |
123 | using (Bitmap mapbmp = CreateMapTile()) | 154 | using (Bitmap mapbmp = CreateMapTile()) |
124 | return OpenJPEG.EncodeFromImage(mapbmp, true); | 155 | { |
156 | if (mapbmp != null) | ||
157 | return OpenJPEG.EncodeFromImage(mapbmp, true); | ||
158 | } | ||
125 | } | 159 | } |
126 | catch (Exception e) // LEGIT: Catching problems caused by OpenJPEG p/invoke | 160 | catch (Exception e) // LEGIT: Catching problems caused by OpenJPEG p/invoke |
127 | { | 161 | { |
@@ -139,9 +173,8 @@ namespace OpenSim.Region.CoreModules.World.LegacyMap | |||
139 | { | 173 | { |
140 | m_config = source; | 174 | m_config = source; |
141 | 175 | ||
142 | IConfig startupConfig = m_config.Configs["Startup"]; | 176 | if (Util.GetConfigVarFromSections<string>( |
143 | if (startupConfig.GetString("MapImageModule", "MapImageModule") != | 177 | m_config, "MapImageModule", new string[] { "Startup", "Map" }, "MapImageModule") != "MapImageModule") |
144 | "MapImageModule") | ||
145 | return; | 178 | return; |
146 | 179 | ||
147 | m_Enabled = true; | 180 | m_Enabled = true; |
@@ -222,342 +255,395 @@ namespace OpenSim.Region.CoreModules.World.LegacyMap | |||
222 | // } | 255 | // } |
223 | // } | 256 | // } |
224 | 257 | ||
258 | private Bitmap FetchTexture(UUID id) | ||
259 | { | ||
260 | AssetBase asset = m_scene.AssetService.Get(id.ToString()); | ||
261 | |||
262 | if (asset != null) | ||
263 | { | ||
264 | m_log.DebugFormat("[MAPTILE]: Static map image texture {0} found for {1}", id, m_scene.Name); | ||
265 | } | ||
266 | else | ||
267 | { | ||
268 | m_log.WarnFormat("[MAPTILE]: Static map image texture {0} not found for {1}", id, m_scene.Name); | ||
269 | return null; | ||
270 | } | ||
271 | |||
272 | ManagedImage managedImage; | ||
273 | Image image; | ||
274 | |||
275 | try | ||
276 | { | ||
277 | if (OpenJPEG.DecodeToImage(asset.Data, out managedImage, out image)) | ||
278 | return new Bitmap(image); | ||
279 | else | ||
280 | return null; | ||
281 | } | ||
282 | catch (DllNotFoundException) | ||
283 | { | ||
284 | m_log.ErrorFormat("[MAPTILE]: OpenJpeg is not installed correctly on this system. Asset Data is empty for {0}", id); | ||
285 | |||
286 | } | ||
287 | catch (IndexOutOfRangeException) | ||
288 | { | ||
289 | m_log.ErrorFormat("[MAPTILE]: OpenJpeg was unable to decode this. Asset Data is empty for {0}", id); | ||
290 | |||
291 | } | ||
292 | catch (Exception) | ||
293 | { | ||
294 | m_log.ErrorFormat("[MAPTILE]: OpenJpeg was unable to decode this. Asset Data is empty for {0}", id); | ||
295 | |||
296 | } | ||
297 | return null; | ||
298 | |||
299 | } | ||
300 | |||
225 | private Bitmap DrawObjectVolume(Scene whichScene, Bitmap mapbmp) | 301 | private Bitmap DrawObjectVolume(Scene whichScene, Bitmap mapbmp) |
226 | { | 302 | { |
227 | int tc = 0; | 303 | int tc = 0; |
228 | double[,] hm = whichScene.Heightmap.GetDoubles(); | 304 | ITerrainChannel hm = whichScene.Heightmap; |
229 | tc = Environment.TickCount; | 305 | tc = Environment.TickCount; |
230 | m_log.Debug("[MAPTILE]: Generating Maptile Step 2: Object Volume Profile"); | 306 | m_log.Debug("[MAPTILE]: Generating Maptile Step 2: Object Volume Profile"); |
231 | EntityBase[] objs = whichScene.GetEntities(); | 307 | EntityBase[] objs = whichScene.GetEntities(); |
232 | Dictionary<uint, DrawStruct> z_sort = new Dictionary<uint, DrawStruct>(); | ||
233 | //SortedList<float, RectangleDrawStruct> z_sort = new SortedList<float, RectangleDrawStruct>(); | ||
234 | List<float> z_sortheights = new List<float>(); | 308 | List<float> z_sortheights = new List<float>(); |
235 | List<uint> z_localIDs = new List<uint>(); | 309 | List<uint> z_localIDs = new List<uint>(); |
310 | Dictionary<uint, DrawStruct> z_sort = new Dictionary<uint, DrawStruct>(); | ||
236 | 311 | ||
237 | lock (objs) | 312 | try |
238 | { | 313 | { |
239 | foreach (EntityBase obj in objs) | 314 | lock (objs) |
240 | { | 315 | { |
241 | // Only draw the contents of SceneObjectGroup | 316 | foreach (EntityBase obj in objs) |
242 | if (obj is SceneObjectGroup) | ||
243 | { | 317 | { |
244 | SceneObjectGroup mapdot = (SceneObjectGroup)obj; | 318 | // Only draw the contents of SceneObjectGroup |
245 | Color mapdotspot = Color.Gray; // Default color when prim color is white | 319 | if (obj is SceneObjectGroup) |
246 | |||
247 | // Loop over prim in group | ||
248 | foreach (SceneObjectPart part in mapdot.Parts) | ||
249 | { | 320 | { |
250 | if (part == null) | 321 | SceneObjectGroup mapdot = (SceneObjectGroup)obj; |
251 | continue; | 322 | Color mapdotspot = Color.Gray; // Default color when prim color is white |
252 | 323 | // Loop over prim in group | |
253 | // Draw if the object is at least 1 meter wide in any direction | 324 | foreach (SceneObjectPart part in mapdot.Parts) |
254 | if (part.Scale.X > 1f || part.Scale.Y > 1f || part.Scale.Z > 1f) | ||
255 | { | 325 | { |
256 | // Try to get the RGBA of the default texture entry.. | 326 | if (part == null) |
257 | // | 327 | continue; |
258 | try | 328 | |
329 | // Draw if the object is at least 1 meter wide in any direction | ||
330 | if (part.Scale.X > 1f || part.Scale.Y > 1f || part.Scale.Z > 1f) | ||
259 | { | 331 | { |
260 | // get the null checks out of the way | 332 | // Try to get the RGBA of the default texture entry.. |
261 | // skip the ones that break | 333 | // |
262 | if (part == null) | 334 | try |
263 | continue; | 335 | { |
336 | // get the null checks out of the way | ||
337 | // skip the ones that break | ||
338 | if (part == null) | ||
339 | continue; | ||
264 | 340 | ||
265 | if (part.Shape == null) | 341 | if (part.Shape == null) |
266 | continue; | 342 | continue; |
267 | 343 | ||
268 | if (part.Shape.PCode == (byte)PCode.Tree || part.Shape.PCode == (byte)PCode.NewTree || part.Shape.PCode == (byte)PCode.Grass) | 344 | if (part.Shape.PCode == (byte)PCode.Tree || part.Shape.PCode == (byte)PCode.NewTree || part.Shape.PCode == (byte)PCode.Grass) |
269 | continue; // eliminates trees from this since we don't really have a good tree representation | 345 | continue; // eliminates trees from this since we don't really have a good tree representation |
270 | // if you want tree blocks on the map comment the above line and uncomment the below line | 346 | // if you want tree blocks on the map comment the above line and uncomment the below line |
271 | //mapdotspot = Color.PaleGreen; | 347 | //mapdotspot = Color.PaleGreen; |
272 | 348 | ||
273 | Primitive.TextureEntry textureEntry = part.Shape.Textures; | 349 | Primitive.TextureEntry textureEntry = part.Shape.Textures; |
274 | 350 | ||
275 | if (textureEntry == null || textureEntry.DefaultTexture == null) | 351 | if (textureEntry == null || textureEntry.DefaultTexture == null) |
276 | continue; | 352 | continue; |
277 | 353 | ||
278 | Color4 texcolor = textureEntry.DefaultTexture.RGBA; | 354 | Color4 texcolor = textureEntry.DefaultTexture.RGBA; |
279 | 355 | ||
280 | // Not sure why some of these are null, oh well. | 356 | // Not sure why some of these are null, oh well. |
281 | 357 | ||
282 | int colorr = 255 - (int)(texcolor.R * 255f); | 358 | int colorr = 255 - (int)(texcolor.R * 255f); |
283 | int colorg = 255 - (int)(texcolor.G * 255f); | 359 | int colorg = 255 - (int)(texcolor.G * 255f); |
284 | int colorb = 255 - (int)(texcolor.B * 255f); | 360 | int colorb = 255 - (int)(texcolor.B * 255f); |
285 | 361 | ||
286 | if (!(colorr == 255 && colorg == 255 && colorb == 255)) | 362 | if (!(colorr == 255 && colorg == 255 && colorb == 255)) |
287 | { | ||
288 | //Try to set the map spot color | ||
289 | try | ||
290 | { | ||
291 | // If the color gets goofy somehow, skip it *shakes fist at Color4 | ||
292 | mapdotspot = Color.FromArgb(colorr, colorg, colorb); | ||
293 | } | ||
294 | catch (ArgumentException) | ||
295 | { | 363 | { |
364 | //Try to set the map spot color | ||
365 | try | ||
366 | { | ||
367 | // If the color gets goofy somehow, skip it *shakes fist at Color4 | ||
368 | mapdotspot = Color.FromArgb(colorr, colorg, colorb); | ||
369 | } | ||
370 | catch (ArgumentException) | ||
371 | { | ||
372 | } | ||
296 | } | 373 | } |
297 | } | 374 | } |
298 | } | 375 | catch (IndexOutOfRangeException) |
299 | catch (IndexOutOfRangeException) | 376 | { |
300 | { | 377 | // Windows Array |
301 | // Windows Array | 378 | } |
302 | } | 379 | catch (ArgumentOutOfRangeException) |
303 | catch (ArgumentOutOfRangeException) | 380 | { |
304 | { | 381 | // Mono Array |
305 | // Mono Array | 382 | } |
306 | } | ||
307 | |||
308 | Vector3 pos = part.GetWorldPosition(); | ||
309 | |||
310 | // skip prim outside of retion | ||
311 | if (pos.X < 0f || pos.X > 256f || pos.Y < 0f || pos.Y > 256f) | ||
312 | continue; | ||
313 | |||
314 | // skip prim in non-finite position | ||
315 | if (Single.IsNaN(pos.X) || Single.IsNaN(pos.Y) || | ||
316 | Single.IsInfinity(pos.X) || Single.IsInfinity(pos.Y)) | ||
317 | continue; | ||
318 | |||
319 | // Figure out if object is under 256m above the height of the terrain | ||
320 | bool isBelow256AboveTerrain = false; | ||
321 | 383 | ||
322 | try | 384 | Vector3 pos = part.GetWorldPosition(); |
323 | { | ||
324 | isBelow256AboveTerrain = (pos.Z < ((float)hm[(int)pos.X, (int)pos.Y] + 256f)); | ||
325 | } | ||
326 | catch (Exception) | ||
327 | { | ||
328 | } | ||
329 | 385 | ||
330 | if (isBelow256AboveTerrain) | 386 | // skip prim outside of retion |
331 | { | 387 | if (!m_scene.PositionIsInCurrentRegion(pos)) |
332 | // Translate scale by rotation so scale is represented properly when object is rotated | ||
333 | Vector3 lscale = new Vector3(part.Shape.Scale.X, part.Shape.Scale.Y, part.Shape.Scale.Z); | ||
334 | Vector3 scale = new Vector3(); | ||
335 | Vector3 tScale = new Vector3(); | ||
336 | Vector3 axPos = new Vector3(pos.X,pos.Y,pos.Z); | ||
337 | |||
338 | Quaternion llrot = part.GetWorldRotation(); | ||
339 | Quaternion rot = new Quaternion(llrot.W, llrot.X, llrot.Y, llrot.Z); | ||
340 | scale = lscale * rot; | ||
341 | |||
342 | // negative scales don't work in this situation | ||
343 | scale.X = Math.Abs(scale.X); | ||
344 | scale.Y = Math.Abs(scale.Y); | ||
345 | scale.Z = Math.Abs(scale.Z); | ||
346 | |||
347 | // This scaling isn't very accurate and doesn't take into account the face rotation :P | ||
348 | int mapdrawstartX = (int)(pos.X - scale.X); | ||
349 | int mapdrawstartY = (int)(pos.Y - scale.Y); | ||
350 | int mapdrawendX = (int)(pos.X + scale.X); | ||
351 | int mapdrawendY = (int)(pos.Y + scale.Y); | ||
352 | |||
353 | // If object is beyond the edge of the map, don't draw it to avoid errors | ||
354 | if (mapdrawstartX < 0 || mapdrawstartX > ((int)Constants.RegionSize - 1) || mapdrawendX < 0 || mapdrawendX > ((int)Constants.RegionSize - 1) | ||
355 | || mapdrawstartY < 0 || mapdrawstartY > ((int)Constants.RegionSize - 1) || mapdrawendY < 0 | ||
356 | || mapdrawendY > ((int)Constants.RegionSize - 1)) | ||
357 | continue; | 388 | continue; |
358 | 389 | ||
359 | #region obb face reconstruction part duex | 390 | // skip prim in non-finite position |
360 | Vector3[] vertexes = new Vector3[8]; | 391 | if (Single.IsNaN(pos.X) || Single.IsNaN(pos.Y) || |
361 | 392 | Single.IsInfinity(pos.X) || Single.IsInfinity(pos.Y)) | |
362 | // float[] distance = new float[6]; | 393 | continue; |
363 | Vector3[] FaceA = new Vector3[6]; // vertex A for Facei | ||
364 | Vector3[] FaceB = new Vector3[6]; // vertex B for Facei | ||
365 | Vector3[] FaceC = new Vector3[6]; // vertex C for Facei | ||
366 | Vector3[] FaceD = new Vector3[6]; // vertex D for Facei | ||
367 | |||
368 | tScale = new Vector3(lscale.X, -lscale.Y, lscale.Z); | ||
369 | scale = ((tScale * rot)); | ||
370 | vertexes[0] = (new Vector3((pos.X + scale.X), (pos.Y + scale.Y), (pos.Z + scale.Z))); | ||
371 | // vertexes[0].x = pos.X + vertexes[0].x; | ||
372 | //vertexes[0].y = pos.Y + vertexes[0].y; | ||
373 | //vertexes[0].z = pos.Z + vertexes[0].z; | ||
374 | |||
375 | FaceA[0] = vertexes[0]; | ||
376 | FaceB[3] = vertexes[0]; | ||
377 | FaceA[4] = vertexes[0]; | ||
378 | |||
379 | tScale = lscale; | ||
380 | scale = ((tScale * rot)); | ||
381 | vertexes[1] = (new Vector3((pos.X + scale.X), (pos.Y + scale.Y), (pos.Z + scale.Z))); | ||
382 | |||
383 | // vertexes[1].x = pos.X + vertexes[1].x; | ||
384 | // vertexes[1].y = pos.Y + vertexes[1].y; | ||
385 | //vertexes[1].z = pos.Z + vertexes[1].z; | ||
386 | |||
387 | FaceB[0] = vertexes[1]; | ||
388 | FaceA[1] = vertexes[1]; | ||
389 | FaceC[4] = vertexes[1]; | ||
390 | |||
391 | tScale = new Vector3(lscale.X, -lscale.Y, -lscale.Z); | ||
392 | scale = ((tScale * rot)); | ||
393 | |||
394 | vertexes[2] = (new Vector3((pos.X + scale.X), (pos.Y + scale.Y), (pos.Z + scale.Z))); | ||
395 | |||
396 | //vertexes[2].x = pos.X + vertexes[2].x; | ||
397 | //vertexes[2].y = pos.Y + vertexes[2].y; | ||
398 | //vertexes[2].z = pos.Z + vertexes[2].z; | ||
399 | |||
400 | FaceC[0] = vertexes[2]; | ||
401 | FaceD[3] = vertexes[2]; | ||
402 | FaceC[5] = vertexes[2]; | ||
403 | |||
404 | tScale = new Vector3(lscale.X, lscale.Y, -lscale.Z); | ||
405 | scale = ((tScale * rot)); | ||
406 | vertexes[3] = (new Vector3((pos.X + scale.X), (pos.Y + scale.Y), (pos.Z + scale.Z))); | ||
407 | |||
408 | //vertexes[3].x = pos.X + vertexes[3].x; | ||
409 | // vertexes[3].y = pos.Y + vertexes[3].y; | ||
410 | // vertexes[3].z = pos.Z + vertexes[3].z; | ||
411 | |||
412 | FaceD[0] = vertexes[3]; | ||
413 | FaceC[1] = vertexes[3]; | ||
414 | FaceA[5] = vertexes[3]; | ||
415 | |||
416 | tScale = new Vector3(-lscale.X, lscale.Y, lscale.Z); | ||
417 | scale = ((tScale * rot)); | ||
418 | vertexes[4] = (new Vector3((pos.X + scale.X), (pos.Y + scale.Y), (pos.Z + scale.Z))); | ||
419 | |||
420 | // vertexes[4].x = pos.X + vertexes[4].x; | ||
421 | // vertexes[4].y = pos.Y + vertexes[4].y; | ||
422 | // vertexes[4].z = pos.Z + vertexes[4].z; | ||
423 | |||
424 | FaceB[1] = vertexes[4]; | ||
425 | FaceA[2] = vertexes[4]; | ||
426 | FaceD[4] = vertexes[4]; | ||
427 | |||
428 | tScale = new Vector3(-lscale.X, lscale.Y, -lscale.Z); | ||
429 | scale = ((tScale * rot)); | ||
430 | vertexes[5] = (new Vector3((pos.X + scale.X), (pos.Y + scale.Y), (pos.Z + scale.Z))); | ||
431 | |||
432 | // vertexes[5].x = pos.X + vertexes[5].x; | ||
433 | // vertexes[5].y = pos.Y + vertexes[5].y; | ||
434 | // vertexes[5].z = pos.Z + vertexes[5].z; | ||
435 | |||
436 | FaceD[1] = vertexes[5]; | ||
437 | FaceC[2] = vertexes[5]; | ||
438 | FaceB[5] = vertexes[5]; | ||
439 | |||
440 | tScale = new Vector3(-lscale.X, -lscale.Y, lscale.Z); | ||
441 | scale = ((tScale * rot)); | ||
442 | vertexes[6] = (new Vector3((pos.X + scale.X), (pos.Y + scale.Y), (pos.Z + scale.Z))); | ||
443 | 394 | ||
444 | // vertexes[6].x = pos.X + vertexes[6].x; | 395 | // Figure out if object is under 256m above the height of the terrain |
445 | // vertexes[6].y = pos.Y + vertexes[6].y; | 396 | bool isBelow256AboveTerrain = false; |
446 | // vertexes[6].z = pos.Z + vertexes[6].z; | ||
447 | 397 | ||
448 | FaceB[2] = vertexes[6]; | 398 | try |
449 | FaceA[3] = vertexes[6]; | 399 | { |
450 | FaceB[4] = vertexes[6]; | 400 | isBelow256AboveTerrain = (pos.Z < ((float)hm[(int)pos.X, (int)pos.Y] + 256f)); |
401 | } | ||
402 | catch (Exception) | ||
403 | { | ||
404 | } | ||
451 | 405 | ||
452 | tScale = new Vector3(-lscale.X, -lscale.Y, -lscale.Z); | 406 | if (isBelow256AboveTerrain) |
453 | scale = ((tScale * rot)); | 407 | { |
454 | vertexes[7] = (new Vector3((pos.X + scale.X), (pos.Y + scale.Y), (pos.Z + scale.Z))); | 408 | // Translate scale by rotation so scale is represented properly when object is rotated |
409 | Vector3 lscale = new Vector3(part.Shape.Scale.X, part.Shape.Scale.Y, part.Shape.Scale.Z); | ||
410 | Vector3 scale = new Vector3(); | ||
411 | Vector3 tScale = new Vector3(); | ||
412 | Vector3 axPos = new Vector3(pos.X, pos.Y, pos.Z); | ||
413 | |||
414 | Quaternion llrot = part.GetWorldRotation(); | ||
415 | Quaternion rot = new Quaternion(llrot.W, llrot.X, llrot.Y, llrot.Z); | ||
416 | scale = lscale * rot; | ||
417 | |||
418 | // negative scales don't work in this situation | ||
419 | scale.X = Math.Abs(scale.X); | ||
420 | scale.Y = Math.Abs(scale.Y); | ||
421 | scale.Z = Math.Abs(scale.Z); | ||
422 | |||
423 | // This scaling isn't very accurate and doesn't take into account the face rotation :P | ||
424 | int mapdrawstartX = (int)(pos.X - scale.X); | ||
425 | int mapdrawstartY = (int)(pos.Y - scale.Y); | ||
426 | int mapdrawendX = (int)(pos.X + scale.X); | ||
427 | int mapdrawendY = (int)(pos.Y + scale.Y); | ||
428 | |||
429 | // If object is beyond the edge of the map, don't draw it to avoid errors | ||
430 | if (mapdrawstartX < 0 | ||
431 | || mapdrawstartX > (hm.Width - 1) | ||
432 | || mapdrawendX < 0 | ||
433 | || mapdrawendX > (hm.Width - 1) | ||
434 | || mapdrawstartY < 0 | ||
435 | || mapdrawstartY > (hm.Height - 1) | ||
436 | || mapdrawendY < 0 | ||
437 | || mapdrawendY > (hm.Height - 1)) | ||
438 | continue; | ||
439 | |||
440 | #region obb face reconstruction part duex | ||
441 | Vector3[] vertexes = new Vector3[8]; | ||
442 | |||
443 | // float[] distance = new float[6]; | ||
444 | Vector3[] FaceA = new Vector3[6]; // vertex A for Facei | ||
445 | Vector3[] FaceB = new Vector3[6]; // vertex B for Facei | ||
446 | Vector3[] FaceC = new Vector3[6]; // vertex C for Facei | ||
447 | Vector3[] FaceD = new Vector3[6]; // vertex D for Facei | ||
448 | |||
449 | tScale = new Vector3(lscale.X, -lscale.Y, lscale.Z); | ||
450 | scale = ((tScale * rot)); | ||
451 | vertexes[0] = (new Vector3((pos.X + scale.X), (pos.Y + scale.Y), (pos.Z + scale.Z))); | ||
452 | // vertexes[0].x = pos.X + vertexes[0].x; | ||
453 | //vertexes[0].y = pos.Y + vertexes[0].y; | ||
454 | //vertexes[0].z = pos.Z + vertexes[0].z; | ||
455 | |||
456 | FaceA[0] = vertexes[0]; | ||
457 | FaceB[3] = vertexes[0]; | ||
458 | FaceA[4] = vertexes[0]; | ||
459 | |||
460 | tScale = lscale; | ||
461 | scale = ((tScale * rot)); | ||
462 | vertexes[1] = (new Vector3((pos.X + scale.X), (pos.Y + scale.Y), (pos.Z + scale.Z))); | ||
463 | |||
464 | // vertexes[1].x = pos.X + vertexes[1].x; | ||
465 | // vertexes[1].y = pos.Y + vertexes[1].y; | ||
466 | //vertexes[1].z = pos.Z + vertexes[1].z; | ||
467 | |||
468 | FaceB[0] = vertexes[1]; | ||
469 | FaceA[1] = vertexes[1]; | ||
470 | FaceC[4] = vertexes[1]; | ||
471 | |||
472 | tScale = new Vector3(lscale.X, -lscale.Y, -lscale.Z); | ||
473 | scale = ((tScale * rot)); | ||
474 | |||
475 | vertexes[2] = (new Vector3((pos.X + scale.X), (pos.Y + scale.Y), (pos.Z + scale.Z))); | ||
476 | |||
477 | //vertexes[2].x = pos.X + vertexes[2].x; | ||
478 | //vertexes[2].y = pos.Y + vertexes[2].y; | ||
479 | //vertexes[2].z = pos.Z + vertexes[2].z; | ||
480 | |||
481 | FaceC[0] = vertexes[2]; | ||
482 | FaceD[3] = vertexes[2]; | ||
483 | FaceC[5] = vertexes[2]; | ||
484 | |||
485 | tScale = new Vector3(lscale.X, lscale.Y, -lscale.Z); | ||
486 | scale = ((tScale * rot)); | ||
487 | vertexes[3] = (new Vector3((pos.X + scale.X), (pos.Y + scale.Y), (pos.Z + scale.Z))); | ||
488 | |||
489 | //vertexes[3].x = pos.X + vertexes[3].x; | ||
490 | // vertexes[3].y = pos.Y + vertexes[3].y; | ||
491 | // vertexes[3].z = pos.Z + vertexes[3].z; | ||
492 | |||
493 | FaceD[0] = vertexes[3]; | ||
494 | FaceC[1] = vertexes[3]; | ||
495 | FaceA[5] = vertexes[3]; | ||
496 | |||
497 | tScale = new Vector3(-lscale.X, lscale.Y, lscale.Z); | ||
498 | scale = ((tScale * rot)); | ||
499 | vertexes[4] = (new Vector3((pos.X + scale.X), (pos.Y + scale.Y), (pos.Z + scale.Z))); | ||
500 | |||
501 | // vertexes[4].x = pos.X + vertexes[4].x; | ||
502 | // vertexes[4].y = pos.Y + vertexes[4].y; | ||
503 | // vertexes[4].z = pos.Z + vertexes[4].z; | ||
504 | |||
505 | FaceB[1] = vertexes[4]; | ||
506 | FaceA[2] = vertexes[4]; | ||
507 | FaceD[4] = vertexes[4]; | ||
508 | |||
509 | tScale = new Vector3(-lscale.X, lscale.Y, -lscale.Z); | ||
510 | scale = ((tScale * rot)); | ||
511 | vertexes[5] = (new Vector3((pos.X + scale.X), (pos.Y + scale.Y), (pos.Z + scale.Z))); | ||
512 | |||
513 | // vertexes[5].x = pos.X + vertexes[5].x; | ||
514 | // vertexes[5].y = pos.Y + vertexes[5].y; | ||
515 | // vertexes[5].z = pos.Z + vertexes[5].z; | ||
516 | |||
517 | FaceD[1] = vertexes[5]; | ||
518 | FaceC[2] = vertexes[5]; | ||
519 | FaceB[5] = vertexes[5]; | ||
520 | |||
521 | tScale = new Vector3(-lscale.X, -lscale.Y, lscale.Z); | ||
522 | scale = ((tScale * rot)); | ||
523 | vertexes[6] = (new Vector3((pos.X + scale.X), (pos.Y + scale.Y), (pos.Z + scale.Z))); | ||
524 | |||
525 | // vertexes[6].x = pos.X + vertexes[6].x; | ||
526 | // vertexes[6].y = pos.Y + vertexes[6].y; | ||
527 | // vertexes[6].z = pos.Z + vertexes[6].z; | ||
528 | |||
529 | FaceB[2] = vertexes[6]; | ||
530 | FaceA[3] = vertexes[6]; | ||
531 | FaceB[4] = vertexes[6]; | ||
532 | |||
533 | tScale = new Vector3(-lscale.X, -lscale.Y, -lscale.Z); | ||
534 | scale = ((tScale * rot)); | ||
535 | vertexes[7] = (new Vector3((pos.X + scale.X), (pos.Y + scale.Y), (pos.Z + scale.Z))); | ||
455 | 536 | ||
456 | // vertexes[7].x = pos.X + vertexes[7].x; | 537 | // vertexes[7].x = pos.X + vertexes[7].x; |
457 | // vertexes[7].y = pos.Y + vertexes[7].y; | 538 | // vertexes[7].y = pos.Y + vertexes[7].y; |
458 | // vertexes[7].z = pos.Z + vertexes[7].z; | 539 | // vertexes[7].z = pos.Z + vertexes[7].z; |
459 | 540 | ||
460 | FaceD[2] = vertexes[7]; | 541 | FaceD[2] = vertexes[7]; |
461 | FaceC[3] = vertexes[7]; | 542 | FaceC[3] = vertexes[7]; |
462 | FaceD[5] = vertexes[7]; | 543 | FaceD[5] = vertexes[7]; |
463 | #endregion | 544 | #endregion |
464 | 545 | ||
465 | //int wy = 0; | 546 | //int wy = 0; |
466 | 547 | ||
467 | //bool breakYN = false; // If we run into an error drawing, break out of the | 548 | //bool breakYN = false; // If we run into an error drawing, break out of the |
468 | // loop so we don't lag to death on error handling | 549 | // loop so we don't lag to death on error handling |
469 | DrawStruct ds = new DrawStruct(); | 550 | DrawStruct ds = new DrawStruct(); |
470 | ds.brush = new SolidBrush(mapdotspot); | 551 | ds.brush = new SolidBrush(mapdotspot); |
471 | //ds.rect = new Rectangle(mapdrawstartX, (255 - mapdrawstartY), mapdrawendX - mapdrawstartX, mapdrawendY - mapdrawstartY); | 552 | //ds.rect = new Rectangle(mapdrawstartX, (255 - mapdrawstartY), mapdrawendX - mapdrawstartX, mapdrawendY - mapdrawstartY); |
472 | 553 | ||
473 | ds.trns = new face[FaceA.Length]; | 554 | ds.trns = new face[FaceA.Length]; |
474 | 555 | ||
475 | for (int i = 0; i < FaceA.Length; i++) | 556 | for (int i = 0; i < FaceA.Length; i++) |
476 | { | 557 | { |
477 | Point[] working = new Point[5]; | 558 | Point[] working = new Point[5]; |
478 | working[0] = project(FaceA[i], axPos); | 559 | working[0] = project(hm, FaceA[i], axPos); |
479 | working[1] = project(FaceB[i], axPos); | 560 | working[1] = project(hm, FaceB[i], axPos); |
480 | working[2] = project(FaceD[i], axPos); | 561 | working[2] = project(hm, FaceD[i], axPos); |
481 | working[3] = project(FaceC[i], axPos); | 562 | working[3] = project(hm, FaceC[i], axPos); |
482 | working[4] = project(FaceA[i], axPos); | 563 | working[4] = project(hm, FaceA[i], axPos); |
483 | 564 | ||
484 | face workingface = new face(); | 565 | face workingface = new face(); |
485 | workingface.pts = working; | 566 | workingface.pts = working; |
486 | 567 | ||
487 | ds.trns[i] = workingface; | 568 | ds.trns[i] = workingface; |
488 | } | 569 | } |
489 | 570 | ||
490 | z_sort.Add(part.LocalId, ds); | 571 | z_sort.Add(part.LocalId, ds); |
491 | z_localIDs.Add(part.LocalId); | 572 | z_localIDs.Add(part.LocalId); |
492 | z_sortheights.Add(pos.Z); | 573 | z_sortheights.Add(pos.Z); |
493 | 574 | ||
494 | //for (int wx = mapdrawstartX; wx < mapdrawendX; wx++) | 575 | // for (int wx = mapdrawstartX; wx < mapdrawendX; wx++) |
495 | //{ | 576 | // { |
496 | //for (wy = mapdrawstartY; wy < mapdrawendY; wy++) | 577 | // for (wy = mapdrawstartY; wy < mapdrawendY; wy++) |
497 | //{ | 578 | // { |
498 | //m_log.InfoFormat("[MAPDEBUG]: {0},{1}({2})", wx, (255 - wy),wy); | 579 | // m_log.InfoFormat("[MAPDEBUG]: {0},{1}({2})", wx, (255 - wy),wy); |
499 | //try | 580 | // try |
500 | //{ | 581 | // { |
501 | // Remember, flip the y! | 582 | // // Remember, flip the y! |
502 | // mapbmp.SetPixel(wx, (255 - wy), mapdotspot); | 583 | // mapbmp.SetPixel(wx, (255 - wy), mapdotspot); |
503 | //} | 584 | // } |
504 | //catch (ArgumentException) | 585 | // catch (ArgumentException) |
505 | //{ | 586 | // { |
506 | // breakYN = true; | 587 | // breakYN = true; |
507 | //} | 588 | // } |
508 | 589 | // } | |
509 | //if (breakYN) | 590 | // if (breakYN) |
510 | // break; | 591 | // break; |
592 | // } | ||
593 | // } | ||
511 | //} | 594 | //} |
595 | } // Object is within 256m Z of terrain | ||
596 | } // object is at least a meter wide | ||
597 | } // loop over group children | ||
598 | } // entitybase is sceneobject group | ||
599 | } // foreach loop over entities | ||
512 | 600 | ||
513 | //if (breakYN) | 601 | float[] sortedZHeights = z_sortheights.ToArray(); |
514 | // break; | 602 | uint[] sortedlocalIds = z_localIDs.ToArray(); |
515 | //} | ||
516 | } // Object is within 256m Z of terrain | ||
517 | } // object is at least a meter wide | ||
518 | } // loop over group children | ||
519 | } // entitybase is sceneobject group | ||
520 | } // foreach loop over entities | ||
521 | 603 | ||
522 | float[] sortedZHeights = z_sortheights.ToArray(); | 604 | // Sort prim by Z position |
523 | uint[] sortedlocalIds = z_localIDs.ToArray(); | 605 | Array.Sort(sortedZHeights, sortedlocalIds); |
524 | 606 | ||
525 | // Sort prim by Z position | 607 | using (Graphics g = Graphics.FromImage(mapbmp)) |
526 | Array.Sort(sortedZHeights, sortedlocalIds); | ||
527 | |||
528 | Graphics g = Graphics.FromImage(mapbmp); | ||
529 | |||
530 | for (int s = 0; s < sortedZHeights.Length; s++) | ||
531 | { | ||
532 | if (z_sort.ContainsKey(sortedlocalIds[s])) | ||
533 | { | 608 | { |
534 | DrawStruct rectDrawStruct = z_sort[sortedlocalIds[s]]; | 609 | for (int s = 0; s < sortedZHeights.Length; s++) |
535 | for (int r = 0; r < rectDrawStruct.trns.Length; r++) | ||
536 | { | 610 | { |
537 | g.FillPolygon(rectDrawStruct.brush,rectDrawStruct.trns[r].pts); | 611 | if (z_sort.ContainsKey(sortedlocalIds[s])) |
612 | { | ||
613 | DrawStruct rectDrawStruct = z_sort[sortedlocalIds[s]]; | ||
614 | for (int r = 0; r < rectDrawStruct.trns.Length; r++) | ||
615 | { | ||
616 | g.FillPolygon(rectDrawStruct.brush,rectDrawStruct.trns[r].pts); | ||
617 | } | ||
618 | //g.FillRectangle(rectDrawStruct.brush , rectDrawStruct.rect); | ||
619 | } | ||
538 | } | 620 | } |
539 | //g.FillRectangle(rectDrawStruct.brush , rectDrawStruct.rect); | ||
540 | } | 621 | } |
541 | } | 622 | } // lock entities objs |
542 | 623 | ||
543 | g.Dispose(); | 624 | } |
544 | } // lock entities objs | 625 | finally |
626 | { | ||
627 | foreach (DrawStruct ds in z_sort.Values) | ||
628 | ds.brush.Dispose(); | ||
629 | } | ||
545 | 630 | ||
546 | m_log.Debug("[MAPTILE]: Generating Maptile Step 2: Done in " + (Environment.TickCount - tc) + " ms"); | 631 | m_log.Debug("[MAPTILE]: Generating Maptile Step 2: Done in " + (Environment.TickCount - tc) + " ms"); |
632 | |||
547 | return mapbmp; | 633 | return mapbmp; |
548 | } | 634 | } |
549 | 635 | ||
550 | private Point project(Vector3 point3d, Vector3 originpos) | 636 | private Point project(ITerrainChannel hm, Vector3 point3d, Vector3 originpos) |
551 | { | 637 | { |
552 | Point returnpt = new Point(); | 638 | Point returnpt = new Point(); |
553 | //originpos = point3d; | 639 | //originpos = point3d; |
554 | //int d = (int)(256f / 1.5f); | 640 | //int d = (int)(256f / 1.5f); |
555 | 641 | ||
556 | //Vector3 topos = new Vector3(0, 0, 0); | 642 | //Vector3 topos = new Vector3(0, 0, 0); |
557 | // float z = -point3d.z - topos.z; | 643 | // float z = -point3d.z - topos.z; |
558 | 644 | ||
559 | returnpt.X = (int)point3d.X;//(int)((topos.x - point3d.x) / z * d); | 645 | returnpt.X = (int)point3d.X;//(int)((topos.x - point3d.x) / z * d); |
560 | returnpt.Y = (int)(((int)Constants.RegionSize - 1) - point3d.Y);//(int)(255 - (((topos.y - point3d.y) / z * d))); | 646 | returnpt.Y = (int)((hm.Width - 1) - point3d.Y);//(int)(255 - (((topos.y - point3d.y) / z * d))); |
561 | 647 | ||
562 | return returnpt; | 648 | return returnpt; |
563 | } | 649 | } |
diff --git a/OpenSim/Region/CoreModules/World/LegacyMap/ShadedMapTileRenderer.cs b/OpenSim/Region/CoreModules/World/LegacyMap/ShadedMapTileRenderer.cs index 992bff3..708286c 100644 --- a/OpenSim/Region/CoreModules/World/LegacyMap/ShadedMapTileRenderer.cs +++ b/OpenSim/Region/CoreModules/World/LegacyMap/ShadedMapTileRenderer.cs | |||
@@ -31,6 +31,7 @@ using System.Reflection; | |||
31 | using log4net; | 31 | using log4net; |
32 | using Nini.Config; | 32 | using Nini.Config; |
33 | using OpenSim.Framework; | 33 | using OpenSim.Framework; |
34 | using OpenSim.Region.Framework.Interfaces; | ||
34 | using OpenSim.Region.Framework.Scenes; | 35 | using OpenSim.Region.Framework.Scenes; |
35 | 36 | ||
36 | namespace OpenSim.Region.CoreModules.World.LegacyMap | 37 | namespace OpenSim.Region.CoreModules.World.LegacyMap |
@@ -39,8 +40,8 @@ namespace OpenSim.Region.CoreModules.World.LegacyMap | |||
39 | { | 40 | { |
40 | private static readonly Color WATER_COLOR = Color.FromArgb(29, 71, 95); | 41 | private static readonly Color WATER_COLOR = Color.FromArgb(29, 71, 95); |
41 | 42 | ||
42 | private static readonly ILog m_log = | 43 | private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); |
43 | LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); | 44 | private static readonly string LogHeader = "[SHADED MAPTILE RENDERER]"; |
44 | 45 | ||
45 | private Scene m_scene; | 46 | private Scene m_scene; |
46 | //private IConfigSource m_config; // not used currently | 47 | //private IConfigSource m_config; // not used currently |
@@ -53,19 +54,26 @@ namespace OpenSim.Region.CoreModules.World.LegacyMap | |||
53 | 54 | ||
54 | public void TerrainToBitmap(Bitmap mapbmp) | 55 | public void TerrainToBitmap(Bitmap mapbmp) |
55 | { | 56 | { |
57 | m_log.DebugFormat("{0} Generating Maptile Step 1: Terrain", LogHeader); | ||
56 | int tc = Environment.TickCount; | 58 | int tc = Environment.TickCount; |
57 | m_log.Debug("[MAPTILE]: Generating Maptile Step 1: Terrain"); | ||
58 | 59 | ||
59 | double[,] hm = m_scene.Heightmap.GetDoubles(); | 60 | ITerrainChannel hm = m_scene.Heightmap; |
61 | |||
62 | if (mapbmp.Width != hm.Width || mapbmp.Height != hm.Height) | ||
63 | { | ||
64 | m_log.ErrorFormat("{0} TerrainToBitmap. Passed bitmap wrong dimensions. passed=<{1},{2}>, size=<{3},{4}>", | ||
65 | LogHeader, mapbmp.Width, mapbmp.Height, hm.Width, hm.Height); | ||
66 | } | ||
67 | |||
60 | bool ShadowDebugContinue = true; | 68 | bool ShadowDebugContinue = true; |
61 | 69 | ||
62 | bool terraincorruptedwarningsaid = false; | 70 | bool terraincorruptedwarningsaid = false; |
63 | 71 | ||
64 | float low = 255; | 72 | float low = 255; |
65 | float high = 0; | 73 | float high = 0; |
66 | for (int x = 0; x < (int)Constants.RegionSize; x++) | 74 | for (int x = 0; x < hm.Width; x++) |
67 | { | 75 | { |
68 | for (int y = 0; y < (int)Constants.RegionSize; y++) | 76 | for (int y = 0; y < hm.Height; y++) |
69 | { | 77 | { |
70 | float hmval = (float)hm[x, y]; | 78 | float hmval = (float)hm[x, y]; |
71 | if (hmval < low) | 79 | if (hmval < low) |
@@ -77,12 +85,12 @@ namespace OpenSim.Region.CoreModules.World.LegacyMap | |||
77 | 85 | ||
78 | float waterHeight = (float)m_scene.RegionInfo.RegionSettings.WaterHeight; | 86 | float waterHeight = (float)m_scene.RegionInfo.RegionSettings.WaterHeight; |
79 | 87 | ||
80 | for (int x = 0; x < (int)Constants.RegionSize; x++) | 88 | for (int x = 0; x < hm.Width; x++) |
81 | { | 89 | { |
82 | for (int y = 0; y < (int)Constants.RegionSize; y++) | 90 | for (int y = 0; y < hm.Height; y++) |
83 | { | 91 | { |
84 | // Y flip the cordinates for the bitmap: hf origin is lower left, bm origin is upper left | 92 | // Y flip the cordinates for the bitmap: hf origin is lower left, bm origin is upper left |
85 | int yr = ((int)Constants.RegionSize - 1) - y; | 93 | int yr = ((int)hm.Height - 1) - y; |
86 | 94 | ||
87 | float heightvalue = (float)hm[x, y]; | 95 | float heightvalue = (float)hm[x, y]; |
88 | 96 | ||
@@ -109,12 +117,12 @@ namespace OpenSim.Region.CoreModules.World.LegacyMap | |||
109 | // . | 117 | // . |
110 | // | 118 | // |
111 | // Shade the terrain for shadows | 119 | // Shade the terrain for shadows |
112 | if (x < ((int)Constants.RegionSize - 1) && yr < ((int)Constants.RegionSize - 1)) | 120 | if (x < (hm.Width - 1) && yr < (hm.Height - 1)) |
113 | { | 121 | { |
114 | float hfvalue = (float)hm[x, y]; | 122 | float hfvalue = (float)hm[x, y]; |
115 | float hfvaluecompare = 0f; | 123 | float hfvaluecompare = 0f; |
116 | 124 | ||
117 | if ((x + 1 < (int)Constants.RegionSize) && (y + 1 < (int)Constants.RegionSize)) | 125 | if ((x + 1 < hm.Width) && (y + 1 < hm.Height)) |
118 | { | 126 | { |
119 | hfvaluecompare = (float)hm[x + 1, y + 1]; // light from north-east => look at land height there | 127 | hfvaluecompare = (float)hm[x + 1, y + 1]; // light from north-east => look at land height there |
120 | } | 128 | } |
@@ -179,7 +187,7 @@ namespace OpenSim.Region.CoreModules.World.LegacyMap | |||
179 | 187 | ||
180 | if (ShadowDebugContinue) | 188 | if (ShadowDebugContinue) |
181 | { | 189 | { |
182 | if ((x - 1 > 0) && (yr + 1 < (int)Constants.RegionSize)) | 190 | if ((x - 1 > 0) && (yr + 1 < hm.Height)) |
183 | { | 191 | { |
184 | color = mapbmp.GetPixel(x - 1, yr + 1); | 192 | color = mapbmp.GetPixel(x - 1, yr + 1); |
185 | int r = color.R; | 193 | int r = color.R; |
@@ -199,7 +207,7 @@ namespace OpenSim.Region.CoreModules.World.LegacyMap | |||
199 | { | 207 | { |
200 | if (!terraincorruptedwarningsaid) | 208 | if (!terraincorruptedwarningsaid) |
201 | { | 209 | { |
202 | 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", m_scene.RegionInfo.RegionName); | 210 | m_log.WarnFormat("[SHADED MAP TILE RENDERER]: Your terrain is corrupted in region {0}, it might take a few minutes to generate the map image depending on the corruption level", m_scene.RegionInfo.RegionName); |
203 | terraincorruptedwarningsaid = true; | 211 | terraincorruptedwarningsaid = true; |
204 | } | 212 | } |
205 | color = Color.Black; | 213 | color = Color.Black; |
@@ -229,16 +237,17 @@ namespace OpenSim.Region.CoreModules.World.LegacyMap | |||
229 | { | 237 | { |
230 | if (!terraincorruptedwarningsaid) | 238 | if (!terraincorruptedwarningsaid) |
231 | { | 239 | { |
232 | 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", m_scene.RegionInfo.RegionName); | 240 | m_log.WarnFormat("[SHADED MAP TILE RENDERER]: Your terrain is corrupted in region {0}, it might take a few minutes to generate the map image depending on the corruption level", m_scene.RegionInfo.RegionName); |
233 | terraincorruptedwarningsaid = true; | 241 | terraincorruptedwarningsaid = true; |
234 | } | 242 | } |
235 | Color black = Color.Black; | 243 | Color black = Color.Black; |
236 | mapbmp.SetPixel(x, ((int)Constants.RegionSize - y) - 1, black); | 244 | mapbmp.SetPixel(x, (hm.Width - y) - 1, black); |
237 | } | 245 | } |
238 | } | 246 | } |
239 | } | 247 | } |
240 | } | 248 | } |
241 | m_log.Debug("[MAPTILE]: Generating Maptile Step 1: Done in " + (Environment.TickCount - tc) + " ms"); | 249 | |
250 | m_log.Debug("[SHADED MAP TILE RENDERER]: Generating Maptile Step 1: Done in " + (Environment.TickCount - tc) + " ms"); | ||
242 | } | 251 | } |
243 | } | 252 | } |
244 | } | 253 | } |
diff --git a/OpenSim/Region/CoreModules/World/LegacyMap/TexturedMapTileRenderer.cs b/OpenSim/Region/CoreModules/World/LegacyMap/TexturedMapTileRenderer.cs index d13c2ef..9f23141 100644 --- a/OpenSim/Region/CoreModules/World/LegacyMap/TexturedMapTileRenderer.cs +++ b/OpenSim/Region/CoreModules/World/LegacyMap/TexturedMapTileRenderer.cs | |||
@@ -34,6 +34,8 @@ using Nini.Config; | |||
34 | using OpenMetaverse; | 34 | using OpenMetaverse; |
35 | using OpenMetaverse.Imaging; | 35 | using OpenMetaverse.Imaging; |
36 | using OpenSim.Framework; | 36 | using OpenSim.Framework; |
37 | using OpenSim.Region.Framework; | ||
38 | using OpenSim.Region.Framework.Interfaces; | ||
37 | using OpenSim.Region.Framework.Scenes; | 39 | using OpenSim.Region.Framework.Scenes; |
38 | 40 | ||
39 | namespace OpenSim.Region.CoreModules.World.LegacyMap | 41 | namespace OpenSim.Region.CoreModules.World.LegacyMap |
@@ -122,8 +124,8 @@ namespace OpenSim.Region.CoreModules.World.LegacyMap | |||
122 | { | 124 | { |
123 | #region Constants | 125 | #region Constants |
124 | 126 | ||
125 | private static readonly ILog m_log = | 127 | private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); |
126 | LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); | 128 | private static readonly string LogHeader = "[TEXTURED MAPTILE RENDERER]"; |
127 | 129 | ||
128 | // some hardcoded terrain UUIDs that work with SL 1.20 (the four default textures and "Blank"). | 130 | // some hardcoded terrain UUIDs that work with SL 1.20 (the four default textures and "Blank"). |
129 | // The color-values were choosen because they "look right" (at least to me) ;-) | 131 | // The color-values were choosen because they "look right" (at least to me) ;-) |
@@ -173,7 +175,7 @@ namespace OpenSim.Region.CoreModules.World.LegacyMap | |||
173 | private Bitmap fetchTexture(UUID id) | 175 | private Bitmap fetchTexture(UUID id) |
174 | { | 176 | { |
175 | AssetBase asset = m_scene.AssetService.Get(id.ToString()); | 177 | AssetBase asset = m_scene.AssetService.Get(id.ToString()); |
176 | m_log.DebugFormat("[TexturedMapTileRenderer]: Fetched texture {0}, found: {1}", id, asset != null); | 178 | m_log.DebugFormat("{0} Fetched texture {1}, found: {2}", LogHeader, id, asset != null); |
177 | if (asset == null) return null; | 179 | if (asset == null) return null; |
178 | 180 | ||
179 | ManagedImage managedImage; | 181 | ManagedImage managedImage; |
@@ -188,18 +190,15 @@ namespace OpenSim.Region.CoreModules.World.LegacyMap | |||
188 | } | 190 | } |
189 | catch (DllNotFoundException) | 191 | catch (DllNotFoundException) |
190 | { | 192 | { |
191 | m_log.ErrorFormat("[TexturedMapTileRenderer]: OpenJpeg is not installed correctly on this system. Asset Data is empty for {0}", id); | 193 | m_log.ErrorFormat("{0} OpenJpeg is not installed correctly on this system. Asset Data is empty for {1}", LogHeader, id); |
192 | |||
193 | } | 194 | } |
194 | catch (IndexOutOfRangeException) | 195 | catch (IndexOutOfRangeException) |
195 | { | 196 | { |
196 | m_log.ErrorFormat("[TexturedMapTileRenderer]: OpenJpeg was unable to encode this. Asset Data is empty for {0}", id); | 197 | m_log.ErrorFormat("{0} OpenJpeg was unable to encode this. Asset Data is empty for {1}", LogHeader, id); |
197 | |||
198 | } | 198 | } |
199 | catch (Exception) | 199 | catch (Exception) |
200 | { | 200 | { |
201 | m_log.ErrorFormat("[TexturedMapTileRenderer]: OpenJpeg was unable to encode this. Asset Data is empty for {0}", id); | 201 | m_log.ErrorFormat("{0} OpenJpeg was unable to encode this. Asset Data is empty for {1}", LogHeader, id); |
202 | |||
203 | } | 202 | } |
204 | return null; | 203 | return null; |
205 | 204 | ||
@@ -233,10 +232,14 @@ namespace OpenSim.Region.CoreModules.World.LegacyMap | |||
233 | if (textureID == UUID.Zero) return defaultColor; // not set | 232 | if (textureID == UUID.Zero) return defaultColor; // not set |
234 | if (m_mapping.ContainsKey(textureID)) return m_mapping[textureID]; // one of the predefined textures | 233 | if (m_mapping.ContainsKey(textureID)) return m_mapping[textureID]; // one of the predefined textures |
235 | 234 | ||
236 | Bitmap bmp = fetchTexture(textureID); | 235 | Color color; |
237 | Color color = bmp == null ? defaultColor : computeAverageColor(bmp); | 236 | |
238 | // store it for future reference | 237 | using (Bitmap bmp = fetchTexture(textureID)) |
239 | m_mapping[textureID] = color; | 238 | { |
239 | color = bmp == null ? defaultColor : computeAverageColor(bmp); | ||
240 | // store it for future reference | ||
241 | m_mapping[textureID] = color; | ||
242 | } | ||
240 | 243 | ||
241 | return color; | 244 | return color; |
242 | } | 245 | } |
@@ -267,8 +270,8 @@ namespace OpenSim.Region.CoreModules.World.LegacyMap | |||
267 | 270 | ||
268 | // the heigthfield might have some jumps in values. Rendered land is smooth, though, | 271 | // the heigthfield might have some jumps in values. Rendered land is smooth, though, |
269 | // as a slope is rendered at that place. So average 4 neighbour values to emulate that. | 272 | // as a slope is rendered at that place. So average 4 neighbour values to emulate that. |
270 | private float getHeight(double[,] hm, int x, int y) { | 273 | private float getHeight(ITerrainChannel hm, int x, int y) { |
271 | if (x < ((int)Constants.RegionSize - 1) && y < ((int)Constants.RegionSize - 1)) | 274 | if (x < (hm.Width - 1) && y < (hm.Height - 1)) |
272 | return (float)(hm[x, y] * .444 + (hm[x + 1, y] + hm[x, y + 1]) * .222 + hm[x + 1, y +1] * .112); | 275 | return (float)(hm[x, y] * .444 + (hm[x + 1, y] + hm[x, y + 1]) * .222 + hm[x + 1, y +1] * .112); |
273 | else | 276 | else |
274 | return (float)hm[x, y]; | 277 | return (float)hm[x, y]; |
@@ -278,7 +281,15 @@ namespace OpenSim.Region.CoreModules.World.LegacyMap | |||
278 | public void TerrainToBitmap(Bitmap mapbmp) | 281 | public void TerrainToBitmap(Bitmap mapbmp) |
279 | { | 282 | { |
280 | int tc = Environment.TickCount; | 283 | int tc = Environment.TickCount; |
281 | m_log.Debug("[MAPTILE]: Generating Maptile Step 1: Terrain"); | 284 | m_log.DebugFormat("{0} Generating Maptile Step 1: Terrain", LogHeader); |
285 | |||
286 | ITerrainChannel hm = m_scene.Heightmap; | ||
287 | |||
288 | if (mapbmp.Width != hm.Width || mapbmp.Height != hm.Height) | ||
289 | { | ||
290 | m_log.ErrorFormat("{0} TerrainToBitmap. Passed bitmap wrong dimensions. passed=<{1},{2}>, size=<{3},{4}>", | ||
291 | LogHeader, mapbmp.Width, mapbmp.Height, hm.Width, hm.Height); | ||
292 | } | ||
282 | 293 | ||
283 | // These textures should be in the AssetCache anyway, as every client conneting to this | 294 | // These textures should be in the AssetCache anyway, as every client conneting to this |
284 | // region needs them. Except on start, when the map is recreated (before anyone connected), | 295 | // region needs them. Except on start, when the map is recreated (before anyone connected), |
@@ -306,19 +317,17 @@ namespace OpenSim.Region.CoreModules.World.LegacyMap | |||
306 | 317 | ||
307 | float waterHeight = (float)settings.WaterHeight; | 318 | float waterHeight = (float)settings.WaterHeight; |
308 | 319 | ||
309 | double[,] hm = m_scene.Heightmap.GetDoubles(); | 320 | for (int x = 0; x < hm.Width; x++) |
310 | |||
311 | for (int x = 0; x < (int)Constants.RegionSize; x++) | ||
312 | { | 321 | { |
313 | float columnRatio = x / ((float)Constants.RegionSize - 1); // 0 - 1, for interpolation | 322 | float columnRatio = x / (hm.Width - 1); // 0 - 1, for interpolation |
314 | for (int y = 0; y < (int)Constants.RegionSize; y++) | 323 | for (int y = 0; y < hm.Height; y++) |
315 | { | 324 | { |
316 | float rowRatio = y / ((float)Constants.RegionSize - 1); // 0 - 1, for interpolation | 325 | float rowRatio = y / (hm.Height - 1); // 0 - 1, for interpolation |
317 | 326 | ||
318 | // Y flip the cordinates for the bitmap: hf origin is lower left, bm origin is upper left | 327 | // Y flip the cordinates for the bitmap: hf origin is lower left, bm origin is upper left |
319 | int yr = ((int)Constants.RegionSize - 1) - y; | 328 | int yr = (hm.Height - 1) - y; |
320 | 329 | ||
321 | float heightvalue = getHeight(hm, x, y); | 330 | float heightvalue = getHeight(m_scene.Heightmap, x, y); |
322 | if (Single.IsInfinity(heightvalue) || Single.IsNaN(heightvalue)) | 331 | if (Single.IsInfinity(heightvalue) || Single.IsNaN(heightvalue)) |
323 | heightvalue = 0; | 332 | heightvalue = 0; |
324 | 333 | ||
@@ -368,9 +377,9 @@ namespace OpenSim.Region.CoreModules.World.LegacyMap | |||
368 | } | 377 | } |
369 | 378 | ||
370 | // Shade the terrain for shadows | 379 | // Shade the terrain for shadows |
371 | if (x < ((int)Constants.RegionSize - 1) && y < ((int)Constants.RegionSize - 1)) | 380 | if (x < (hm.Width - 1) && y < (hm.Height - 1)) |
372 | { | 381 | { |
373 | float hfvaluecompare = getHeight(hm, x + 1, y + 1); // light from north-east => look at land height there | 382 | float hfvaluecompare = getHeight(m_scene.Heightmap, x + 1, y + 1); // light from north-east => look at land height there |
374 | if (Single.IsInfinity(hfvaluecompare) || Single.IsNaN(hfvaluecompare)) | 383 | if (Single.IsInfinity(hfvaluecompare) || Single.IsNaN(hfvaluecompare)) |
375 | hfvaluecompare = 0f; | 384 | hfvaluecompare = 0f; |
376 | 385 | ||
@@ -412,7 +421,8 @@ namespace OpenSim.Region.CoreModules.World.LegacyMap | |||
412 | } | 421 | } |
413 | } | 422 | } |
414 | } | 423 | } |
415 | m_log.Debug("[MAPTILE]: Generating Maptile Step 1: Done in " + (Environment.TickCount - tc) + " ms"); | 424 | |
425 | m_log.Debug("[TEXTURED MAP TILE RENDERER]: Generating Maptile Step 1: Done in " + (Environment.TickCount - tc) + " ms"); | ||
416 | } | 426 | } |
417 | } | 427 | } |
418 | } | 428 | } |