2023-03-14 08:02:43 +03:00
|
|
|
/*
|
|
|
|
Copyright (c) 2009-2010 Mikko Mononen memon@inside.org
|
|
|
|
recast4j copyright (c) 2015-2019 Piotr Piastucki piotr@jtilia.org
|
2023-03-15 17:00:29 +03:00
|
|
|
DotRecast Copyright (c) 2023 Choi Ikpil ikpil@naver.com
|
2023-03-14 08:02:43 +03:00
|
|
|
|
|
|
|
This software is provided 'as-is', without any express or implied
|
|
|
|
warranty. In no event will the authors be held liable for any damages
|
|
|
|
arising from the use of this software.
|
|
|
|
Permission is granted to anyone to use this software for any purpose,
|
|
|
|
including commercial applications, and to alter it and redistribute it
|
|
|
|
freely, subject to the following restrictions:
|
|
|
|
1. The origin of this software must not be misrepresented; you must not
|
|
|
|
claim that you wrote the original software. If you use this software
|
|
|
|
in a product, an acknowledgment in the product documentation would be
|
|
|
|
appreciated but is not required.
|
|
|
|
2. Altered source versions must be plainly marked as such, and must not be
|
|
|
|
misrepresented as being the original software.
|
|
|
|
3. This notice may not be removed or altered from any source distribution.
|
|
|
|
*/
|
|
|
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
using DotRecast.Core;
|
2023-10-16 17:55:34 +03:00
|
|
|
using DotRecast.Core.Numerics;
|
2023-03-14 08:02:43 +03:00
|
|
|
using DotRecast.Recast.Geom;
|
|
|
|
using NUnit.Framework;
|
|
|
|
|
|
|
|
namespace DotRecast.Detour.TileCache.Test;
|
|
|
|
|
2023-04-25 17:22:44 +03:00
|
|
|
[Parallelizable]
|
2023-03-16 19:48:49 +03:00
|
|
|
public class TileCacheNavigationTest : AbstractTileCacheTest
|
|
|
|
{
|
2023-03-14 08:02:43 +03:00
|
|
|
protected readonly long[] startRefs = { 281475006070787L };
|
|
|
|
protected readonly long[] endRefs = { 281474986147841L };
|
2023-10-12 17:52:32 +03:00
|
|
|
protected readonly RcVec3f[] startPoss = { new RcVec3f(39.447338f, 9.998177f, -0.784811f) };
|
|
|
|
protected readonly RcVec3f[] endPoss = { new RcVec3f(19.292645f, 11.611748f, -57.750366f) };
|
2023-12-21 19:23:13 +03:00
|
|
|
private readonly DtStatus[] statuses = { DtStatus.DT_SUCCESS };
|
2023-03-16 19:48:49 +03:00
|
|
|
|
|
|
|
private readonly long[][] results =
|
|
|
|
{
|
|
|
|
new[]
|
|
|
|
{
|
|
|
|
281475006070787L, 281475006070785L, 281475005022208L, 281475005022209L, 281475003973633L,
|
2023-03-14 08:02:43 +03:00
|
|
|
281475003973634L, 281475003973632L, 281474996633604L, 281474996633605L, 281474996633603L, 281474995585027L,
|
|
|
|
281474995585029L, 281474995585026L, 281474995585028L, 281474995585024L, 281474991390721L, 281474991390722L,
|
|
|
|
281474991390725L, 281474991390720L, 281474987196418L, 281474987196417L, 281474988244995L, 281474988245001L,
|
|
|
|
281474988244997L, 281474988244998L, 281474988245002L, 281474988245000L, 281474988244999L, 281474988244994L,
|
2023-03-16 19:48:49 +03:00
|
|
|
281474985099264L, 281474985099266L, 281474986147841L
|
|
|
|
}
|
|
|
|
};
|
2023-03-14 08:02:43 +03:00
|
|
|
|
2023-06-08 15:38:02 +03:00
|
|
|
protected DtNavMesh navmesh;
|
|
|
|
protected DtNavMeshQuery query;
|
2023-03-14 08:02:43 +03:00
|
|
|
|
|
|
|
[SetUp]
|
2023-05-05 02:44:48 +03:00
|
|
|
public void SetUp()
|
2023-03-16 19:48:49 +03:00
|
|
|
{
|
2023-03-14 08:02:43 +03:00
|
|
|
bool cCompatibility = true;
|
2023-09-24 12:42:41 +03:00
|
|
|
IInputGeomProvider geom = SimpleInputGeomProvider.LoadFile("dungeon.obj");
|
2023-03-14 08:02:43 +03:00
|
|
|
TestTileLayerBuilder layerBuilder = new TestTileLayerBuilder(geom);
|
2023-05-10 16:44:51 +03:00
|
|
|
List<byte[]> layers = layerBuilder.Build(RcByteOrder.LITTLE_ENDIAN, cCompatibility, 1);
|
2023-06-08 16:24:34 +03:00
|
|
|
DtTileCache tc = GetTileCache(geom, RcByteOrder.LITTLE_ENDIAN, cCompatibility);
|
2023-03-16 19:48:49 +03:00
|
|
|
foreach (byte[] data in layers)
|
|
|
|
{
|
2023-05-05 02:44:48 +03:00
|
|
|
tc.AddTile(data, 0);
|
2023-03-14 08:02:43 +03:00
|
|
|
}
|
2023-03-16 19:48:49 +03:00
|
|
|
|
2023-08-19 06:48:47 +03:00
|
|
|
for (int y = 0; y < layerBuilder.th; ++y)
|
2023-03-16 19:48:49 +03:00
|
|
|
{
|
2023-08-19 06:48:47 +03:00
|
|
|
for (int x = 0; x < layerBuilder.tw; ++x)
|
2023-03-16 19:48:49 +03:00
|
|
|
{
|
2023-05-05 02:44:48 +03:00
|
|
|
foreach (long refs in tc.GetTilesAt(x, y))
|
2023-03-16 19:48:49 +03:00
|
|
|
{
|
2023-05-05 02:44:48 +03:00
|
|
|
tc.BuildNavMeshTile(refs);
|
2023-03-14 08:02:43 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2023-03-16 19:48:49 +03:00
|
|
|
|
2023-05-05 02:44:48 +03:00
|
|
|
navmesh = tc.GetNavMesh();
|
2023-06-08 15:38:02 +03:00
|
|
|
query = new DtNavMeshQuery(navmesh);
|
2023-03-14 08:02:43 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
2023-05-05 02:44:48 +03:00
|
|
|
public void TestFindPathWithDefaultHeuristic()
|
2023-03-16 19:48:49 +03:00
|
|
|
{
|
2023-06-08 15:38:02 +03:00
|
|
|
IDtQueryFilter filter = new DtQueryDefaultFilter();
|
2023-06-23 01:33:03 +03:00
|
|
|
var path = new List<long>();
|
2023-03-16 19:48:49 +03:00
|
|
|
for (int i = 0; i < startRefs.Length; i++)
|
|
|
|
{
|
2023-03-14 08:02:43 +03:00
|
|
|
long startRef = startRefs[i];
|
|
|
|
long endRef = endRefs[i];
|
2023-06-03 15:47:26 +03:00
|
|
|
RcVec3f startPos = startPoss[i];
|
|
|
|
RcVec3f endPos = endPoss[i];
|
2023-06-23 01:33:03 +03:00
|
|
|
var status = query.FindPath(startRef, endRef, startPos, endPos, filter, ref path, DtFindPathOption.NoOption);
|
|
|
|
Assert.That(status, Is.EqualTo(statuses[i]));
|
|
|
|
Assert.That(path.Count, Is.EqualTo(results[i].Length));
|
2023-03-16 19:48:49 +03:00
|
|
|
for (int j = 0; j < results[i].Length; j++)
|
|
|
|
{
|
2023-06-23 01:33:03 +03:00
|
|
|
Assert.That(path[j], Is.EqualTo(results[i][j])); // TODO : 확인 필요
|
2023-03-14 08:02:43 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
2023-05-05 02:44:48 +03:00
|
|
|
public void TestFindPathWithNoHeuristic()
|
2023-03-16 19:48:49 +03:00
|
|
|
{
|
2023-06-08 15:38:02 +03:00
|
|
|
IDtQueryFilter filter = new DtQueryDefaultFilter();
|
2023-06-23 01:33:03 +03:00
|
|
|
var path = new List<long>();
|
2023-03-16 19:48:49 +03:00
|
|
|
for (int i = 0; i < startRefs.Length; i++)
|
|
|
|
{
|
2023-03-14 08:02:43 +03:00
|
|
|
long startRef = startRefs[i];
|
|
|
|
long endRef = endRefs[i];
|
2023-06-03 15:47:26 +03:00
|
|
|
RcVec3f startPos = startPoss[i];
|
|
|
|
RcVec3f endPos = endPoss[i];
|
2023-06-23 01:33:03 +03:00
|
|
|
var status = query.FindPath(startRef, endRef, startPos, endPos, filter, ref path, DtFindPathOption.ZeroScale);
|
|
|
|
Assert.That(status, Is.EqualTo(statuses[i]));
|
|
|
|
Assert.That(path.Count, Is.EqualTo(results[i].Length));
|
2023-03-16 19:48:49 +03:00
|
|
|
for (int j = 0; j < results[i].Length; j++)
|
|
|
|
{
|
2023-06-23 01:33:03 +03:00
|
|
|
Assert.That(path[j], Is.EqualTo(results[i][j])); // TODO : 확인 필요
|
2023-03-14 08:02:43 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2023-03-16 19:48:49 +03:00
|
|
|
}
|