forked from mirror/DotRecast
add tile grid view
This commit is contained in:
parent
0832ed3fdb
commit
1ff0f85b1f
|
@ -111,6 +111,23 @@ public class DebugDraw
|
||||||
End();
|
End();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void DebugDrawGridXZ(float ox, float oy, float oz, int w, int h, float size, int col, float lineWidth)
|
||||||
|
{
|
||||||
|
Begin(DebugDrawPrimitives.LINES, lineWidth);
|
||||||
|
for (int i = 0; i <= h; ++i)
|
||||||
|
{
|
||||||
|
Vertex(ox,oy,oz+i*size, col);
|
||||||
|
Vertex(ox+w*size,oy,oz+i*size, col);
|
||||||
|
}
|
||||||
|
for (int i = 0; i <= w; ++i)
|
||||||
|
{
|
||||||
|
Vertex(ox+i*size,oy,oz, col);
|
||||||
|
Vertex(ox+i*size,oy,oz+h*size, col);
|
||||||
|
}
|
||||||
|
End();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
public void AppendBoxWire(float minx, float miny, float minz, float maxx, float maxy, float maxz, int col)
|
public void AppendBoxWire(float minx, float miny, float minz, float maxx, float maxy, float maxz, int col)
|
||||||
{
|
{
|
||||||
// Top
|
// Top
|
||||||
|
|
|
@ -19,6 +19,7 @@ freely, subject to the following restrictions:
|
||||||
*/
|
*/
|
||||||
|
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.Diagnostics.Tracing;
|
||||||
using DotRecast.Core;
|
using DotRecast.Core;
|
||||||
using DotRecast.Detour;
|
using DotRecast.Detour;
|
||||||
using DotRecast.Recast.DemoTool.Builder;
|
using DotRecast.Recast.DemoTool.Builder;
|
||||||
|
@ -78,6 +79,18 @@ public class NavMeshRenderer
|
||||||
DrawGeomBounds(geom);
|
DrawGeomBounds(geom);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (geom != null && settings.tiled)
|
||||||
|
{
|
||||||
|
int gw = 0, gh = 0;
|
||||||
|
RcVec3f bmin = geom.GetMeshBoundsMin();
|
||||||
|
RcVec3f bmax = geom.GetMeshBoundsMax();
|
||||||
|
Recast.CalcGridSize(bmin, bmax, settings.cellSize, out gw, out gh);
|
||||||
|
int tw = (gw + settings.tileSize - 1) / settings.tileSize;
|
||||||
|
int th = (gh + settings.tileSize - 1) / settings.tileSize;
|
||||||
|
float s = settings.tileSize * settings.cellSize;
|
||||||
|
_debugDraw.DebugDrawGridXZ(bmin[0], bmin[1], bmin[2], tw, th, s, DebugDraw.DuRGBA(0, 0, 0, 64), 1.0f);
|
||||||
|
}
|
||||||
|
|
||||||
if (navMesh != null && navQuery != null
|
if (navMesh != null && navQuery != null
|
||||||
&& (drawMode == DrawMode.DRAWMODE_NAVMESH
|
&& (drawMode == DrawMode.DRAWMODE_NAVMESH
|
||||||
|| drawMode == DrawMode.DRAWMODE_NAVMESH_TRANS
|
|| drawMode == DrawMode.DRAWMODE_NAVMESH_TRANS
|
||||||
|
@ -104,8 +117,7 @@ public class NavMeshRenderer
|
||||||
if (drawMode == DrawMode.DRAWMODE_NAVMESH_NODES)
|
if (drawMode == DrawMode.DRAWMODE_NAVMESH_NODES)
|
||||||
{
|
{
|
||||||
_debugDraw.DebugDrawNavMeshNodes(navQuery);
|
_debugDraw.DebugDrawNavMeshNodes(navQuery);
|
||||||
_debugDraw.DebugDrawNavMeshPolysWithFlags(navMesh, SampleAreaModifications.SAMPLE_POLYFLAGS_DISABLED,
|
_debugDraw.DebugDrawNavMeshPolysWithFlags(navMesh, SampleAreaModifications.SAMPLE_POLYFLAGS_DISABLED, DebugDraw.DuRGBA(0, 0, 0, 128));
|
||||||
DebugDraw.DuRGBA(0, 0, 0, 128));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,11 @@
|
||||||
using DotRecast.Core;
|
using System.Reflection.Metadata;
|
||||||
|
using DotRecast.Core;
|
||||||
using DotRecast.Recast.Demo.Draw;
|
using DotRecast.Recast.Demo.Draw;
|
||||||
using DotRecast.Recast.DemoTool;
|
using DotRecast.Recast.DemoTool;
|
||||||
using DotRecast.Recast.DemoTool.Tools;
|
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;
|
namespace DotRecast.Recast.Demo.Tools;
|
||||||
|
|
||||||
|
@ -9,6 +13,9 @@ public class TileTool : IRcTool
|
||||||
{
|
{
|
||||||
private readonly TileToolImpl _impl;
|
private readonly TileToolImpl _impl;
|
||||||
|
|
||||||
|
private bool _hitPosSet;
|
||||||
|
private RcVec3f _hitPos;
|
||||||
|
|
||||||
public TileTool()
|
public TileTool()
|
||||||
{
|
{
|
||||||
_impl = new();
|
_impl = new();
|
||||||
|
@ -25,14 +32,51 @@ public class TileTool : IRcTool
|
||||||
|
|
||||||
public void Layout()
|
public void Layout()
|
||||||
{
|
{
|
||||||
|
if (ImGui.Button("Create All Tile"))
|
||||||
|
{
|
||||||
|
// if (m_sample)
|
||||||
|
// m_sample->buildAllTiles();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (ImGui.Button("Remove All Tile"))
|
||||||
|
{
|
||||||
|
// if (m_sample)
|
||||||
|
// m_sample->removeAllTiles();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void HandleClick(RcVec3f s, RcVec3f p, bool shift)
|
public void HandleClick(RcVec3f s, RcVec3f p, bool shift)
|
||||||
{
|
{
|
||||||
|
_hitPosSet = true;
|
||||||
|
_hitPos = p;
|
||||||
|
|
||||||
|
var sample = _impl.GetSample();
|
||||||
|
if (null != sample)
|
||||||
|
{
|
||||||
|
if (shift)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void HandleRender(NavMeshRenderer renderer)
|
public void HandleRender(NavMeshRenderer renderer)
|
||||||
{
|
{
|
||||||
|
if (_hitPosSet)
|
||||||
|
{
|
||||||
|
RecastDebugDraw dd = renderer.GetDebugDraw();
|
||||||
|
var s = _impl.GetSample().GetSettings().agentRadius;
|
||||||
|
dd.Begin(LINES, 2.0f);
|
||||||
|
dd.Vertex(_hitPos[0] - s, _hitPos[1] + 0.1f, _hitPos[2], DuRGBA(0, 0, 0, 128));
|
||||||
|
dd.Vertex(_hitPos[0] + s, _hitPos[1] + 0.1f, _hitPos[2], DuRGBA(0, 0, 0, 128));
|
||||||
|
dd.Vertex(_hitPos[0], _hitPos[1] - s + 0.1f, _hitPos[2], DuRGBA(0, 0, 0, 128));
|
||||||
|
dd.Vertex(_hitPos[0], _hitPos[1] + s + 0.1f, _hitPos[2], DuRGBA(0, 0, 0, 128));
|
||||||
|
dd.Vertex(_hitPos[0], _hitPos[1] + 0.1f, _hitPos[2] - s, DuRGBA(0, 0, 0, 128));
|
||||||
|
dd.Vertex(_hitPos[0], _hitPos[1] + 0.1f, _hitPos[2] + s, DuRGBA(0, 0, 0, 128));
|
||||||
|
dd.End();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void HandleUpdate(float dt)
|
public void HandleUpdate(float dt)
|
||||||
|
|
Loading…
Reference in New Issue