add demo tile cache comp factory

This commit is contained in:
ikpil 2023-08-19 14:55:45 +09:00
parent 6c97161746
commit 2050c476a2
6 changed files with 181 additions and 4 deletions

View File

@ -0,0 +1,21 @@
using DotRecast.Core;
using DotRecast.Detour.TileCache.Io.Compress;
namespace DotRecast.Recast.Demo;
public class DtTileCacheCompressorDemoFactory : IDtTileCacheCompressorFactory
{
public static readonly DtTileCacheCompressorDemoFactory Shared = new();
private DtTileCacheCompressorDemoFactory()
{
}
public IRcCompressor Get(bool cCompatibility)
{
if (cCompatibility)
return DtTileCacheFastLzCompressor.Shared;
return DtTileCacheLZ4DemoCompressor.Shared;
}
}

View File

@ -0,0 +1,49 @@
/*
Copyright (c) 2009-2010 Mikko Mononen memon@inside.org
recast4j copyright (c) 2015-2019 Piotr Piastucki piotr@jtilia.org
DotRecast Copyright (c) 2023 Choi Ikpil ikpil@naver.com
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 K4os.Compression.LZ4;
namespace DotRecast.Recast.Demo
{
public class DtTileCacheLZ4DemoCompressor : IRcCompressor
{
public static readonly DtTileCacheLZ4DemoCompressor Shared = new();
private DtTileCacheLZ4DemoCompressor()
{
}
public byte[] Decompress(byte[] buf)
{
return LZ4Pickler.Unpickle(buf);
}
public byte[] Decompress(byte[] buf, int offset, int len, int outputlen)
{
return LZ4Pickler.Unpickle(buf, offset, len);
}
public byte[] Compress(byte[] buf)
{
return LZ4Pickler.Pickle(buf);
}
}
}

View File

@ -16,7 +16,7 @@ public class ObstacleTool : IRcTool
public ObstacleTool() public ObstacleTool()
{ {
_impl = new(); _impl = new(DtTileCacheCompressorDemoFactory.Shared);
} }
public ISampleTool GetTool() public ISampleTool GetTool()
@ -30,9 +30,9 @@ public class ObstacleTool : IRcTool
public void Layout() public void Layout()
{ {
if (ImGui.Button("Remove All")) if (ImGui.Button("Remove All Temp Obstacles"))
{ {
//m_sample->clearAllTempObstacles(); _impl.ClearAllTempObstacles();
} }
ImGui.Separator(); ImGui.Separator();

View File

@ -0,0 +1,57 @@
using DotRecast.Detour;
using DotRecast.Detour.TileCache;
using DotRecast.Recast.Geom;
namespace DotRecast.Recast.Toolset.Geom
{
public class DemoDtTileCacheMeshProcess : IDtTileCacheMeshProcess
{
private IInputGeomProvider _geom;
public DemoDtTileCacheMeshProcess()
{
}
public void Init(IInputGeomProvider geom)
{
_geom = geom;
}
public void Process(DtNavMeshCreateParams option)
{
// // Update poly flags from areas.
// for (int i = 0; i < option.polyCount; ++i)
// {
// if (option.polyAreas[i] == DtTileCacheBuilder.DT_TILECACHE_WALKABLE_AREA)
// option.polyAreas[i] = SAMPLE_POLYAREA_GROUND;
//
// if (option.polyAreas[i] == SAMPLE_POLYAREA_GROUND ||
// option.polyAreas[i] == SAMPLE_POLYAREA_GRASS ||
// option.polyAreas[i] == SAMPLE_POLYAREA_ROAD)
// {
// option.polyFlags[i] = SAMPLE_POLYFLAGS_WALK;
// }
// else if (option.polyAreas[i] == SAMPLE_POLYAREA_WATER)
// {
// option.polyFlags[i] = SAMPLE_POLYFLAGS_SWIM;
// }
// else if (option.polyAreas[i] == SAMPLE_POLYAREA_DOOR)
// {
// option.polyFlags[i] = SAMPLE_POLYFLAGS_WALK | SAMPLE_POLYFLAGS_DOOR;
// }
// }
//
// // Pass in off-mesh connections.
// if (null != _geom)
// {
// option.offMeshConVerts = _geom.GetOffMeshConnectionVerts();
// option.offMeshConRad = _geom.GetOffMeshConnectionRads();
// option.offMeshConDir = _geom.GetOffMeshConnectionDirs();
// option.offMeshConAreas = _geom.GetOffMeshConnectionAreas();
// option.offMeshConFlags = _geom.GetOffMeshConnectionFlags();
// option.offMeshConUserID = _geom.GetOffMeshConnectionId();
// option.offMeshConCount = _geom.GetOffMeshConnectionCount();
// }
}
}
}

View File

@ -19,6 +19,7 @@ freely, subject to the following restrictions:
*/ */
using DotRecast.Core; using DotRecast.Core;
using DotRecast.Detour;
namespace DotRecast.Recast.Toolset.Geom namespace DotRecast.Recast.Toolset.Geom
{ {

View File

@ -1,12 +1,25 @@
using DotRecast.Core; using DotRecast.Core;
using DotRecast.Detour;
using DotRecast.Detour.TileCache; using DotRecast.Detour.TileCache;
using DotRecast.Detour.TileCache.Io.Compress;
using DotRecast.Recast.Geom;
using DotRecast.Recast.Toolset.Geom;
namespace DotRecast.Recast.Toolset.Tools namespace DotRecast.Recast.Toolset.Tools
{ {
public class ObstacleToolImpl : ISampleTool public class ObstacleToolImpl : ISampleTool
{ {
private Sample _sample; private Sample _sample;
private readonly IDtTileCacheCompressorFactory _compFactory;
private readonly IDtTileCacheMeshProcess _mProc;
private DtTileCache _tc;
public ObstacleToolImpl(IDtTileCacheCompressorFactory compFactory, IDtTileCacheMeshProcess meshProcessor = null)
{
_compFactory = compFactory;
_mProc = meshProcessor ?? new DemoDtTileCacheMeshProcess();
}
public string GetName() public string GetName()
{ {
return "Create Temp Obstacles"; return "Create Temp Obstacles";
@ -22,6 +35,10 @@ namespace DotRecast.Recast.Toolset.Tools
return _sample; return _sample;
} }
public void ClearAllTempObstacles()
{
}
public void RemoveTempObstacle(RcVec3f sp, RcVec3f sq) public void RemoveTempObstacle(RcVec3f sp, RcVec3f sq)
{ {
// .. // ..
@ -32,5 +49,37 @@ namespace DotRecast.Recast.Toolset.Tools
//p[1] -= 0.5f; //p[1] -= 0.5f;
//m_tileCache->addObstacle(p, 1.0f, 2.0f, 0); //m_tileCache->addObstacle(p, 1.0f, 2.0f, 0);
} }
public DtTileCache GetTileCache(IInputGeomProvider geom, RcByteOrder order, bool cCompatibility)
{
// DtTileCacheParams option = new DtTileCacheParams();
// RcUtils.CalcTileCount(geom.GetMeshBoundsMin(), geom.GetMeshBoundsMax(), m_cellSize, m_tileSize, m_tileSize, out var tw, out var th);
// option.ch = m_cellHeight;
// option.cs = m_cellSize;
// option.orig = geom.GetMeshBoundsMin();
// 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 = tw * th * EXPECTED_LAYERS_PER_TILE;
// option.maxObstacles = 128;
//
// DtNavMeshParams navMeshParams = new DtNavMeshParams();
// navMeshParams.orig = geom.GetMeshBoundsMin();
// navMeshParams.tileWidth = m_tileSize * m_cellSize;
// navMeshParams.tileHeight = m_tileSize * m_cellSize;
// navMeshParams.maxTiles = 256;
// navMeshParams.maxPolys = 16384;
//
// var navMesh = new DtNavMesh(navMeshParams, 6);
// var comp = _compFactory.Get(cCompatibility);
// var storageParams = new DtTileCacheStorageParams(order, cCompatibility);
// var process = new TestTileCacheMeshProcess();
// DtTileCache tc = new DtTileCache(option, storageParams, navMesh, comp, process);
// return tc;
return null;
}
} }
} }