forked from mirror/DotRecast
remove tile in tile tool
This commit is contained in:
parent
d5f1b4be54
commit
1dbf7aac44
|
@ -34,8 +34,7 @@ namespace DotRecast.Detour.Dynamic
|
|||
|
||||
private RcHeightfield Clone(RcHeightfield source)
|
||||
{
|
||||
RcHeightfield clone = new RcHeightfield(source.width, source.height, source.bmin, source.bmax, source.cs,
|
||||
source.ch, source.borderSize);
|
||||
RcHeightfield clone = new RcHeightfield(source.width, source.height, source.bmin, source.bmax, source.cs, source.ch, source.borderSize);
|
||||
for (int z = 0, pz = 0; z < source.height; z++, pz += source.width)
|
||||
{
|
||||
for (int x = 0; x < source.width; x++)
|
||||
|
|
|
@ -4,7 +4,6 @@ using DotRecast.Recast.DemoTool;
|
|||
using DotRecast.Recast.DemoTool.Tools;
|
||||
using ImGuiNET;
|
||||
using static DotRecast.Recast.Demo.Draw.DebugDraw;
|
||||
using static DotRecast.Recast.Demo.Draw.DebugDrawPrimitives;
|
||||
|
||||
namespace DotRecast.Recast.Demo.Tools;
|
||||
|
||||
|
@ -50,14 +49,16 @@ public class TileTool : IRcTool
|
|||
_hitPos = p;
|
||||
|
||||
var sample = _impl.GetSample();
|
||||
if (null != sample)
|
||||
if (null == sample)
|
||||
return;
|
||||
|
||||
if (shift)
|
||||
{
|
||||
if (shift)
|
||||
{
|
||||
}
|
||||
else
|
||||
{
|
||||
}
|
||||
_impl.RemoveTile(_hitPos);
|
||||
}
|
||||
else
|
||||
{
|
||||
_impl.BuildTile(_hitPos);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -76,23 +77,24 @@ public class TileTool : IRcTool
|
|||
{
|
||||
var bmin = geom.GetMeshBoundsMin();
|
||||
var bmax = geom.GetMeshBoundsMax();
|
||||
|
||||
|
||||
var settings = sample.GetSettings();
|
||||
var s = settings.agentRadius;
|
||||
|
||||
float ts = settings.tileSize * settings.cellSize;
|
||||
int tx = (int)((_hitPos.x - bmin[0]) / ts);
|
||||
int ty = (int)((_hitPos.z - bmin[2]) / ts);
|
||||
|
||||
RcVec3f lastBuiltTileBmin = RcVec3f.Zero;
|
||||
RcVec3f lastBuiltTileBmax = RcVec3f.Zero;
|
||||
|
||||
lastBuiltTileBmin[0] = bmin[0] + tx*ts;
|
||||
|
||||
lastBuiltTileBmin[0] = bmin[0] + tx * ts;
|
||||
lastBuiltTileBmin[1] = bmin[1];
|
||||
lastBuiltTileBmin[2] = bmin[2] + ty*ts;
|
||||
|
||||
lastBuiltTileBmax[0] = bmin[0] + (tx+1)*ts;
|
||||
lastBuiltTileBmin[2] = bmin[2] + ty * ts;
|
||||
|
||||
lastBuiltTileBmax[0] = bmin[0] + (tx + 1) * ts;
|
||||
lastBuiltTileBmax[1] = bmax[1];
|
||||
lastBuiltTileBmax[2] = bmin[2] + (ty+1)*ts;
|
||||
lastBuiltTileBmax[2] = bmin[2] + (ty + 1) * ts;
|
||||
|
||||
dd.DebugDrawCross(_hitPos.x, _hitPos.y + 0.1f, _hitPos.z, s, DuRGBA(0, 0, 0, 128), 2.0f);
|
||||
dd.DebugDrawBoxWire(
|
||||
|
|
|
@ -1,4 +1,6 @@
|
|||
namespace DotRecast.Recast.DemoTool.Tools
|
||||
using DotRecast.Core;
|
||||
|
||||
namespace DotRecast.Recast.DemoTool.Tools
|
||||
{
|
||||
public class TileToolImpl : ISampleTool
|
||||
{
|
||||
|
@ -18,5 +20,41 @@
|
|||
{
|
||||
return _sample;
|
||||
}
|
||||
|
||||
public void BuildTile(RcVec3f pos)
|
||||
{
|
||||
var settings = _sample.GetSettings();
|
||||
var geom = _sample.GetInputGeom();
|
||||
var navMesh = _sample.GetNavMesh();
|
||||
|
||||
float ts = settings.tileSize * settings.cellSize;
|
||||
|
||||
var bmin = geom.GetMeshBoundsMin();
|
||||
|
||||
int tx = (int)((pos.x - bmin[0]) / ts);
|
||||
int ty = (int)((pos.z - bmin[2]) / ts);
|
||||
|
||||
var tileRef = navMesh.GetTileRefAt(tx, ty, 0);
|
||||
navMesh.RemoveTile(tileRef);
|
||||
|
||||
navMesh.AddTile()
|
||||
}
|
||||
|
||||
public void RemoveTile(RcVec3f pos)
|
||||
{
|
||||
var settings = _sample.GetSettings();
|
||||
var geom = _sample.GetInputGeom();
|
||||
var navMesh = _sample.GetNavMesh();
|
||||
|
||||
float ts = settings.tileSize * settings.cellSize;
|
||||
|
||||
var bmin = geom.GetMeshBoundsMin();
|
||||
|
||||
int tx = (int)((pos.x - bmin[0]) / ts);
|
||||
int ty = (int)((pos.z - bmin[2]) / ts);
|
||||
|
||||
var tileRef = navMesh.GetTileRefAt(tx, ty, 0);
|
||||
navMesh.RemoveTile(tileRef);
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue