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.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 MeshDataReaderWriterTest
|
|
|
|
{
|
2023-03-14 08:02:43 +03:00
|
|
|
private const int VERTS_PER_POLYGON = 6;
|
|
|
|
private MeshData meshData;
|
|
|
|
|
|
|
|
[SetUp]
|
2023-03-16 19:48:49 +03:00
|
|
|
public void setUp()
|
|
|
|
{
|
2023-03-14 08:02:43 +03:00
|
|
|
RecastTestMeshBuilder rcBuilder = new RecastTestMeshBuilder();
|
|
|
|
meshData = rcBuilder.getMeshData();
|
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
2023-03-16 19:48:49 +03:00
|
|
|
public void testCCompatibility()
|
|
|
|
{
|
2023-03-14 08:02:43 +03:00
|
|
|
test(true, ByteOrder.BIG_ENDIAN);
|
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
2023-03-16 19:48:49 +03:00
|
|
|
public void testCompact()
|
|
|
|
{
|
2023-03-14 08:02:43 +03:00
|
|
|
test(false, ByteOrder.BIG_ENDIAN);
|
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
2023-03-16 19:48:49 +03:00
|
|
|
public void testCCompatibilityLE()
|
|
|
|
{
|
2023-03-14 08:02:43 +03:00
|
|
|
test(true, ByteOrder.LITTLE_ENDIAN);
|
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
2023-03-16 19:48:49 +03:00
|
|
|
public void testCompactLE()
|
|
|
|
{
|
2023-03-14 08:02:43 +03:00
|
|
|
test(false, ByteOrder.LITTLE_ENDIAN);
|
|
|
|
}
|
|
|
|
|
2023-03-16 19:48:49 +03:00
|
|
|
public void test(bool cCompatibility, ByteOrder order)
|
|
|
|
{
|
2023-03-14 08:02:43 +03:00
|
|
|
using var ms = new MemoryStream();
|
|
|
|
using var bwos = new BinaryWriter(ms);
|
2023-03-16 19:48:49 +03:00
|
|
|
|
2023-03-14 08:02:43 +03:00
|
|
|
MeshDataWriter writer = new MeshDataWriter();
|
|
|
|
writer.write(bwos, meshData, order, cCompatibility);
|
|
|
|
ms.Seek(0, SeekOrigin.Begin);
|
2023-03-16 19:48:49 +03:00
|
|
|
|
2023-03-14 08:02:43 +03:00
|
|
|
using var bris = new BinaryReader(ms);
|
|
|
|
MeshDataReader reader = new MeshDataReader();
|
|
|
|
MeshData readData = reader.read(bris, VERTS_PER_POLYGON);
|
|
|
|
|
|
|
|
Assert.That(readData.header.vertCount, Is.EqualTo(meshData.header.vertCount));
|
|
|
|
Assert.That(readData.header.polyCount, Is.EqualTo(meshData.header.polyCount));
|
|
|
|
Assert.That(readData.header.detailMeshCount, Is.EqualTo(meshData.header.detailMeshCount));
|
|
|
|
Assert.That(readData.header.detailTriCount, Is.EqualTo(meshData.header.detailTriCount));
|
|
|
|
Assert.That(readData.header.detailVertCount, Is.EqualTo(meshData.header.detailVertCount));
|
|
|
|
Assert.That(readData.header.bvNodeCount, Is.EqualTo(meshData.header.bvNodeCount));
|
|
|
|
Assert.That(readData.header.offMeshConCount, Is.EqualTo(meshData.header.offMeshConCount));
|
2023-03-16 19:48:49 +03:00
|
|
|
for (int i = 0; i < meshData.header.vertCount; i++)
|
|
|
|
{
|
2023-03-14 08:02:43 +03:00
|
|
|
Assert.That(readData.verts[i], Is.EqualTo(meshData.verts[i]));
|
|
|
|
}
|
2023-03-16 19:48:49 +03:00
|
|
|
|
|
|
|
for (int i = 0; i < meshData.header.polyCount; i++)
|
|
|
|
{
|
2023-03-14 08:02:43 +03:00
|
|
|
Assert.That(readData.polys[i].vertCount, Is.EqualTo(meshData.polys[i].vertCount));
|
|
|
|
Assert.That(readData.polys[i].areaAndtype, Is.EqualTo(meshData.polys[i].areaAndtype));
|
2023-03-16 19:48:49 +03:00
|
|
|
for (int j = 0; j < meshData.polys[i].vertCount; j++)
|
|
|
|
{
|
2023-03-14 08:02:43 +03:00
|
|
|
Assert.That(readData.polys[i].verts[j], Is.EqualTo(meshData.polys[i].verts[j]));
|
|
|
|
Assert.That(readData.polys[i].neis[j], Is.EqualTo(meshData.polys[i].neis[j]));
|
|
|
|
}
|
|
|
|
}
|
2023-03-16 19:48:49 +03:00
|
|
|
|
|
|
|
for (int i = 0; i < meshData.header.detailMeshCount; i++)
|
|
|
|
{
|
2023-03-14 08:02:43 +03:00
|
|
|
Assert.That(readData.detailMeshes[i].vertBase, Is.EqualTo(meshData.detailMeshes[i].vertBase));
|
|
|
|
Assert.That(readData.detailMeshes[i].vertCount, Is.EqualTo(meshData.detailMeshes[i].vertCount));
|
|
|
|
Assert.That(readData.detailMeshes[i].triBase, Is.EqualTo(meshData.detailMeshes[i].triBase));
|
|
|
|
Assert.That(readData.detailMeshes[i].triCount, Is.EqualTo(meshData.detailMeshes[i].triCount));
|
|
|
|
}
|
2023-03-16 19:48:49 +03:00
|
|
|
|
|
|
|
for (int i = 0; i < meshData.header.detailVertCount; i++)
|
|
|
|
{
|
2023-03-14 08:02:43 +03:00
|
|
|
Assert.That(readData.detailVerts[i], Is.EqualTo(meshData.detailVerts[i]));
|
|
|
|
}
|
2023-03-16 19:48:49 +03:00
|
|
|
|
|
|
|
for (int i = 0; i < meshData.header.detailTriCount; i++)
|
|
|
|
{
|
2023-03-14 08:02:43 +03:00
|
|
|
Assert.That(readData.detailTris[i], Is.EqualTo(meshData.detailTris[i]));
|
|
|
|
}
|
2023-03-16 19:48:49 +03:00
|
|
|
|
|
|
|
for (int i = 0; i < meshData.header.bvNodeCount; i++)
|
|
|
|
{
|
2023-03-14 08:02:43 +03:00
|
|
|
Assert.That(readData.bvTree[i].i, Is.EqualTo(meshData.bvTree[i].i));
|
2023-03-16 19:48:49 +03:00
|
|
|
for (int j = 0; j < 3; j++)
|
|
|
|
{
|
2023-03-14 08:02:43 +03:00
|
|
|
Assert.That(readData.bvTree[i].bmin[j], Is.EqualTo(meshData.bvTree[i].bmin[j]));
|
|
|
|
Assert.That(readData.bvTree[i].bmax[j], Is.EqualTo(meshData.bvTree[i].bmax[j]));
|
|
|
|
}
|
|
|
|
}
|
2023-03-16 19:48:49 +03:00
|
|
|
|
|
|
|
for (int i = 0; i < meshData.header.offMeshConCount; i++)
|
|
|
|
{
|
2023-03-14 08:02:43 +03:00
|
|
|
Assert.That(readData.offMeshCons[i].flags, Is.EqualTo(meshData.offMeshCons[i].flags));
|
|
|
|
Assert.That(readData.offMeshCons[i].rad, Is.EqualTo(meshData.offMeshCons[i].rad));
|
|
|
|
Assert.That(readData.offMeshCons[i].poly, Is.EqualTo(meshData.offMeshCons[i].poly));
|
|
|
|
Assert.That(readData.offMeshCons[i].side, Is.EqualTo(meshData.offMeshCons[i].side));
|
|
|
|
Assert.That(readData.offMeshCons[i].userId, Is.EqualTo(meshData.offMeshCons[i].userId));
|
2023-03-16 19:48:49 +03:00
|
|
|
for (int j = 0; j < 6; j++)
|
|
|
|
{
|
2023-03-14 08:02:43 +03:00
|
|
|
Assert.That(readData.offMeshCons[i].pos[j], Is.EqualTo(meshData.offMeshCons[i].pos[j]));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2023-03-16 19:48:49 +03:00
|
|
|
}
|