remove nodes and use bitmap
parent
fc2c870e05
commit
28df1f23d0
|
@ -12,32 +12,27 @@ namespace OpenSim.Modules.PathFinding
|
|||
{
|
||||
class PathFinder
|
||||
{
|
||||
private List<NodeInfo> m_nodes = new List<NodeInfo>();
|
||||
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)
|
||||
{
|
||||
generateEmptryNodeGrid(new Vector2((int)m_scene.RegionInfo.RegionSizeX, (int)m_scene.RegionInfo.RegionSizeY));
|
||||
convertRegionToNodeList(terrain);
|
||||
convertRegionToBitmap(terrain);
|
||||
saveDebugImageToDisc();
|
||||
}
|
||||
|
||||
public void generatePath(Vector2 start, Vector2 target)
|
||||
{
|
||||
|
||||
|
||||
}
|
||||
|
||||
private void convertRegionToNodeList(bool terrain)
|
||||
private void convertRegionToBitmap(bool terrain)
|
||||
{
|
||||
if (terrain == true)
|
||||
{
|
||||
|
@ -49,109 +44,22 @@ namespace OpenSim.Modules.PathFinding
|
|||
|
||||
//Block the position then water is on this place.
|
||||
if (baseheight <= m_scene.RegionInfo.RegionSettings.WaterHeight)
|
||||
setNoteBlocked(new Vector2(X, Y), true);
|
||||
m_bitmap.SetPixel(X, Y, Color.Black);
|
||||
|
||||
//Allow all positions they have terrain over the water height.
|
||||
if (baseheight > m_scene.RegionInfo.RegionSettings.WaterHeight)
|
||||
setNoteBlocked(new Vector2(X, Y), false);
|
||||
m_bitmap.SetPixel(X, Y, Color.White);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Bitmap _objectData = new Bitmap((int)m_scene.RegionInfo.RegionSizeX, (int)m_scene.RegionInfo.RegionSizeY);
|
||||
PathFindingSceneGenerator.DrawObjectVolume(m_scene, ref _objectData);
|
||||
convertBitmapToNodeList(ref _objectData);
|
||||
PathFindingSceneGenerator.DrawObjectVolume(m_scene, ref m_bitmap);
|
||||
}
|
||||
|
||||
private void setNoteBlocked(Vector2 position, bool state)
|
||||
{
|
||||
NodeInfo _infoNode = m_nodes.Find(X => X.Position.X.Equals(position.X) && X.Position.Y.Equals(position.Y));
|
||||
|
||||
if(_infoNode != null)
|
||||
{
|
||||
_infoNode.Blocked = state;
|
||||
}
|
||||
else
|
||||
{
|
||||
Console.WriteLine("setNoteBlocked: Cant find Node at " + position.ToString());
|
||||
}
|
||||
}
|
||||
|
||||
private bool getNoteBlocked(Vector2 position)
|
||||
{
|
||||
NodeInfo _infoNode = m_nodes.Find(X => X.Position.X.Equals(position.X) && X.Position.Y.Equals(position.Y));
|
||||
|
||||
if (_infoNode != null)
|
||||
{
|
||||
return _infoNode.Blocked;
|
||||
}
|
||||
else
|
||||
{
|
||||
Console.WriteLine("getNoteBlocked: Cant find Node at " + position.ToString());
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
private void generateEmptryNodeGrid(Vector2 size)
|
||||
{
|
||||
for (int X = 0; X <= size.X; X++)
|
||||
{
|
||||
for (int Y = 0; Y <= size.Y; Y++)
|
||||
{
|
||||
m_nodes.Add(new NodeInfo(new Vector2(X, Y)));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void convertBitmapToNodeList(ref Bitmap bitmap)
|
||||
{
|
||||
for (int X = 0; X < bitmap.Width; X++)
|
||||
{
|
||||
for (int Y = 0; Y < bitmap.Height; Y++)
|
||||
{
|
||||
Color _pixelColor = bitmap.GetPixel(X, Y);
|
||||
|
||||
Console.WriteLine("convertBitmapToNodeList: X:"+X+" Y:"+Y+" COLOR:" + _pixelColor.R +";" + _pixelColor.G + ";" + _pixelColor.B);
|
||||
|
||||
bool blocking = true;
|
||||
|
||||
if (_pixelColor.R == 255)
|
||||
blocking = false;
|
||||
|
||||
setNoteBlocked(new Vector2(X, Y), false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private Bitmap convertNodeListToBitmap()
|
||||
{
|
||||
Bitmap _bitmap = new Bitmap((int)m_scene.RegionInfo.RegionSizeX, (int)m_scene.RegionInfo.RegionSizeY);
|
||||
|
||||
for (int X = 0; X < _bitmap.Width; X++)
|
||||
{
|
||||
for (int Y = 0; Y < _bitmap.Height; Y++)
|
||||
{
|
||||
bool _nodeState = getNoteBlocked(new Vector2(X, Y));
|
||||
|
||||
if(_nodeState == true)
|
||||
{
|
||||
_bitmap.SetPixel(X, Y, Color.Black);
|
||||
}
|
||||
else
|
||||
{
|
||||
_bitmap.SetPixel(X, Y, Color.White);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return _bitmap;
|
||||
}
|
||||
|
||||
private void saveDebugImageToDisc()
|
||||
{
|
||||
Bitmap _bitmap = convertNodeListToBitmap();
|
||||
_bitmap.Save(m_requestID + ".png", ImageFormat.Png);
|
||||
m_bitmap.Save(m_requestID + ".png", ImageFormat.Png);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue