rework
parent
6730366897
commit
796c45bbea
|
@ -31,6 +31,8 @@ namespace OpenSim.Modules.PathFinding
|
||||||
private string m_dataDirectory = "./PathFindingData";
|
private string m_dataDirectory = "./PathFindingData";
|
||||||
private IScriptModuleComms m_scriptModule;
|
private IScriptModuleComms m_scriptModule;
|
||||||
|
|
||||||
|
private List<Environment> m_environments = new List<Environment>();
|
||||||
|
|
||||||
public string Name
|
public string Name
|
||||||
{
|
{
|
||||||
get { return "BasicPathFindingModule"; }
|
get { return "BasicPathFindingModule"; }
|
||||||
|
@ -100,8 +102,16 @@ namespace OpenSim.Modules.PathFinding
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
m_scriptModule.RegisterScriptInvocation(this, "osCreateNewPathFindingScene");
|
m_scriptModule.RegisterScriptInvocation(this, "osGeneratePathEnv");
|
||||||
m_scriptModule.RegisterScriptInvocation(this, "osGetPath");
|
m_scriptModule.RegisterScriptInvocation(this, "osKeepAlivePathEnv");
|
||||||
|
m_scriptModule.RegisterScriptInvocation(this, "osSetPositionData");
|
||||||
|
m_scriptModule.RegisterScriptInvocation(this, "osGeneratePath");
|
||||||
|
|
||||||
|
m_scriptModule.RegisterScriptInvocation(this, "osGenerateDebugImage");
|
||||||
|
|
||||||
|
m_scriptModule.RegisterConstant("PATH_ENV_SUCCESSFUL", 19850);
|
||||||
|
m_scriptModule.RegisterConstant("PATH_ENV_NOT_FOUND", 19851);
|
||||||
|
m_scriptModule.RegisterConstant("PATH_ENV_OUT_OF_RANGE", 19852);
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
|
@ -120,28 +130,149 @@ namespace OpenSim.Modules.PathFinding
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
#region Asyn Funktions
|
||||||
|
|
||||||
|
private void generatePathEnvironment(ScriptRequestData requestData, int size)
|
||||||
|
{
|
||||||
|
UUID _envID = UUID.Random();
|
||||||
|
Environment _newEnv = new Environment(_envID.ToString(), size);
|
||||||
|
|
||||||
|
lock(m_environments)
|
||||||
|
{
|
||||||
|
m_environments.Add(_newEnv);
|
||||||
|
}
|
||||||
|
|
||||||
|
m_scriptModule.DispatchReply(requestData.ScriptID, 19850, _envID.ToString(), requestData.RequestID.ToString());
|
||||||
|
}
|
||||||
|
|
||||||
|
private void keepAlivePathEnv(ScriptRequestData requestData)
|
||||||
|
{
|
||||||
|
Environment _env = m_environments.Find(X => X.ID == requestData.EnvironmentID);
|
||||||
|
|
||||||
|
if(_env != null)
|
||||||
|
{
|
||||||
|
_env.LastTimeUsed = (Int32)(DateTime.UtcNow.Subtract(new DateTime(1970, 1, 1))).TotalSeconds;
|
||||||
|
m_scriptModule.DispatchReply(requestData.ScriptID, 19850, "", requestData.RequestID.ToString());
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
m_scriptModule.DispatchReply(requestData.ScriptID, 19851, "", requestData.RequestID.ToString());
|
||||||
|
}
|
||||||
|
|
||||||
|
private void setPositionData(ScriptRequestData requestData, Vector3 position, int walkable, int isTarget)
|
||||||
|
{
|
||||||
|
Environment _env = m_environments.Find(X => X.ID == requestData.EnvironmentID);
|
||||||
|
|
||||||
|
if (_env != null)
|
||||||
|
{
|
||||||
|
PathNode _node = _env.Nodes.Find(X => X.PositionX == (int)position.X && X.PositionY == (int)position.Y);
|
||||||
|
|
||||||
|
if (_node == null)
|
||||||
|
_node = new PathNode((int)position.X, (int)position.Y, false, false);
|
||||||
|
|
||||||
|
if (walkable == 1)
|
||||||
|
_node.Walkable = true;
|
||||||
|
|
||||||
|
if (walkable == 0)
|
||||||
|
_node.Walkable = false;
|
||||||
|
|
||||||
|
if (isTarget == 1)
|
||||||
|
_node.Target = true;
|
||||||
|
|
||||||
|
if (isTarget == 0)
|
||||||
|
_node.Target = false;
|
||||||
|
|
||||||
|
m_scriptModule.DispatchReply(requestData.ScriptID, 19850, "", requestData.RequestID.ToString());
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
m_scriptModule.DispatchReply(requestData.ScriptID, 19851, "", requestData.RequestID.ToString());
|
||||||
|
}
|
||||||
|
|
||||||
|
private void generatePath(ScriptRequestData requestData)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private void generateDebugImage(ScriptRequestData requestData)
|
||||||
|
{
|
||||||
|
Environment _env = m_environments.Find(X => X.ID == requestData.EnvironmentID);
|
||||||
|
|
||||||
|
if (_env != null)
|
||||||
|
{
|
||||||
|
Bitmap _bitmap = new Bitmap(_env.Size, _env.Size);
|
||||||
|
|
||||||
|
foreach(PathNode thisNode in _env.Nodes)
|
||||||
|
{
|
||||||
|
if (thisNode.Walkable)
|
||||||
|
_bitmap.SetPixel(thisNode.PositionX, thisNode.PositionY, Color.Green);
|
||||||
|
|
||||||
|
if (!thisNode.Walkable)
|
||||||
|
_bitmap.SetPixel(thisNode.PositionX, thisNode.PositionY, Color.Black);
|
||||||
|
|
||||||
|
if (!thisNode.Target)
|
||||||
|
_bitmap.SetPixel(thisNode.PositionX, thisNode.PositionY, Color.Blue);
|
||||||
|
}
|
||||||
|
|
||||||
|
_bitmap.Save(requestData.EnvironmentID + ".png");
|
||||||
|
m_scriptModule.DispatchReply(requestData.ScriptID, 19850, "", requestData.RequestID.ToString());
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
m_scriptModule.DispatchReply(requestData.ScriptID, 19851, "", requestData.RequestID.ToString());
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
#region Script Funktions
|
#region Script Funktions
|
||||||
|
|
||||||
private void createPathFindingScene(UUID script, UUID requestID, bool terrain, Vector3 start, Vector3 target)
|
[ScriptInvocation]
|
||||||
|
public string osGeneratePathEnv(UUID hostID, UUID scriptID, int size)
|
||||||
{
|
{
|
||||||
PathFinder _worker = new PathFinder(requestID, m_scene);
|
UUID requestKey = UUID.Random();
|
||||||
_worker.preparePathFindingScene(terrain);
|
|
||||||
_worker.setPositions(new Vector2(start.X, start.Y), new Vector2(target.X, target.Y));
|
|
||||||
|
|
||||||
m_scriptModule.DispatchReply(script, 0, "", requestID.ToString());
|
SceneObjectGroup _host = m_scene.GetSceneObjectGroup(hostID);
|
||||||
|
(new Thread(delegate () { generatePathEnvironment(new ScriptRequestData(hostID, scriptID), size); })).Start();
|
||||||
|
|
||||||
|
return requestKey.ToString();
|
||||||
}
|
}
|
||||||
|
|
||||||
[ScriptInvocation]
|
[ScriptInvocation]
|
||||||
public string osCreateNewPathFindingScene(UUID hostID, UUID scriptID, int terrain, Vector3 start, Vector3 target)
|
public string osKeepAlivePathEnv(UUID hostID, UUID scriptID, String environmentID)
|
||||||
{
|
{
|
||||||
UUID requestKey = UUID.Random();
|
UUID requestKey = UUID.Random();
|
||||||
bool useTerrain = false;
|
|
||||||
|
|
||||||
if (terrain == 1)
|
|
||||||
useTerrain = true;
|
|
||||||
|
|
||||||
SceneObjectGroup _host = m_scene.GetSceneObjectGroup(hostID);
|
SceneObjectGroup _host = m_scene.GetSceneObjectGroup(hostID);
|
||||||
(new Thread(delegate () { createPathFindingScene(scriptID, requestKey, useTerrain, start, target); })).Start();
|
(new Thread(delegate () { keepAlivePathEnv(new ScriptRequestData(hostID, scriptID, environmentID, requestKey)); })).Start();
|
||||||
|
|
||||||
|
return requestKey.ToString();
|
||||||
|
}
|
||||||
|
|
||||||
|
[ScriptInvocation]
|
||||||
|
public void osSetPositionData(UUID hostID, UUID scriptID, String environmentID, Vector3 position, int walkable, int isTarget)
|
||||||
|
{
|
||||||
|
SceneObjectGroup _host = m_scene.GetSceneObjectGroup(hostID);
|
||||||
|
(new Thread(delegate () { setPositionData(new ScriptRequestData(hostID, scriptID, environmentID), position, walkable, isTarget); })).Start();
|
||||||
|
}
|
||||||
|
|
||||||
|
[ScriptInvocation]
|
||||||
|
public string osGeneratePath(UUID hostID, UUID scriptID, String environmentID)
|
||||||
|
{
|
||||||
|
UUID requestKey = UUID.Random();
|
||||||
|
|
||||||
|
SceneObjectGroup _host = m_scene.GetSceneObjectGroup(hostID);
|
||||||
|
(new Thread(delegate () { generatePath(new ScriptRequestData(hostID, scriptID, environmentID, requestKey)); })).Start();
|
||||||
|
|
||||||
|
return requestKey.ToString();
|
||||||
|
}
|
||||||
|
|
||||||
|
[ScriptInvocation]
|
||||||
|
public string osGenerateDebugImage(UUID hostID, UUID scriptID, String environmentID)
|
||||||
|
{
|
||||||
|
UUID requestKey = UUID.Random();
|
||||||
|
|
||||||
|
SceneObjectGroup _host = m_scene.GetSceneObjectGroup(hostID);
|
||||||
|
(new Thread(delegate () { generateDebugImage(new ScriptRequestData(hostID, scriptID, environmentID, requestKey)); })).Start();
|
||||||
|
|
||||||
return requestKey.ToString();
|
return requestKey.ToString();
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,41 @@
|
||||||
|
using OpenMetaverse;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace OpenSim.Modules.PathFinding
|
||||||
|
{
|
||||||
|
class Environment
|
||||||
|
{
|
||||||
|
public String ID = null;
|
||||||
|
|
||||||
|
public int Size = 0;
|
||||||
|
public int LastTimeUsed = 0;
|
||||||
|
|
||||||
|
private List<PathNode> m_nodes = new List<PathNode>();
|
||||||
|
public List<PathNode> Nodes
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
LastTimeUsed = (Int32)(DateTime.UtcNow.Subtract(new DateTime(1970, 1, 1))).TotalSeconds;
|
||||||
|
return m_nodes;
|
||||||
|
}
|
||||||
|
set
|
||||||
|
{
|
||||||
|
LastTimeUsed = (Int32)(DateTime.UtcNow.Subtract(new DateTime(1970, 1, 1))).TotalSeconds;
|
||||||
|
m_nodes = value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public Environment(String envID, int size)
|
||||||
|
{
|
||||||
|
ID = envID;
|
||||||
|
|
||||||
|
Size = size;
|
||||||
|
|
||||||
|
LastTimeUsed = (Int32)(DateTime.UtcNow.Subtract(new DateTime(1970, 1, 1))).TotalSeconds;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,21 +0,0 @@
|
||||||
using OpenMetaverse;
|
|
||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Text;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
|
|
||||||
namespace OpenSim.Modules.PathFinding
|
|
||||||
{
|
|
||||||
class NodeInfo
|
|
||||||
{
|
|
||||||
public Vector2 Position = new Vector2(0, 0);
|
|
||||||
public int Counter = 0;
|
|
||||||
public bool Blocked = true;
|
|
||||||
|
|
||||||
public NodeInfo(Vector2 position)
|
|
||||||
{
|
|
||||||
Position = position;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,83 +0,0 @@
|
||||||
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)
|
|
||||||
{
|
|
||||||
Console.WriteLine("StartX = " + ((int)m_bitmap.Size.Width - (int)start.X));
|
|
||||||
Console.WriteLine("StartY = " + ((int)m_bitmap.Size.Height - (int)start.Y));
|
|
||||||
m_bitmap.SetPixel(m_bitmap.Size.Width - (int)start.X, m_bitmap.Size.Height - (int)start.Y, Color.Green);
|
|
||||||
m_bitmap.SetPixel(m_bitmap.Size.Width - (int)target.X, m_bitmap.Size.Height - (int)target.Y, 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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,370 +0,0 @@
|
||||||
using OpenMetaverse;
|
|
||||||
using OpenSim.Region.CoreModules.World.LegacyMap;
|
|
||||||
using OpenSim.Region.Framework.Interfaces;
|
|
||||||
using OpenSim.Region.Framework.Scenes;
|
|
||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Drawing;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Text;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
|
|
||||||
namespace OpenSim.Modules.PathFinding
|
|
||||||
{
|
|
||||||
class PathFindingSceneGenerator
|
|
||||||
{
|
|
||||||
public static Bitmap DrawObjectVolume(Scene whichScene, ref Bitmap mapbmp)
|
|
||||||
{
|
|
||||||
int tc = 0;
|
|
||||||
ITerrainChannel hm = whichScene.Heightmap;
|
|
||||||
tc = Environment.TickCount;
|
|
||||||
EntityBase[] objs = whichScene.GetEntities();
|
|
||||||
List<float> z_sortheights = new List<float>();
|
|
||||||
List<uint> z_localIDs = new List<uint>();
|
|
||||||
Dictionary<uint, DrawStruct> z_sort = new Dictionary<uint, DrawStruct>();
|
|
||||||
|
|
||||||
try
|
|
||||||
{
|
|
||||||
lock (objs)
|
|
||||||
{
|
|
||||||
foreach (EntityBase obj in objs)
|
|
||||||
{
|
|
||||||
// Only draw the contents of SceneObjectGroup
|
|
||||||
if (obj is SceneObjectGroup)
|
|
||||||
{
|
|
||||||
SceneObjectGroup mapdot = (SceneObjectGroup)obj;
|
|
||||||
|
|
||||||
if (mapdot.IsPhantom == true)
|
|
||||||
continue;
|
|
||||||
|
|
||||||
Color mapdotspot = Color.Black; // Default color when prim color is white
|
|
||||||
// Loop over prim in group
|
|
||||||
foreach (SceneObjectPart part in mapdot.Parts)
|
|
||||||
{
|
|
||||||
if (part == null)
|
|
||||||
continue;
|
|
||||||
|
|
||||||
if (part.Description.Contains("allowedpath"))
|
|
||||||
mapdotspot = Color.White;
|
|
||||||
|
|
||||||
// Draw if the object is at least 1 meter wide in any direction
|
|
||||||
if (part.Scale.X > 1f || part.Scale.Y > 1f || part.Scale.Z > 1f)
|
|
||||||
{
|
|
||||||
// Try to get the RGBA of the default texture entry..
|
|
||||||
//
|
|
||||||
try
|
|
||||||
{
|
|
||||||
// get the null checks out of the way
|
|
||||||
// skip the ones that break
|
|
||||||
if (part == null)
|
|
||||||
continue;
|
|
||||||
|
|
||||||
if (part.Shape == null)
|
|
||||||
continue;
|
|
||||||
|
|
||||||
if (part.Shape.PCode == (byte)PCode.Tree || part.Shape.PCode == (byte)PCode.NewTree || part.Shape.PCode == (byte)PCode.Grass)
|
|
||||||
continue; // eliminates trees from this since we don't really have a good tree representation
|
|
||||||
// if you want tree blocks on the map comment the above line and uncomment the below line
|
|
||||||
//mapdotspot = Color.PaleGreen;
|
|
||||||
|
|
||||||
Primitive.TextureEntry textureEntry = part.Shape.Textures;
|
|
||||||
|
|
||||||
if (textureEntry == null || textureEntry.DefaultTexture == null)
|
|
||||||
continue;
|
|
||||||
|
|
||||||
Color4 texcolor = textureEntry.DefaultTexture.RGBA;
|
|
||||||
|
|
||||||
// Not sure why some of these are null, oh well.
|
|
||||||
|
|
||||||
int colorr = 255 - (int)(texcolor.R * 255f);
|
|
||||||
int colorg = 255 - (int)(texcolor.G * 255f);
|
|
||||||
int colorb = 255 - (int)(texcolor.B * 255f);
|
|
||||||
|
|
||||||
if (!(colorr == 255 && colorg == 255 && colorb == 255))
|
|
||||||
{
|
|
||||||
//Try to set the map spot color
|
|
||||||
try
|
|
||||||
{
|
|
||||||
// If the color gets goofy somehow, skip it *shakes fist at Color4
|
|
||||||
//mapdotspot = Color.FromArgb(colorr, colorg, colorb);
|
|
||||||
}
|
|
||||||
catch (ArgumentException)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
catch (IndexOutOfRangeException)
|
|
||||||
{
|
|
||||||
// Windows Array
|
|
||||||
}
|
|
||||||
catch (ArgumentOutOfRangeException)
|
|
||||||
{
|
|
||||||
// Mono Array
|
|
||||||
}
|
|
||||||
|
|
||||||
Vector3 pos = part.GetWorldPosition();
|
|
||||||
|
|
||||||
// skip prim outside of region
|
|
||||||
if (!whichScene.PositionIsInCurrentRegion(pos))
|
|
||||||
continue;
|
|
||||||
|
|
||||||
// skip prim in non-finite position
|
|
||||||
if (Single.IsNaN(pos.X) || Single.IsNaN(pos.Y) ||
|
|
||||||
Single.IsInfinity(pos.X) || Single.IsInfinity(pos.Y))
|
|
||||||
continue;
|
|
||||||
|
|
||||||
// Figure out if object is under 256m above the height of the terrain
|
|
||||||
bool isBelow256AboveTerrain = false;
|
|
||||||
|
|
||||||
try
|
|
||||||
{
|
|
||||||
isBelow256AboveTerrain = (pos.Z < ((float)hm[(int)pos.X, (int)pos.Y] + 256f));
|
|
||||||
}
|
|
||||||
catch (Exception)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
if (isBelow256AboveTerrain)
|
|
||||||
{
|
|
||||||
// Translate scale by rotation so scale is represented properly when object is rotated
|
|
||||||
Vector3 lscale = new Vector3(part.Shape.Scale.X, part.Shape.Scale.Y, part.Shape.Scale.Z);
|
|
||||||
lscale *= 0.5f;
|
|
||||||
|
|
||||||
Vector3 scale = new Vector3();
|
|
||||||
Vector3 tScale = new Vector3();
|
|
||||||
Vector3 axPos = new Vector3(pos.X, pos.Y, pos.Z);
|
|
||||||
|
|
||||||
Quaternion rot = part.GetWorldRotation();
|
|
||||||
scale = lscale * rot;
|
|
||||||
|
|
||||||
// negative scales don't work in this situation
|
|
||||||
scale.X = Math.Abs(scale.X);
|
|
||||||
scale.Y = Math.Abs(scale.Y);
|
|
||||||
scale.Z = Math.Abs(scale.Z);
|
|
||||||
|
|
||||||
// This scaling isn't very accurate and doesn't take into account the face rotation :P
|
|
||||||
int mapdrawstartX = (int)(pos.X - scale.X);
|
|
||||||
int mapdrawstartY = (int)(pos.Y - scale.Y);
|
|
||||||
int mapdrawendX = (int)(pos.X + scale.X);
|
|
||||||
int mapdrawendY = (int)(pos.Y + scale.Y);
|
|
||||||
|
|
||||||
// If object is beyond the edge of the map, don't draw it to avoid errors
|
|
||||||
if (mapdrawstartX < 0
|
|
||||||
|| mapdrawstartX > (hm.Width - 1)
|
|
||||||
|| mapdrawendX < 0
|
|
||||||
|| mapdrawendX > (hm.Width - 1)
|
|
||||||
|| mapdrawstartY < 0
|
|
||||||
|| mapdrawstartY > (hm.Height - 1)
|
|
||||||
|| mapdrawendY < 0
|
|
||||||
|| mapdrawendY > (hm.Height - 1))
|
|
||||||
continue;
|
|
||||||
|
|
||||||
#region obb face reconstruction part duex
|
|
||||||
Vector3[] vertexes = new Vector3[8];
|
|
||||||
|
|
||||||
// float[] distance = new float[6];
|
|
||||||
Vector3[] FaceA = new Vector3[6]; // vertex A for Facei
|
|
||||||
Vector3[] FaceB = new Vector3[6]; // vertex B for Facei
|
|
||||||
Vector3[] FaceC = new Vector3[6]; // vertex C for Facei
|
|
||||||
Vector3[] FaceD = new Vector3[6]; // vertex D for Facei
|
|
||||||
|
|
||||||
tScale = new Vector3(lscale.X, -lscale.Y, lscale.Z);
|
|
||||||
scale = ((tScale * rot));
|
|
||||||
vertexes[0] = (new Vector3((pos.X + scale.X), (pos.Y + scale.Y), (pos.Z + scale.Z)));
|
|
||||||
// vertexes[0].x = pos.X + vertexes[0].x;
|
|
||||||
//vertexes[0].y = pos.Y + vertexes[0].y;
|
|
||||||
//vertexes[0].z = pos.Z + vertexes[0].z;
|
|
||||||
|
|
||||||
FaceA[0] = vertexes[0];
|
|
||||||
FaceB[3] = vertexes[0];
|
|
||||||
FaceA[4] = vertexes[0];
|
|
||||||
|
|
||||||
tScale = lscale;
|
|
||||||
scale = ((tScale * rot));
|
|
||||||
vertexes[1] = (new Vector3((pos.X + scale.X), (pos.Y + scale.Y), (pos.Z + scale.Z)));
|
|
||||||
|
|
||||||
// vertexes[1].x = pos.X + vertexes[1].x;
|
|
||||||
// vertexes[1].y = pos.Y + vertexes[1].y;
|
|
||||||
//vertexes[1].z = pos.Z + vertexes[1].z;
|
|
||||||
|
|
||||||
FaceB[0] = vertexes[1];
|
|
||||||
FaceA[1] = vertexes[1];
|
|
||||||
FaceC[4] = vertexes[1];
|
|
||||||
|
|
||||||
tScale = new Vector3(lscale.X, -lscale.Y, -lscale.Z);
|
|
||||||
scale = ((tScale * rot));
|
|
||||||
vertexes[2] = (new Vector3((pos.X + scale.X), (pos.Y + scale.Y), (pos.Z + scale.Z)));
|
|
||||||
|
|
||||||
//vertexes[2].x = pos.X + vertexes[2].x;
|
|
||||||
//vertexes[2].y = pos.Y + vertexes[2].y;
|
|
||||||
//vertexes[2].z = pos.Z + vertexes[2].z;
|
|
||||||
|
|
||||||
FaceC[0] = vertexes[2];
|
|
||||||
FaceD[3] = vertexes[2];
|
|
||||||
FaceC[5] = vertexes[2];
|
|
||||||
|
|
||||||
tScale = new Vector3(lscale.X, lscale.Y, -lscale.Z);
|
|
||||||
scale = ((tScale * rot));
|
|
||||||
vertexes[3] = (new Vector3((pos.X + scale.X), (pos.Y + scale.Y), (pos.Z + scale.Z)));
|
|
||||||
|
|
||||||
//vertexes[3].x = pos.X + vertexes[3].x;
|
|
||||||
// vertexes[3].y = pos.Y + vertexes[3].y;
|
|
||||||
// vertexes[3].z = pos.Z + vertexes[3].z;
|
|
||||||
|
|
||||||
FaceD[0] = vertexes[3];
|
|
||||||
FaceC[1] = vertexes[3];
|
|
||||||
FaceA[5] = vertexes[3];
|
|
||||||
|
|
||||||
tScale = new Vector3(-lscale.X, lscale.Y, lscale.Z);
|
|
||||||
scale = ((tScale * rot));
|
|
||||||
vertexes[4] = (new Vector3((pos.X + scale.X), (pos.Y + scale.Y), (pos.Z + scale.Z)));
|
|
||||||
|
|
||||||
// vertexes[4].x = pos.X + vertexes[4].x;
|
|
||||||
// vertexes[4].y = pos.Y + vertexes[4].y;
|
|
||||||
// vertexes[4].z = pos.Z + vertexes[4].z;
|
|
||||||
|
|
||||||
FaceB[1] = vertexes[4];
|
|
||||||
FaceA[2] = vertexes[4];
|
|
||||||
FaceD[4] = vertexes[4];
|
|
||||||
|
|
||||||
tScale = new Vector3(-lscale.X, lscale.Y, -lscale.Z);
|
|
||||||
scale = ((tScale * rot));
|
|
||||||
vertexes[5] = (new Vector3((pos.X + scale.X), (pos.Y + scale.Y), (pos.Z + scale.Z)));
|
|
||||||
|
|
||||||
// vertexes[5].x = pos.X + vertexes[5].x;
|
|
||||||
// vertexes[5].y = pos.Y + vertexes[5].y;
|
|
||||||
// vertexes[5].z = pos.Z + vertexes[5].z;
|
|
||||||
|
|
||||||
FaceD[1] = vertexes[5];
|
|
||||||
FaceC[2] = vertexes[5];
|
|
||||||
FaceB[5] = vertexes[5];
|
|
||||||
|
|
||||||
tScale = new Vector3(-lscale.X, -lscale.Y, lscale.Z);
|
|
||||||
scale = ((tScale * rot));
|
|
||||||
vertexes[6] = (new Vector3((pos.X + scale.X), (pos.Y + scale.Y), (pos.Z + scale.Z)));
|
|
||||||
|
|
||||||
// vertexes[6].x = pos.X + vertexes[6].x;
|
|
||||||
// vertexes[6].y = pos.Y + vertexes[6].y;
|
|
||||||
// vertexes[6].z = pos.Z + vertexes[6].z;
|
|
||||||
|
|
||||||
FaceB[2] = vertexes[6];
|
|
||||||
FaceA[3] = vertexes[6];
|
|
||||||
FaceB[4] = vertexes[6];
|
|
||||||
|
|
||||||
tScale = new Vector3(-lscale.X, -lscale.Y, -lscale.Z);
|
|
||||||
scale = ((tScale * rot));
|
|
||||||
vertexes[7] = (new Vector3((pos.X + scale.X), (pos.Y + scale.Y), (pos.Z + scale.Z)));
|
|
||||||
|
|
||||||
// vertexes[7].x = pos.X + vertexes[7].x;
|
|
||||||
// vertexes[7].y = pos.Y + vertexes[7].y;
|
|
||||||
// vertexes[7].z = pos.Z + vertexes[7].z;
|
|
||||||
|
|
||||||
FaceD[2] = vertexes[7];
|
|
||||||
FaceC[3] = vertexes[7];
|
|
||||||
FaceD[5] = vertexes[7];
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
//int wy = 0;
|
|
||||||
|
|
||||||
//bool breakYN = false; // If we run into an error drawing, break out of the
|
|
||||||
// loop so we don't lag to death on error handling
|
|
||||||
DrawStruct ds = new DrawStruct();
|
|
||||||
ds.brush = new SolidBrush(mapdotspot);
|
|
||||||
//ds.rect = new Rectangle(mapdrawstartX, (255 - mapdrawstartY), mapdrawendX - mapdrawstartX, mapdrawendY - mapdrawstartY);
|
|
||||||
|
|
||||||
ds.trns = new face[FaceA.Length];
|
|
||||||
|
|
||||||
for (int i = 0; i < FaceA.Length; i++)
|
|
||||||
{
|
|
||||||
Point[] working = new Point[5];
|
|
||||||
working[0] = project(hm, FaceA[i], axPos);
|
|
||||||
working[1] = project(hm, FaceB[i], axPos);
|
|
||||||
working[2] = project(hm, FaceD[i], axPos);
|
|
||||||
working[3] = project(hm, FaceC[i], axPos);
|
|
||||||
working[4] = project(hm, FaceA[i], axPos);
|
|
||||||
|
|
||||||
face workingface = new face();
|
|
||||||
workingface.pts = working;
|
|
||||||
|
|
||||||
ds.trns[i] = workingface;
|
|
||||||
}
|
|
||||||
|
|
||||||
z_sort.Add(part.LocalId, ds);
|
|
||||||
z_localIDs.Add(part.LocalId);
|
|
||||||
z_sortheights.Add(pos.Z);
|
|
||||||
|
|
||||||
// for (int wx = mapdrawstartX; wx < mapdrawendX; wx++)
|
|
||||||
// {
|
|
||||||
// for (wy = mapdrawstartY; wy < mapdrawendY; wy++)
|
|
||||||
// {
|
|
||||||
// m_log.InfoFormat("[MAPDEBUG]: {0},{1}({2})", wx, (255 - wy),wy);
|
|
||||||
// try
|
|
||||||
// {
|
|
||||||
// // Remember, flip the y!
|
|
||||||
// mapbmp.SetPixel(wx, (255 - wy), mapdotspot);
|
|
||||||
// }
|
|
||||||
// catch (ArgumentException)
|
|
||||||
// {
|
|
||||||
// breakYN = true;
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// if (breakYN)
|
|
||||||
// break;
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
//}
|
|
||||||
} // Object is within 256m Z of terrain
|
|
||||||
} // object is at least a meter wide
|
|
||||||
} // loop over group children
|
|
||||||
} // entitybase is sceneobject group
|
|
||||||
} // foreach loop over entities
|
|
||||||
|
|
||||||
float[] sortedZHeights = z_sortheights.ToArray();
|
|
||||||
uint[] sortedlocalIds = z_localIDs.ToArray();
|
|
||||||
|
|
||||||
// Sort prim by Z position
|
|
||||||
Array.Sort(sortedZHeights, sortedlocalIds);
|
|
||||||
|
|
||||||
using (Graphics g = Graphics.FromImage(mapbmp))
|
|
||||||
{
|
|
||||||
for (int s = 0; s < sortedZHeights.Length; s++)
|
|
||||||
{
|
|
||||||
if (z_sort.ContainsKey(sortedlocalIds[s]))
|
|
||||||
{
|
|
||||||
DrawStruct rectDrawStruct = z_sort[sortedlocalIds[s]];
|
|
||||||
for (int r = 0; r < rectDrawStruct.trns.Length; r++)
|
|
||||||
{
|
|
||||||
g.FillPolygon(rectDrawStruct.brush, rectDrawStruct.trns[r].pts);
|
|
||||||
}
|
|
||||||
//g.FillRectangle(rectDrawStruct.brush , rectDrawStruct.rect);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} // lock entities objs
|
|
||||||
|
|
||||||
}
|
|
||||||
finally
|
|
||||||
{
|
|
||||||
foreach (DrawStruct ds in z_sort.Values)
|
|
||||||
ds.brush.Dispose();
|
|
||||||
}
|
|
||||||
|
|
||||||
return mapbmp;
|
|
||||||
}
|
|
||||||
|
|
||||||
private static Point project(ITerrainChannel hm, Vector3 point3d, Vector3 originpos)
|
|
||||||
{
|
|
||||||
Point returnpt = new Point();
|
|
||||||
//originpos = point3d;
|
|
||||||
//int d = (int)(256f / 1.5f);
|
|
||||||
|
|
||||||
//Vector3 topos = new Vector3(0, 0, 0);
|
|
||||||
// float z = -point3d.z - topos.z;
|
|
||||||
|
|
||||||
returnpt.X = (int)point3d.X;//(int)((topos.x - point3d.x) / z * d);
|
|
||||||
returnpt.Y = (int)((hm.Width - 1) - point3d.Y);//(int)(255 - (((topos.y - point3d.y) / z * d)));
|
|
||||||
|
|
||||||
return returnpt;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -0,0 +1,44 @@
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace OpenSim.Modules.PathFinding
|
||||||
|
{
|
||||||
|
class PathNode
|
||||||
|
{
|
||||||
|
public int PositionX = 0;
|
||||||
|
public int PositionY = 0;
|
||||||
|
|
||||||
|
public bool Walkable = false;
|
||||||
|
public bool Target = false;
|
||||||
|
|
||||||
|
public int Coast = 0;
|
||||||
|
|
||||||
|
public PathNode Parent = null;
|
||||||
|
|
||||||
|
public PathNode(int positionX, int positionY)
|
||||||
|
{
|
||||||
|
PositionX = positionX;
|
||||||
|
PositionY = positionY;
|
||||||
|
}
|
||||||
|
|
||||||
|
public PathNode(int positionX, int positionY, bool isWalkable)
|
||||||
|
{
|
||||||
|
PositionX = positionX;
|
||||||
|
PositionY = positionY;
|
||||||
|
|
||||||
|
Walkable = isWalkable;
|
||||||
|
}
|
||||||
|
|
||||||
|
public PathNode(int positionX, int positionY, bool isWalkable, bool isTarget)
|
||||||
|
{
|
||||||
|
PositionX = positionX;
|
||||||
|
PositionY = positionY;
|
||||||
|
|
||||||
|
Walkable = isWalkable;
|
||||||
|
Target = isTarget;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,38 @@
|
||||||
|
using OpenMetaverse;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace OpenSim.Modules.PathFinding
|
||||||
|
{
|
||||||
|
class ScriptRequestData
|
||||||
|
{
|
||||||
|
public UUID HostID = UUID.Zero;
|
||||||
|
public UUID ScriptID = UUID.Zero;
|
||||||
|
public String EnvironmentID = null;
|
||||||
|
public UUID RequestID = UUID.Zero;
|
||||||
|
|
||||||
|
public ScriptRequestData(UUID host, UUID script)
|
||||||
|
{
|
||||||
|
HostID = host;
|
||||||
|
ScriptID = script;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ScriptRequestData(UUID host, UUID script, String envID)
|
||||||
|
{
|
||||||
|
HostID = host;
|
||||||
|
ScriptID = script;
|
||||||
|
EnvironmentID = envID;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ScriptRequestData(UUID host, UUID script, String envID, UUID requestID)
|
||||||
|
{
|
||||||
|
HostID = host;
|
||||||
|
ScriptID = script;
|
||||||
|
EnvironmentID = envID;
|
||||||
|
RequestID = requestID;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue