DotRecastNetSim/test/DotRecast.Detour.Test/Io/MeshSetReaderTest.cs

140 lines
5.6 KiB
C#
Raw Normal View History

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-03-16 19:48:49 +03:00
public class MeshSetReaderTest
{
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
{
byte[] @is = RcResources.Load("all_tiles_navmesh.bin");
2023-03-14 08:02:43 +03:00
using var ms = new MemoryStream(@is);
2023-08-19 09:45:05 +03:00
using var br = new BinaryReader(ms);
DtNavMesh mesh = reader.Read(br, 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));
const int MAX_NEIS = 32;
DtMeshTile[] tiles = new DtMeshTile[MAX_NEIS];
int nneis = 0;
nneis = mesh.GetTilesAt(4, 7, tiles, MAX_NEIS);
Assert.That(nneis, Is.EqualTo(1));
2023-03-14 08:02:43 +03:00
Assert.That(tiles[0].data.polys.Length, Is.EqualTo(7));
Assert.That(tiles[0].data.verts.Length, Is.EqualTo(22 * 3));
nneis = mesh.GetTilesAt(1, 6, tiles, MAX_NEIS);
Assert.That(nneis, Is.EqualTo(1));
2023-03-14 08:02:43 +03:00
Assert.That(tiles[0].data.polys.Length, Is.EqualTo(7));
Assert.That(tiles[0].data.verts.Length, Is.EqualTo(26 * 3));
nneis = mesh.GetTilesAt(6, 2, tiles, MAX_NEIS);
Assert.That(nneis, Is.EqualTo(1));
2023-03-14 08:02:43 +03:00
Assert.That(tiles[0].data.polys.Length, Is.EqualTo(1));
Assert.That(tiles[0].data.verts.Length, Is.EqualTo(4 * 3));
nneis = mesh.GetTilesAt(7, 6, tiles, MAX_NEIS);
Assert.That(nneis, Is.EqualTo(1));
2023-03-14 08:02:43 +03:00
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
{
byte[] @is = RcResources.Load("dungeon_all_tiles_navmesh.bin");
2023-03-14 08:02:43 +03:00
using var ms = new MemoryStream(@is);
2023-08-19 09:45:05 +03:00
using var br = new BinaryReader(ms);
2023-03-14 08:02:43 +03:00
2023-08-19 09:45:05 +03:00
DtNavMesh mesh = reader.Read(br, 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));
const int MAX_NEIS = 32;
DtMeshTile[] tiles = new DtMeshTile[MAX_NEIS];
int nneis = 0;
nneis = mesh.GetTilesAt(6, 9, tiles, MAX_NEIS);
Assert.That(nneis, Is.EqualTo(1));
2023-03-14 08:02:43 +03:00
Assert.That(tiles[0].data.polys.Length, Is.EqualTo(2));
Assert.That(tiles[0].data.verts.Length, Is.EqualTo(7 * 3));
nneis = mesh.GetTilesAt(2, 9, tiles, MAX_NEIS);
Assert.That(nneis, Is.EqualTo(1));
2023-03-14 08:02:43 +03:00
Assert.That(tiles[0].data.polys.Length, Is.EqualTo(2));
Assert.That(tiles[0].data.verts.Length, Is.EqualTo(9 * 3));
nneis = mesh.GetTilesAt(4, 3, tiles, MAX_NEIS);
Assert.That(nneis, Is.EqualTo(1));
2023-03-14 08:02:43 +03:00
Assert.That(tiles[0].data.polys.Length, Is.EqualTo(3));
Assert.That(tiles[0].data.verts.Length, Is.EqualTo(6 * 3));
nneis = mesh.GetTilesAt(2, 8, tiles, MAX_NEIS);
Assert.That(nneis, Is.EqualTo(1));
2023-03-14 08:02:43 +03:00
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
{
byte[] @is = RcResources.Load("dungeon_all_tiles_navmesh_32bit.bin");
2023-03-14 08:02:43 +03:00
using var ms = new MemoryStream(@is);
2023-08-19 09:45:05 +03:00
using var br = new BinaryReader(ms);
2023-03-14 08:02:43 +03:00
2023-08-19 09:45:05 +03:00
DtNavMesh mesh = reader.Read32Bit(br, 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));
const int MAX_NEIS = 32;
DtMeshTile[] tiles = new DtMeshTile[MAX_NEIS];
int nneis = 0;
nneis = mesh.GetTilesAt(6, 9, tiles, MAX_NEIS);
Assert.That(nneis, Is.EqualTo(1));
2023-03-14 08:02:43 +03:00
Assert.That(tiles[0].data.polys.Length, Is.EqualTo(2));
Assert.That(tiles[0].data.verts.Length, Is.EqualTo(7 * 3));
nneis = mesh.GetTilesAt(2, 9, tiles, MAX_NEIS);
Assert.That(nneis, Is.EqualTo(1));
2023-03-14 08:02:43 +03:00
Assert.That(tiles[0].data.polys.Length, Is.EqualTo(2));
Assert.That(tiles[0].data.verts.Length, Is.EqualTo(9 * 3));
nneis = mesh.GetTilesAt(4, 3, tiles, MAX_NEIS);
Assert.That(nneis, Is.EqualTo(1));
2023-03-14 08:02:43 +03:00
Assert.That(tiles[0].data.polys.Length, Is.EqualTo(3));
Assert.That(tiles[0].data.verts.Length, Is.EqualTo(6 * 3));
nneis = mesh.GetTilesAt(2, 8, tiles, MAX_NEIS);
Assert.That(nneis, Is.EqualTo(1));
2023-03-14 08:02:43 +03:00
Assert.That(tiles[0].data.polys.Length, Is.EqualTo(5));
Assert.That(tiles[0].data.verts.Length, Is.EqualTo(17 * 3));
}
}