completed test navmesh tool

This commit is contained in:
ikpil 2023-03-26 12:01:05 +09:00
parent a64d731ee4
commit bf76188248
3 changed files with 95 additions and 103 deletions

View File

@ -1,6 +1,5 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using Silk.NET.Windowing;
using DotRecast.Core; using DotRecast.Core;
using DotRecast.Detour; using DotRecast.Detour;
using DotRecast.Recast.Demo.Builder; using DotRecast.Recast.Demo.Builder;
@ -19,8 +18,8 @@ public class TestNavmeshTool : Tool
private Sample m_sample; private Sample m_sample;
private int toolModeIdx = -1; private int m_toolModeIdx = TestNavmeshToolMode.PATHFIND_FOLLOW.Idx;
private TestNavmeshToolMode m_toolMode = TestNavmeshToolMode.PATHFIND_FOLLOW; private TestNavmeshToolMode m_toolMode => TestNavmeshToolMode.Values[m_toolModeIdx];
private bool m_sposSet; private bool m_sposSet;
private bool m_eposSet; private bool m_eposSet;
private float[] m_spos; private float[] m_spos;
@ -45,6 +44,8 @@ public class TestNavmeshTool : Tool
private readonly List<float[]> randomPoints = new(); private readonly List<float[]> randomPoints = new();
private bool constrainByCircle; private bool constrainByCircle;
private int includeFlags = SampleAreaModifications.SAMPLE_POLYFLAGS_ALL;
private int excludeFlags = 0;
public TestNavmeshTool() public TestNavmeshTool()
{ {
@ -75,7 +76,7 @@ public class TestNavmeshTool : Tool
public override void layout() public override void layout()
{ {
TestNavmeshToolMode previousToolMode = m_toolMode; var previousToolMode = m_toolMode;
int previousStraightPathOptions = m_straightPathOptions; int previousStraightPathOptions = m_straightPathOptions;
int previousIncludeFlags = m_filter.getIncludeFlags(); int previousIncludeFlags = m_filter.getIncludeFlags();
int previousExcludeFlags = m_filter.getExcludeFlags(); int previousExcludeFlags = m_filter.getExcludeFlags();
@ -83,104 +84,71 @@ public class TestNavmeshTool : Tool
ImGui.Text("Mode"); ImGui.Text("Mode");
ImGui.Separator(); ImGui.Separator();
ImGui.RadioButton("Pathfind Follow", ref toolModeIdx, (int)TestNavmeshToolMode.PATHFIND_FOLLOW); ImGui.RadioButton(TestNavmeshToolMode.PATHFIND_FOLLOW.Label, ref m_toolModeIdx, TestNavmeshToolMode.PATHFIND_FOLLOW.Idx);
ImGui.RadioButton("Pathfind Straight", ref toolModeIdx, (int)TestNavmeshToolMode.PATHFIND_STRAIGHT); ImGui.RadioButton(TestNavmeshToolMode.PATHFIND_STRAIGHT.Label, ref m_toolModeIdx, TestNavmeshToolMode.PATHFIND_STRAIGHT.Idx);
ImGui.RadioButton("Pathfind Sliced", ref toolModeIdx, (int)TestNavmeshToolMode.PATHFIND_SLICED); ImGui.RadioButton(TestNavmeshToolMode.PATHFIND_SLICED.Label, ref m_toolModeIdx, TestNavmeshToolMode.PATHFIND_SLICED.Idx);
ImGui.RadioButton("Distance to Wall", ref toolModeIdx, (int)TestNavmeshToolMode.DISTANCE_TO_WALL); ImGui.RadioButton(TestNavmeshToolMode.DISTANCE_TO_WALL.Label, ref m_toolModeIdx, TestNavmeshToolMode.DISTANCE_TO_WALL.Idx);
ImGui.RadioButton("Raycast", ref toolModeIdx, (int)TestNavmeshToolMode.RAYCAST); ImGui.RadioButton(TestNavmeshToolMode.RAYCAST.Label, ref m_toolModeIdx, TestNavmeshToolMode.RAYCAST.Idx);
ImGui.RadioButton("Find Polys in Circle", ref toolModeIdx, (int)TestNavmeshToolMode.FIND_POLYS_IN_CIRCLE); ImGui.RadioButton(TestNavmeshToolMode.FIND_POLYS_IN_CIRCLE.Label, ref m_toolModeIdx, TestNavmeshToolMode.FIND_POLYS_IN_CIRCLE.Idx);
ImGui.RadioButton("Find Polys in Shape", ref toolModeIdx, (int)TestNavmeshToolMode.FIND_POLYS_IN_SHAPE); ImGui.RadioButton(TestNavmeshToolMode.FIND_POLYS_IN_SHAPE.Label, ref m_toolModeIdx, TestNavmeshToolMode.FIND_POLYS_IN_SHAPE.Idx);
ImGui.RadioButton("Find Local Neighbourhood", ref toolModeIdx, (int)TestNavmeshToolMode.FIND_LOCAL_NEIGHBOURHOOD); ImGui.RadioButton(TestNavmeshToolMode.FIND_LOCAL_NEIGHBOURHOOD.Label, ref m_toolModeIdx, TestNavmeshToolMode.FIND_LOCAL_NEIGHBOURHOOD.Idx);
ImGui.RadioButton("Random Points in Circle", ref toolModeIdx, (int)TestNavmeshToolMode.RANDOM_POINTS_IN_CIRCLE); ImGui.RadioButton(TestNavmeshToolMode.RANDOM_POINTS_IN_CIRCLE.Label, ref m_toolModeIdx, TestNavmeshToolMode.RANDOM_POINTS_IN_CIRCLE.Idx);
ImGui.NewLine(); ImGui.NewLine();
if (toolModeIdx == (int)TestNavmeshToolMode.PATHFIND_FOLLOW) // selecting mode
{ ImGui.Text(m_toolMode.Label);
ImGui.Separator();
ImGui.NewLine();
if (m_toolMode == TestNavmeshToolMode.PATHFIND_FOLLOW)
{
} }
if (toolModeIdx == (int)TestNavmeshToolMode.PATHFIND_STRAIGHT) if (m_toolMode == TestNavmeshToolMode.PATHFIND_STRAIGHT)
{ {
// m_toolMode = TestNavmeshToolMode.PATHFIND_STRAIGHT;
// nk_layout_row_dynamic(ctx, 20, 1);
ImGui.Text("Vertices at crossings"); ImGui.Text("Vertices at crossings");
// nk_layout_row_dynamic(ctx, 20, 1); ImGui.Separator();
// if (nk_option_label(ctx, "None", m_straightPathOptions == 0)) { ImGui.RadioButton("None", ref m_straightPathOptions, 0);
// m_straightPathOptions = 0; ImGui.RadioButton("Area", ref m_straightPathOptions, NavMeshQuery.DT_STRAIGHTPATH_AREA_CROSSINGS);
// } ImGui.RadioButton("All", ref m_straightPathOptions, NavMeshQuery.DT_STRAIGHTPATH_ALL_CROSSINGS);
// nk_layout_row_dynamic(ctx, 20, 1);
// if (nk_option_label(ctx, "Area", m_straightPathOptions == NavMeshQuery.DT_STRAIGHTPATH_AREA_CROSSINGS)) {
// m_straightPathOptions = NavMeshQuery.DT_STRAIGHTPATH_AREA_CROSSINGS;
// }
// nk_layout_row_dynamic(ctx, 20, 1);
// if (nk_option_label(ctx, "All", m_straightPathOptions == NavMeshQuery.DT_STRAIGHTPATH_ALL_CROSSINGS)) {
// m_straightPathOptions = NavMeshQuery.DT_STRAIGHTPATH_ALL_CROSSINGS;
// }
// nk_layout_row_dynamic(ctx, 5, 1);
// nk_spacing(ctx, 1);
} }
if (toolModeIdx == (int)TestNavmeshToolMode.RANDOM_POINTS_IN_CIRCLE) if (m_toolMode == TestNavmeshToolMode.RANDOM_POINTS_IN_CIRCLE)
{ {
// constrainByCircle = nk_check_text(ctx, "Constrained", constrainByCircle); ImGui.Checkbox("Constrained", ref constrainByCircle);
} }
// nk_layout_row_dynamic(ctx, 5, 1);
// nk_spacing(ctx, 1); ImGui.Text("Common");
// nk_layout_row_dynamic(ctx, 20, 1); ImGui.Separator();
ImGui.Text("Include Flags"); ImGui.Text("Include Flags");
// nk_layout_row_dynamic(ctx, 20, 1); ImGui.Separator();
// int includeFlags = 0; ImGui.CheckboxFlags("Walk", ref includeFlags, SampleAreaModifications.SAMPLE_POLYFLAGS_WALK);
// if (nk_option_label(ctx, "Walk", ImGui.CheckboxFlags("Swim", ref includeFlags, SampleAreaModifications.SAMPLE_POLYFLAGS_SWIM);
// (m_filter.getIncludeFlags() & SampleAreaModifications.SAMPLE_POLYFLAGS_WALK) != 0)) { ImGui.CheckboxFlags("Door", ref includeFlags, SampleAreaModifications.SAMPLE_POLYFLAGS_DOOR);
// includeFlags |= SampleAreaModifications.SAMPLE_POLYFLAGS_WALK; ImGui.CheckboxFlags("Jump", ref includeFlags, SampleAreaModifications.SAMPLE_POLYFLAGS_JUMP);
// } ImGui.NewLine();
// if (nk_option_label(ctx, "Swim",
// (m_filter.getIncludeFlags() & SampleAreaModifications.SAMPLE_POLYFLAGS_SWIM) != 0)) { m_filter.setIncludeFlags(includeFlags);
// includeFlags |= SampleAreaModifications.SAMPLE_POLYFLAGS_SWIM;
// }
// if (nk_option_label(ctx, "Door",
// (m_filter.getIncludeFlags() & SampleAreaModifications.SAMPLE_POLYFLAGS_DOOR) != 0)) {
// includeFlags |= SampleAreaModifications.SAMPLE_POLYFLAGS_DOOR;
// }
// if (nk_option_label(ctx, "Jump",
// (m_filter.getIncludeFlags() & SampleAreaModifications.SAMPLE_POLYFLAGS_JUMP) != 0)) {
// includeFlags |= SampleAreaModifications.SAMPLE_POLYFLAGS_JUMP;
// }
// m_filter.setIncludeFlags(includeFlags);
//
// nk_layout_row_dynamic(ctx, 5, 1);
// nk_spacing(ctx, 1);
// nk_layout_row_dynamic(ctx, 20, 1);
ImGui.Text("Exclude Flags"); ImGui.Text("Exclude Flags");
// nk_layout_row_dynamic(ctx, 20, 1); ImGui.Separator();
// int excludeFlags = 0; ImGui.CheckboxFlags("Walk", ref excludeFlags, SampleAreaModifications.SAMPLE_POLYFLAGS_WALK);
// if (nk_option_label(ctx, "Walk", ImGui.CheckboxFlags("Swim", ref excludeFlags, SampleAreaModifications.SAMPLE_POLYFLAGS_SWIM);
// (m_filter.getExcludeFlags() & SampleAreaModifications.SAMPLE_POLYFLAGS_WALK) != 0)) { ImGui.CheckboxFlags("Door", ref excludeFlags, SampleAreaModifications.SAMPLE_POLYFLAGS_DOOR);
// excludeFlags |= SampleAreaModifications.SAMPLE_POLYFLAGS_WALK; ImGui.CheckboxFlags("Jump", ref excludeFlags, SampleAreaModifications.SAMPLE_POLYFLAGS_JUMP);
// } ImGui.NewLine();
// if (nk_option_label(ctx, "Swim",
// (m_filter.getExcludeFlags() & SampleAreaModifications.SAMPLE_POLYFLAGS_SWIM) != 0)) { m_filter.setExcludeFlags(excludeFlags);
// excludeFlags |= SampleAreaModifications.SAMPLE_POLYFLAGS_SWIM;
// } bool previousEnableRaycast = enableRaycast;
// if (nk_option_label(ctx, "Door", ImGui.Checkbox("Raycast shortcuts", ref enableRaycast);
// (m_filter.getExcludeFlags() & SampleAreaModifications.SAMPLE_POLYFLAGS_DOOR) != 0)) {
// excludeFlags |= SampleAreaModifications.SAMPLE_POLYFLAGS_DOOR; if (previousToolMode != m_toolMode || m_straightPathOptions != previousStraightPathOptions
// } || previousIncludeFlags != includeFlags || previousExcludeFlags != excludeFlags
// if (nk_option_label(ctx, "Jump", || previousEnableRaycast != enableRaycast || previousConstrainByCircle != constrainByCircle) {
// (m_filter.getExcludeFlags() & SampleAreaModifications.SAMPLE_POLYFLAGS_JUMP) != 0)) { recalc();
// excludeFlags |= SampleAreaModifications.SAMPLE_POLYFLAGS_JUMP; }
// }
// m_filter.setExcludeFlags(excludeFlags);
//
// nk_layout_row_dynamic(ctx, 30, 1);
// bool previousEnableRaycast = enableRaycast;
// enableRaycast = nk_check_label(ctx, "Raycast shortcuts", enableRaycast);
//
// if (previousToolMode != m_toolMode || m_straightPathOptions != previousStraightPathOptions
// || previousIncludeFlags != includeFlags || previousExcludeFlags != excludeFlags
// || previousEnableRaycast != enableRaycast || previousConstrainByCircle != constrainByCircle) {
// recalc();
// }
} }
public override string getName() public override string getName()

View File

@ -1,7 +1,20 @@
namespace DotRecast.Recast.Demo.Tools; using System.Collections.Immutable;
public enum TestNavmeshToolMode namespace DotRecast.Recast.Demo.Tools;
public class TestNavmeshToolMode
{ {
public static readonly TestNavmeshToolMode PATHFIND_FOLLOW = new(0, "Pathfind Follow");
public static readonly TestNavmeshToolMode PATHFIND_STRAIGHT = new(1, "Pathfind Straight");
public static readonly TestNavmeshToolMode PATHFIND_SLICED = new(2, "Pathfind Sliced");
public static readonly TestNavmeshToolMode DISTANCE_TO_WALL = new(3, "Distance to Wall");
public static readonly TestNavmeshToolMode RAYCAST = new(4, "Raycast");
public static readonly TestNavmeshToolMode FIND_POLYS_IN_CIRCLE = new(5, "Find Polys in Circle");
public static readonly TestNavmeshToolMode FIND_POLYS_IN_SHAPE = new(6, "Find Polys in Shape");
public static readonly TestNavmeshToolMode FIND_LOCAL_NEIGHBOURHOOD = new(7, "Find Local Neighbourhood");
public static readonly TestNavmeshToolMode RANDOM_POINTS_IN_CIRCLE = new(8, "Random Points in Circle");
public static readonly ImmutableArray<TestNavmeshToolMode> Values = ImmutableArray.Create(
PATHFIND_FOLLOW, PATHFIND_FOLLOW,
PATHFIND_STRAIGHT, PATHFIND_STRAIGHT,
PATHFIND_SLICED, PATHFIND_SLICED,
@ -11,4 +24,15 @@ public enum TestNavmeshToolMode
FIND_POLYS_IN_SHAPE, FIND_POLYS_IN_SHAPE,
FIND_LOCAL_NEIGHBOURHOOD, FIND_LOCAL_NEIGHBOURHOOD,
RANDOM_POINTS_IN_CIRCLE RANDOM_POINTS_IN_CIRCLE
);
public int Idx { get; }
public string Label { get; }
private TestNavmeshToolMode(int idx, string label)
{
Idx = idx;
Label = label;
}
} }

View File

@ -27,7 +27,7 @@ namespace DotRecast.Recast.Demo.Tools;
public class ToolsView : IRcView public class ToolsView : IRcView
{ {
//private readonly NkColor white = NkColor.create(); //private readonly NkColor white = NkColor.create();
private int _currentToolIdx = -1; private int _currentToolIdx = 0;
private Tool currentTool; private Tool currentTool;
private bool enabled; private bool enabled;
private readonly Tool[] tools; private readonly Tool[] tools;