DotRecastNetSim/test/DotRecast.Detour.TileCache..../AbstractTileCacheTest.cs

80 lines
3.3 KiB
C#
Raw Normal View History

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 DotRecast.Core;
using DotRecast.Detour.TileCache.Io.Compress;
using DotRecast.Recast.Geom;
2023-04-25 17:22:44 +03:00
using NUnit.Framework;
2023-03-25 09:43:20 +03:00
using static DotRecast.Core.RecastMath;
2023-03-14 08:02:43 +03:00
using static DotRecast.Recast.RecastVectors;
namespace DotRecast.Detour.TileCache.Test;
2023-04-25 17:22:44 +03:00
[Parallelizable]
2023-03-16 19:48:49 +03:00
public class AbstractTileCacheTest
{
2023-03-14 08:02:43 +03:00
private const int EXPECTED_LAYERS_PER_TILE = 4;
private readonly float m_cellSize = 0.3f;
private readonly float m_cellHeight = 0.2f;
private readonly float m_agentHeight = 2.0f;
private readonly float m_agentRadius = 0.6f;
private readonly float m_agentMaxClimb = 0.9f;
private readonly float m_edgeMaxError = 1.3f;
private readonly int m_tileSize = 48;
2023-03-16 19:48:49 +03:00
protected class TestTileCacheMeshProcess : TileCacheMeshProcess
{
public void process(NavMeshDataCreateParams option)
{
for (int i = 0; i < option.polyCount; ++i)
{
2023-03-14 08:02:43 +03:00
option.polyFlags[i] = 1;
}
}
}
2023-03-16 19:48:49 +03:00
public TileCache getTileCache(InputGeomProvider geom, ByteOrder order, bool cCompatibility)
{
2023-03-14 08:02:43 +03:00
TileCacheParams option = new TileCacheParams();
int[] twh = Recast.Recast.calcTileCount(geom.getMeshBoundsMin(), geom.getMeshBoundsMax(), m_cellSize, m_tileSize, m_tileSize);
option.ch = m_cellHeight;
option.cs = m_cellSize;
2023-04-12 17:53:28 +03:00
option.orig = geom.getMeshBoundsMin();
2023-03-14 08:02:43 +03:00
option.height = m_tileSize;
option.width = m_tileSize;
option.walkableHeight = m_agentHeight;
option.walkableRadius = m_agentRadius;
option.walkableClimb = m_agentMaxClimb;
option.maxSimplificationError = m_edgeMaxError;
option.maxTiles = twh[0] * twh[1] * EXPECTED_LAYERS_PER_TILE;
option.maxObstacles = 128;
NavMeshParams navMeshParams = new NavMeshParams();
2023-03-29 18:59:00 +03:00
copy(ref navMeshParams.orig, geom.getMeshBoundsMin());
2023-03-14 08:02:43 +03:00
navMeshParams.tileWidth = m_tileSize * m_cellSize;
navMeshParams.tileHeight = m_tileSize * m_cellSize;
navMeshParams.maxTiles = 256;
navMeshParams.maxPolys = 16384;
NavMesh navMesh = new NavMesh(navMeshParams, 6);
TileCache tc = new TileCache(option, new TileCacheStorageParams(order, cCompatibility), navMesh,
2023-03-16 19:48:49 +03:00
TileCacheCompressorFactory.get(cCompatibility), new TestTileCacheMeshProcess());
2023-03-14 08:02:43 +03:00
return tc;
}
2023-04-29 07:29:40 +03:00
}