From 8044b85ec58066cdc43a7de5d20bb42256b4b9c2 Mon Sep 17 00:00:00 2001 From: ikpil Date: Sun, 30 Jul 2023 11:17:10 +0900 Subject: [PATCH] rename Recast.Recast -> RcUtils --- .../Draw/NavMeshRenderer.cs | 2 +- src/DotRecast.Recast.Demo/RecastDemo.cs | 2 +- src/DotRecast.Recast.Demo/Tools/ObstacleTool.cs | 15 ++++++++++++++- .../Builder/TileNavMeshBuilder.cs | 4 ++-- .../Tools/ObstacleToolImpl.cs | 16 +++++++++++++++- .../Tools/TileToolImpl.cs | 4 ++-- src/DotRecast.Recast/RcConstants.cs | 13 ++++++++++++- src/DotRecast.Recast/{Recast.cs => RcUtils.cs} | 6 +++--- src/DotRecast.Recast/RecastBuilder.cs | 4 ++-- src/DotRecast.Recast/RecastBuilderConfig.cs | 2 +- src/DotRecast.Recast/RecastVoxelization.cs | 4 ++-- .../Io/MeshSetReaderWriterTest.cs | 2 +- .../AbstractTileCacheTest.cs | 2 +- .../TestTileLayerBuilder.cs | 2 +- test/DotRecast.Recast.Test/RecastSoloMeshTest.cs | 2 +- test/DotRecast.Recast.Test/RecastTest.cs | 6 +++--- 16 files changed, 62 insertions(+), 24 deletions(-) rename src/DotRecast.Recast/{Recast.cs => RcUtils.cs} (98%) diff --git a/src/DotRecast.Recast.Demo/Draw/NavMeshRenderer.cs b/src/DotRecast.Recast.Demo/Draw/NavMeshRenderer.cs index f3edad6..2efa693 100644 --- a/src/DotRecast.Recast.Demo/Draw/NavMeshRenderer.cs +++ b/src/DotRecast.Recast.Demo/Draw/NavMeshRenderer.cs @@ -84,7 +84,7 @@ public class NavMeshRenderer int gw = 0, gh = 0; RcVec3f bmin = geom.GetMeshBoundsMin(); RcVec3f bmax = geom.GetMeshBoundsMax(); - Recast.CalcGridSize(bmin, bmax, settings.cellSize, out gw, out gh); + RcUtils.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; diff --git a/src/DotRecast.Recast.Demo/RecastDemo.cs b/src/DotRecast.Recast.Demo/RecastDemo.cs index 504df5b..44aeffc 100644 --- a/src/DotRecast.Recast.Demo/RecastDemo.cs +++ b/src/DotRecast.Recast.Demo/RecastDemo.cs @@ -451,7 +451,7 @@ public class RecastDemo : IRecastDemoChannel var settings = _sample.GetSettings(); RcVec3f bmin = _sample.GetInputGeom().GetMeshBoundsMin(); RcVec3f bmax = _sample.GetInputGeom().GetMeshBoundsMax(); - Recast.CalcGridSize(bmin, bmax, settings.cellSize, out var gw, out var gh); + RcUtils.CalcGridSize(bmin, bmax, settings.cellSize, out var gw, out var gh); settingsView.SetVoxels(gw, gh); settingsView.SetTiles(tileNavMeshBuilder.GetTiles(_sample.GetInputGeom(), settings.cellSize, settings.tileSize)); settingsView.SetMaxTiles(tileNavMeshBuilder.GetMaxTiles(_sample.GetInputGeom(), settings.cellSize, settings.tileSize)); diff --git a/src/DotRecast.Recast.Demo/Tools/ObstacleTool.cs b/src/DotRecast.Recast.Demo/Tools/ObstacleTool.cs index 3bf1437..739d85d 100644 --- a/src/DotRecast.Recast.Demo/Tools/ObstacleTool.cs +++ b/src/DotRecast.Recast.Demo/Tools/ObstacleTool.cs @@ -11,6 +11,8 @@ public class ObstacleTool : IRcTool { private static readonly ILogger Logger = Log.ForContext(); private readonly ObstacleToolImpl _impl; + private bool _hitPosSet; + private RcVec3f _hitPos; public ObstacleTool() { @@ -32,7 +34,7 @@ public class ObstacleTool : IRcTool { //m_sample->clearAllTempObstacles(); } - + ImGui.Separator(); ImGui.Text("Click LMB to create an obstacle."); @@ -41,6 +43,17 @@ public class ObstacleTool : IRcTool public void HandleClick(RcVec3f s, RcVec3f p, bool shift) { + _hitPosSet = true; + _hitPos = p; + + if (shift) + { + _impl.RemoveTempObstacle(s, p); + } + else + { + _impl.AddTempObstacle(_hitPos); + } } public void HandleRender(NavMeshRenderer renderer) diff --git a/src/DotRecast.Recast.DemoTool/Builder/TileNavMeshBuilder.cs b/src/DotRecast.Recast.DemoTool/Builder/TileNavMeshBuilder.cs index e9fb3a9..e8473a5 100644 --- a/src/DotRecast.Recast.DemoTool/Builder/TileNavMeshBuilder.cs +++ b/src/DotRecast.Recast.DemoTool/Builder/TileNavMeshBuilder.cs @@ -128,7 +128,7 @@ namespace DotRecast.Recast.DemoTool.Builder private int GetTileBits(DemoInputGeomProvider geom, float cellSize, int tileSize) { - Recast.CalcGridSize(geom.GetMeshBoundsMin(), geom.GetMeshBoundsMax(), cellSize, out var gw, out var gh); + RcUtils.CalcGridSize(geom.GetMeshBoundsMin(), geom.GetMeshBoundsMax(), cellSize, out var gw, out var gh); int tw = (gw + tileSize - 1) / tileSize; int th = (gh + tileSize - 1) / tileSize; int tileBits = Math.Min(DetourCommon.Ilog2(DetourCommon.NextPow2(tw * th)), 14); @@ -137,7 +137,7 @@ namespace DotRecast.Recast.DemoTool.Builder public int[] GetTiles(DemoInputGeomProvider geom, float cellSize, int tileSize) { - Recast.CalcGridSize(geom.GetMeshBoundsMin(), geom.GetMeshBoundsMax(), cellSize, out var gw, out var gh); + RcUtils.CalcGridSize(geom.GetMeshBoundsMin(), geom.GetMeshBoundsMax(), cellSize, out var gw, out var gh); int tw = (gw + tileSize - 1) / tileSize; int th = (gh + tileSize - 1) / tileSize; return new int[] { tw, th }; diff --git a/src/DotRecast.Recast.DemoTool/Tools/ObstacleToolImpl.cs b/src/DotRecast.Recast.DemoTool/Tools/ObstacleToolImpl.cs index 4b3e819..2edfc3a 100644 --- a/src/DotRecast.Recast.DemoTool/Tools/ObstacleToolImpl.cs +++ b/src/DotRecast.Recast.DemoTool/Tools/ObstacleToolImpl.cs @@ -1,4 +1,7 @@ -namespace DotRecast.Recast.DemoTool.Tools +using DotRecast.Core; +using DotRecast.Detour.TileCache; + +namespace DotRecast.Recast.DemoTool.Tools { public class ObstacleToolImpl : ISampleTool { @@ -18,5 +21,16 @@ { return _sample; } + + public void RemoveTempObstacle(RcVec3f sp, RcVec3f sq) + { + // .. + } + + public void AddTempObstacle(RcVec3f pos) + { + //p[1] -= 0.5f; + //m_tileCache->addObstacle(p, 1.0f, 2.0f, 0); + } } } \ No newline at end of file diff --git a/src/DotRecast.Recast.DemoTool/Tools/TileToolImpl.cs b/src/DotRecast.Recast.DemoTool/Tools/TileToolImpl.cs index 4ad48f3..c8eb280 100644 --- a/src/DotRecast.Recast.DemoTool/Tools/TileToolImpl.cs +++ b/src/DotRecast.Recast.DemoTool/Tools/TileToolImpl.cs @@ -36,7 +36,7 @@ namespace DotRecast.Recast.DemoTool.Tools var bmin = geom.GetMeshBoundsMin(); var bmax = geom.GetMeshBoundsMax(); int gw = 0, gh = 0; - Recast.CalcGridSize(bmin, bmax, settings.cellSize, out gw, out gh); + RcUtils.CalcGridSize(bmin, bmax, settings.cellSize, out gw, out gh); int ts = settings.tileSize; int tw = (gw + ts - 1) / ts; @@ -64,7 +64,7 @@ namespace DotRecast.Recast.DemoTool.Tools var bmin = geom.GetMeshBoundsMin(); var bmax = geom.GetMeshBoundsMax(); int gw = 0, gh = 0; - Recast.CalcGridSize(bmin, bmax, settings.cellSize, out gw, out gh); + RcUtils.CalcGridSize(bmin, bmax, settings.cellSize, out gw, out gh); int ts = settings.tileSize; int tw = (gw + ts - 1) / ts; diff --git a/src/DotRecast.Recast/RcConstants.cs b/src/DotRecast.Recast/RcConstants.cs index 9d340c5..aebf84c 100644 --- a/src/DotRecast.Recast/RcConstants.cs +++ b/src/DotRecast.Recast/RcConstants.cs @@ -22,9 +22,20 @@ namespace DotRecast.Recast { public static class RcConstants { + /// Represents the null area. + /// When a data element is given this value it is considered to no longer be + /// assigned to a usable area. (E.g. It is un-walkable.) public const int RC_NULL_AREA = 0; - public const int RC_NOT_CONNECTED = 0x3f; + + /// The default area id used to indicate a walkable polygon. + /// This is also the maximum allowed area id, and the only non-null area id + /// recognized by some steps in the build process. + public const int RC_WALKABLE_AREA = 63; + /// The value returned by #rcGetCon if the specified direction is not connected + /// to another span. (Has no neighbor.) + public const int RC_NOT_CONNECTED = 0x3f; + /// Defines the number of bits allocated to rcSpan::smin and rcSpan::smax. public const int SPAN_HEIGHT_BITS = 20; diff --git a/src/DotRecast.Recast/Recast.cs b/src/DotRecast.Recast/RcUtils.cs similarity index 98% rename from src/DotRecast.Recast/Recast.cs rename to src/DotRecast.Recast/RcUtils.cs index f19abff..2954b1a 100644 --- a/src/DotRecast.Recast/Recast.cs +++ b/src/DotRecast.Recast/RcUtils.cs @@ -23,9 +23,9 @@ using DotRecast.Core; namespace DotRecast.Recast { - using static RcConstants; - - public static class Recast + using static DotRecast.Recast.RcConstants; + + public static class RcUtils { public static void CalcBounds(float[] verts, int nv, float[] bmin, float[] bmax) { diff --git a/src/DotRecast.Recast/RecastBuilder.cs b/src/DotRecast.Recast/RecastBuilder.cs index 2308b46..2a36c04 100644 --- a/src/DotRecast.Recast/RecastBuilder.cs +++ b/src/DotRecast.Recast/RecastBuilder.cs @@ -45,7 +45,7 @@ namespace DotRecast.Recast { RcVec3f bmin = geom.GetMeshBoundsMin(); RcVec3f bmax = geom.GetMeshBoundsMax(); - Recast.CalcTileCount(bmin, bmax, cfg.Cs, cfg.TileSizeX, cfg.TileSizeZ, out var tw, out var th); + RcUtils.CalcTileCount(bmin, bmax, cfg.Cs, cfg.TileSizeX, cfg.TileSizeZ, out var tw, out var th); List results = new List(); if (null != taskFactory) { @@ -64,7 +64,7 @@ namespace DotRecast.Recast { RcVec3f bmin = geom.GetMeshBoundsMin(); RcVec3f bmax = geom.GetMeshBoundsMax(); - Recast.CalcTileCount(bmin, bmax, cfg.Cs, cfg.TileSizeX, cfg.TileSizeZ, out var tw, out var th); + RcUtils.CalcTileCount(bmin, bmax, cfg.Cs, cfg.TileSizeX, cfg.TileSizeZ, out var tw, out var th); Task task; if (1 < threads) { diff --git a/src/DotRecast.Recast/RecastBuilderConfig.cs b/src/DotRecast.Recast/RecastBuilderConfig.cs index 8eb20df..5533c2e 100644 --- a/src/DotRecast.Recast/RecastBuilderConfig.cs +++ b/src/DotRecast.Recast/RecastBuilderConfig.cs @@ -92,7 +92,7 @@ namespace DotRecast.Recast } else { - Recast.CalcGridSize(this.bmin, this.bmax, cfg.Cs, out width, out height); + RcUtils.CalcGridSize(this.bmin, this.bmax, cfg.Cs, out width, out height); } } } diff --git a/src/DotRecast.Recast/RecastVoxelization.cs b/src/DotRecast.Recast/RecastVoxelization.cs index ae6074c..2895c82 100644 --- a/src/DotRecast.Recast/RecastVoxelization.cs +++ b/src/DotRecast.Recast/RecastVoxelization.cs @@ -57,7 +57,7 @@ namespace DotRecast.Recast { int[] tris = node.tris; int ntris = tris.Length / 3; - int[] m_triareas = Recast.MarkWalkableTriangles(ctx, cfg.WalkableSlopeAngle, verts, tris, ntris, cfg.WalkableAreaMod); + int[] m_triareas = RcUtils.MarkWalkableTriangles(ctx, cfg.WalkableSlopeAngle, verts, tris, ntris, cfg.WalkableAreaMod); RecastRasterization.RasterizeTriangles(solid, verts, tris, m_triareas, ntris, cfg.WalkableClimb, ctx); } } @@ -65,7 +65,7 @@ namespace DotRecast.Recast { int[] tris = geom.GetTris(); int ntris = tris.Length / 3; - int[] m_triareas = Recast.MarkWalkableTriangles(ctx, cfg.WalkableSlopeAngle, verts, tris, ntris, cfg.WalkableAreaMod); + int[] m_triareas = RcUtils.MarkWalkableTriangles(ctx, cfg.WalkableSlopeAngle, verts, tris, ntris, cfg.WalkableAreaMod); RecastRasterization.RasterizeTriangles(solid, verts, tris, m_triareas, ntris, cfg.WalkableClimb, ctx); } } diff --git a/test/DotRecast.Detour.Test/Io/MeshSetReaderWriterTest.cs b/test/DotRecast.Detour.Test/Io/MeshSetReaderWriterTest.cs index 6f843d1..916bfc1 100644 --- a/test/DotRecast.Detour.Test/Io/MeshSetReaderWriterTest.cs +++ b/test/DotRecast.Detour.Test/Io/MeshSetReaderWriterTest.cs @@ -69,7 +69,7 @@ public class MeshSetReaderWriterTest RcVec3f bmin = geom.GetMeshBoundsMin(); RcVec3f bmax = geom.GetMeshBoundsMax(); - Recast.Recast.CalcTileCount(bmin, bmax, m_cellSize, m_tileSize, m_tileSize, out var tw, out var th); + Recast.RcUtils.CalcTileCount(bmin, bmax, m_cellSize, m_tileSize, m_tileSize, out var tw, out var th); for (int y = 0; y < th; ++y) { for (int x = 0; x < tw; ++x) diff --git a/test/DotRecast.Detour.TileCache.Test/AbstractTileCacheTest.cs b/test/DotRecast.Detour.TileCache.Test/AbstractTileCacheTest.cs index 7b60708..c5ef78b 100644 --- a/test/DotRecast.Detour.TileCache.Test/AbstractTileCacheTest.cs +++ b/test/DotRecast.Detour.TileCache.Test/AbstractTileCacheTest.cs @@ -53,7 +53,7 @@ public class AbstractTileCacheTest public DtTileCache GetTileCache(IInputGeomProvider geom, RcByteOrder order, bool cCompatibility) { DtTileCacheParams option = new DtTileCacheParams(); - Recast.Recast.CalcTileCount(geom.GetMeshBoundsMin(), geom.GetMeshBoundsMax(), m_cellSize, m_tileSize, m_tileSize, out var tw, out var th); + Recast.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(); diff --git a/test/DotRecast.Detour.TileCache.Test/TestTileLayerBuilder.cs b/test/DotRecast.Detour.TileCache.Test/TestTileLayerBuilder.cs index c1ca2d5..cf4e50a 100644 --- a/test/DotRecast.Detour.TileCache.Test/TestTileLayerBuilder.cs +++ b/test/DotRecast.Detour.TileCache.Test/TestTileLayerBuilder.cs @@ -57,7 +57,7 @@ public class TestTileLayerBuilder : AbstractTileLayersBuilder true, m_detailSampleDist, m_detailSampleMaxError, SampleAreaModifications.SAMPLE_AREAMOD_GROUND); RcVec3f bmin = geom.GetMeshBoundsMin(); RcVec3f bmax = geom.GetMeshBoundsMax(); - Recast.Recast.CalcTileCount(bmin, bmax, m_cellSize, m_tileSize, m_tileSize, out tw, out th); + Recast.RcUtils.CalcTileCount(bmin, bmax, m_cellSize, m_tileSize, m_tileSize, out tw, out th); } public List Build(RcByteOrder order, bool cCompatibility, int threads) diff --git a/test/DotRecast.Recast.Test/RecastSoloMeshTest.cs b/test/DotRecast.Recast.Test/RecastSoloMeshTest.cs index e47acee..3d075fa 100644 --- a/test/DotRecast.Recast.Test/RecastSoloMeshTest.cs +++ b/test/DotRecast.Recast.Test/RecastSoloMeshTest.cs @@ -131,7 +131,7 @@ public class RecastSoloMeshTest // Find triangles which are walkable based on their slope and rasterize them. // If your input data is multiple meshes, you can transform them here, calculate // the are type for each of the meshes and rasterize them. - int[] m_triareas = Recast.MarkWalkableTriangles(m_ctx, cfg.WalkableSlopeAngle, verts, tris, ntris, cfg.WalkableAreaMod); + int[] m_triareas = RcUtils.MarkWalkableTriangles(m_ctx, cfg.WalkableSlopeAngle, verts, tris, ntris, cfg.WalkableAreaMod); RecastRasterization.RasterizeTriangles(m_solid, verts, tris, m_triareas, ntris, cfg.WalkableClimb, m_ctx); } diff --git a/test/DotRecast.Recast.Test/RecastTest.cs b/test/DotRecast.Recast.Test/RecastTest.cs index b43e0f8..921f112 100644 --- a/test/DotRecast.Recast.Test/RecastTest.cs +++ b/test/DotRecast.Recast.Test/RecastTest.cs @@ -39,18 +39,18 @@ public class RecastTest RcTelemetry ctx = new RcTelemetry(); { int[] areas = { 42 }; - Recast.ClearUnwalkableTriangles(ctx, walkableSlopeAngle, verts, nv, unwalkable_tri, nt, areas); + RcUtils.ClearUnwalkableTriangles(ctx, walkableSlopeAngle, verts, nv, unwalkable_tri, nt, areas); Assert.That(areas[0], Is.EqualTo(RC_NULL_AREA), "Sets area ID of unwalkable triangle to RC_NULL_AREA"); } { int[] areas = { 42 }; - Recast.ClearUnwalkableTriangles(ctx, walkableSlopeAngle, verts, nv, walkable_tri, nt, areas); + RcUtils.ClearUnwalkableTriangles(ctx, walkableSlopeAngle, verts, nv, walkable_tri, nt, areas); Assert.That(areas[0], Is.EqualTo(42), "Does not modify walkable triangle aread ID's"); } { int[] areas = { 42 }; walkableSlopeAngle = 0; - Recast.ClearUnwalkableTriangles(ctx, walkableSlopeAngle, verts, nv, walkable_tri, nt, areas); + RcUtils.ClearUnwalkableTriangles(ctx, walkableSlopeAngle, verts, nv, walkable_tri, nt, areas); Assert.That(areas[0], Is.EqualTo(RC_NULL_AREA), "Slopes equal to the max slope are considered unwalkable."); } }