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 System.Collections.Generic;
|
|
|
|
using DotRecast.Core;
|
2023-08-19 06:48:47 +03:00
|
|
|
using DotRecast.Detour.TileCache.Io.Compress;
|
2023-08-05 16:39:18 +03:00
|
|
|
using DotRecast.Detour.TileCache.Test.Io;
|
2023-03-14 08:02:43 +03:00
|
|
|
using DotRecast.Recast;
|
|
|
|
using DotRecast.Recast.Geom;
|
|
|
|
|
|
|
|
namespace DotRecast.Detour.TileCache.Test;
|
|
|
|
|
2023-08-19 06:48:47 +03:00
|
|
|
public class TestTileLayerBuilder : DtTileCacheLayerBuilder
|
2023-03-16 19:48:49 +03:00
|
|
|
{
|
2023-08-19 06:48:47 +03:00
|
|
|
private const float CellSize = 0.3f;
|
|
|
|
private const float CellHeight = 0.2f;
|
2023-03-14 08:02:43 +03:00
|
|
|
|
2023-08-19 06:48:47 +03:00
|
|
|
private const float AgentHeight = 2.0f;
|
|
|
|
private const float AgentRadius = 0.6f;
|
|
|
|
private const float AgentMaxClimb = 0.9f;
|
|
|
|
private const float AgentMaxSlope = 45.0f;
|
2023-03-14 08:02:43 +03:00
|
|
|
|
2023-08-19 06:48:47 +03:00
|
|
|
private const int RegionMinSize = 8;
|
|
|
|
private const int RegionMergeSize = 20;
|
|
|
|
private const float RegionMinArea = RegionMinSize * RegionMinSize * CellSize * CellSize;
|
|
|
|
private const float RegionMergeArea = RegionMergeSize * RegionMergeSize * CellSize * CellSize;
|
2023-03-14 08:02:43 +03:00
|
|
|
|
2023-08-19 06:48:47 +03:00
|
|
|
private const float EdgeMaxLen = 12.0f;
|
|
|
|
private const float EdgeMaxError = 1.3f;
|
|
|
|
private const int VertsPerPoly = 6;
|
|
|
|
private const float DetailSampleDist = 6.0f;
|
|
|
|
private const float DetailSampleMaxError = 1.0f;
|
2023-03-14 08:02:43 +03:00
|
|
|
|
2023-08-19 06:48:47 +03:00
|
|
|
private readonly RcConfig _cfg;
|
|
|
|
private const int m_tileSize = 48;
|
2023-03-14 08:02:43 +03:00
|
|
|
|
2023-08-19 06:48:47 +03:00
|
|
|
private readonly IInputGeomProvider _geom;
|
|
|
|
public readonly int tw;
|
|
|
|
public readonly int th;
|
2023-08-05 16:39:18 +03:00
|
|
|
|
2023-08-19 06:48:47 +03:00
|
|
|
public TestTileLayerBuilder(IInputGeomProvider geom) : base(DtTileCacheCompressorForTestFactory.Shared)
|
|
|
|
{
|
|
|
|
_geom = geom;
|
|
|
|
_cfg = new RcConfig(true, m_tileSize, m_tileSize, RcConfig.CalcBorder(AgentRadius, CellSize),
|
|
|
|
RcPartition.WATERSHED, CellSize, CellHeight, AgentMaxSlope, true, true, true, AgentHeight,
|
|
|
|
AgentRadius, AgentMaxClimb, RegionMinArea, RegionMergeArea, EdgeMaxLen, EdgeMaxError, VertsPerPoly,
|
|
|
|
true, DetailSampleDist, DetailSampleMaxError, SampleAreaModifications.SAMPLE_AREAMOD_GROUND);
|
2023-03-16 19:48:49 +03:00
|
|
|
|
2023-08-19 06:48:47 +03:00
|
|
|
RcVec3f bmin = geom.GetMeshBoundsMin();
|
|
|
|
RcVec3f bmax = geom.GetMeshBoundsMax();
|
|
|
|
RcUtils.CalcTileCount(bmin, bmax, CellSize, m_tileSize, m_tileSize, out tw, out th);
|
2023-03-14 08:02:43 +03:00
|
|
|
}
|
|
|
|
|
2023-08-19 06:48:47 +03:00
|
|
|
public List<byte[]> Build(RcByteOrder order, bool cCompatibility, int threads)
|
2023-03-16 19:48:49 +03:00
|
|
|
{
|
2023-08-19 06:48:47 +03:00
|
|
|
return Build(_geom, _cfg, order, cCompatibility, threads, tw, th);
|
2023-03-14 08:02:43 +03:00
|
|
|
}
|
2023-06-01 16:25:15 +03:00
|
|
|
}
|