forked from bit/DotRecastNetSim
transfer the ownership of managing the sample settings to the demo toolkit.
This commit is contained in:
parent
869c1e7b98
commit
96928355c1
|
@ -300,8 +300,6 @@ public class RecastDemo
|
|||
private DemoInputGeomProvider LoadInputMesh(byte[] stream)
|
||||
{
|
||||
DemoInputGeomProvider geom = DemoObjImporter.Load(stream);
|
||||
sample = new Sample(geom, ImmutableArray<RecastBuilderResult>.Empty, null, settingsView, dd);
|
||||
toolset.SetEnabled(true);
|
||||
return geom;
|
||||
}
|
||||
|
||||
|
@ -368,7 +366,12 @@ public class RecastDemo
|
|||
|
||||
_imgui = new ImGuiController(_gl, window, _input);
|
||||
|
||||
DemoInputGeomProvider geom = LoadInputMesh(Loader.ToBytes("nav_test.obj"));
|
||||
sample = new Sample(geom, ImmutableArray<RecastBuilderResult>.Empty, null, dd);
|
||||
|
||||
settingsView = new RcSettingsView();
|
||||
settingsView.SetSample(sample);
|
||||
|
||||
toolset = new RcToolsetView(
|
||||
new TestNavmeshTool(),
|
||||
new OffMeshConnectionTool(),
|
||||
|
@ -377,6 +380,7 @@ public class RecastDemo
|
|||
new JumpLinkBuilderTool(),
|
||||
new DynamicUpdateTool()
|
||||
);
|
||||
toolset.SetEnabled(true);
|
||||
logView = new RcLogView();
|
||||
|
||||
_canvas = new RcCanvas(window, settingsView, toolset, logView);
|
||||
|
@ -392,10 +396,6 @@ public class RecastDemo
|
|||
Logger.Information(version);
|
||||
Logger.Information(renderGl);
|
||||
Logger.Information(glslString);
|
||||
|
||||
|
||||
DemoInputGeomProvider geom = LoadInputMesh(Loader.ToBytes("nav_test.obj"));
|
||||
sample = new Sample(geom, ImmutableArray<RecastBuilderResult>.Empty, null, settingsView, dd);
|
||||
}
|
||||
|
||||
private void UpdateKeyboard(float dt)
|
||||
|
@ -430,7 +430,7 @@ public class RecastDemo
|
|||
*/
|
||||
if (sample.GetInputGeom() != null)
|
||||
{
|
||||
var settings = settingsView.GetSettings();
|
||||
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);
|
||||
|
@ -485,7 +485,9 @@ public class RecastDemo
|
|||
if (settingsView.IsMeshInputTrigerred())
|
||||
{
|
||||
var bytes = Loader.ToBytes(settingsView.GetMeshInputFilePath());
|
||||
sample.Update(LoadInputMesh(bytes), null, null);
|
||||
var geom = LoadInputMesh(bytes);
|
||||
|
||||
sample.Update(geom, ImmutableArray<RecastBuilderResult>.Empty, null);
|
||||
}
|
||||
else if (settingsView.IsNavMeshInputTrigerred())
|
||||
{
|
||||
|
@ -516,7 +518,7 @@ public class RecastDemo
|
|||
{
|
||||
if (!building)
|
||||
{
|
||||
var settings = settingsView.GetSettings();
|
||||
var settings = sample.GetSettings();
|
||||
var partitioning = settings.partitioning;
|
||||
var cellSize = settings.cellSize;
|
||||
var cellHeight = settings.cellHeight;
|
||||
|
|
|
@ -22,7 +22,6 @@ using System.Collections.Generic;
|
|||
using DotRecast.Detour;
|
||||
using DotRecast.Recast.Demo.Draw;
|
||||
using DotRecast.Recast.DemoTool.Geom;
|
||||
|
||||
using DotRecast.Recast.Demo.UI;
|
||||
using DotRecast.Recast.DemoTool;
|
||||
|
||||
|
@ -33,17 +32,17 @@ public class Sample
|
|||
private DemoInputGeomProvider _inputGeom;
|
||||
private DtNavMesh _navMesh;
|
||||
private DtNavMeshQuery _navMeshQuery;
|
||||
private readonly RcSettings _settings;
|
||||
private readonly RcSampleSettings _settings;
|
||||
private IList<RecastBuilderResult> _recastResults;
|
||||
private bool _changed;
|
||||
|
||||
public Sample(DemoInputGeomProvider inputGeom, IList<RecastBuilderResult> recastResults, DtNavMesh navMesh,
|
||||
RcSettingsView settingsView, RecastDebugDraw debugDraw)
|
||||
public Sample(DemoInputGeomProvider inputGeom, IList<RecastBuilderResult> recastResults, DtNavMesh navMesh, RecastDebugDraw debugDraw)
|
||||
{
|
||||
_inputGeom = inputGeom;
|
||||
_recastResults = recastResults;
|
||||
_navMesh = navMesh;
|
||||
_settings = settingsView.GetSettings();
|
||||
_settings = new();
|
||||
|
||||
SetQuery(navMesh);
|
||||
_changed = true;
|
||||
}
|
||||
|
@ -68,7 +67,7 @@ public class Sample
|
|||
return _navMesh;
|
||||
}
|
||||
|
||||
public RcSettings GetSettings()
|
||||
public RcSampleSettings GetSettings()
|
||||
{
|
||||
return _settings;
|
||||
}
|
||||
|
|
|
@ -1,15 +1,19 @@
|
|||
using System;
|
||||
using System.Numerics;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.Immutable;
|
||||
using System.Drawing;
|
||||
using System.IO;
|
||||
using ImGuiNET;
|
||||
using Serilog;
|
||||
|
||||
namespace DotRecast.Recast.Demo.UI;
|
||||
|
||||
// original code : https://gist.github.com/prime31/91d1582624eb2635395417393018016e
|
||||
public class ImFilePicker
|
||||
{
|
||||
private static readonly ILogger Logger = Log.ForContext<RecastDemo>();
|
||||
|
||||
private static readonly Dictionary<string, ImFilePicker> _filePickers = new Dictionary<string, ImFilePicker>();
|
||||
|
||||
public string RootFolder;
|
||||
|
@ -77,7 +81,7 @@ public class ImFilePicker
|
|||
|
||||
ImGui.PopStyleColor();
|
||||
}
|
||||
|
||||
|
||||
var fileSystemEntries = GetFileSystemEntries(di.FullName);
|
||||
foreach (var fse in fileSystemEntries)
|
||||
{
|
||||
|
@ -157,7 +161,20 @@ public class ImFilePicker
|
|||
var files = new List<string>();
|
||||
var dirs = new List<string>();
|
||||
|
||||
foreach (var fse in Directory.GetFileSystemEntries(fullName, ""))
|
||||
ImmutableArray<string> fileEntries;
|
||||
try
|
||||
{
|
||||
fileEntries = Directory
|
||||
.GetFileSystemEntries(fullName, "")
|
||||
.ToImmutableArray();
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Logger.Error(e, "");
|
||||
return files;
|
||||
}
|
||||
|
||||
foreach (var fse in fileEntries)
|
||||
{
|
||||
if (Directory.Exists(fse))
|
||||
{
|
||||
|
|
|
@ -47,12 +47,17 @@ public class RcSettingsView : IRcView
|
|||
private bool _mouseInside;
|
||||
public bool IsMouseInside() => _mouseInside;
|
||||
|
||||
private readonly RcSettings _settings;
|
||||
private Sample _sample;
|
||||
private RcCanvas _canvas;
|
||||
|
||||
public RcSettingsView()
|
||||
{
|
||||
_settings = new();
|
||||
|
||||
}
|
||||
|
||||
public void SetSample(Sample sample)
|
||||
{
|
||||
_sample = sample;
|
||||
}
|
||||
|
||||
public void Bind(RcCanvas canvas)
|
||||
|
@ -60,17 +65,14 @@ public class RcSettingsView : IRcView
|
|||
_canvas = canvas;
|
||||
}
|
||||
|
||||
public RcSettings GetSettings()
|
||||
{
|
||||
return _settings;
|
||||
}
|
||||
|
||||
public void Update(double dt)
|
||||
{
|
||||
}
|
||||
|
||||
public void Draw(double dt)
|
||||
{
|
||||
var settings = _sample.GetSettings();
|
||||
|
||||
int width = 310;
|
||||
var posX = _canvas.Size.X - width;
|
||||
ImGui.SetNextWindowPos(new Vector2(posX, 0));
|
||||
|
@ -112,23 +114,23 @@ public class RcSettingsView : IRcView
|
|||
ImGui.Text("Rasterization");
|
||||
ImGui.Separator();
|
||||
|
||||
ImGui.SliderFloat("Cell Size", ref _settings.cellSize, 0.01f, 1f, "%.2f");
|
||||
ImGui.SliderFloat("Cell Height", ref _settings.cellHeight, 0.01f, 1f, "%.2f");
|
||||
ImGui.SliderFloat("Cell Size", ref settings.cellSize, 0.01f, 1f, "%.2f");
|
||||
ImGui.SliderFloat("Cell Height", ref settings.cellHeight, 0.01f, 1f, "%.2f");
|
||||
ImGui.Text($"Voxels {voxels[0]} x {voxels[1]}");
|
||||
ImGui.NewLine();
|
||||
|
||||
ImGui.Text("Agent");
|
||||
ImGui.Separator();
|
||||
ImGui.SliderFloat("Height", ref _settings.agentHeight, 0.1f, 5f, "%.1f");
|
||||
ImGui.SliderFloat("Radius", ref _settings.agentRadius, 0.1f, 5f, "%.1f");
|
||||
ImGui.SliderFloat("Max Climb", ref _settings.agentMaxClimb, 0.1f, 5f, "%.1f");
|
||||
ImGui.SliderFloat("Max Slope", ref _settings.agentMaxSlope, 1f, 90f, "%.0f");
|
||||
ImGui.SliderFloat("Height", ref settings.agentHeight, 0.1f, 5f, "%.1f");
|
||||
ImGui.SliderFloat("Radius", ref settings.agentRadius, 0.1f, 5f, "%.1f");
|
||||
ImGui.SliderFloat("Max Climb", ref settings.agentMaxClimb, 0.1f, 5f, "%.1f");
|
||||
ImGui.SliderFloat("Max Slope", ref settings.agentMaxSlope, 1f, 90f, "%.0f");
|
||||
ImGui.NewLine();
|
||||
|
||||
ImGui.Text("Region");
|
||||
ImGui.Separator();
|
||||
ImGui.SliderInt("Min Region Size", ref _settings.minRegionSize, 1, 150);
|
||||
ImGui.SliderInt("Merged Region Size", ref _settings.mergedRegionSize, 1, 150);
|
||||
ImGui.SliderInt("Min Region Size", ref settings.minRegionSize, 1, 150);
|
||||
ImGui.SliderInt("Merged Region Size", ref settings.mergedRegionSize, 1, 150);
|
||||
ImGui.NewLine();
|
||||
|
||||
ImGui.Text("Partitioning");
|
||||
|
@ -136,38 +138,38 @@ public class RcSettingsView : IRcView
|
|||
PartitionType.Values.ForEach(partition =>
|
||||
{
|
||||
var label = partition.Name.Substring(0, 1).ToUpper() + partition.Name.Substring(1).ToLower();
|
||||
ImGui.RadioButton(label, ref _settings.partitioningIdx, partition.Idx);
|
||||
ImGui.RadioButton(label, ref settings.partitioningIdx, partition.Idx);
|
||||
});
|
||||
ImGui.NewLine();
|
||||
|
||||
ImGui.Text("Filtering");
|
||||
ImGui.Separator();
|
||||
ImGui.Checkbox("Low Hanging Obstacles", ref _settings.filterLowHangingObstacles);
|
||||
ImGui.Checkbox("Ledge Spans", ref _settings.filterLedgeSpans);
|
||||
ImGui.Checkbox("Walkable Low Height Spans", ref _settings.filterWalkableLowHeightSpans);
|
||||
ImGui.Checkbox("Low Hanging Obstacles", ref settings.filterLowHangingObstacles);
|
||||
ImGui.Checkbox("Ledge Spans", ref settings.filterLedgeSpans);
|
||||
ImGui.Checkbox("Walkable Low Height Spans", ref settings.filterWalkableLowHeightSpans);
|
||||
ImGui.NewLine();
|
||||
|
||||
ImGui.Text("Polygonization");
|
||||
ImGui.Separator();
|
||||
ImGui.SliderFloat("Max Edge Length", ref _settings.edgeMaxLen, 0f, 50f, "%.1f");
|
||||
ImGui.SliderFloat("Max Edge Error", ref _settings.edgeMaxError, 0.1f, 3f, "%.1f");
|
||||
ImGui.SliderInt("Vert Per Poly", ref _settings.vertsPerPoly, 3, 12);
|
||||
ImGui.SliderFloat("Max Edge Length", ref settings.edgeMaxLen, 0f, 50f, "%.1f");
|
||||
ImGui.SliderFloat("Max Edge Error", ref settings.edgeMaxError, 0.1f, 3f, "%.1f");
|
||||
ImGui.SliderInt("Vert Per Poly", ref settings.vertsPerPoly, 3, 12);
|
||||
ImGui.NewLine();
|
||||
|
||||
ImGui.Text("Detail Mesh");
|
||||
ImGui.Separator();
|
||||
ImGui.SliderFloat("Sample Distance", ref _settings.detailSampleDist, 0f, 16f, "%.1f");
|
||||
ImGui.SliderFloat("Max Sample Error", ref _settings.detailSampleMaxError, 0f, 16f, "%.1f");
|
||||
ImGui.SliderFloat("Sample Distance", ref settings.detailSampleDist, 0f, 16f, "%.1f");
|
||||
ImGui.SliderFloat("Max Sample Error", ref settings.detailSampleMaxError, 0f, 16f, "%.1f");
|
||||
ImGui.NewLine();
|
||||
|
||||
ImGui.Text("Tiling");
|
||||
ImGui.Separator();
|
||||
ImGui.Checkbox("Enable", ref _settings.tiled);
|
||||
if (_settings.tiled)
|
||||
ImGui.Checkbox("Enable", ref settings.tiled);
|
||||
if (settings.tiled)
|
||||
{
|
||||
if (0 < (_settings.tileSize % 16))
|
||||
_settings.tileSize = _settings.tileSize + (16 - (_settings.tileSize % 16));
|
||||
ImGui.SliderInt("Tile Size", ref _settings.tileSize, 16, 1024);
|
||||
if (0 < (settings.tileSize % 16))
|
||||
settings.tileSize = settings.tileSize + (16 - (settings.tileSize % 16));
|
||||
ImGui.SliderInt("Tile Size", ref settings.tileSize, 16, 1024);
|
||||
|
||||
ImGui.Text($"Tiles {tiles[0]} x {tiles[1]}");
|
||||
ImGui.Text($"Max Tiles {maxTiles}");
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
namespace DotRecast.Recast.DemoTool
|
||||
{
|
||||
public class RcSettings
|
||||
public class RcSampleSettings
|
||||
{
|
||||
public float cellSize = 0.3f;
|
||||
public float cellHeight = 0.2f;
|
Loading…
Reference in New Issue