2020-06-10 15:44:15 +00:00
|
|
|
|
using log4net;
|
|
|
|
|
using Mono.Addins;
|
|
|
|
|
using Nini.Config;
|
|
|
|
|
using OpenMetaverse;
|
|
|
|
|
using OpenSim.Region.Framework.Interfaces;
|
|
|
|
|
using OpenSim.Region.Framework.Scenes;
|
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Drawing;
|
2020-06-10 16:03:33 +00:00
|
|
|
|
using System.Drawing.Imaging;
|
2020-06-10 15:44:15 +00:00
|
|
|
|
using System.IO;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Reflection;
|
|
|
|
|
using System.Security.Cryptography;
|
|
|
|
|
using System.Text;
|
2020-06-10 16:03:33 +00:00
|
|
|
|
using System.Threading;
|
2020-06-10 15:44:15 +00:00
|
|
|
|
using System.Timers;
|
|
|
|
|
|
|
|
|
|
[assembly: Addin("BasicPathFindingModule", "0.1")]
|
|
|
|
|
[assembly: AddinDependency("OpenSim.Region.Framework", OpenSim.VersionInfo.VersionNumber)]
|
|
|
|
|
namespace OpenSim.Modules.PathFinding
|
|
|
|
|
{
|
|
|
|
|
[Extension(Path = "/OpenSim/RegionModules", NodeName = "RegionModule", Id = "BasicPathFindingModule")]
|
|
|
|
|
|
|
|
|
|
public class BasicPathFindingModule : INonSharedRegionModule
|
|
|
|
|
{
|
|
|
|
|
#region Region Module
|
|
|
|
|
private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
|
|
|
|
|
|
|
|
|
|
private Scene m_scene = null;
|
|
|
|
|
private IConfig m_config = null;
|
|
|
|
|
private bool m_enabled = true;
|
|
|
|
|
private string m_dataDirectory = "./PathFindingData";
|
|
|
|
|
private IScriptModuleComms m_scriptModule;
|
|
|
|
|
|
|
|
|
|
public string Name
|
|
|
|
|
{
|
|
|
|
|
get { return "BasicPathFindingModule"; }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public Type ReplaceableInterface
|
|
|
|
|
{
|
|
|
|
|
get { return null; }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void AddRegion(Scene scene)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void Close()
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void Initialise(IConfigSource source)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
m_config = source.Configs["XEngine"];
|
|
|
|
|
|
|
|
|
|
if (m_config != null)
|
|
|
|
|
{
|
|
|
|
|
m_dataDirectory = m_config.GetString("PathFindingDataDirectory", m_dataDirectory);
|
|
|
|
|
m_enabled = m_config.GetBoolean("EnablePathFinding", m_enabled);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
m_log.Error("[" + Name + "]: Cant find config.");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
catch (Exception e)
|
|
|
|
|
{
|
|
|
|
|
m_log.ErrorFormat("[" + Name + "]: initialization error: {0}", e.Message);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (m_enabled)
|
|
|
|
|
{
|
|
|
|
|
m_log.Info("[" + Name + "]: module is enabled");
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
m_log.Info("[" + Name + "]: module is disabled");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void RegionLoaded(Scene scene)
|
|
|
|
|
{
|
|
|
|
|
if (m_enabled)
|
|
|
|
|
{
|
|
|
|
|
m_log.Info("[" + Name + "]: Load region " + scene.Name);
|
|
|
|
|
|
|
|
|
|
m_scene = scene;
|
|
|
|
|
m_scriptModule = m_scene.RequestModuleInterface<IScriptModuleComms>();
|
|
|
|
|
if (m_scriptModule == null)
|
|
|
|
|
{
|
|
|
|
|
m_log.ErrorFormat("[" + Name + "]: Failed to load IScriptModuleComms!");
|
|
|
|
|
m_enabled = false;
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
m_scriptModule.RegisterScriptInvocation(this, "osCreateNewPathFindingScene");
|
|
|
|
|
//m_scriptModule.RegisterScriptInvocation(this, "osAddObjectToPathFindingScene");
|
|
|
|
|
//m_scriptModule.RegisterScriptInvocation(this, "osGetPath");
|
|
|
|
|
}
|
|
|
|
|
catch (Exception e)
|
|
|
|
|
{
|
|
|
|
|
m_log.WarnFormat("[" + Name + "]: script method registration failed; {0}", e.Message);
|
|
|
|
|
m_enabled = false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void RemoveRegion(Scene scene)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region Script Funktions
|
|
|
|
|
|
|
|
|
|
private bool checkIsPositionBlockedByObjekts(int posX, int posY)
|
|
|
|
|
{
|
|
|
|
|
List<SceneObjectGroup> _objects = m_scene.GetSceneObjectGroups().FindAll(X => X.IsPhantom != true && (int)X.AbsolutePosition.X == posX && (int)X.AbsolutePosition.Y == posY);
|
|
|
|
|
|
|
|
|
|
if (_objects.Count != 0)
|
|
|
|
|
return true;
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2020-06-10 16:03:33 +00:00
|
|
|
|
private void createTestImage()
|
2020-06-10 15:44:15 +00:00
|
|
|
|
{
|
|
|
|
|
Bitmap _map = new Bitmap((int)m_scene.RegionInfo.RegionSizeX, (int)m_scene.RegionInfo.RegionSizeY);
|
|
|
|
|
|
|
|
|
|
for (int X = 0; X <= m_scene.RegionInfo.RegionSizeX; X++)
|
|
|
|
|
{
|
2020-06-10 16:03:33 +00:00
|
|
|
|
m_log.Info("X: " + X);
|
2020-06-10 15:44:15 +00:00
|
|
|
|
for (int Y = 0; Y <= m_scene.RegionInfo.RegionSizeY; Y++)
|
|
|
|
|
{
|
2020-06-10 16:03:33 +00:00
|
|
|
|
m_log.Info("Y: " + Y);
|
|
|
|
|
|
|
|
|
|
_map.SetPixel(X, Y, Color.Green);
|
|
|
|
|
|
2020-06-10 15:44:15 +00:00
|
|
|
|
float baseheight = (float)m_scene.Heightmap[X, Y];
|
|
|
|
|
|
|
|
|
|
if (baseheight <= m_scene.RegionInfo.RegionSettings.WaterHeight)
|
|
|
|
|
_map.SetPixel(X, Y, Color.Red);
|
|
|
|
|
|
|
|
|
|
//if (checkIsPositionBlockedByObjekts(new LSL_Vector(X, Y, 0)) == true)
|
2020-06-10 16:03:33 +00:00
|
|
|
|
//_map.SetPixel(X, Y, Color.Yellow);
|
2020-06-10 15:44:15 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-06-10 16:03:33 +00:00
|
|
|
|
_map.Save("debug.png", ImageFormat.Png);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[ScriptInvocation]
|
|
|
|
|
public string osCreateNewPathFindingScene(UUID hostID, UUID scriptID)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
(new Thread(delegate () { createTestImage(); })).Start();
|
2020-06-10 15:44:15 +00:00
|
|
|
|
|
|
|
|
|
return "";
|
|
|
|
|
}
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|