diff --git a/src/DotRecast.Recast.Demo/Settings/RcSettingsView.cs b/src/DotRecast.Recast.Demo/Settings/RcSettingsView.cs index d5da4f8..daf6bf7 100644 --- a/src/DotRecast.Recast.Demo/Settings/RcSettingsView.cs +++ b/src/DotRecast.Recast.Demo/Settings/RcSettingsView.cs @@ -16,7 +16,9 @@ freely, subject to the following restrictions: 3. This notice may not be removed or altered from any source distribution. */ +using System.Linq; using System.Numerics; +using DotRecast.Core; using DotRecast.Recast.Demo.Draw; using DotRecast.Recast.Demo.UI; using ImGuiNET; @@ -37,21 +39,22 @@ public class RcSettingsView : IRcView private int minRegionSize = 8; private int mergedRegionSize = 20; + private int _partitioning = 0; private PartitionType partitioning = PartitionType.WATERSHED; private bool filterLowHangingObstacles = true; private bool filterLedgeSpans = true; private bool filterWalkableLowHeightSpans = true; - private readonly float[] edgeMaxLen = new[] { 12f }; - private readonly float[] edgeMaxError = new[] { 1.3f }; - private readonly int[] vertsPerPoly = new[] { 6 }; + private float edgeMaxLen = 12f; + private float edgeMaxError = 1.3f; + private int vertsPerPoly = 6; - private readonly float[] detailSampleDist = new[] { 6f }; - private readonly float[] detailSampleMaxError = new[] { 1f }; + private float detailSampleDist = 6f; + private float detailSampleMaxError = 1f; private bool tiled = false; - private readonly int[] tileSize = new[] { 32 }; + private int tileSize = 32; // public readonly NkColor white = NkColor.create(); // public readonly NkColor background = NkColor.create(); @@ -76,7 +79,7 @@ public class RcSettingsView : IRcView return true; } - public bool renderInternal(IWindow i, int x, int y, int width, int height, int mouseX, int mouseY) + public bool renderInternal(IWindow win, int x, int y, int width, int height, int mouseX, int mouseY) { bool mouseInside = false; ImGui.Text("Input Mesh"); @@ -88,67 +91,62 @@ public class RcSettingsView : IRcView ImGui.Text("Rasterization"); ImGui.Separator(); - ImGui.SliderFloat("Cell Size", ref cellSize, 0.01f, 1f, $"{cellSize}"); - ImGui.SliderFloat("Cell Height", ref cellHeight, 0.01f, 1f, $"{cellHeight}"); + ImGui.SliderFloat("Cell Size", ref cellSize, 0.01f, 1f, "%.2f"); + ImGui.SliderFloat("Cell Height", ref cellHeight, 0.01f, 1f, "%.2f"); ImGui.Text($"Voxels {voxels[0]} x {voxels[1]}"); ImGui.NewLine(); ImGui.Text("Agent"); ImGui.Separator(); - ImGui.SliderFloat("Height", ref agentHeight, 5f, 0.1f, $"{agentHeight}"); - ImGui.SliderFloat("Radius", ref agentRadius, 5f, 0.1f, $"{agentRadius}"); - ImGui.SliderFloat("Max Climb", ref agentMaxClimb, 5f, 0.1f, $"{agentMaxClimb}"); - ImGui.SliderFloat("Max Slope", ref agentMaxSlope, 90f, 1f, $"{agentMaxSlope}"); + ImGui.SliderFloat("Height", ref agentHeight, 0.1f, 5f, "%.1f"); + ImGui.SliderFloat("Radius", ref agentRadius, 0.1f, 5f, "%.1f"); + ImGui.SliderFloat("Max Climb", ref agentMaxClimb, 0.1f, 5f, "%.1f"); + ImGui.SliderFloat("Max Slope", ref agentMaxSlope, 1f, 90f, "%.0f"); ImGui.NewLine(); ImGui.Text("Region"); ImGui.Separator(); - ImGui.SliderInt("Min Region Size", ref minRegionSize, 1, 150); - ImGui.SliderInt("Merged Region Size", ref mergedRegionSize, 1, 150); - // - // nk_layout_row_dynamic(ctx, 3, 1); - // nk_spacing(ctx, 1); - // nk_layout_row_dynamic(ctx, 18, 1); - // nk_label(ctx, "Partitioning", NK_TEXT_ALIGN_LEFT); - // partitioning = NuklearUIHelper.nk_radio(ctx, PartitionType.values(), partitioning, - // p => p.name().substring(0, 1) + p.name().substring(1).toLowerCase()); - // - // nk_layout_row_dynamic(ctx, 3, 1); - // nk_spacing(ctx, 1); - // nk_layout_row_dynamic(ctx, 18, 1); - // nk_label(ctx, "Filtering", NK_TEXT_ALIGN_LEFT); + ImGui.SliderInt("Min Region Size", ref minRegionSize, 1, 150, "%.0f"); + ImGui.SliderInt("Merged Region Size", ref mergedRegionSize, 1, 150, "%.0f"); + ImGui.NewLine(); + + ImGui.Text("Partitioning"); + PartitionType.Values.forEach(partition => + { + var label = partition.Name.Substring(0, 1).ToUpper() + + partition.Name.Substring(1).ToLower(); + ImGui.RadioButton(label, ref _partitioning, partition.Idx); + }); + ImGui.NewLine(); + + ImGui.Text("Filtering"); + ImGui.Checkbox("Low Hanging Obstacles", ref filterLowHangingObstacles); + ImGui.Checkbox("Ledge Spans", ref filterLedgeSpans); + ImGui.Checkbox("Walkable Low Height Spans", ref filterWalkableLowHeightSpans); + ImGui.NewLine(); + + ImGui.Text("Polygonization"); // nk_layout_row_dynamic(ctx, 20, 1); - // filterLowHangingObstacles = nk_option_text(ctx, "Low Hanging Obstacles", filterLowHangingObstacles); + ImGui.SliderFloat("Max Edge Length", ref edgeMaxLen, 0f, 50f, "%.1f"); // nk_layout_row_dynamic(ctx, 20, 1); - // filterLedgeSpans = nk_option_text(ctx, "Ledge Spans", filterLedgeSpans); - // nk_layout_row_dynamic(ctx, 20, 1); - // filterWalkableLowHeightSpans = nk_option_text(ctx, "Walkable Low Height Spans", - // filterWalkableLowHeightSpans); - // - // nk_layout_row_dynamic(ctx, 3, 1); - // nk_spacing(ctx, 1); - // nk_layout_row_dynamic(ctx, 18, 1); - // nk_label(ctx, "Polygonization", NK_TEXT_ALIGN_LEFT); - // nk_layout_row_dynamic(ctx, 20, 1); - // nk_property_float(ctx, "Max Edge Length", 0f, edgeMaxLen, 50f, 0.1f, 0.1f); - // nk_layout_row_dynamic(ctx, 20, 1); - // nk_property_float(ctx, "Max Edge Error", 0.1f, edgeMaxError, 3f, 0.1f, 0.1f); + ImGui.SliderFloat("Max Edge Error", ref edgeMaxError, 0.1f, 3f, "%.1f"); // nk_layout_row_dynamic(ctx, 20, 1); // nk_property_int(ctx, "Vert Per Poly", 3, vertsPerPoly, 12, 1, 1); - // + ImGui.NewLine(); + // nk_layout_row_dynamic(ctx, 3, 1); // nk_spacing(ctx, 1); // nk_layout_row_dynamic(ctx, 18, 1); // nk_label(ctx, "Detail Mesh", NK_TEXT_ALIGN_LEFT); // nk_layout_row_dynamic(ctx, 20, 1); - // nk_property_float(ctx, "Sample Distance", 0f, detailSampleDist, 16f, 0.1f, 0.1f); + ImGui.SliderFloat("Sample Distance", ref detailSampleDist, 0f, 16f, "%.1f"); // nk_layout_row_dynamic(ctx, 20, 1); - // nk_property_float(ctx, "Max Sample Error", 0f, detailSampleMaxError, 16f, 0.1f, 0.1f); + ImGui.SliderFloat("Max Sample Error", ref detailSampleMaxError, 0f, 16f, "%.1f"); // // nk_layout_row_dynamic(ctx, 3, 1); // nk_spacing(ctx, 1); // nk_layout_row_dynamic(ctx, 18, 1); - // nk_label(ctx, "Tiling", NK_TEXT_ALIGN_LEFT); + ImGui.Text("Tiling"); // nk_layout_row_dynamic(ctx, 20, 1); // tiled = nk_check_text(ctx, "Enable", tiled); // if (tiled) { @@ -172,7 +170,7 @@ public class RcSettingsView : IRcView // navMeshInputTrigerred = nk_button_text(ctx, "Load Nav Mesh..."); // // nk_layout_row_dynamic(ctx, 18, 1); - // nk_label(ctx, "Draw", NK_TEXT_ALIGN_LEFT); + ImGui.Text("Draw"); // drawMode = NuklearUIHelper.nk_radio(ctx, DrawMode.values(), drawMode, dm => dm.toString()); // // nk_window_get_bounds(ctx, rect); @@ -263,27 +261,27 @@ public class RcSettingsView : IRcView public float getEdgeMaxLen() { - return edgeMaxLen[0]; + return edgeMaxLen; } public float getEdgeMaxError() { - return edgeMaxError[0]; + return edgeMaxError; } public int getVertsPerPoly() { - return vertsPerPoly[0]; + return vertsPerPoly; } public float getDetailSampleDist() { - return detailSampleDist[0]; + return detailSampleDist; } public float getDetailSampleMaxError() { - return detailSampleMaxError[0]; + return detailSampleMaxError; } public void setVoxels(int[] voxels) @@ -299,7 +297,7 @@ public class RcSettingsView : IRcView public int getTileSize() { - return tileSize[0]; + return tileSize; } public void setTiles(int[] tiles) diff --git a/src/DotRecast.Recast.Demo/Tools/ConvexVolumeTool.cs b/src/DotRecast.Recast.Demo/Tools/ConvexVolumeTool.cs index 5659f97..d050439 100644 --- a/src/DotRecast.Recast.Demo/Tools/ConvexVolumeTool.cs +++ b/src/DotRecast.Recast.Demo/Tools/ConvexVolumeTool.cs @@ -25,6 +25,7 @@ using DotRecast.Core; using DotRecast.Recast.Demo.Builder; using DotRecast.Recast.Demo.Draw; using DotRecast.Recast.Demo.Geom; +using ImGuiNET; using static DotRecast.Recast.Demo.Draw.DebugDraw; using static DotRecast.Recast.Demo.Draw.DebugDrawPrimitives; @@ -34,9 +35,9 @@ public class ConvexVolumeTool : Tool { private Sample sample; private AreaModification areaType = SampleAreaModifications.SAMPLE_AREAMOD_GRASS; - private readonly float[] boxHeight = new[] { 6f }; - private readonly float[] boxDescent = new[] { 1f }; - private readonly float[] polyOffset = new[] { 0f }; + private float boxHeight = 6f; + private float boxDescent = 1f; + private float polyOffset = 0f; private readonly List pts = new(); private readonly List hull = new(); @@ -99,13 +100,13 @@ public class ConvexVolumeTool : Tool minh = Math.Min(minh, verts[i * 3 + 1]); } - minh -= boxDescent[0]; - maxh = minh + boxHeight[0]; + minh -= boxDescent; + maxh = minh + boxHeight; - if (polyOffset[0] > 0.01f) + if (polyOffset > 0.01f) { float[] offset = new float[verts.Length * 2]; - int noffset = PolyUtils.offsetPoly(verts, hull.Count, polyOffset[0], offset, + int noffset = PolyUtils.offsetPoly(verts, hull.Count, polyOffset, offset, offset.Length); if (noffset > 0) { @@ -151,8 +152,8 @@ public class ConvexVolumeTool : Tool minh = Math.Min(minh, pts[i + 1]); } - minh -= boxDescent[0]; - maxh = minh + boxHeight[0]; + minh -= boxDescent; + maxh = minh + boxHeight; dd.begin(POINTS, 4.0f); for (int i = 0; i < pts.Count; i += 3) @@ -187,11 +188,11 @@ public class ConvexVolumeTool : Tool public override void layout(IWindow ctx) { // nk_layout_row_dynamic(ctx, 20, 1); - // nk_property_float(ctx, "Shape Height", 0.1f, boxHeight, 20f, 0.1f, 0.1f); + ImGui.SliderFloat("Shape Height", ref boxHeight, 0.1f, 20f, "%.1f"); // nk_layout_row_dynamic(ctx, 20, 1); - // nk_property_float(ctx, "Shape Descent", 0.1f, boxDescent, 20f, 0.1f, 0.1f); + ImGui.SliderFloat("Shape Descent", ref boxDescent, 0.1f, 20f, "%.1f"); // nk_layout_row_dynamic(ctx, 20, 1); - // nk_property_float(ctx, "Poly Offset", 0.1f, polyOffset, 10f, 0.1f, 0.1f); + ImGui.SliderFloat("Poly Offset", ref polyOffset, 0.1f, 10f, "%.1f"); // nk_label(ctx, "Area Type", NK_TEXT_ALIGN_LEFT); // nk_layout_row_dynamic(ctx, 20, 1); // if (nk_option_label(ctx, "Ground", areaType == SampleAreaModifications.SAMPLE_AREAMOD_GROUND)) { diff --git a/src/DotRecast.Recast.Demo/Tools/CrowdProfilingTool.cs b/src/DotRecast.Recast.Demo/Tools/CrowdProfilingTool.cs index 330e72a..fb2e191 100644 --- a/src/DotRecast.Recast.Demo/Tools/CrowdProfilingTool.cs +++ b/src/DotRecast.Recast.Demo/Tools/CrowdProfilingTool.cs @@ -24,6 +24,7 @@ using DotRecast.Detour; using DotRecast.Detour.Crowd; using DotRecast.Recast.Demo.Builder; using DotRecast.Recast.Demo.Draw; +using ImGuiNET; using Silk.NET.Windowing; using static DotRecast.Recast.Demo.Draw.DebugDraw; @@ -32,16 +33,16 @@ namespace DotRecast.Recast.Demo.Tools; public class CrowdProfilingTool { private readonly Func agentParamsSupplier; - private readonly int[] expandSimOptions = new[] { 1 }; - private readonly int[] expandCrowdOptions = new[] { 1 }; - private readonly int[] agents = new[] { 1000 }; - private readonly int[] randomSeed = new[] { 270 }; - private readonly int[] numberOfZones = new[] { 4 }; - private readonly float[] zoneRadius = new[] { 20f }; - private readonly float[] percentMobs = new[] { 80f }; - private readonly float[] percentTravellers = new[] { 15f }; - private readonly int[] pathQueueSize = new[] { 32 }; - private readonly int[] maxIterations = new[] { 300 }; + private int expandSimOptions = 1; + private int expandCrowdOptions = 1; + private int agents = 1000; + private int randomSeed = 270; + private int numberOfZones = 4; + private float zoneRadius = 20f; + private float percentMobs = 80f; + private float percentTravellers = 15f; + private int pathQueueSize = 32; + private int maxIterations = 300; private Crowd crowd; private NavMesh navMesh; private CrowdConfig config; @@ -66,11 +67,11 @@ public class CrowdProfilingTool // nk_layout_row_dynamic(ctx, 20, 1); // nk_property_int(ctx, "Number of Zones", 0, numberOfZones, 10, 1, 1); // nk_layout_row_dynamic(ctx, 20, 1); - // nk_property_float(ctx, "Zone Radius", 0, zoneRadius, 100, 1, 1); + ImGui.SliderFloat("Zone Radius", ref zoneRadius, 0, 100, "%.0f"); // nk_layout_row_dynamic(ctx, 20, 1); - // nk_property_float(ctx, "Mobs %", 0, percentMobs, 100, 1, 1); + ImGui.SliderFloat("Mobs %", ref percentMobs, 0, 100, "%.0f"); // nk_layout_row_dynamic(ctx, 20, 1); - // nk_property_float(ctx, "Travellers %", 0, percentTravellers, 100, 1, 1); + ImGui.SliderFloat("Travellers %", ref percentTravellers, 0, 100, "%.0f"); // nk_tree_state_pop(ctx); // } // if (nk_tree_state_push(ctx, 0, "Crowd Options", expandCrowdOptions)) { @@ -159,7 +160,7 @@ public class CrowdProfilingTool { int zone = (int)(rnd.frand() * zones.Count); Result result = navquery.findRandomPointWithinCircle(zones[zone].getRandomRef(), - zones[zone].getRandomPt(), zoneRadius[0], filter, rnd); + zones[zone].getRandomPt(), zoneRadius, filter, rnd); if (result.succeeded()) { pos = result.result.getRandomPt(); @@ -174,9 +175,9 @@ public class CrowdProfilingTool zones.Clear(); QueryFilter filter = new DefaultQueryFilter(); NavMeshQuery navquery = new NavMeshQuery(navMesh); - for (int i = 0; i < numberOfZones[0]; i++) + for (int i = 0; i < numberOfZones; i++) { - float zoneSeparation = zoneRadius[0] * zoneRadius[0] * 16; + float zoneSeparation = zoneRadius * zoneRadius * 16; for (int k = 0; k < 100; k++) { Result result = navquery.findRandomPoint(filter, rnd); @@ -239,8 +240,8 @@ public class CrowdProfilingTool long startTime = Stopwatch.GetTimestamp(); if (crowd != null) { - crowd.config().pathQueueSize = pathQueueSize[0]; - crowd.config().maxFindPathIterations = maxIterations[0]; + crowd.config().pathQueueSize = pathQueueSize; + crowd.config().maxFindPathIterations = maxIterations; crowd.update(dt, null); } @@ -280,7 +281,7 @@ public class CrowdProfilingTool if (nearestPoly.succeeded()) { Result result = navquery.findRandomPointAroundCircle(nearestPoly.result.getNearestRef(), - agentData.home, zoneRadius[0] * 2f, filter, rnd); + agentData.home, zoneRadius * 2f, filter, rnd); if (result.succeeded()) { crowd.requestMoveTarget(ag, result.result.getRandomRef(), result.result.getRandomPt()); @@ -295,7 +296,7 @@ public class CrowdProfilingTool if (nearestPoly.succeeded()) { Result result = navquery.findRandomPointAroundCircle(nearestPoly.result.getNearestRef(), - agentData.home, zoneRadius[0] * 0.2f, filter, rnd); + agentData.home, zoneRadius * 0.2f, filter, rnd); if (result.succeeded()) { crowd.requestMoveTarget(ag, result.result.getRandomRef(), result.result.getRandomPt()); @@ -309,7 +310,7 @@ public class CrowdProfilingTool List potentialTargets = new(); foreach (FindRandomPointResult zone in zones) { - if (DemoMath.vDistSqr(zone.getRandomPt(), ag.npos, 0) > zoneRadius[0] * zoneRadius[0]) + if (DemoMath.vDistSqr(zone.getRandomPt(), ag.npos, 0) > zoneRadius * zoneRadius) { potentialTargets.Add(zone); } diff --git a/src/DotRecast.Recast.Demo/Tools/CrowdTool.cs b/src/DotRecast.Recast.Demo/Tools/CrowdTool.cs index fe9fa87..8b3df37 100644 --- a/src/DotRecast.Recast.Demo/Tools/CrowdTool.cs +++ b/src/DotRecast.Recast.Demo/Tools/CrowdTool.cs @@ -27,6 +27,7 @@ using DotRecast.Detour.Crowd.Tracking; using DotRecast.Recast.Demo.Builder; using DotRecast.Recast.Demo.Draw; using DotRecast.Recast.Demo.Geom; +using ImGuiNET; using static DotRecast.Recast.Demo.Draw.DebugDraw; using static DotRecast.Recast.Demo.Draw.DebugDrawPrimitives; @@ -232,8 +233,8 @@ public class CrowdTool : Tool ap.collisionQueryRange = ap.radius * 12.0f; ap.pathOptimizationRange = ap.radius * 30.0f; ap.updateFlags = getUpdateFlags(); - ap.obstacleAvoidanceType = toolParams.m_obstacleAvoidanceType[0]; - ap.separationWeight = toolParams.m_separationWeight[0]; + ap.obstacleAvoidanceType = toolParams.m_obstacleAvoidanceType; + ap.separationWeight = toolParams.m_separationWeight; return ap; } @@ -729,7 +730,7 @@ public class CrowdTool : Tool // nk_layout_row_dynamic(ctx, 20, 1); // toolParams.m_separation = nk_option_text(ctx, "Separation", toolParams.m_separation); // nk_layout_row_dynamic(ctx, 20, 1); - // nk_property_float(ctx, "Separation Weight", 0f, toolParams.m_separationWeight, 20f, 0.01f, 0.01f); + ImGui.SliderFloat("Separation Weight", ref toolParams.m_separationWeight, 0f, 20f, "%.2f"); // if (m_optimizeVis != toolParams.m_optimizeVis || m_optimizeTopo != toolParams.m_optimizeTopo // || m_anticipateTurns != toolParams.m_anticipateTurns || m_obstacleAvoidance != toolParams.m_obstacleAvoidance // || m_separation != toolParams.m_separation @@ -784,7 +785,7 @@ public class CrowdTool : Tool } int updateFlags = getUpdateFlags(); - profilingTool.updateAgentParams(updateFlags, toolParams.m_obstacleAvoidanceType[0], toolParams.m_separationWeight[0]); + profilingTool.updateAgentParams(updateFlags, toolParams.m_obstacleAvoidanceType, toolParams.m_separationWeight); foreach (CrowdAgent ag in crowd.getActiveAgents()) { CrowdAgentParams option = new CrowdAgentParams(); @@ -798,8 +799,8 @@ public class CrowdTool : Tool option.queryFilterType = ag.option.queryFilterType; option.userData = ag.option.userData; option.updateFlags = updateFlags; - option.obstacleAvoidanceType = toolParams.m_obstacleAvoidanceType[0]; - option.separationWeight = toolParams.m_separationWeight[0]; + option.obstacleAvoidanceType = toolParams.m_obstacleAvoidanceType; + option.separationWeight = toolParams.m_separationWeight; crowd.updateAgentParameters(ag, option); } } diff --git a/src/DotRecast.Recast.Demo/Tools/CrowdToolParams.cs b/src/DotRecast.Recast.Demo/Tools/CrowdToolParams.cs index da12bf3..aa1f029 100644 --- a/src/DotRecast.Recast.Demo/Tools/CrowdToolParams.cs +++ b/src/DotRecast.Recast.Demo/Tools/CrowdToolParams.cs @@ -20,7 +20,7 @@ namespace DotRecast.Recast.Demo.Tools; public class CrowdToolParams { - public readonly int[] m_expandSelectedDebugDraw = new[] { 1 }; + public int m_expandSelectedDebugDraw = 1; public bool m_showCorners; public bool m_showCollisionSegments; public bool m_showPath; @@ -28,19 +28,19 @@ public class CrowdToolParams public bool m_showOpt; public bool m_showNeis; - public readonly int[] m_expandDebugDraw = new[] { 0 }; + public int m_expandDebugDraw = 0; public bool m_showLabels; public bool m_showGrid; public bool m_showNodes; public bool m_showPerfGraph; public bool m_showDetailAll; - public readonly int[] m_expandOptions = new[] { 1 }; + public int m_expandOptions = 1; public bool m_anticipateTurns = true; public bool m_optimizeVis = true; public bool m_optimizeTopo = true; public bool m_obstacleAvoidance = true; - public readonly int[] m_obstacleAvoidanceType = new[] { 3 }; + public int m_obstacleAvoidanceType = 3; public bool m_separation; - public readonly float[] m_separationWeight = new[] { 2f }; + public float m_separationWeight = 2f; } \ No newline at end of file diff --git a/src/DotRecast.Recast.Demo/Tools/DynamicUpdateTool.cs b/src/DotRecast.Recast.Demo/Tools/DynamicUpdateTool.cs index 11e6119..1ce2fa1 100644 --- a/src/DotRecast.Recast.Demo/Tools/DynamicUpdateTool.cs +++ b/src/DotRecast.Recast.Demo/Tools/DynamicUpdateTool.cs @@ -29,6 +29,7 @@ using DotRecast.Recast.Demo.Draw; using DotRecast.Recast.Demo.Geom; using DotRecast.Recast.Demo.Tools.Gizmos; using DotRecast.Recast.Demo.UI; +using ImGuiNET; using Silk.NET.Windowing; using static DotRecast.Recast.Demo.Draw.DebugDraw; using static DotRecast.Recast.Demo.Draw.DebugDrawPrimitives; @@ -59,24 +60,24 @@ public class DynamicUpdateTool : Tool private Sample sample; private ToolMode mode = ToolMode.BUILD; - private readonly float[] cellSize = new[] { 0.3f }; + private float cellSize = 0.3f; private PartitionType partitioning = PartitionType.WATERSHED; private bool filterLowHangingObstacles = true; private bool filterLedgeSpans = true; private bool filterWalkableLowHeightSpans = true; - private readonly float[] walkableHeight = new[] { 2f }; - private readonly float[] walkableRadius = new[] { 0.6f }; - private readonly float[] walkableClimb = new[] { 0.9f }; - private readonly float[] walkableSlopeAngle = new[] { 45f }; - private readonly float[] minRegionArea = new[] { 6f }; - private readonly float[] regionMergeSize = new[] { 36f }; - private readonly float[] maxEdgeLen = new[] { 12f }; - private readonly float[] maxSimplificationError = new[] { 1.3f }; - private readonly int[] vertsPerPoly = new[] { 6 }; + private float walkableHeight = 2f; + private float walkableRadius = 0.6f; + private float walkableClimb = 0.9f; + private float walkableSlopeAngle = 45f; + private float minRegionArea = 6f; + private float regionMergeSize = 36f; + private float maxEdgeLen = 12f; + private float maxSimplificationError = 1.3f; + private int vertsPerPoly = 6; private bool buildDetailMesh = true; private bool compression = true; - private readonly float[] detailSampleDist = new[] { 6f }; - private readonly float[] detailSampleMaxError = new[] { 1f }; + private float detailSampleDist = 6f; + private float detailSampleMaxError = 1f; private bool showColliders = false; private long buildTime; private long raycastTime; @@ -510,20 +511,20 @@ public class DynamicUpdateTool : Tool // nk_layout_row_dynamic(ctx, 1, 1); // nk_spacing(ctx, 1); // nk_layout_row_dynamic(ctx, 18, 1); - // nk_label(ctx, "Rasterization", NK_TEXT_ALIGN_LEFT); + ImGui.Text("Rasterization"); // nk_layout_row_dynamic(ctx, 18, 2); // nk_label(ctx, "Cell Size", NK_TEXT_ALIGN_LEFT); // nk_label(ctx, string.format("%.2f", cellSize[0]), NK_TEXT_ALIGN_RIGHT); // nk_layout_row_dynamic(ctx, 1, 1); // nk_spacing(ctx, 1); // nk_layout_row_dynamic(ctx, 18, 1); - // nk_label(ctx, "Agent", NK_TEXT_ALIGN_LEFT); + ImGui.Text("Agent"); // nk_layout_row_dynamic(ctx, 20, 1); - // nk_property_float(ctx, "Height", 0f, walkableHeight, 5f, 0.01f, 0.01f); + ImGui.SliderFloat("Height", ref walkableHeight, 0f, 5f, "%.2f"); // nk_layout_row_dynamic(ctx, 20, 1); - // nk_property_float(ctx, "Radius", 0f, walkableRadius, 10f, 0.01f, 0.01f); + ImGui.SliderFloat("Radius", ref walkableRadius, 0f, 10f, "%.2f"); // nk_layout_row_dynamic(ctx, 20, 1); - // nk_property_float(ctx, "Max Climb", 0f, walkableClimb, 10f, 0.01f, 0.01f); + ImGui.SliderFloat("Max Climb", ref walkableClimb, 0f, 10f, "%.2f"); // nk_layout_row_dynamic(ctx, 18, 2); // nk_label(ctx, "Max Slope", NK_TEXT_ALIGN_LEFT); // nk_label(ctx, string.format("%.0f", walkableSlopeAngle[0]), NK_TEXT_ALIGN_RIGHT); @@ -531,14 +532,14 @@ public class DynamicUpdateTool : Tool // nk_layout_row_dynamic(ctx, 1, 1); // nk_spacing(ctx, 1); // nk_layout_row_dynamic(ctx, 18, 1); - // nk_label(ctx, "Partitioning", NK_TEXT_ALIGN_LEFT); + ImGui.Text("Partitioning"); // partitioning = NuklearUIHelper.nk_radio(ctx, PartitionType.values(), partitioning, // p => p.name().substring(0, 1) + p.name().substring(1).toLowerCase()); // // nk_layout_row_dynamic(ctx, 1, 1); // nk_spacing(ctx, 1); // nk_layout_row_dynamic(ctx, 18, 1); - // nk_label(ctx, "Filtering", NK_TEXT_ALIGN_LEFT); + ImGui.Text("Filtering"); // nk_layout_row_dynamic(ctx, 18, 1); // filterLowHangingObstacles = nk_option_text(ctx, "Low Hanging Obstacles", filterLowHangingObstacles); // nk_layout_row_dynamic(ctx, 18, 1); @@ -549,20 +550,20 @@ public class DynamicUpdateTool : Tool // nk_layout_row_dynamic(ctx, 1, 1); // nk_spacing(ctx, 1); // nk_layout_row_dynamic(ctx, 18, 1); - // nk_label(ctx, "Region", NK_TEXT_ALIGN_LEFT); + ImGui.Text("Region"); // nk_layout_row_dynamic(ctx, 20, 1); - // nk_property_float(ctx, "Min Region Size", 0, minRegionArea, 150, 0.1f, 0.1f); + ImGui.SliderFloat("Min Region Size", ref minRegionArea, 0, 150, "%.1f"); // nk_layout_row_dynamic(ctx, 20, 1); - // nk_property_float(ctx, "Merged Region Size", 0, regionMergeSize, 400, 0.1f, 0.1f); + ImGui.SliderFloat("Merged Region Size", ref regionMergeSize, 0, 400, "%.1f"); // // nk_layout_row_dynamic(ctx, 1, 1); // nk_spacing(ctx, 1); // nk_layout_row_dynamic(ctx, 18, 1); - // nk_label(ctx, "Polygonization", NK_TEXT_ALIGN_LEFT); + ImGui.Text("Polygonization"); // nk_layout_row_dynamic(ctx, 20, 1); - // nk_property_float(ctx, "Max Edge Length", 0f, maxEdgeLen, 50f, 0.1f, 0.1f); + ImGui.SliderFloat("Max Edge Length", ref maxEdgeLen, 0f, 50f, "%.1f"); // nk_layout_row_dynamic(ctx, 20, 1); - // nk_property_float(ctx, "Max Edge Error", 0.1f, maxSimplificationError, 10f, 0.1f, 0.1f); + ImGui.SliderFloat("Max Edge Error", ref maxSimplificationError, 0.1f, 10f, "%.1f"); // nk_layout_row_dynamic(ctx, 20, 1); // nk_property_int(ctx, "Verts Per Poly", 3, vertsPerPoly, 12, 1, 1); // @@ -573,9 +574,9 @@ public class DynamicUpdateTool : Tool // nk_layout_row_dynamic(ctx, 20, 1); // buildDetailMesh = nk_check_text(ctx, "Enable", buildDetailMesh); // nk_layout_row_dynamic(ctx, 20, 1); - // nk_property_float(ctx, "Sample Distance", 0f, detailSampleDist, 16f, 0.1f, 0.1f); + ImGui.SliderFloat("Sample Distance", ref detailSampleDist, 0f, 16f, "%.1f"); // nk_layout_row_dynamic(ctx, 20, 1); - // nk_property_float(ctx, "Max Sample Error", 0f, detailSampleMaxError, 16f, 0.1f, 0.1f); + ImGui.SliderFloat("Max Sample Error", ref detailSampleMaxError, 0f, 16f, "%.1f"); // nk_layout_row_dynamic(ctx, 1, 1); // nk_spacing(ctx, 1); // nk_layout_row_dynamic(ctx, 20, 1); @@ -590,7 +591,7 @@ public class DynamicUpdateTool : Tool // nk_layout_row_dynamic(ctx, 1, 1); // nk_spacing(ctx, 1); // nk_layout_row_dynamic(ctx, 18, 1); - // nk_label(ctx, "Colliders", NK_TEXT_ALIGN_LEFT); + ImGui.Text("Colliders"); // nk_layout_row_dynamic(ctx, 20, 1); // showColliders = nk_check_text(ctx, "Show", showColliders); // nk_layout_row_dynamic(ctx, 20, 1); @@ -726,39 +727,39 @@ public class DynamicUpdateTool : Tool private void configDynaMesh() { dynaMesh.config.partitionType = partitioning; - dynaMesh.config.walkableHeight = walkableHeight[0]; - dynaMesh.config.walkableSlopeAngle = walkableSlopeAngle[0]; - dynaMesh.config.walkableRadius = walkableRadius[0]; - dynaMesh.config.walkableClimb = walkableClimb[0]; + dynaMesh.config.walkableHeight = walkableHeight; + dynaMesh.config.walkableSlopeAngle = walkableSlopeAngle; + dynaMesh.config.walkableRadius = walkableRadius; + dynaMesh.config.walkableClimb = walkableClimb; dynaMesh.config.filterLowHangingObstacles = filterLowHangingObstacles; dynaMesh.config.filterLedgeSpans = filterLedgeSpans; dynaMesh.config.filterWalkableLowHeightSpans = filterWalkableLowHeightSpans; - dynaMesh.config.minRegionArea = minRegionArea[0]; - dynaMesh.config.regionMergeArea = regionMergeSize[0]; - dynaMesh.config.maxEdgeLen = maxEdgeLen[0]; - dynaMesh.config.maxSimplificationError = maxSimplificationError[0]; - dynaMesh.config.vertsPerPoly = vertsPerPoly[0]; + dynaMesh.config.minRegionArea = minRegionArea; + dynaMesh.config.regionMergeArea = regionMergeSize; + dynaMesh.config.maxEdgeLen = maxEdgeLen; + dynaMesh.config.maxSimplificationError = maxSimplificationError; + dynaMesh.config.vertsPerPoly = vertsPerPoly; dynaMesh.config.buildDetailMesh = buildDetailMesh; - dynaMesh.config.detailSampleDistance = detailSampleDist[0]; - dynaMesh.config.detailSampleMaxError = detailSampleMaxError[0]; + dynaMesh.config.detailSampleDistance = detailSampleDist; + dynaMesh.config.detailSampleMaxError = detailSampleMaxError; } private void updateUI() { - cellSize[0] = dynaMesh.config.cellSize; + cellSize = dynaMesh.config.cellSize; partitioning = dynaMesh.config.partitionType; - walkableHeight[0] = dynaMesh.config.walkableHeight; - walkableSlopeAngle[0] = dynaMesh.config.walkableSlopeAngle; - walkableRadius[0] = dynaMesh.config.walkableRadius; - walkableClimb[0] = dynaMesh.config.walkableClimb; - minRegionArea[0] = dynaMesh.config.minRegionArea; - regionMergeSize[0] = dynaMesh.config.regionMergeArea; - maxEdgeLen[0] = dynaMesh.config.maxEdgeLen; - maxSimplificationError[0] = dynaMesh.config.maxSimplificationError; - vertsPerPoly[0] = dynaMesh.config.vertsPerPoly; + walkableHeight = dynaMesh.config.walkableHeight; + walkableSlopeAngle = dynaMesh.config.walkableSlopeAngle; + walkableRadius = dynaMesh.config.walkableRadius; + walkableClimb = dynaMesh.config.walkableClimb; + minRegionArea = dynaMesh.config.minRegionArea; + regionMergeSize = dynaMesh.config.regionMergeArea; + maxEdgeLen = dynaMesh.config.maxEdgeLen; + maxSimplificationError = dynaMesh.config.maxSimplificationError; + vertsPerPoly = dynaMesh.config.vertsPerPoly; buildDetailMesh = dynaMesh.config.buildDetailMesh; - detailSampleDist[0] = dynaMesh.config.detailSampleDistance; - detailSampleMaxError[0] = dynaMesh.config.detailSampleMaxError; + detailSampleDist = dynaMesh.config.detailSampleDistance; + detailSampleMaxError = dynaMesh.config.detailSampleMaxError; filterLowHangingObstacles = dynaMesh.config.filterLowHangingObstacles; filterLedgeSpans = dynaMesh.config.filterLedgeSpans; filterWalkableLowHeightSpans = dynaMesh.config.filterWalkableLowHeightSpans; diff --git a/src/DotRecast.Recast.Demo/Tools/JumpLinkBuilderTool.cs b/src/DotRecast.Recast.Demo/Tools/JumpLinkBuilderTool.cs index c25468d..86055b4 100644 --- a/src/DotRecast.Recast.Demo/Tools/JumpLinkBuilderTool.cs +++ b/src/DotRecast.Recast.Demo/Tools/JumpLinkBuilderTool.cs @@ -22,6 +22,7 @@ using DotRecast.Detour.Extras.Jumplink; using DotRecast.Recast.Demo.Builder; using DotRecast.Recast.Demo.Draw; using DotRecast.Recast.Demo.Geom; +using ImGuiNET; using static DotRecast.Detour.DetourCommon; using static DotRecast.Recast.Demo.Draw.DebugDraw; using static DotRecast.Recast.Demo.Draw.DebugDrawPrimitives; @@ -326,37 +327,37 @@ public class JumpLinkBuilderTool : Tool // if (!sample.getRecastResults().isEmpty()) { // // nk_layout_row_dynamic(ctx, 18, 1); - // nk_label(ctx, "Options", NK_TEXT_ALIGN_LEFT); + ImGui.Text("Options"); // nk_layout_row_dynamic(ctx, 20, 1); - // nk_property_float(ctx, "Ground Tolerance", 0f, option.groundTolerance, 2f, 0.05f, 0.01f); + ImGui.SliderFloat("Ground Tolerance", ref option.groundTolerance, 0f, 2f, "%.2f"); // nk_layout_row_dynamic(ctx, 5, 1); // nk_spacing(ctx, 1); // // nk_layout_row_dynamic(ctx, 18, 1); // nk_label(ctx, "Climb Down", NK_TEXT_ALIGN_LEFT); // nk_layout_row_dynamic(ctx, 20, 1); - // nk_property_float(ctx, "Distance", 0f, option.climbDownDistance, 5f, 0.05f, 0.01f); + ImGui.SliderFloat("Distance", ref option.climbDownDistance, 0f, 5f, "%.2f"); // nk_layout_row_dynamic(ctx, 20, 1); - // nk_property_float(ctx, "Min Cliff Height", 0f, option.climbDownMinHeight, 10f, 0.05f, 0.01f); + ImGui.SliderFloat("Min Cliff Height", ref option.climbDownMinHeight, 0f, 10f, "%.2f"); // nk_layout_row_dynamic(ctx, 20, 1); - // nk_property_float(ctx, "Max Cliff Height", 0f, option.climbDownMaxHeight, 10f, 0.05f, 0.01f); + ImGui.SliderFloat("Max Cliff Height", ref option.climbDownMaxHeight, 0f, 10f, "%.2f"); // nk_layout_row_dynamic(ctx, 5, 1); // nk_spacing(ctx, 1); // // nk_layout_row_dynamic(ctx, 18, 1); // nk_label(ctx, "Jump Down", NK_TEXT_ALIGN_LEFT); // nk_layout_row_dynamic(ctx, 20, 1); - // nk_property_float(ctx, "Max Distance", 0f, option.edgeJumpEndDistance, 10f, 0.05f, 0.01f); + ImGui.SliderFloat("Max Distance", ref option.edgeJumpEndDistance, 0f, 10f, "%.2f"); // nk_layout_row_dynamic(ctx, 20, 1); - // nk_property_float(ctx, "Jump Height", 0f, option.edgeJumpHeight, 10f, 0.05f, 0.01f); + ImGui.SliderFloat("Jump Height", ref option.edgeJumpHeight, 0f, 10f, "%.2f"); // nk_layout_row_dynamic(ctx, 20, 1); - // nk_property_float(ctx, "Max Jump Down", 0f, option.edgeJumpDownMaxHeight, 10f, 0.05f, 0.01f); + ImGui.SliderFloat("Max Jump Down", ref option.edgeJumpDownMaxHeight, 0f, 10f, "%.2f"); // nk_layout_row_dynamic(ctx, 20, 1); - // nk_property_float(ctx, "Max Jump Up", 0f, option.edgeJumpUpMaxHeight, 10f, 0.05f, 0.01f); + ImGui.SliderFloat("Max Jump Up", ref option.edgeJumpUpMaxHeight, 0f, 10f, "%.2f"); // nk_layout_row_dynamic(ctx, 5, 1); // nk_spacing(ctx, 1); // nk_layout_row_dynamic(ctx, 18, 1); - // nk_label(ctx, "Mode", NK_TEXT_ALIGN_LEFT); + ImGui.Text("Mode"); // nk_layout_row_dynamic(ctx, 20, 1); // int buildTypes = 0; // buildTypes |= nk_option_text(ctx, "Climb Down", diff --git a/src/DotRecast.Recast.Demo/Tools/JumpLinkBuilderToolParams.cs b/src/DotRecast.Recast.Demo/Tools/JumpLinkBuilderToolParams.cs index 26dcebc..b00d9fe 100644 --- a/src/DotRecast.Recast.Demo/Tools/JumpLinkBuilderToolParams.cs +++ b/src/DotRecast.Recast.Demo/Tools/JumpLinkBuilderToolParams.cs @@ -31,13 +31,13 @@ public class JumpLinkBuilderToolParams public const int DRAW_ANNOTATIONS = 1 << 6; public int flags = DRAW_WALKABLE_SURFACE | DRAW_WALKABLE_BORDER | DRAW_SELECTED_EDGE | DRAW_ANIM_TRAJECTORY | DRAW_LAND_SAMPLES | DRAW_ANNOTATIONS; - public readonly float[] groundTolerance = new[] { 0.3f }; - public readonly float[] climbDownDistance = new[] { 0.4f }; - public readonly float[] climbDownMaxHeight = new[] { 3.2f }; - public readonly float[] climbDownMinHeight = new[] { 1.5f }; - public readonly float[] edgeJumpEndDistance = new[] { 2f }; - public readonly float[] edgeJumpHeight = new[] { 0.4f }; - public readonly float[] edgeJumpDownMaxHeight = new[] { 2.5f }; - public readonly float[] edgeJumpUpMaxHeight = new[] { 0.3f }; + public float groundTolerance = 0.3f; + public float climbDownDistance = 0.4f; + public float climbDownMaxHeight = 3.2f; + public float climbDownMinHeight = 1.5f; + public float edgeJumpEndDistance = 2f; + public float edgeJumpHeight = 0.4f; + public float edgeJumpDownMaxHeight = 2.5f; + public float edgeJumpUpMaxHeight = 0.3f; public int buildTypes = (1 << (int)JumpLinkType.EDGE_CLIMB_DOWN) | (1 << (int)JumpLinkType.EDGE_JUMP); } \ No newline at end of file diff --git a/src/DotRecast.Recast/PartitionType.cs b/src/DotRecast.Recast/PartitionType.cs index 202d345..9874a84 100644 --- a/src/DotRecast.Recast/PartitionType.cs +++ b/src/DotRecast.Recast/PartitionType.cs @@ -1,11 +1,26 @@ -namespace DotRecast.Recast +using System.Collections.Immutable; + +namespace DotRecast.Recast { /// < Tessellate edges between areas during contour /// simplification. - public enum PartitionType + public class PartitionType { - WATERSHED, - MONOTONE, - LAYERS + public static readonly PartitionType WATERSHED = new PartitionType(0, nameof(WATERSHED)); + public static readonly PartitionType MONOTONE = new PartitionType(1, nameof(MONOTONE)); + public static readonly PartitionType LAYERS = new PartitionType(2, nameof(LAYERS)); + + public static readonly ImmutableArray Values = ImmutableArray.Create(WATERSHED, MONOTONE, LAYERS); + + public int Idx { get; } + public string Name { get; } + + private PartitionType(int idx, string name) + { + Idx = idx; + Name = name; + } + + public override string ToString() => Name; } } \ No newline at end of file diff --git a/test/DotRecast.Recast.Test/RecastLayersTest.cs b/test/DotRecast.Recast.Test/RecastLayersTest.cs index 1f4cc4f..565d00b 100644 --- a/test/DotRecast.Recast.Test/RecastLayersTest.cs +++ b/test/DotRecast.Recast.Test/RecastLayersTest.cs @@ -43,7 +43,7 @@ public class RecastLayersTest private const int m_vertsPerPoly = 6; private const float m_detailSampleDist = 6.0f; private const float m_detailSampleMaxError = 1.0f; - private const PartitionType m_partitionType = PartitionType.WATERSHED; + private readonly PartitionType m_partitionType = PartitionType.WATERSHED; private const int m_tileSize = 48; [Test] diff --git a/test/DotRecast.Recast.Test/RecastTileMeshTest.cs b/test/DotRecast.Recast.Test/RecastTileMeshTest.cs index 99abb73..970ef66 100644 --- a/test/DotRecast.Recast.Test/RecastTileMeshTest.cs +++ b/test/DotRecast.Recast.Test/RecastTileMeshTest.cs @@ -48,7 +48,7 @@ public class RecastTileMeshTest private const int m_vertsPerPoly = 6; private const float m_detailSampleDist = 6.0f; private const float m_detailSampleMaxError = 1.0f; - private const PartitionType m_partitionType = PartitionType.WATERSHED; + private PartitionType m_partitionType = PartitionType.WATERSHED; private const int m_tileSize = 32; [Test]