2023-03-14 08:02:43 +03:00
|
|
|
/*
|
|
|
|
recast4j Copyright (c) 2015-2019 Piotr Piastucki piotr@jtilia.org
|
|
|
|
|
|
|
|
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;
|
|
|
|
using DotRecast.Detour.Io;
|
|
|
|
using NUnit.Framework;
|
|
|
|
|
|
|
|
namespace DotRecast.Detour.Test.Io;
|
|
|
|
|
2023-04-25 17:22:44 +03:00
|
|
|
[Parallelizable]
|
2023-03-16 19:48:49 +03:00
|
|
|
public class MeshSetReaderTest
|
|
|
|
{
|
2023-06-08 16:24:34 +03:00
|
|
|
private readonly DtMeshSetReader reader = new DtMeshSetReader();
|
2023-03-14 08:02:43 +03:00
|
|
|
|
|
|
|
[Test]
|
2023-05-05 02:44:48 +03:00
|
|
|
public void TestNavmesh()
|
2023-03-16 19:48:49 +03:00
|
|
|
{
|
2023-03-14 08:02:43 +03:00
|
|
|
byte[] @is = Loader.ToBytes("all_tiles_navmesh.bin");
|
|
|
|
using var ms = new MemoryStream(@is);
|
|
|
|
using var bris = new BinaryReader(ms);
|
2023-06-08 15:38:02 +03:00
|
|
|
DtNavMesh mesh = reader.Read(bris, 6);
|
2023-05-05 02:44:48 +03:00
|
|
|
Assert.That(mesh.GetMaxTiles(), Is.EqualTo(128));
|
|
|
|
Assert.That(mesh.GetParams().maxPolys, Is.EqualTo(0x8000));
|
|
|
|
Assert.That(mesh.GetParams().tileWidth, Is.EqualTo(9.6f).Within(0.001f));
|
2023-06-08 15:38:02 +03:00
|
|
|
List<DtMeshTile> tiles = mesh.GetTilesAt(4, 7);
|
2023-03-14 08:02:43 +03:00
|
|
|
Assert.That(tiles.Count, Is.EqualTo(1));
|
|
|
|
Assert.That(tiles[0].data.polys.Length, Is.EqualTo(7));
|
|
|
|
Assert.That(tiles[0].data.verts.Length, Is.EqualTo(22 * 3));
|
2023-05-05 02:44:48 +03:00
|
|
|
tiles = mesh.GetTilesAt(1, 6);
|
2023-03-14 08:02:43 +03:00
|
|
|
Assert.That(tiles.Count, Is.EqualTo(1));
|
|
|
|
Assert.That(tiles[0].data.polys.Length, Is.EqualTo(7));
|
|
|
|
Assert.That(tiles[0].data.verts.Length, Is.EqualTo(26 * 3));
|
2023-05-05 02:44:48 +03:00
|
|
|
tiles = mesh.GetTilesAt(6, 2);
|
2023-03-14 08:02:43 +03:00
|
|
|
Assert.That(tiles.Count, Is.EqualTo(1));
|
|
|
|
Assert.That(tiles[0].data.polys.Length, Is.EqualTo(1));
|
|
|
|
Assert.That(tiles[0].data.verts.Length, Is.EqualTo(4 * 3));
|
2023-05-05 02:44:48 +03:00
|
|
|
tiles = mesh.GetTilesAt(7, 6);
|
2023-03-14 08:02:43 +03:00
|
|
|
Assert.That(tiles.Count, Is.EqualTo(1));
|
|
|
|
Assert.That(tiles[0].data.polys.Length, Is.EqualTo(8));
|
|
|
|
Assert.That(tiles[0].data.verts.Length, Is.EqualTo(24 * 3));
|
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
2023-05-05 02:44:48 +03:00
|
|
|
public void TestDungeon()
|
2023-03-16 19:48:49 +03:00
|
|
|
{
|
2023-03-14 08:02:43 +03:00
|
|
|
byte[] @is = Loader.ToBytes("dungeon_all_tiles_navmesh.bin");
|
|
|
|
using var ms = new MemoryStream(@is);
|
|
|
|
using var bris = new BinaryReader(ms);
|
|
|
|
|
2023-06-08 15:38:02 +03:00
|
|
|
DtNavMesh mesh = reader.Read(bris, 6);
|
2023-05-05 02:44:48 +03:00
|
|
|
Assert.That(mesh.GetMaxTiles(), Is.EqualTo(128));
|
|
|
|
Assert.That(mesh.GetParams().maxPolys, Is.EqualTo(0x8000));
|
|
|
|
Assert.That(mesh.GetParams().tileWidth, Is.EqualTo(9.6f).Within(0.001f));
|
2023-06-08 15:38:02 +03:00
|
|
|
List<DtMeshTile> tiles = mesh.GetTilesAt(6, 9);
|
2023-03-14 08:02:43 +03:00
|
|
|
Assert.That(tiles.Count, Is.EqualTo(1));
|
|
|
|
Assert.That(tiles[0].data.polys.Length, Is.EqualTo(2));
|
|
|
|
Assert.That(tiles[0].data.verts.Length, Is.EqualTo(7 * 3));
|
2023-05-05 02:44:48 +03:00
|
|
|
tiles = mesh.GetTilesAt(2, 9);
|
2023-03-14 08:02:43 +03:00
|
|
|
Assert.That(tiles.Count, Is.EqualTo(1));
|
|
|
|
Assert.That(tiles[0].data.polys.Length, Is.EqualTo(2));
|
|
|
|
Assert.That(tiles[0].data.verts.Length, Is.EqualTo(9 * 3));
|
2023-05-05 02:44:48 +03:00
|
|
|
tiles = mesh.GetTilesAt(4, 3);
|
2023-03-14 08:02:43 +03:00
|
|
|
Assert.That(tiles.Count, Is.EqualTo(1));
|
|
|
|
Assert.That(tiles[0].data.polys.Length, Is.EqualTo(3));
|
|
|
|
Assert.That(tiles[0].data.verts.Length, Is.EqualTo(6 * 3));
|
2023-05-05 02:44:48 +03:00
|
|
|
tiles = mesh.GetTilesAt(2, 8);
|
2023-03-14 08:02:43 +03:00
|
|
|
Assert.That(tiles.Count, Is.EqualTo(1));
|
|
|
|
Assert.That(tiles[0].data.polys.Length, Is.EqualTo(5));
|
|
|
|
Assert.That(tiles[0].data.verts.Length, Is.EqualTo(17 * 3));
|
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
2023-05-05 02:44:48 +03:00
|
|
|
public void TestDungeon32Bit()
|
2023-03-16 19:48:49 +03:00
|
|
|
{
|
2023-03-14 08:02:43 +03:00
|
|
|
byte[] @is = Loader.ToBytes("dungeon_all_tiles_navmesh_32bit.bin");
|
|
|
|
using var ms = new MemoryStream(@is);
|
|
|
|
using var bris = new BinaryReader(ms);
|
|
|
|
|
2023-06-08 15:38:02 +03:00
|
|
|
DtNavMesh mesh = reader.Read32Bit(bris, 6);
|
2023-05-05 02:44:48 +03:00
|
|
|
Assert.That(mesh.GetMaxTiles(), Is.EqualTo(128));
|
|
|
|
Assert.That(mesh.GetParams().maxPolys, Is.EqualTo(0x8000));
|
|
|
|
Assert.That(mesh.GetParams().tileWidth, Is.EqualTo(9.6f).Within(0.001f));
|
2023-06-08 15:38:02 +03:00
|
|
|
List<DtMeshTile> tiles = mesh.GetTilesAt(6, 9);
|
2023-03-14 08:02:43 +03:00
|
|
|
Assert.That(tiles.Count, Is.EqualTo(1));
|
|
|
|
Assert.That(tiles[0].data.polys.Length, Is.EqualTo(2));
|
|
|
|
Assert.That(tiles[0].data.verts.Length, Is.EqualTo(7 * 3));
|
2023-05-05 02:44:48 +03:00
|
|
|
tiles = mesh.GetTilesAt(2, 9);
|
2023-03-14 08:02:43 +03:00
|
|
|
Assert.That(tiles.Count, Is.EqualTo(1));
|
|
|
|
Assert.That(tiles[0].data.polys.Length, Is.EqualTo(2));
|
|
|
|
Assert.That(tiles[0].data.verts.Length, Is.EqualTo(9 * 3));
|
2023-05-05 02:44:48 +03:00
|
|
|
tiles = mesh.GetTilesAt(4, 3);
|
2023-03-14 08:02:43 +03:00
|
|
|
Assert.That(tiles.Count, Is.EqualTo(1));
|
|
|
|
Assert.That(tiles[0].data.polys.Length, Is.EqualTo(3));
|
|
|
|
Assert.That(tiles[0].data.verts.Length, Is.EqualTo(6 * 3));
|
2023-05-05 02:44:48 +03:00
|
|
|
tiles = mesh.GetTilesAt(2, 8);
|
2023-03-14 08:02:43 +03:00
|
|
|
Assert.That(tiles.Count, Is.EqualTo(1));
|
|
|
|
Assert.That(tiles[0].data.polys.Length, Is.EqualTo(5));
|
|
|
|
Assert.That(tiles[0].data.verts.Length, Is.EqualTo(17 * 3));
|
|
|
|
}
|
2023-04-29 07:29:40 +03:00
|
|
|
}
|