aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/CoreModules/World/LegacyMap/MapImageModule.cs
diff options
context:
space:
mode:
authorDavid Walter Seikel2016-11-03 21:44:39 +1000
committerDavid Walter Seikel2016-11-03 21:44:39 +1000
commit134f86e8d5c414409631b25b8c6f0ee45fbd8631 (patch)
tree216b89d3fb89acfb81be1e440c25c41ab09fa96d /OpenSim/Region/CoreModules/World/LegacyMap/MapImageModule.cs
parentMore changing to production grid. Double oops. (diff)
downloadopensim-SC_OLD-134f86e8d5c414409631b25b8c6f0ee45fbd8631.zip
opensim-SC_OLD-134f86e8d5c414409631b25b8c6f0ee45fbd8631.tar.gz
opensim-SC_OLD-134f86e8d5c414409631b25b8c6f0ee45fbd8631.tar.bz2
opensim-SC_OLD-134f86e8d5c414409631b25b8c6f0ee45fbd8631.tar.xz
Initial update to OpenSim 0.8.2.1 source code.
Diffstat (limited to 'OpenSim/Region/CoreModules/World/LegacyMap/MapImageModule.cs')
-rw-r--r--OpenSim/Region/CoreModules/World/LegacyMap/MapImageModule.cs694
1 files changed, 390 insertions, 304 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 }