From 1ff0f85b1facf30bfe4c0971ec86c5a401325765 Mon Sep 17 00:00:00 2001 From: ikpil Date: Thu, 27 Jul 2023 00:16:52 +0900 Subject: [PATCH] add tile grid view --- src/DotRecast.Recast.Demo/Draw/DebugDraw.cs | 21 ++++++++- .../Draw/NavMeshRenderer.cs | 16 ++++++- src/DotRecast.Recast.Demo/Tools/TileTool.cs | 46 ++++++++++++++++++- 3 files changed, 78 insertions(+), 5 deletions(-) diff --git a/src/DotRecast.Recast.Demo/Draw/DebugDraw.cs b/src/DotRecast.Recast.Demo/Draw/DebugDraw.cs index 994ea96..2b7c661 100644 --- a/src/DotRecast.Recast.Demo/Draw/DebugDraw.cs +++ b/src/DotRecast.Recast.Demo/Draw/DebugDraw.cs @@ -111,6 +111,23 @@ public class DebugDraw 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) { // Top @@ -189,7 +206,7 @@ public class DebugDraw { GetOpenGlDraw().Vertex(pos, color); } - + public void Vertex(RcVec3f pos, int color) { GetOpenGlDraw().Vertex(pos, color); @@ -703,4 +720,4 @@ public class DebugDraw { return FrustumTest(new float[] { bmin.x, bmin.y, bmin.z, bmax.x, bmax.y, bmax.z }); } -} +} \ No newline at end of file diff --git a/src/DotRecast.Recast.Demo/Draw/NavMeshRenderer.cs b/src/DotRecast.Recast.Demo/Draw/NavMeshRenderer.cs index a6ad7fc..50f1560 100644 --- a/src/DotRecast.Recast.Demo/Draw/NavMeshRenderer.cs +++ b/src/DotRecast.Recast.Demo/Draw/NavMeshRenderer.cs @@ -19,6 +19,7 @@ freely, subject to the following restrictions: */ using System.Collections.Generic; +using System.Diagnostics.Tracing; using DotRecast.Core; using DotRecast.Detour; using DotRecast.Recast.DemoTool.Builder; @@ -78,6 +79,18 @@ public class NavMeshRenderer 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 && (drawMode == DrawMode.DRAWMODE_NAVMESH || drawMode == DrawMode.DRAWMODE_NAVMESH_TRANS @@ -104,8 +117,7 @@ public class NavMeshRenderer if (drawMode == DrawMode.DRAWMODE_NAVMESH_NODES) { _debugDraw.DebugDrawNavMeshNodes(navQuery); - _debugDraw.DebugDrawNavMeshPolysWithFlags(navMesh, SampleAreaModifications.SAMPLE_POLYFLAGS_DISABLED, - DebugDraw.DuRGBA(0, 0, 0, 128)); + _debugDraw.DebugDrawNavMeshPolysWithFlags(navMesh, SampleAreaModifications.SAMPLE_POLYFLAGS_DISABLED, DebugDraw.DuRGBA(0, 0, 0, 128)); } } diff --git a/src/DotRecast.Recast.Demo/Tools/TileTool.cs b/src/DotRecast.Recast.Demo/Tools/TileTool.cs index 56a5acb..a106594 100644 --- a/src/DotRecast.Recast.Demo/Tools/TileTool.cs +++ b/src/DotRecast.Recast.Demo/Tools/TileTool.cs @@ -1,7 +1,11 @@ -using DotRecast.Core; +using System.Reflection.Metadata; +using DotRecast.Core; using DotRecast.Recast.Demo.Draw; 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; @@ -9,6 +13,9 @@ public class TileTool : IRcTool { private readonly TileToolImpl _impl; + private bool _hitPosSet; + private RcVec3f _hitPos; + public TileTool() { _impl = new(); @@ -25,14 +32,51 @@ public class TileTool : IRcTool 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) { + _hitPosSet = true; + _hitPos = p; + + var sample = _impl.GetSample(); + if (null != sample) + { + if (shift) + { + } + else + { + } + } } 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)