2023-03-14 08:02:43 +03:00
|
|
|
/*
|
|
|
|
recast4j copyright (c) 2021 Piotr Piastucki piotr@jtilia.org
|
2023-08-19 10:13:37 +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.IO;
|
|
|
|
using DotRecast.Core;
|
|
|
|
using DotRecast.Detour.Dynamic.Io;
|
|
|
|
using NUnit.Framework;
|
|
|
|
|
|
|
|
namespace DotRecast.Detour.Dynamic.Test.Io;
|
|
|
|
|
2023-04-25 17:22:44 +03:00
|
|
|
[Parallelizable]
|
2023-03-16 19:48:49 +03:00
|
|
|
public class VoxelFileReaderTest
|
|
|
|
{
|
2023-03-14 08:02:43 +03:00
|
|
|
[Test]
|
2023-05-05 02:44:48 +03:00
|
|
|
public void ShouldReadSingleTileFile()
|
2023-03-16 19:48:49 +03:00
|
|
|
{
|
2023-03-14 08:02:43 +03:00
|
|
|
byte[] bytes = Loader.ToBytes("test.voxels");
|
|
|
|
using var ms = new MemoryStream(bytes);
|
2023-08-19 09:45:05 +03:00
|
|
|
using var br = new BinaryReader(ms);
|
2023-03-16 19:48:49 +03:00
|
|
|
|
2023-09-16 06:49:58 +03:00
|
|
|
DtVoxelFileReader reader = new DtVoxelFileReader(DtVoxelTileLZ4ForTestCompressor.Shared);
|
|
|
|
DtVoxelFile f = reader.Read(br);
|
2023-03-14 08:02:43 +03:00
|
|
|
Assert.That(f.useTiles, Is.False);
|
2023-03-16 19:48:49 +03:00
|
|
|
Assert.That(f.bounds, Is.EqualTo(new float[] { -100.0f, 0f, -100f, 100f, 5f, 100f }));
|
2023-03-14 08:02:43 +03:00
|
|
|
Assert.That(f.cellSize, Is.EqualTo(0.25f));
|
|
|
|
Assert.That(f.walkableRadius, Is.EqualTo(0.5f));
|
|
|
|
Assert.That(f.walkableHeight, Is.EqualTo(2f));
|
|
|
|
Assert.That(f.walkableClimb, Is.EqualTo(0.5f));
|
|
|
|
Assert.That(f.maxEdgeLen, Is.EqualTo(20f));
|
|
|
|
Assert.That(f.maxSimplificationError, Is.EqualTo(2f));
|
|
|
|
Assert.That(f.minRegionArea, Is.EqualTo(2f));
|
|
|
|
Assert.That(f.tiles.Count, Is.EqualTo(1));
|
|
|
|
Assert.That(f.tiles[0].cellHeight, Is.EqualTo(0.001f));
|
|
|
|
Assert.That(f.tiles[0].width, Is.EqualTo(810));
|
|
|
|
Assert.That(f.tiles[0].depth, Is.EqualTo(810));
|
2023-06-03 15:47:26 +03:00
|
|
|
Assert.That(f.tiles[0].boundsMin, Is.EqualTo(RcVec3f.Of(-101.25f, 0f, -101.25f)));
|
|
|
|
Assert.That(f.tiles[0].boundsMax, Is.EqualTo(RcVec3f.Of(101.25f, 5.0f, 101.25f)));
|
2023-03-14 08:02:43 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
2023-05-05 02:44:48 +03:00
|
|
|
public void ShouldReadMultiTileFile()
|
2023-03-16 19:48:49 +03:00
|
|
|
{
|
2023-03-14 08:02:43 +03:00
|
|
|
byte[] bytes = Loader.ToBytes("test_tiles.voxels");
|
|
|
|
using var ms = new MemoryStream(bytes);
|
2023-08-19 09:45:05 +03:00
|
|
|
using var br = new BinaryReader(ms);
|
2023-03-16 19:48:49 +03:00
|
|
|
|
2023-09-16 06:49:58 +03:00
|
|
|
DtVoxelFileReader reader = new DtVoxelFileReader(DtVoxelTileLZ4ForTestCompressor.Shared);
|
|
|
|
DtVoxelFile f = reader.Read(br);
|
2023-03-16 19:48:49 +03:00
|
|
|
|
2023-03-14 08:02:43 +03:00
|
|
|
Assert.That(f.useTiles, Is.True);
|
|
|
|
Assert.That(f.bounds, Is.EqualTo(new float[] { -100.0f, 0f, -100f, 100f, 5f, 100f }));
|
|
|
|
Assert.That(f.cellSize, Is.EqualTo(0.25f));
|
|
|
|
Assert.That(f.walkableRadius, Is.EqualTo(0.5f));
|
|
|
|
Assert.That(f.walkableHeight, Is.EqualTo(2f));
|
|
|
|
Assert.That(f.walkableClimb, Is.EqualTo(0.5f));
|
|
|
|
Assert.That(f.maxEdgeLen, Is.EqualTo(20f));
|
|
|
|
Assert.That(f.maxSimplificationError, Is.EqualTo(2f));
|
|
|
|
Assert.That(f.minRegionArea, Is.EqualTo(2f));
|
|
|
|
Assert.That(f.tiles.Count, Is.EqualTo(100));
|
|
|
|
Assert.That(f.tiles[0].cellHeight, Is.EqualTo(0.001f));
|
|
|
|
Assert.That(f.tiles[0].width, Is.EqualTo(90));
|
|
|
|
Assert.That(f.tiles[0].depth, Is.EqualTo(90));
|
2023-06-03 15:47:26 +03:00
|
|
|
Assert.That(f.tiles[0].boundsMin, Is.EqualTo(RcVec3f.Of(-101.25f, 0f, -101.25f)));
|
|
|
|
Assert.That(f.tiles[0].boundsMax, Is.EqualTo(RcVec3f.Of(-78.75f, 5.0f, -78.75f)));
|
2023-03-14 08:02:43 +03:00
|
|
|
}
|
2023-04-29 07:29:40 +03:00
|
|
|
}
|