transfer the ownership of managing the sample settings to the demo toolkit.

This commit is contained in:
ikpil 2023-06-11 16:27:17 +09:00
parent 869c1e7b98
commit 96928355c1
5 changed files with 67 additions and 47 deletions

View File

@ -300,8 +300,6 @@ public class RecastDemo
private DemoInputGeomProvider LoadInputMesh(byte[] stream) private DemoInputGeomProvider LoadInputMesh(byte[] stream)
{ {
DemoInputGeomProvider geom = DemoObjImporter.Load(stream); DemoInputGeomProvider geom = DemoObjImporter.Load(stream);
sample = new Sample(geom, ImmutableArray<RecastBuilderResult>.Empty, null, settingsView, dd);
toolset.SetEnabled(true);
return geom; return geom;
} }
@ -368,7 +366,12 @@ public class RecastDemo
_imgui = new ImGuiController(_gl, window, _input); _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 = new RcSettingsView();
settingsView.SetSample(sample);
toolset = new RcToolsetView( toolset = new RcToolsetView(
new TestNavmeshTool(), new TestNavmeshTool(),
new OffMeshConnectionTool(), new OffMeshConnectionTool(),
@ -377,6 +380,7 @@ public class RecastDemo
new JumpLinkBuilderTool(), new JumpLinkBuilderTool(),
new DynamicUpdateTool() new DynamicUpdateTool()
); );
toolset.SetEnabled(true);
logView = new RcLogView(); logView = new RcLogView();
_canvas = new RcCanvas(window, settingsView, toolset, logView); _canvas = new RcCanvas(window, settingsView, toolset, logView);
@ -392,10 +396,6 @@ public class RecastDemo
Logger.Information(version); Logger.Information(version);
Logger.Information(renderGl); Logger.Information(renderGl);
Logger.Information(glslString); 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) private void UpdateKeyboard(float dt)
@ -430,7 +430,7 @@ public class RecastDemo
*/ */
if (sample.GetInputGeom() != null) if (sample.GetInputGeom() != null)
{ {
var settings = settingsView.GetSettings(); var settings = sample.GetSettings();
RcVec3f bmin = sample.GetInputGeom().GetMeshBoundsMin(); RcVec3f bmin = sample.GetInputGeom().GetMeshBoundsMin();
RcVec3f bmax = sample.GetInputGeom().GetMeshBoundsMax(); RcVec3f bmax = sample.GetInputGeom().GetMeshBoundsMax();
Recast.CalcGridSize(bmin, bmax, settings.cellSize, out var gw, out var gh); Recast.CalcGridSize(bmin, bmax, settings.cellSize, out var gw, out var gh);
@ -485,7 +485,9 @@ public class RecastDemo
if (settingsView.IsMeshInputTrigerred()) if (settingsView.IsMeshInputTrigerred())
{ {
var bytes = Loader.ToBytes(settingsView.GetMeshInputFilePath()); 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()) else if (settingsView.IsNavMeshInputTrigerred())
{ {
@ -516,7 +518,7 @@ public class RecastDemo
{ {
if (!building) if (!building)
{ {
var settings = settingsView.GetSettings(); var settings = sample.GetSettings();
var partitioning = settings.partitioning; var partitioning = settings.partitioning;
var cellSize = settings.cellSize; var cellSize = settings.cellSize;
var cellHeight = settings.cellHeight; var cellHeight = settings.cellHeight;

View File

@ -22,7 +22,6 @@ using System.Collections.Generic;
using DotRecast.Detour; using DotRecast.Detour;
using DotRecast.Recast.Demo.Draw; using DotRecast.Recast.Demo.Draw;
using DotRecast.Recast.DemoTool.Geom; using DotRecast.Recast.DemoTool.Geom;
using DotRecast.Recast.Demo.UI; using DotRecast.Recast.Demo.UI;
using DotRecast.Recast.DemoTool; using DotRecast.Recast.DemoTool;
@ -33,17 +32,17 @@ public class Sample
private DemoInputGeomProvider _inputGeom; private DemoInputGeomProvider _inputGeom;
private DtNavMesh _navMesh; private DtNavMesh _navMesh;
private DtNavMeshQuery _navMeshQuery; private DtNavMeshQuery _navMeshQuery;
private readonly RcSettings _settings; private readonly RcSampleSettings _settings;
private IList<RecastBuilderResult> _recastResults; private IList<RecastBuilderResult> _recastResults;
private bool _changed; private bool _changed;
public Sample(DemoInputGeomProvider inputGeom, IList<RecastBuilderResult> recastResults, DtNavMesh navMesh, public Sample(DemoInputGeomProvider inputGeom, IList<RecastBuilderResult> recastResults, DtNavMesh navMesh, RecastDebugDraw debugDraw)
RcSettingsView settingsView, RecastDebugDraw debugDraw)
{ {
_inputGeom = inputGeom; _inputGeom = inputGeom;
_recastResults = recastResults; _recastResults = recastResults;
_navMesh = navMesh; _navMesh = navMesh;
_settings = settingsView.GetSettings(); _settings = new();
SetQuery(navMesh); SetQuery(navMesh);
_changed = true; _changed = true;
} }
@ -68,7 +67,7 @@ public class Sample
return _navMesh; return _navMesh;
} }
public RcSettings GetSettings() public RcSampleSettings GetSettings()
{ {
return _settings; return _settings;
} }

View File

@ -1,15 +1,19 @@
using System; using System;
using System.Numerics; using System.Numerics;
using System.Collections.Generic; using System.Collections.Generic;
using System.Collections.Immutable;
using System.Drawing; using System.Drawing;
using System.IO; using System.IO;
using ImGuiNET; using ImGuiNET;
using Serilog;
namespace DotRecast.Recast.Demo.UI; namespace DotRecast.Recast.Demo.UI;
// original code : https://gist.github.com/prime31/91d1582624eb2635395417393018016e // original code : https://gist.github.com/prime31/91d1582624eb2635395417393018016e
public class ImFilePicker public class ImFilePicker
{ {
private static readonly ILogger Logger = Log.ForContext<RecastDemo>();
private static readonly Dictionary<string, ImFilePicker> _filePickers = new Dictionary<string, ImFilePicker>(); private static readonly Dictionary<string, ImFilePicker> _filePickers = new Dictionary<string, ImFilePicker>();
public string RootFolder; public string RootFolder;
@ -77,7 +81,7 @@ public class ImFilePicker
ImGui.PopStyleColor(); ImGui.PopStyleColor();
} }
var fileSystemEntries = GetFileSystemEntries(di.FullName); var fileSystemEntries = GetFileSystemEntries(di.FullName);
foreach (var fse in fileSystemEntries) foreach (var fse in fileSystemEntries)
{ {
@ -157,7 +161,20 @@ public class ImFilePicker
var files = new List<string>(); var files = new List<string>();
var dirs = 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)) if (Directory.Exists(fse))
{ {

View File

@ -47,12 +47,17 @@ public class RcSettingsView : IRcView
private bool _mouseInside; private bool _mouseInside;
public bool IsMouseInside() => _mouseInside; public bool IsMouseInside() => _mouseInside;
private readonly RcSettings _settings; private Sample _sample;
private RcCanvas _canvas; private RcCanvas _canvas;
public RcSettingsView() public RcSettingsView()
{ {
_settings = new();
}
public void SetSample(Sample sample)
{
_sample = sample;
} }
public void Bind(RcCanvas canvas) public void Bind(RcCanvas canvas)
@ -60,17 +65,14 @@ public class RcSettingsView : IRcView
_canvas = canvas; _canvas = canvas;
} }
public RcSettings GetSettings()
{
return _settings;
}
public void Update(double dt) public void Update(double dt)
{ {
} }
public void Draw(double dt) public void Draw(double dt)
{ {
var settings = _sample.GetSettings();
int width = 310; int width = 310;
var posX = _canvas.Size.X - width; var posX = _canvas.Size.X - width;
ImGui.SetNextWindowPos(new Vector2(posX, 0)); ImGui.SetNextWindowPos(new Vector2(posX, 0));
@ -112,23 +114,23 @@ public class RcSettingsView : IRcView
ImGui.Text("Rasterization"); ImGui.Text("Rasterization");
ImGui.Separator(); ImGui.Separator();
ImGui.SliderFloat("Cell Size", ref _settings.cellSize, 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.SliderFloat("Cell Height", ref settings.cellHeight, 0.01f, 1f, "%.2f");
ImGui.Text($"Voxels {voxels[0]} x {voxels[1]}"); ImGui.Text($"Voxels {voxels[0]} x {voxels[1]}");
ImGui.NewLine(); ImGui.NewLine();
ImGui.Text("Agent"); ImGui.Text("Agent");
ImGui.Separator(); ImGui.Separator();
ImGui.SliderFloat("Height", ref _settings.agentHeight, 0.1f, 5f, "%.1f"); ImGui.SliderFloat("Height", ref settings.agentHeight, 0.1f, 5f, "%.1f");
ImGui.SliderFloat("Radius", ref _settings.agentRadius, 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 Climb", ref settings.agentMaxClimb, 0.1f, 5f, "%.1f");
ImGui.SliderFloat("Max Slope", ref _settings.agentMaxSlope, 1f, 90f, "%.0f"); ImGui.SliderFloat("Max Slope", ref settings.agentMaxSlope, 1f, 90f, "%.0f");
ImGui.NewLine(); ImGui.NewLine();
ImGui.Text("Region"); ImGui.Text("Region");
ImGui.Separator(); ImGui.Separator();
ImGui.SliderInt("Min Region Size", ref _settings.minRegionSize, 1, 150); ImGui.SliderInt("Min Region Size", ref settings.minRegionSize, 1, 150);
ImGui.SliderInt("Merged Region Size", ref _settings.mergedRegionSize, 1, 150); ImGui.SliderInt("Merged Region Size", ref settings.mergedRegionSize, 1, 150);
ImGui.NewLine(); ImGui.NewLine();
ImGui.Text("Partitioning"); ImGui.Text("Partitioning");
@ -136,38 +138,38 @@ public class RcSettingsView : IRcView
PartitionType.Values.ForEach(partition => PartitionType.Values.ForEach(partition =>
{ {
var label = partition.Name.Substring(0, 1).ToUpper() + partition.Name.Substring(1).ToLower(); 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.NewLine();
ImGui.Text("Filtering"); ImGui.Text("Filtering");
ImGui.Separator(); ImGui.Separator();
ImGui.Checkbox("Low Hanging Obstacles", ref _settings.filterLowHangingObstacles); ImGui.Checkbox("Low Hanging Obstacles", ref settings.filterLowHangingObstacles);
ImGui.Checkbox("Ledge Spans", ref _settings.filterLedgeSpans); ImGui.Checkbox("Ledge Spans", ref settings.filterLedgeSpans);
ImGui.Checkbox("Walkable Low Height Spans", ref _settings.filterWalkableLowHeightSpans); ImGui.Checkbox("Walkable Low Height Spans", ref settings.filterWalkableLowHeightSpans);
ImGui.NewLine(); ImGui.NewLine();
ImGui.Text("Polygonization"); ImGui.Text("Polygonization");
ImGui.Separator(); ImGui.Separator();
ImGui.SliderFloat("Max Edge Length", ref _settings.edgeMaxLen, 0f, 50f, "%.1f"); ImGui.SliderFloat("Max Edge Length", ref settings.edgeMaxLen, 0f, 50f, "%.1f");
ImGui.SliderFloat("Max Edge Error", ref _settings.edgeMaxError, 0.1f, 3f, "%.1f"); ImGui.SliderFloat("Max Edge Error", ref settings.edgeMaxError, 0.1f, 3f, "%.1f");
ImGui.SliderInt("Vert Per Poly", ref _settings.vertsPerPoly, 3, 12); ImGui.SliderInt("Vert Per Poly", ref settings.vertsPerPoly, 3, 12);
ImGui.NewLine(); ImGui.NewLine();
ImGui.Text("Detail Mesh"); ImGui.Text("Detail Mesh");
ImGui.Separator(); ImGui.Separator();
ImGui.SliderFloat("Sample Distance", ref _settings.detailSampleDist, 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.SliderFloat("Max Sample Error", ref settings.detailSampleMaxError, 0f, 16f, "%.1f");
ImGui.NewLine(); ImGui.NewLine();
ImGui.Text("Tiling"); ImGui.Text("Tiling");
ImGui.Separator(); ImGui.Separator();
ImGui.Checkbox("Enable", ref _settings.tiled); ImGui.Checkbox("Enable", ref settings.tiled);
if (_settings.tiled) if (settings.tiled)
{ {
if (0 < (_settings.tileSize % 16)) if (0 < (settings.tileSize % 16))
_settings.tileSize = _settings.tileSize + (16 - (_settings.tileSize % 16)); settings.tileSize = settings.tileSize + (16 - (settings.tileSize % 16));
ImGui.SliderInt("Tile Size", ref _settings.tileSize, 16, 1024); ImGui.SliderInt("Tile Size", ref settings.tileSize, 16, 1024);
ImGui.Text($"Tiles {tiles[0]} x {tiles[1]}"); ImGui.Text($"Tiles {tiles[0]} x {tiles[1]}");
ImGui.Text($"Max Tiles {maxTiles}"); ImGui.Text($"Max Tiles {maxTiles}");

View File

@ -1,6 +1,6 @@
namespace DotRecast.Recast.DemoTool namespace DotRecast.Recast.DemoTool
{ {
public class RcSettings public class RcSampleSettings
{ {
public float cellSize = 0.3f; public float cellSize = 0.3f;
public float cellHeight = 0.2f; public float cellHeight = 0.2f;