using OpenMetaverse; using OpenSim.Region.Framework.Scenes; using System; using System.Collections.Generic; using System.Drawing; using System.Drawing.Imaging; using System.Linq; using System.Text; using System.Threading.Tasks; namespace OpenSim.Modules.PathFinding { class PathFinder { private UUID m_requestID = UUID.Zero; private Scene m_scene = null; private Bitmap m_bitmap = null; public PathFinder(UUID requestID, Scene localScene) { m_requestID = requestID; m_scene = localScene; m_bitmap = new Bitmap((int)m_scene.RegionInfo.RegionSizeX, (int)m_scene.RegionInfo.RegionSizeY); } public void preparePathFindingScene(bool terrain) { convertRegionToBitmap(terrain); } public void setPositions(Vector2 start, Vector2 target) { m_bitmap.SetPixel(m_bitmap.Size.Width - (int)start.Y, m_bitmap.Size.Height - (int)start.X, Color.Green); m_bitmap.SetPixel(m_bitmap.Size.Width - (int)target.Y, m_bitmap.Size.Height - (int)target.X, Color.Red); saveDebugImageToDisc(); } private void convertRegionToBitmap(bool terrain) { if (terrain == true) { for (int X = 0; X < m_scene.RegionInfo.RegionSizeX; X++) { for (int Y = 0; Y < m_scene.RegionInfo.RegionSizeY; Y++) { float baseheight = (float)m_scene.Heightmap[(int)m_scene.RegionInfo.RegionSizeX - X, (int)m_scene.RegionInfo.RegionSizeY - Y]; //Block the position then water is on this place. if (baseheight <= m_scene.RegionInfo.RegionSettings.WaterHeight) m_bitmap.SetPixel(X, Y, Color.Black); //Allow all positions they have terrain over the water height. if (baseheight > m_scene.RegionInfo.RegionSettings.WaterHeight) m_bitmap.SetPixel(X, Y, Color.White); } } } else { for (int X = 0; X < m_scene.RegionInfo.RegionSizeX; X++) { for (int Y = 0; Y < m_scene.RegionInfo.RegionSizeY; Y++) { m_bitmap.SetPixel(X, Y, Color.Black); } } } PathFindingSceneGenerator.DrawObjectVolume(m_scene, ref m_bitmap); } private void saveDebugImageToDisc() { m_bitmap.Save(m_requestID + ".png", ImageFormat.Png); } } }