MapImageModule.cs 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656
  1. /*
  2. * Copyright (c) Contributors, http://opensimulator.org/
  3. * See CONTRIBUTORS.TXT for a full list of copyright holders.
  4. *
  5. * Redistribution and use in source and binary forms, with or without
  6. * modification, are permitted provided that the following conditions are met:
  7. * * Redistributions of source code must retain the above copyright
  8. * notice, this list of conditions and the following disclaimer.
  9. * * Redistributions in binary form must reproduce the above copyright
  10. * notice, this list of conditions and the following disclaimer in the
  11. * documentation and/or other materials provided with the distribution.
  12. * * Neither the name of the OpenSimulator Project nor the
  13. * names of its contributors may be used to endorse or promote products
  14. * derived from this software without specific prior written permission.
  15. *
  16. * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
  17. * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  18. * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  19. * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
  20. * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  21. * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  22. * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  23. * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  24. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  25. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  26. */
  27. using System;
  28. using System.Collections.Generic;
  29. using System.Drawing;
  30. using System.Reflection;
  31. using log4net;
  32. using Mono.Addins;
  33. using Nini.Config;
  34. using OpenMetaverse;
  35. using OpenMetaverse.Imaging;
  36. using OpenSim.Framework;
  37. using OpenSim.Region.Framework.Interfaces;
  38. using OpenSim.Region.Framework.Scenes;
  39. namespace OpenSim.Region.CoreModules.World.LegacyMap
  40. {
  41. public enum DrawRoutine
  42. {
  43. Rectangle,
  44. Polygon,
  45. Ellipse
  46. }
  47. public struct face
  48. {
  49. public Point[] pts;
  50. }
  51. public struct DrawStruct
  52. {
  53. public DrawRoutine dr;
  54. // public Rectangle rect;
  55. public SolidBrush brush;
  56. public face[] trns;
  57. }
  58. [Extension(Path = "/OpenSim/RegionModules", NodeName = "RegionModule", Id = "MapImageModule")]
  59. public class MapImageModule : IMapImageGenerator, INonSharedRegionModule
  60. {
  61. private static readonly ILog m_log =
  62. LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
  63. private Scene m_scene;
  64. private IConfigSource m_config;
  65. private IMapTileTerrainRenderer terrainRenderer;
  66. private bool m_Enabled = false;
  67. #region IMapImageGenerator Members
  68. public Bitmap CreateMapTile()
  69. {
  70. bool drawPrimVolume = true;
  71. bool textureTerrain = false;
  72. bool generateMaptiles = true;
  73. Bitmap mapbmp;
  74. string[] configSections = new string[] { "Map", "Startup" };
  75. drawPrimVolume
  76. = Util.GetConfigVarFromSections<bool>(m_config, "DrawPrimOnMapTile", configSections, drawPrimVolume);
  77. textureTerrain
  78. = Util.GetConfigVarFromSections<bool>(m_config, "TextureOnMapTile", configSections, textureTerrain);
  79. generateMaptiles
  80. = Util.GetConfigVarFromSections<bool>(m_config, "GenerateMaptiles", configSections, generateMaptiles);
  81. if (generateMaptiles)
  82. {
  83. if (String.IsNullOrEmpty(m_scene.RegionInfo.MaptileStaticFile))
  84. {
  85. if (textureTerrain)
  86. {
  87. terrainRenderer = new TexturedMapTileRenderer();
  88. }
  89. else
  90. {
  91. terrainRenderer = new ShadedMapTileRenderer();
  92. }
  93. terrainRenderer.Initialise(m_scene, m_config);
  94. mapbmp = new Bitmap((int)m_scene.Heightmap.Width, (int)m_scene.Heightmap.Height,
  95. System.Drawing.Imaging.PixelFormat.Format24bppRgb);
  96. //long t = System.Environment.TickCount;
  97. //for (int i = 0; i < 10; ++i) {
  98. terrainRenderer.TerrainToBitmap(mapbmp);
  99. //}
  100. //t = System.Environment.TickCount - t;
  101. //m_log.InfoFormat("[MAPTILE] generation of 10 maptiles needed {0} ms", t);
  102. if (drawPrimVolume)
  103. {
  104. DrawObjectVolume(m_scene, mapbmp);
  105. }
  106. }
  107. else
  108. {
  109. try
  110. {
  111. mapbmp = new Bitmap(m_scene.RegionInfo.MaptileStaticFile);
  112. }
  113. catch (Exception)
  114. {
  115. m_log.ErrorFormat(
  116. "[MAPTILE]: Failed to load Static map image texture file: {0} for {1}",
  117. m_scene.RegionInfo.MaptileStaticFile, m_scene.Name);
  118. //mapbmp = new Bitmap((int)m_scene.Heightmap.Width, (int)m_scene.Heightmap.Height, System.Drawing.Imaging.PixelFormat.Format24bppRgb);
  119. mapbmp = null;
  120. }
  121. if (mapbmp != null)
  122. m_log.DebugFormat(
  123. "[MAPTILE]: Static map image texture file {0} found for {1}",
  124. m_scene.RegionInfo.MaptileStaticFile, m_scene.Name);
  125. }
  126. }
  127. else
  128. {
  129. mapbmp = FetchTexture(m_scene.RegionInfo.RegionSettings.TerrainImageID);
  130. }
  131. return mapbmp;
  132. }
  133. public byte[] WriteJpeg2000Image()
  134. {
  135. try
  136. {
  137. using (Bitmap mapbmp = CreateMapTile())
  138. {
  139. if (mapbmp != null)
  140. return OpenJPEG.EncodeFromImage(mapbmp, true);
  141. }
  142. }
  143. catch (Exception e) // LEGIT: Catching problems caused by OpenJPEG p/invoke
  144. {
  145. m_log.Error("Failed generating terrain map: " + e);
  146. }
  147. return null;
  148. }
  149. #endregion
  150. #region Region Module interface
  151. public void Initialise(IConfigSource source)
  152. {
  153. m_config = source;
  154. if (Util.GetConfigVarFromSections<string>(
  155. m_config, "MapImageModule", new string[] { "Startup", "Map" }, "MapImageModule") != "MapImageModule")
  156. return;
  157. m_Enabled = true;
  158. }
  159. public void AddRegion(Scene scene)
  160. {
  161. if (!m_Enabled)
  162. return;
  163. m_scene = scene;
  164. m_scene.RegisterModuleInterface<IMapImageGenerator>(this);
  165. }
  166. public void RegionLoaded(Scene scene)
  167. {
  168. }
  169. public void RemoveRegion(Scene scene)
  170. {
  171. }
  172. public void Close()
  173. {
  174. }
  175. public string Name
  176. {
  177. get { return "MapImageModule"; }
  178. }
  179. public Type ReplaceableInterface
  180. {
  181. get { return null; }
  182. }
  183. #endregion
  184. // TODO: unused:
  185. // private void ShadeBuildings(Bitmap map)
  186. // {
  187. // lock (map)
  188. // {
  189. // lock (m_scene.Entities)
  190. // {
  191. // foreach (EntityBase entity in m_scene.Entities.Values)
  192. // {
  193. // if (entity is SceneObjectGroup)
  194. // {
  195. // SceneObjectGroup sog = (SceneObjectGroup) entity;
  196. //
  197. // foreach (SceneObjectPart primitive in sog.Children.Values)
  198. // {
  199. // int x = (int) (primitive.AbsolutePosition.X - (primitive.Scale.X / 2));
  200. // int y = (int) (primitive.AbsolutePosition.Y - (primitive.Scale.Y / 2));
  201. // int w = (int) primitive.Scale.X;
  202. // int h = (int) primitive.Scale.Y;
  203. //
  204. // int dx;
  205. // for (dx = x; dx < x + w; dx++)
  206. // {
  207. // int dy;
  208. // for (dy = y; dy < y + h; dy++)
  209. // {
  210. // if (x < 0 || y < 0)
  211. // continue;
  212. // if (x >= map.Width || y >= map.Height)
  213. // continue;
  214. //
  215. // map.SetPixel(dx, dy, Color.DarkGray);
  216. // }
  217. // }
  218. // }
  219. // }
  220. // }
  221. // }
  222. // }
  223. // }
  224. private Bitmap FetchTexture(UUID id)
  225. {
  226. AssetBase asset = m_scene.AssetService.Get(id.ToString());
  227. if (asset != null)
  228. {
  229. m_log.DebugFormat("[MAPTILE]: Static map image texture {0} found for {1}", id, m_scene.Name);
  230. }
  231. else
  232. {
  233. m_log.WarnFormat("[MAPTILE]: Static map image texture {0} not found for {1}", id, m_scene.Name);
  234. return null;
  235. }
  236. ManagedImage managedImage;
  237. Image image;
  238. try
  239. {
  240. if (OpenJPEG.DecodeToImage(asset.Data, out managedImage, out image))
  241. return new Bitmap(image);
  242. else
  243. return null;
  244. }
  245. catch (DllNotFoundException)
  246. {
  247. m_log.ErrorFormat("[MAPTILE]: OpenJpeg is not installed correctly on this system. Asset Data is empty for {0}", id);
  248. }
  249. catch (IndexOutOfRangeException)
  250. {
  251. m_log.ErrorFormat("[MAPTILE]: OpenJpeg was unable to decode this. Asset Data is empty for {0}", id);
  252. }
  253. catch (Exception)
  254. {
  255. m_log.ErrorFormat("[MAPTILE]: OpenJpeg was unable to decode this. Asset Data is empty for {0}", id);
  256. }
  257. return null;
  258. }
  259. private Bitmap DrawObjectVolume(Scene whichScene, Bitmap mapbmp)
  260. {
  261. int tc = 0;
  262. ITerrainChannel hm = whichScene.Heightmap;
  263. tc = Environment.TickCount;
  264. m_log.Debug("[MAPTILE]: Generating Maptile Step 2: Object Volume Profile");
  265. EntityBase[] objs = whichScene.GetEntities();
  266. List<float> z_sortheights = new List<float>();
  267. List<uint> z_localIDs = new List<uint>();
  268. Dictionary<uint, DrawStruct> z_sort = new Dictionary<uint, DrawStruct>();
  269. try
  270. {
  271. lock (objs)
  272. {
  273. foreach (EntityBase obj in objs)
  274. {
  275. // Only draw the contents of SceneObjectGroup
  276. if (obj is SceneObjectGroup)
  277. {
  278. SceneObjectGroup mapdot = (SceneObjectGroup)obj;
  279. Color mapdotspot = Color.Gray; // Default color when prim color is white
  280. // Loop over prim in group
  281. foreach (SceneObjectPart part in mapdot.Parts)
  282. {
  283. if (part == null)
  284. continue;
  285. // Draw if the object is at least 1 meter wide in any direction
  286. if (part.Scale.X > 1f || part.Scale.Y > 1f || part.Scale.Z > 1f)
  287. {
  288. // Try to get the RGBA of the default texture entry..
  289. //
  290. try
  291. {
  292. // get the null checks out of the way
  293. // skip the ones that break
  294. if (part == null)
  295. continue;
  296. if (part.Shape == null)
  297. continue;
  298. if (part.Shape.PCode == (byte)PCode.Tree || part.Shape.PCode == (byte)PCode.NewTree || part.Shape.PCode == (byte)PCode.Grass)
  299. continue; // eliminates trees from this since we don't really have a good tree representation
  300. // if you want tree blocks on the map comment the above line and uncomment the below line
  301. //mapdotspot = Color.PaleGreen;
  302. Primitive.TextureEntry textureEntry = part.Shape.Textures;
  303. if (textureEntry == null || textureEntry.DefaultTexture == null)
  304. continue;
  305. Color4 texcolor = textureEntry.DefaultTexture.RGBA;
  306. // Not sure why some of these are null, oh well.
  307. int colorr = 255 - (int)(texcolor.R * 255f);
  308. int colorg = 255 - (int)(texcolor.G * 255f);
  309. int colorb = 255 - (int)(texcolor.B * 255f);
  310. if (!(colorr == 255 && colorg == 255 && colorb == 255))
  311. {
  312. //Try to set the map spot color
  313. try
  314. {
  315. // If the color gets goofy somehow, skip it *shakes fist at Color4
  316. mapdotspot = Color.FromArgb(colorr, colorg, colorb);
  317. }
  318. catch (ArgumentException)
  319. {
  320. }
  321. }
  322. }
  323. catch (IndexOutOfRangeException)
  324. {
  325. // Windows Array
  326. }
  327. catch (ArgumentOutOfRangeException)
  328. {
  329. // Mono Array
  330. }
  331. Vector3 pos = part.GetWorldPosition();
  332. // skip prim outside of retion
  333. if (!m_scene.PositionIsInCurrentRegion(pos))
  334. continue;
  335. // skip prim in non-finite position
  336. if (Single.IsNaN(pos.X) || Single.IsNaN(pos.Y) ||
  337. Single.IsInfinity(pos.X) || Single.IsInfinity(pos.Y))
  338. continue;
  339. // Figure out if object is under 256m above the height of the terrain
  340. bool isBelow256AboveTerrain = false;
  341. try
  342. {
  343. isBelow256AboveTerrain = (pos.Z < ((float)hm[(int)pos.X, (int)pos.Y] + 256f));
  344. }
  345. catch (Exception)
  346. {
  347. }
  348. if (isBelow256AboveTerrain)
  349. {
  350. // Translate scale by rotation so scale is represented properly when object is rotated
  351. Vector3 lscale = new Vector3(part.Shape.Scale.X, part.Shape.Scale.Y, part.Shape.Scale.Z);
  352. Vector3 scale = new Vector3();
  353. Vector3 tScale = new Vector3();
  354. Vector3 axPos = new Vector3(pos.X, pos.Y, pos.Z);
  355. Quaternion llrot = part.GetWorldRotation();
  356. Quaternion rot = new Quaternion(llrot.W, llrot.X, llrot.Y, llrot.Z);
  357. scale = lscale * rot;
  358. // negative scales don't work in this situation
  359. scale.X = Math.Abs(scale.X);
  360. scale.Y = Math.Abs(scale.Y);
  361. scale.Z = Math.Abs(scale.Z);
  362. // This scaling isn't very accurate and doesn't take into account the face rotation :P
  363. int mapdrawstartX = (int)(pos.X - scale.X);
  364. int mapdrawstartY = (int)(pos.Y - scale.Y);
  365. int mapdrawendX = (int)(pos.X + scale.X);
  366. int mapdrawendY = (int)(pos.Y + scale.Y);
  367. // If object is beyond the edge of the map, don't draw it to avoid errors
  368. if (mapdrawstartX < 0
  369. || mapdrawstartX > (hm.Width - 1)
  370. || mapdrawendX < 0
  371. || mapdrawendX > (hm.Width - 1)
  372. || mapdrawstartY < 0
  373. || mapdrawstartY > (hm.Height - 1)
  374. || mapdrawendY < 0
  375. || mapdrawendY > (hm.Height - 1))
  376. continue;
  377. #region obb face reconstruction part duex
  378. Vector3[] vertexes = new Vector3[8];
  379. // float[] distance = new float[6];
  380. Vector3[] FaceA = new Vector3[6]; // vertex A for Facei
  381. Vector3[] FaceB = new Vector3[6]; // vertex B for Facei
  382. Vector3[] FaceC = new Vector3[6]; // vertex C for Facei
  383. Vector3[] FaceD = new Vector3[6]; // vertex D for Facei
  384. tScale = new Vector3(lscale.X, -lscale.Y, lscale.Z);
  385. scale = ((tScale * rot));
  386. vertexes[0] = (new Vector3((pos.X + scale.X), (pos.Y + scale.Y), (pos.Z + scale.Z)));
  387. // vertexes[0].x = pos.X + vertexes[0].x;
  388. //vertexes[0].y = pos.Y + vertexes[0].y;
  389. //vertexes[0].z = pos.Z + vertexes[0].z;
  390. FaceA[0] = vertexes[0];
  391. FaceB[3] = vertexes[0];
  392. FaceA[4] = vertexes[0];
  393. tScale = lscale;
  394. scale = ((tScale * rot));
  395. vertexes[1] = (new Vector3((pos.X + scale.X), (pos.Y + scale.Y), (pos.Z + scale.Z)));
  396. // vertexes[1].x = pos.X + vertexes[1].x;
  397. // vertexes[1].y = pos.Y + vertexes[1].y;
  398. //vertexes[1].z = pos.Z + vertexes[1].z;
  399. FaceB[0] = vertexes[1];
  400. FaceA[1] = vertexes[1];
  401. FaceC[4] = vertexes[1];
  402. tScale = new Vector3(lscale.X, -lscale.Y, -lscale.Z);
  403. scale = ((tScale * rot));
  404. vertexes[2] = (new Vector3((pos.X + scale.X), (pos.Y + scale.Y), (pos.Z + scale.Z)));
  405. //vertexes[2].x = pos.X + vertexes[2].x;
  406. //vertexes[2].y = pos.Y + vertexes[2].y;
  407. //vertexes[2].z = pos.Z + vertexes[2].z;
  408. FaceC[0] = vertexes[2];
  409. FaceD[3] = vertexes[2];
  410. FaceC[5] = vertexes[2];
  411. tScale = new Vector3(lscale.X, lscale.Y, -lscale.Z);
  412. scale = ((tScale * rot));
  413. vertexes[3] = (new Vector3((pos.X + scale.X), (pos.Y + scale.Y), (pos.Z + scale.Z)));
  414. //vertexes[3].x = pos.X + vertexes[3].x;
  415. // vertexes[3].y = pos.Y + vertexes[3].y;
  416. // vertexes[3].z = pos.Z + vertexes[3].z;
  417. FaceD[0] = vertexes[3];
  418. FaceC[1] = vertexes[3];
  419. FaceA[5] = vertexes[3];
  420. tScale = new Vector3(-lscale.X, lscale.Y, lscale.Z);
  421. scale = ((tScale * rot));
  422. vertexes[4] = (new Vector3((pos.X + scale.X), (pos.Y + scale.Y), (pos.Z + scale.Z)));
  423. // vertexes[4].x = pos.X + vertexes[4].x;
  424. // vertexes[4].y = pos.Y + vertexes[4].y;
  425. // vertexes[4].z = pos.Z + vertexes[4].z;
  426. FaceB[1] = vertexes[4];
  427. FaceA[2] = vertexes[4];
  428. FaceD[4] = vertexes[4];
  429. tScale = new Vector3(-lscale.X, lscale.Y, -lscale.Z);
  430. scale = ((tScale * rot));
  431. vertexes[5] = (new Vector3((pos.X + scale.X), (pos.Y + scale.Y), (pos.Z + scale.Z)));
  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. FaceD[1] = vertexes[5];
  436. FaceC[2] = vertexes[5];
  437. FaceB[5] = vertexes[5];
  438. tScale = new Vector3(-lscale.X, -lscale.Y, lscale.Z);
  439. scale = ((tScale * rot));
  440. vertexes[6] = (new Vector3((pos.X + scale.X), (pos.Y + scale.Y), (pos.Z + scale.Z)));
  441. // vertexes[6].x = pos.X + vertexes[6].x;
  442. // vertexes[6].y = pos.Y + vertexes[6].y;
  443. // vertexes[6].z = pos.Z + vertexes[6].z;
  444. FaceB[2] = vertexes[6];
  445. FaceA[3] = vertexes[6];
  446. FaceB[4] = vertexes[6];
  447. tScale = new Vector3(-lscale.X, -lscale.Y, -lscale.Z);
  448. scale = ((tScale * rot));
  449. vertexes[7] = (new Vector3((pos.X + scale.X), (pos.Y + scale.Y), (pos.Z + scale.Z)));
  450. // vertexes[7].x = pos.X + vertexes[7].x;
  451. // vertexes[7].y = pos.Y + vertexes[7].y;
  452. // vertexes[7].z = pos.Z + vertexes[7].z;
  453. FaceD[2] = vertexes[7];
  454. FaceC[3] = vertexes[7];
  455. FaceD[5] = vertexes[7];
  456. #endregion
  457. //int wy = 0;
  458. //bool breakYN = false; // If we run into an error drawing, break out of the
  459. // loop so we don't lag to death on error handling
  460. DrawStruct ds = new DrawStruct();
  461. ds.brush = new SolidBrush(mapdotspot);
  462. //ds.rect = new Rectangle(mapdrawstartX, (255 - mapdrawstartY), mapdrawendX - mapdrawstartX, mapdrawendY - mapdrawstartY);
  463. ds.trns = new face[FaceA.Length];
  464. for (int i = 0; i < FaceA.Length; i++)
  465. {
  466. Point[] working = new Point[5];
  467. working[0] = project(hm, FaceA[i], axPos);
  468. working[1] = project(hm, FaceB[i], axPos);
  469. working[2] = project(hm, FaceD[i], axPos);
  470. working[3] = project(hm, FaceC[i], axPos);
  471. working[4] = project(hm, FaceA[i], axPos);
  472. face workingface = new face();
  473. workingface.pts = working;
  474. ds.trns[i] = workingface;
  475. }
  476. z_sort.Add(part.LocalId, ds);
  477. z_localIDs.Add(part.LocalId);
  478. z_sortheights.Add(pos.Z);
  479. // for (int wx = mapdrawstartX; wx < mapdrawendX; wx++)
  480. // {
  481. // for (wy = mapdrawstartY; wy < mapdrawendY; wy++)
  482. // {
  483. // m_log.InfoFormat("[MAPDEBUG]: {0},{1}({2})", wx, (255 - wy),wy);
  484. // try
  485. // {
  486. // // Remember, flip the y!
  487. // mapbmp.SetPixel(wx, (255 - wy), mapdotspot);
  488. // }
  489. // catch (ArgumentException)
  490. // {
  491. // breakYN = true;
  492. // }
  493. // }
  494. // if (breakYN)
  495. // break;
  496. // }
  497. // }
  498. //}
  499. } // Object is within 256m Z of terrain
  500. } // object is at least a meter wide
  501. } // loop over group children
  502. } // entitybase is sceneobject group
  503. } // foreach loop over entities
  504. float[] sortedZHeights = z_sortheights.ToArray();
  505. uint[] sortedlocalIds = z_localIDs.ToArray();
  506. // Sort prim by Z position
  507. Array.Sort(sortedZHeights, sortedlocalIds);
  508. using (Graphics g = Graphics.FromImage(mapbmp))
  509. {
  510. for (int s = 0; s < sortedZHeights.Length; s++)
  511. {
  512. if (z_sort.ContainsKey(sortedlocalIds[s]))
  513. {
  514. DrawStruct rectDrawStruct = z_sort[sortedlocalIds[s]];
  515. for (int r = 0; r < rectDrawStruct.trns.Length; r++)
  516. {
  517. g.FillPolygon(rectDrawStruct.brush,rectDrawStruct.trns[r].pts);
  518. }
  519. //g.FillRectangle(rectDrawStruct.brush , rectDrawStruct.rect);
  520. }
  521. }
  522. }
  523. } // lock entities objs
  524. }
  525. finally
  526. {
  527. foreach (DrawStruct ds in z_sort.Values)
  528. ds.brush.Dispose();
  529. }
  530. m_log.Debug("[MAPTILE]: Generating Maptile Step 2: Done in " + (Environment.TickCount - tc) + " ms");
  531. return mapbmp;
  532. }
  533. private Point project(ITerrainChannel hm, Vector3 point3d, Vector3 originpos)
  534. {
  535. Point returnpt = new Point();
  536. //originpos = point3d;
  537. //int d = (int)(256f / 1.5f);
  538. //Vector3 topos = new Vector3(0, 0, 0);
  539. // float z = -point3d.z - topos.z;
  540. returnpt.X = (int)point3d.X;//(int)((topos.x - point3d.x) / z * d);
  541. returnpt.Y = (int)((hm.Width - 1) - point3d.Y);//(int)(255 - (((topos.y - point3d.y) / z * d)));
  542. return returnpt;
  543. }
  544. public Bitmap CreateViewImage(Vector3 camPos, Vector3 camDir, float fov, int width, int height, bool useTextures)
  545. {
  546. return null;
  547. }
  548. }
  549. }