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;
|
2023-08-19 07:03:00 +03:00
|
|
|
using System.Linq;
|
2023-03-14 08:02:43 +03:00
|
|
|
using DotRecast.Core;
|
2023-10-16 17:55:34 +03:00
|
|
|
using DotRecast.Core.Numerics;
|
2023-08-19 06:48:47 +03:00
|
|
|
using DotRecast.Detour.TileCache.Io.Compress;
|
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 09:31:51 +03:00
|
|
|
public TestTileLayerBuilder(IInputGeomProvider geom) : base(DtTileCacheCompressorFactory.Shared)
|
2023-08-19 06:48:47 +03:00
|
|
|
{
|
|
|
|
_geom = geom;
|
2023-09-02 07:31:30 +03:00
|
|
|
_cfg = new RcConfig(true, m_tileSize, m_tileSize,
|
|
|
|
RcConfig.CalcBorder(AgentRadius, CellSize),
|
|
|
|
RcPartition.WATERSHED,
|
|
|
|
CellSize, CellHeight,
|
|
|
|
AgentMaxSlope, AgentHeight, AgentRadius, AgentMaxClimb,
|
|
|
|
RegionMinArea, RegionMergeArea,
|
|
|
|
EdgeMaxLen, EdgeMaxError,
|
|
|
|
VertsPerPoly,
|
|
|
|
DetailSampleDist, DetailSampleMaxError,
|
|
|
|
true, true, true,
|
|
|
|
SampleAreaModifications.SAMPLE_AREAMOD_GROUND, true);
|
2023-03-16 19:48:49 +03:00
|
|
|
|
2023-08-19 06:48:47 +03:00
|
|
|
RcVec3f bmin = geom.GetMeshBoundsMin();
|
|
|
|
RcVec3f bmax = geom.GetMeshBoundsMax();
|
2024-05-11 19:11:03 +03:00
|
|
|
RcRecast.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 07:16:29 +03:00
|
|
|
var storageParams = new DtTileCacheStorageParams(order, cCompatibility);
|
|
|
|
var results = Build(_geom, _cfg, storageParams, threads, tw, th);
|
2023-08-19 07:03:00 +03:00
|
|
|
return results
|
|
|
|
.SelectMany(x => x.layers)
|
|
|
|
.ToList();
|
2023-03-14 08:02:43 +03:00
|
|
|
}
|
2023-06-01 16:25:15 +03:00
|
|
|
}
|