added tile tool

This commit is contained in:
ikpil 2023-07-27 15:39:21 +09:00
parent afc515c498
commit 60850b0cbf
4 changed files with 78 additions and 23 deletions

View File

@ -1,14 +1,17 @@
using DotRecast.Core;
using System;
using DotRecast.Core;
using DotRecast.Recast.Demo.Draw;
using DotRecast.Recast.DemoTool;
using DotRecast.Recast.DemoTool.Tools;
using ImGuiNET;
using Serilog;
using static DotRecast.Recast.Demo.Draw.DebugDraw;
namespace DotRecast.Recast.Demo.Tools;
public class TileTool : IRcTool
{
private static readonly ILogger Logger = Log.ForContext<TileTool>();
private readonly TileToolImpl _impl;
private bool _hitPosSet;
@ -58,7 +61,8 @@ public class TileTool : IRcTool
}
else
{
_impl.BuildTile(_hitPos);
_impl.BuildTile(_hitPos, out var tileBuildTicks, out var tileTriCount, out var tileMemUsage);
Logger.Information($"{tileBuildTicks / (float)TimeSpan.TicksPerMillisecond}ms / {tileTriCount}Tris / {tileMemUsage}kB ");
}
}
@ -101,6 +105,8 @@ public class TileTool : IRcTool
lastBuiltTileBmin.x, lastBuiltTileBmin.y, lastBuiltTileBmin.z,
lastBuiltTileBmax.x, lastBuiltTileBmax.y, lastBuiltTileBmax.z,
DuRGBA(255, 255, 255, 64), 1.0f);
// 표기
}
}

View File

@ -89,8 +89,8 @@ namespace DotRecast.Recast.DemoTool.Builder
return navMesh;
}
private List<DtMeshData> BuildMeshData(DemoInputGeomProvider geom, float cellSize, float cellHeight, float agentHeight,
float agentRadius, float agentMaxClimb, List<RecastBuilderResult> results)
public List<DtMeshData> BuildMeshData(DemoInputGeomProvider geom, float cellSize, float cellHeight, float agentHeight,
float agentRadius, float agentMaxClimb, IList<RecastBuilderResult> results)
{
// Add tiles to nav mesh
List<DtMeshData> meshData = new List<DtMeshData>();

View File

@ -1,4 +1,7 @@
using DotRecast.Core;
using System.Collections.Generic;
using System.Collections.Immutable;
using System.Linq;
using DotRecast.Core;
using DotRecast.Detour.TileCache;
using DotRecast.Recast.DemoTool.Builder;
@ -23,37 +26,81 @@ namespace DotRecast.Recast.DemoTool.Tools
return _sample;
}
public void BuildTile(RcVec3f pos)
public bool BuildTile(RcVec3f pos, out long tileBuildTicks, out int tileTriCount, out int tileMemUsage)
{
var settings = _sample.GetSettings();
var geom = _sample.GetInputGeom();
var navMesh = _sample.GetNavMesh();
tileBuildTicks = 0;
tileTriCount = 0;
tileMemUsage = 0;
if (null == settings || null == geom || navMesh == null)
return;
return false;
float ts = settings.tileSize * settings.cellSize;
var bmin = geom.GetMeshBoundsMin();
RcVec3f bmin = geom.GetMeshBoundsMin();
RcVec3f bmax = geom.GetMeshBoundsMax();
int tx = (int)((pos.x - bmin[0]) / ts);
int ty = (int)((pos.z - bmin[2]) / ts);
// var tnmb = new TileNavMeshBuilder();
// tnmb.BuildRecastResult(geom, settings.partitioning, )
RcConfig cfg = new RcConfig(
true,
settings.tileSize,
settings.tileSize,
RcConfig.CalcBorder(settings.agentRadius, settings.cellSize),
settings.partitioning,
settings.cellSize,
settings.cellHeight,
settings.agentMaxSlope,
settings.filterLowHangingObstacles,
settings.filterLedgeSpans,
settings.filterWalkableLowHeightSpans,
settings.agentHeight,
settings.agentRadius,
settings.agentMaxClimb,
settings.minRegionSize * settings.minRegionSize * settings.cellSize * settings.cellSize,
settings.mergedRegionSize * settings.mergedRegionSize * settings.cellSize * settings.cellSize,
settings.edgeMaxLen,
settings.edgeMaxError,
settings.vertsPerPoly,
true,
settings.detailSampleDist,
settings.detailSampleMaxError,
SampleAreaModifications.SAMPLE_AREAMOD_WALKABLE
);
//var tileRef = navMesh.GetTileRefAt(tx, ty, 0);
// navMesh.RemoveTile(tileRef);
var rb = new RecastBuilder();
var result = rb.BuildTile(geom, cfg, bmin, bmax, tx, ty, new RcAtomicInteger(0), 1);
var tb = new TileNavMeshBuilder();
var meshData = tb.BuildMeshData(geom,
settings.cellSize, settings.cellHeight, settings.agentHeight, settings.agentRadius, settings.agentMaxClimb,
ImmutableArray.Create(result)
).First();
navMesh.UpdateTile(meshData, 0);
var telemetry = result.GetTelemetry();
tileBuildTicks = telemetry.ToList().Sum(x => x.Ticks);
tileTriCount = 0; // ...
tileMemUsage = 0; // ...
return true;
}
public void RemoveTile(RcVec3f pos)
public bool RemoveTile(RcVec3f pos)
{
var settings = _sample.GetSettings();
var geom = _sample.GetInputGeom();
var navMesh = _sample.GetNavMesh();
if (null == settings || null == geom || navMesh == null)
return;
return false;
float ts = settings.tileSize * settings.cellSize;
@ -64,6 +111,8 @@ namespace DotRecast.Recast.DemoTool.Tools
var tileRef = navMesh.GetTileRefAt(tx, ty, 0);
navMesh.RemoveTile(tileRef);
return true;
}
}
}

View File

@ -143,7 +143,7 @@ namespace DotRecast.Recast
return Task.WhenAll(tasks.ToArray());
}
private RecastBuilderResult BuildTile(IInputGeomProvider geom, RcConfig cfg, RcVec3f bmin, RcVec3f bmax, int tx,
public RecastBuilderResult BuildTile(IInputGeomProvider geom, RcConfig cfg, RcVec3f bmin, RcVec3f bmax, int tx,
int ty, RcAtomicInteger counter, int total)
{
RecastBuilderResult result = Build(geom, new RecastBuilderConfig(cfg, bmin, bmax, tx, ty));