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 System.IO;
|
|
|
|
using DotRecast.Core;
|
2023-04-23 08:13:10 +03:00
|
|
|
using DotRecast.Detour.QueryResults;
|
2023-03-14 08:02:43 +03:00
|
|
|
using DotRecast.Detour.TileCache.Io;
|
|
|
|
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 TileCacheFindPathTest : AbstractTileCacheTest
|
|
|
|
{
|
2023-06-03 15:47:26 +03:00
|
|
|
private readonly RcVec3f start = RcVec3f.Of(39.44734f, 9.998177f, -0.784811f);
|
|
|
|
private readonly RcVec3f end = RcVec3f.Of(19.292645f, 11.611748f, -57.750366f);
|
2023-06-08 15:38:02 +03:00
|
|
|
private readonly DtNavMesh navmesh;
|
|
|
|
private readonly DtNavMeshQuery query;
|
2023-03-14 08:02:43 +03:00
|
|
|
|
2023-03-16 19:48:49 +03:00
|
|
|
public TileCacheFindPathTest()
|
|
|
|
{
|
2023-03-14 08:02:43 +03:00
|
|
|
using var msis = new MemoryStream(Loader.ToBytes("dungeon_all_tiles_tilecache.bin"));
|
|
|
|
using var @is = new BinaryReader(msis);
|
2023-06-08 16:24:34 +03:00
|
|
|
DtTileCache tcC = new DtTileCacheReader().Read(@is, 6, new TestTileCacheMeshProcess());
|
2023-05-05 02:44:48 +03:00
|
|
|
navmesh = tcC.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 TestFindPath()
|
2023-03-16 19:48:49 +03:00
|
|
|
{
|
2023-06-08 15:38:02 +03:00
|
|
|
IDtQueryFilter filter = new DtQueryDefaultFilter();
|
2023-06-03 15:47:26 +03:00
|
|
|
RcVec3f extents = RcVec3f.Of(2f, 4f, 2f);
|
2023-06-11 07:28:05 +03:00
|
|
|
query.FindNearestPoly(start, extents, filter, out var startRef, out var startPos, out var _);
|
|
|
|
query.FindNearestPoly(end, extents, filter, out var endRef, out var endPos, out var _);
|
|
|
|
|
2023-05-05 02:44:48 +03:00
|
|
|
Result<List<long>> path = query.FindPath(startRef, endRef, startPos, endPos, filter);
|
2023-03-14 08:02:43 +03:00
|
|
|
int maxStraightPath = 256;
|
|
|
|
int options = 0;
|
2023-05-05 02:44:48 +03:00
|
|
|
Result<List<StraightPathItem>> pathStr = query.FindStraightPath(startPos, endPos, path.result, maxStraightPath, options);
|
2023-03-14 08:02:43 +03:00
|
|
|
Assert.That(pathStr.result.Count, Is.EqualTo(8));
|
|
|
|
}
|
|
|
|
}
|