completed DynamicUpdateTool View

This commit is contained in:
ikpil 2023-03-26 14:52:12 +09:00
parent cd4ea6d622
commit 57eaea29a1
2 changed files with 190 additions and 194 deletions

View File

@ -41,7 +41,7 @@ public class RcSettingsView : IRcView
private int minRegionSize = 8; private int minRegionSize = 8;
private int mergedRegionSize = 20; private int mergedRegionSize = 20;
private int _partitioning = 0; private int partitioningIdx = 0;
private PartitionType partitioning = PartitionType.WATERSHED; private PartitionType partitioning = PartitionType.WATERSHED;
private bool filterLowHangingObstacles = true; private bool filterLowHangingObstacles = true;
@ -139,7 +139,7 @@ public class RcSettingsView : IRcView
{ {
var label = partition.Name.Substring(0, 1).ToUpper() var label = partition.Name.Substring(0, 1).ToUpper()
+ partition.Name.Substring(1).ToLower(); + partition.Name.Substring(1).ToLower();
ImGui.RadioButton(label, ref _partitioning, partition.Idx); ImGui.RadioButton(label, ref partitioningIdx, partition.Idx);
}); });
ImGui.NewLine(); ImGui.NewLine();

View File

@ -17,8 +17,11 @@ freely, subject to the following restrictions:
*/ */
using System; using System;
using System.Collections;
using System.Collections.Generic; using System.Collections.Generic;
using System.Collections.Immutable;
using System.Diagnostics; using System.Diagnostics;
using System.Runtime.Serialization;
using System.Threading.Tasks; using System.Threading.Tasks;
using DotRecast.Core; using DotRecast.Core;
using DotRecast.Detour.Dynamic; using DotRecast.Detour.Dynamic;
@ -30,6 +33,7 @@ using DotRecast.Recast.Demo.Geom;
using DotRecast.Recast.Demo.Tools.Gizmos; using DotRecast.Recast.Demo.Tools.Gizmos;
using DotRecast.Recast.Demo.UI; using DotRecast.Recast.Demo.UI;
using ImGuiNET; using ImGuiNET;
using Silk.NET.OpenAL;
using Silk.NET.Windowing; using Silk.NET.Windowing;
using static DotRecast.Recast.Demo.Draw.DebugDraw; using static DotRecast.Recast.Demo.Draw.DebugDraw;
using static DotRecast.Recast.Demo.Draw.DebugDrawPrimitives; using static DotRecast.Recast.Demo.Draw.DebugDrawPrimitives;
@ -37,30 +41,46 @@ using static DotRecast.Core.RecastMath;
namespace DotRecast.Recast.Demo.Tools; namespace DotRecast.Recast.Demo.Tools;
public class DynamicUpdateToolMode
{
public static readonly DynamicUpdateToolMode BUILD = new(0, "Build");
public static readonly DynamicUpdateToolMode COLLIDERS = new(1, "Colliders");
public static readonly DynamicUpdateToolMode RAYCAST = new(2, "Raycast");
public static readonly ImmutableArray<DynamicUpdateToolMode> Values = ImmutableArray.Create(
BUILD, COLLIDERS, RAYCAST
);
public int Idx { get; }
public string Label { get; }
private DynamicUpdateToolMode(int idx, string label)
{
Idx = idx;
Label = label;
}
}
public enum ColliderShape
{
SPHERE,
CAPSULE,
BOX,
CYLINDER,
COMPOSITE,
CONVEX,
TRIMESH_BRIDGE,
TRIMESH_HOUSE
}
public class DynamicUpdateTool : Tool public class DynamicUpdateTool : Tool
{ {
private enum ToolMode
{
BUILD,
COLLIDERS,
RAYCAST
}
private enum ColliderShape
{
SPHERE,
CAPSULE,
BOX,
CYLINDER,
COMPOSITE,
CONVEX,
TRIMESH_BRIDGE,
TRIMESH_HOUSE
}
private Sample sample; private Sample sample;
private ToolMode mode = ToolMode.BUILD; private int toolModeIdx = DynamicUpdateToolMode.BUILD.Idx;
private DynamicUpdateToolMode mode = DynamicUpdateToolMode.BUILD;
private float cellSize = 0.3f; private float cellSize = 0.3f;
private int partitioningIdx = PartitionType.WATERSHED.Idx;
private PartitionType partitioning = PartitionType.WATERSHED; private PartitionType partitioning = PartitionType.WATERSHED;
private bool filterLowHangingObstacles = true; private bool filterLowHangingObstacles = true;
private bool filterLedgeSpans = true; private bool filterLedgeSpans = true;
@ -81,6 +101,8 @@ public class DynamicUpdateTool : Tool
private bool showColliders = false; private bool showColliders = false;
private long buildTime; private long buildTime;
private long raycastTime; private long raycastTime;
private int colliderShapeIdx = (int)ColliderShape.SPHERE;
private ColliderShape colliderShape = ColliderShape.SPHERE; private ColliderShape colliderShape = ColliderShape.SPHERE;
private DynamicNavMesh dynaMesh; private DynamicNavMesh dynaMesh;
@ -113,7 +135,7 @@ public class DynamicUpdateTool : Tool
public override void handleClick(float[] s, float[] p, bool shift) public override void handleClick(float[] s, float[] p, bool shift)
{ {
if (mode == ToolMode.COLLIDERS) if (mode == DynamicUpdateToolMode.COLLIDERS)
{ {
if (!shift) if (!shift)
{ {
@ -163,7 +185,7 @@ public class DynamicUpdateTool : Tool
} }
} }
if (mode == ToolMode.RAYCAST) if (mode == DynamicUpdateToolMode.RAYCAST)
{ {
if (shift) if (shift)
{ {
@ -346,7 +368,7 @@ public class DynamicUpdateTool : Tool
public override void handleClickRay(float[] start, float[] dir, bool shift) public override void handleClickRay(float[] start, float[] dir, bool shift)
{ {
if (mode == ToolMode.COLLIDERS) if (mode == DynamicUpdateToolMode.COLLIDERS)
{ {
if (shift) if (shift)
{ {
@ -394,7 +416,7 @@ public class DynamicUpdateTool : Tool
public override void handleRender(NavMeshRenderer renderer) public override void handleRender(NavMeshRenderer renderer)
{ {
if (mode == ToolMode.COLLIDERS) if (mode == DynamicUpdateToolMode.COLLIDERS)
{ {
if (showColliders) if (showColliders)
{ {
@ -402,7 +424,7 @@ public class DynamicUpdateTool : Tool
} }
} }
if (mode == ToolMode.RAYCAST) if (mode == DynamicUpdateToolMode.RAYCAST)
{ {
RecastDebugDraw dd = renderer.getDebugDraw(); RecastDebugDraw dd = renderer.getDebugDraw();
int startCol = duRGBA(128, 25, 0, 192); int startCol = duRGBA(128, 25, 0, 192);
@ -481,173 +503,147 @@ public class DynamicUpdateTool : Tool
public override void layout() public override void layout()
{ {
// nk_layout_row_dynamic(ctx, 18, 1); ImGui.Text($"Dynamic Update Tool Modes");
// if (nk_option_label(ctx, "Build", mode == ToolMode.BUILD)) { ImGui.Separator();
// mode = ToolMode.BUILD;
// } var prevMode = mode;
// nk_layout_row_dynamic(ctx, 18, 1); ImGui.RadioButton(DynamicUpdateToolMode.BUILD.Label, ref toolModeIdx, DynamicUpdateToolMode.BUILD.Idx);
// if (nk_option_label(ctx, "Colliders", mode == ToolMode.COLLIDERS)) { ImGui.RadioButton(DynamicUpdateToolMode.COLLIDERS.Label, ref toolModeIdx, DynamicUpdateToolMode.COLLIDERS.Idx);
// mode = ToolMode.COLLIDERS; ImGui.RadioButton(DynamicUpdateToolMode.RAYCAST.Label, ref toolModeIdx, DynamicUpdateToolMode.RAYCAST.Idx);
// } ImGui.NewLine();
// nk_layout_row_dynamic(ctx, 18, 1);
// if (nk_option_label(ctx, "Raycast", mode == ToolMode.RAYCAST)) { if (prevMode.Idx != toolModeIdx)
// mode = ToolMode.RAYCAST; {
// } mode = DynamicUpdateToolMode.Values[toolModeIdx];
// }
// nk_layout_row_dynamic(ctx, 1, 1);
// nk_spacing(ctx, 1); ImGui.Text($"Selected mode - {mode.Label}");
// if (mode == ToolMode.BUILD) { ImGui.Separator();
// nk_layout_row_dynamic(ctx, 18, 1);
// if (nk_button_text(ctx, "Load Voxels...")) { if (mode == DynamicUpdateToolMode.BUILD)
// load(); {
// } if (ImGui.Button("Load Voxels..."))
// if (dynaMesh != null) { {
// nk_layout_row_dynamic(ctx, 18, 1); load();
// compression = nk_check_text(ctx, "Compression", compression); }
// if (nk_button_text(ctx, "Save Voxels...")) {
// save(); if (dynaMesh != null)
// } {
// } ImGui.Checkbox("Compression", ref compression);
// nk_layout_row_dynamic(ctx, 1, 1); if (ImGui.Button("Save Voxels..."))
// nk_spacing(ctx, 1); {
// nk_layout_row_dynamic(ctx, 18, 1); save();
ImGui.Text("Rasterization"); }
// nk_layout_row_dynamic(ctx, 18, 2); }
ImGui.Text("Cell Size");
// nk_label(ctx, string.format("%.2f", cellSize[0]), NK_TEXT_ALIGN_RIGHT); ImGui.NewLine();
// nk_layout_row_dynamic(ctx, 1, 1);
// nk_spacing(ctx, 1); ImGui.Text("Rasterization");
// nk_layout_row_dynamic(ctx, 18, 1); ImGui.Separator();
ImGui.Text("Agent"); ImGui.Text($"Cell Size - {cellSize}");
// nk_layout_row_dynamic(ctx, 20, 1); ImGui.NewLine();
ImGui.SliderFloat("Height", ref walkableHeight, 0f, 5f, "%.2f");
// nk_layout_row_dynamic(ctx, 20, 1); ImGui.Text("Agent");
ImGui.SliderFloat("Radius", ref walkableRadius, 0f, 10f, "%.2f"); ImGui.Separator();
// nk_layout_row_dynamic(ctx, 20, 1); ImGui.SliderFloat("Height", ref walkableHeight, 0f, 5f, "%.2f");
ImGui.SliderFloat("Max Climb", ref walkableClimb, 0f, 10f, "%.2f"); ImGui.SliderFloat("Radius", ref walkableRadius, 0f, 10f, "%.2f");
// nk_layout_row_dynamic(ctx, 18, 2); ImGui.SliderFloat("Max Climb", ref walkableClimb, 0f, 10f, "%.2f");
ImGui.Text("Max Slope"); ImGui.Text($"Max Slope : {walkableSlopeAngle}");
// nk_label(ctx, string.format("%.0f", walkableSlopeAngle[0]), NK_TEXT_ALIGN_RIGHT); ImGui.NewLine();
//
// nk_layout_row_dynamic(ctx, 1, 1); ImGui.Text("Partitioning");
// nk_spacing(ctx, 1); ImGui.Separator();
// nk_layout_row_dynamic(ctx, 18, 1); PartitionType.Values.forEach(partition =>
ImGui.Text("Partitioning"); {
// partitioning = NuklearUIHelper.nk_radio(ctx, PartitionType.values(), partitioning, var label = partition.Name.Substring(0, 1).ToUpper()
// p => p.name().substring(0, 1) + p.name().substring(1).toLowerCase()); + partition.Name.Substring(1).ToLower();
// ImGui.RadioButton(label, ref partitioningIdx, partition.Idx);
// nk_layout_row_dynamic(ctx, 1, 1); });
// nk_spacing(ctx, 1); ImGui.NewLine();
// nk_layout_row_dynamic(ctx, 18, 1);
ImGui.Text("Filtering"); ImGui.Text("Filtering");
// nk_layout_row_dynamic(ctx, 18, 1); ImGui.Separator();
// filterLowHangingObstacles = nk_option_text(ctx, "Low Hanging Obstacles", filterLowHangingObstacles); ImGui.Checkbox("Low Hanging Obstacles", ref filterLowHangingObstacles);
// nk_layout_row_dynamic(ctx, 18, 1); ImGui.Checkbox("Ledge Spans", ref filterLedgeSpans);
// filterLedgeSpans = nk_option_text(ctx, "Ledge Spans", filterLedgeSpans); ImGui.Checkbox("Walkable Low Height Spans", ref filterWalkableLowHeightSpans);
// nk_layout_row_dynamic(ctx, 18, 1); ImGui.NewLine();
// filterWalkableLowHeightSpans = nk_option_text(ctx, "Walkable Low Height Spans", filterWalkableLowHeightSpans);
// ImGui.Text("Region");
// nk_layout_row_dynamic(ctx, 1, 1); ImGui.Separator();
// nk_spacing(ctx, 1); ImGui.SliderFloat("Min Region Size", ref minRegionArea, 0, 150, "%.1f");
// nk_layout_row_dynamic(ctx, 18, 1); ImGui.SliderFloat("Merged Region Size", ref regionMergeSize, 0, 400, "%.1f");
ImGui.Text("Region"); ImGui.NewLine();
// nk_layout_row_dynamic(ctx, 20, 1);
ImGui.SliderFloat("Min Region Size", ref minRegionArea, 0, 150, "%.1f"); ImGui.Text("Polygonization");
// nk_layout_row_dynamic(ctx, 20, 1); ImGui.Separator();
ImGui.SliderFloat("Merged Region Size", ref regionMergeSize, 0, 400, "%.1f"); ImGui.SliderFloat("Max Edge Length", ref maxEdgeLen, 0f, 50f, "%.1f");
// ImGui.SliderFloat("Max Edge Error", ref maxSimplificationError, 0.1f, 10f, "%.1f");
// nk_layout_row_dynamic(ctx, 1, 1); ImGui.SliderInt("Verts Per Poly", ref vertsPerPoly, 3, 12);
// nk_spacing(ctx, 1); ImGui.NewLine();
// nk_layout_row_dynamic(ctx, 18, 1);
ImGui.Text("Polygonization"); ImGui.Text("Detail Mesh");
// nk_layout_row_dynamic(ctx, 20, 1); ImGui.Separator();
ImGui.SliderFloat("Max Edge Length", ref maxEdgeLen, 0f, 50f, "%.1f"); ImGui.Checkbox("Enable", ref buildDetailMesh);
// nk_layout_row_dynamic(ctx, 20, 1); ImGui.SliderFloat("Sample Distance", ref detailSampleDist, 0f, 16f, "%.1f");
ImGui.SliderFloat("Max Edge Error", ref maxSimplificationError, 0.1f, 10f, "%.1f"); ImGui.SliderFloat("Max Sample Error", ref detailSampleMaxError, 0f, 16f, "%.1f");
// nk_layout_row_dynamic(ctx, 20, 1); ImGui.NewLine();
ImGui.SliderInt("Verts Per Poly", ref vertsPerPoly, 3, 12);
// if (ImGui.Button("Build"))
// nk_layout_row_dynamic(ctx, 1, 1); {
// nk_spacing(ctx, 1); if (dynaMesh != null)
// nk_layout_row_dynamic(ctx, 18, 1); {
ImGui.Text("Detail Mesh"); buildDynaMesh();
// nk_layout_row_dynamic(ctx, 20, 1); sample.setChanged(false);
// buildDetailMesh = nk_check_text(ctx, "Enable", buildDetailMesh); }
// nk_layout_row_dynamic(ctx, 20, 1); }
ImGui.SliderFloat("Sample Distance", ref detailSampleDist, 0f, 16f, "%.1f"); }
// nk_layout_row_dynamic(ctx, 20, 1);
ImGui.SliderFloat("Max Sample Error", ref detailSampleMaxError, 0f, 16f, "%.1f"); if (mode == DynamicUpdateToolMode.COLLIDERS)
// nk_layout_row_dynamic(ctx, 1, 1); {
// nk_spacing(ctx, 1); ImGui.Text("Colliders");
// nk_layout_row_dynamic(ctx, 20, 1); ImGui.Separator();
// if (nk_button_text(ctx, "Build")) { var prev = colliderShape;
// if (dynaMesh != null) { ImGui.Checkbox("Show", ref showColliders);
// buildDynaMesh(); ImGui.RadioButton("Sphere", ref colliderShapeIdx, (int)ColliderShape.SPHERE);
// sample.setChanged(false); ImGui.RadioButton("Capsule", ref colliderShapeIdx, (int)ColliderShape.CAPSULE);
// } ImGui.RadioButton("Box", ref colliderShapeIdx, (int)ColliderShape.BOX);
// } ImGui.RadioButton("Cylinder", ref colliderShapeIdx, (int)ColliderShape.CYLINDER);
// } ImGui.RadioButton("Composite", ref colliderShapeIdx, (int)ColliderShape.COMPOSITE);
// if (mode == ToolMode.COLLIDERS) { ImGui.RadioButton("Convex Trimesh", ref colliderShapeIdx, (int)ColliderShape.CONVEX);
// nk_layout_row_dynamic(ctx, 1, 1); ImGui.RadioButton("Trimesh Bridge", ref colliderShapeIdx, (int)ColliderShape.TRIMESH_BRIDGE);
// nk_spacing(ctx, 1); ImGui.RadioButton("Trimesh House", ref colliderShapeIdx, (int)ColliderShape.TRIMESH_HOUSE);
// nk_layout_row_dynamic(ctx, 18, 1); ImGui.NewLine();
ImGui.Text("Colliders");
// nk_layout_row_dynamic(ctx, 20, 1); if ((int)prev != colliderShapeIdx)
// showColliders = nk_check_text(ctx, "Show", showColliders); {
// nk_layout_row_dynamic(ctx, 20, 1); colliderShape = (ColliderShape)colliderShapeIdx;
// if (nk_option_label(ctx, "Sphere", colliderShape == ColliderShape.SPHERE)) { }
// colliderShape = ColliderShape.SPHERE; }
// }
// nk_layout_row_dynamic(ctx, 18, 1); if (mode == DynamicUpdateToolMode.RAYCAST)
// if (nk_option_label(ctx, "Capsule", colliderShape == ColliderShape.CAPSULE)) { {
// colliderShape = ColliderShape.CAPSULE; ImGui.Text($"Raycast Time: {raycastTime} ms");
// } ImGui.Separator();
// nk_layout_row_dynamic(ctx, 18, 1); if (sposSet)
// if (nk_option_label(ctx, "Box", colliderShape == ColliderShape.BOX)) { {
// colliderShape = ColliderShape.BOX; ImGui.Text($"Start: {spos[0]}, {spos[1] + 1.3f}, {spos[2]}");
// } }
// nk_layout_row_dynamic(ctx, 18, 1);
// if (nk_option_label(ctx, "Cylinder", colliderShape == ColliderShape.CYLINDER)) { if (eposSet)
// colliderShape = ColliderShape.CYLINDER; {
// } ImGui.Text($"End: {epos[0]}, {epos[1] + 1.3f}, {epos[2]}");
// nk_layout_row_dynamic(ctx, 18, 1); }
// if (nk_option_label(ctx, "Composite", colliderShape == ColliderShape.COMPOSITE)) {
// colliderShape = ColliderShape.COMPOSITE; if (raycastHit)
// } {
// nk_layout_row_dynamic(ctx, 18, 1); ImGui.Text($"Hit: {raycastHitPos[0]}, {raycastHitPos[1]}, {raycastHitPos[2]}");
// if (nk_option_label(ctx, "Convex Trimesh", colliderShape == ColliderShape.CONVEX)) { }
// colliderShape = ColliderShape.CONVEX; ImGui.NewLine();
// } }
// nk_layout_row_dynamic(ctx, 18, 1); else
// if (nk_option_label(ctx, "Trimesh Bridge", colliderShape == ColliderShape.TRIMESH_BRIDGE)) { {
// colliderShape = ColliderShape.TRIMESH_BRIDGE; ImGui.Text($"Build Time: {buildTime} ms");
// } }
// nk_layout_row_dynamic(ctx, 18, 1);
// if (nk_option_label(ctx, "Trimesh House", colliderShape == ColliderShape.TRIMESH_HOUSE)) {
// colliderShape = ColliderShape.TRIMESH_HOUSE;
// }
// }
// nk_layout_row_dynamic(ctx, 2, 1);
// nk_spacing(ctx, 1);
// nk_layout_row_dynamic(ctx, 18, 1);
// if (mode == ToolMode.RAYCAST) {
// nk_label(ctx, string.format("Raycast Time: %d ms", raycastTime), NK_TEXT_ALIGN_LEFT);
// if (sposSet) {
// nk_layout_row_dynamic(ctx, 18, 1);
// nk_label(ctx, string.format("Start: %.3f, %.3f, %.3f", spos[0], spos[1] + 1.3f, spos[2]), NK_TEXT_ALIGN_LEFT);
// }
// if (eposSet) {
// nk_layout_row_dynamic(ctx, 18, 1);
// nk_label(ctx, string.format("End: %.3f, %.3f, %.3f", epos[0], epos[1] + 1.3f, epos[2]), NK_TEXT_ALIGN_LEFT);
// }
// if (raycastHit) {
// nk_layout_row_dynamic(ctx, 18, 1);
// nk_label(ctx, string.format("Hit: %.3f, %.3f, %.3f", raycastHitPos[0], raycastHitPos[1], raycastHitPos[2]),
// NK_TEXT_ALIGN_LEFT);
// }
// } else {
// nk_label(ctx, string.format("Build Time: %d ms", buildTime), NK_TEXT_ALIGN_LEFT);
// }
} }
private void load() private void load()