diff --git a/src/DotRecast.Detour/DtNavMesh.cs b/src/DotRecast.Detour/DtNavMesh.cs index e784ea7..0421f22 100644 --- a/src/DotRecast.Detour/DtNavMesh.cs +++ b/src/DotRecast.Detour/DtNavMesh.cs @@ -20,7 +20,6 @@ freely, subject to the following restrictions: using System; using System.Collections.Generic; -using System.Collections.Immutable; using DotRecast.Core; namespace DotRecast.Detour diff --git a/src/DotRecast.Recast.Demo/Messages/IRecastDemoChannel.cs b/src/DotRecast.Recast.Demo/Messages/IRecastDemoChannel.cs new file mode 100644 index 0000000..677f2f0 --- /dev/null +++ b/src/DotRecast.Recast.Demo/Messages/IRecastDemoChannel.cs @@ -0,0 +1,6 @@ +namespace DotRecast.Recast.Demo.Messages; + +public interface IRecastDemoChannel +{ + void SendMessage(IRecastDemoMessage message); +} \ No newline at end of file diff --git a/src/DotRecast.Recast.Demo/Messages/IRecastDemoMessage.cs b/src/DotRecast.Recast.Demo/Messages/IRecastDemoMessage.cs new file mode 100644 index 0000000..7ec17aa --- /dev/null +++ b/src/DotRecast.Recast.Demo/Messages/IRecastDemoMessage.cs @@ -0,0 +1,6 @@ +namespace DotRecast.Recast.Demo.Messages; + +public class IRecastDemoMessage +{ + +} \ No newline at end of file diff --git a/src/DotRecast.Recast.Demo/Messages/SourceGeomSelected.cs b/src/DotRecast.Recast.Demo/Messages/SourceGeomSelected.cs new file mode 100644 index 0000000..37fd46d --- /dev/null +++ b/src/DotRecast.Recast.Demo/Messages/SourceGeomSelected.cs @@ -0,0 +1,6 @@ +namespace DotRecast.Recast.Demo.Messages; + +public class SourceGeomSelected : IRecastDemoMessage +{ + public required string FilePath { get; init; } +} \ No newline at end of file diff --git a/src/DotRecast.Recast.Demo/RecastDemo.cs b/src/DotRecast.Recast.Demo/RecastDemo.cs index a4b6bda..1b8af5d 100644 --- a/src/DotRecast.Recast.Demo/RecastDemo.cs +++ b/src/DotRecast.Recast.Demo/RecastDemo.cs @@ -37,6 +37,7 @@ using DotRecast.Detour.Extras.Unity.Astar; using DotRecast.Detour.Io; using DotRecast.Recast.DemoTool.Builder; using DotRecast.Recast.Demo.Draw; +using DotRecast.Recast.Demo.Messages; using DotRecast.Recast.DemoTool.Geom; using DotRecast.Recast.Demo.Tools; using DotRecast.Recast.Demo.UI; @@ -48,7 +49,7 @@ using Window = Silk.NET.Windowing.Window; namespace DotRecast.Recast.Demo; -public class RecastDemo +public class RecastDemo : IRecastDemoChannel { private static readonly ILogger Logger = Log.ForContext(); @@ -117,9 +118,11 @@ public class RecastDemo private long prevFrameTime; private RecastDebugDraw dd; + private Queue _messages; public RecastDemo() { + _messages = new(); } public void Run() @@ -370,7 +373,7 @@ public class RecastDemo DemoInputGeomProvider geom = LoadInputMesh(Loader.ToBytes("nav_test.obj")); sample = new Sample(geom, ImmutableArray.Empty, null); - settingsView = new RcSettingsView(); + settingsView = new RcSettingsView(this); settingsView.SetSample(sample); toolset = new RcToolsetView( @@ -491,14 +494,7 @@ public class RecastDemo simIter++; } - if (settingsView.IsMeshInputTrigerred()) - { - var bytes = Loader.ToBytes(settingsView.GetMeshInputFilePath()); - var geom = LoadInputMesh(bytes); - - sample.Update(geom, ImmutableArray.Empty, null); - } - else if (settingsView.IsNavMeshInputTrigerred()) + if (settingsView.IsNavMeshInputTrigerred()) { // try (MemoryStack stack = StackPush()) { // PointerBuffer aFilterPatterns = stack.MallocPointer(4); @@ -758,6 +754,11 @@ public class RecastDemo toolset.SetSample(sample); } + if (_messages.TryDequeue(out var msg)) + { + OnMessage(msg); + } + var io = ImGui.GetIO(); @@ -794,4 +795,21 @@ public class RecastDemo window.SwapBuffers(); } + + public void SendMessage(IRecastDemoMessage message) + { + _messages.Enqueue(message); + } + + public void OnMessage(IRecastDemoMessage message) + { + if (message is SourceGeomSelected args) + { + var bytes = Loader.ToBytes(args.FilePath); + var geom = LoadInputMesh(bytes); + + sample.Update(geom, ImmutableArray.Empty, null); + } + } + } \ No newline at end of file diff --git a/src/DotRecast.Recast.Demo/UI/RcSettingsView.cs b/src/DotRecast.Recast.Demo/UI/RcSettingsView.cs index 125781c..d184f4f 100644 --- a/src/DotRecast.Recast.Demo/UI/RcSettingsView.cs +++ b/src/DotRecast.Recast.Demo/UI/RcSettingsView.cs @@ -23,6 +23,7 @@ using System.Linq; using System.Numerics; using DotRecast.Core; using DotRecast.Recast.Demo.Draw; +using DotRecast.Recast.Demo.Messages; using DotRecast.Recast.DemoTool; using ImGuiNET; using Serilog; @@ -31,8 +32,9 @@ namespace DotRecast.Recast.Demo.UI; public class RcSettingsView : IRcView { - private static readonly ILogger Logger = Log.ForContext(); + private static readonly ILogger Logger = Log.ForContext(); + private readonly IRecastDemoChannel _channel; private bool buildTriggered; private long buildTime; @@ -43,8 +45,6 @@ public class RcSettingsView : IRcView private int drawMode = DrawMode.DRAWMODE_NAVMESH.Idx; - private string meshInputFilePath; - private bool meshInputTrigerred; private bool navMeshInputTrigerred; private bool _isHovered; @@ -53,8 +53,9 @@ public class RcSettingsView : IRcView private Sample _sample; private RcCanvas _canvas; - public RcSettingsView() + public RcSettingsView(IRecastDemoChannel channel) { + _channel = channel; } public void SetSample(Sample sample) @@ -104,17 +105,15 @@ public class RcSettingsView : IRcView var picker = ImFilePicker.GetFilePicker(strLoadSourceGeom, Path.Combine(Environment.CurrentDirectory), ".obj"); if (picker.Draw()) { - meshInputTrigerred = true; - meshInputFilePath = picker.SelectedFile; + _channel.SendMessage(new SourceGeomSelected() + { + FilePath = picker.SelectedFile, + }); ImFilePicker.RemoveFilePicker(strLoadSourceGeom); } ImGui.EndPopup(); } - else - { - meshInputTrigerred = false; - } ImGui.Text($"Verts: {voxels[0]} Tris: {voxels[1]}"); ImGui.NewLine(); @@ -192,26 +191,37 @@ public class RcSettingsView : IRcView ImGui.Text($"Build Time: {buildTime} ms"); ImGui.Separator(); - buildTriggered = ImGui.Button("Build Nav Mesh"); - const string strLoadNavMesh = "Load Nav Mesh..."; - if (ImGui.Button(strLoadNavMesh)) + buildTriggered = ImGui.Button("Build NavMesh"); { - ImGui.OpenPopup(strLoadNavMesh); - } - - bool isLoadNavMesh = true; - if (ImGui.BeginPopupModal(strLoadNavMesh, ref isLoadNavMesh, ImGuiWindowFlags.NoTitleBar)) - { - var picker = ImFilePicker.GetFilePicker(strLoadNavMesh, Path.Combine(Environment.CurrentDirectory)); - if (picker.Draw()) + const string strLoadNavMesh = "Load NavMesh"; + if (ImGui.Button(strLoadNavMesh)) { - Console.WriteLine(picker.SelectedFile); - ImFilePicker.RemoveFilePicker(strLoadNavMesh); + ImGui.OpenPopup(strLoadNavMesh); } - ImGui.EndPopup(); + bool isLoadNavMesh = true; + if (ImGui.BeginPopupModal(strLoadNavMesh, ref isLoadNavMesh, ImGuiWindowFlags.NoTitleBar)) + { + var picker = ImFilePicker.GetFilePicker(strLoadNavMesh, Path.Combine(Environment.CurrentDirectory)); + if (picker.Draw()) + { + Logger.Information(picker.SelectedFile); + ImFilePicker.RemoveFilePicker(strLoadNavMesh); + } + + ImGui.EndPopup(); + } } + { + const string strSaveNavMesh = "Save NavMesh"; + if (ImGui.Button(strSaveNavMesh)) + { + + } + } + + ImGui.NewLine(); ImGui.Text("Draw"); @@ -262,16 +272,6 @@ public class RcSettingsView : IRcView this.maxPolys = maxPolys; } - public bool IsMeshInputTrigerred() - { - return meshInputTrigerred; - } - - public string GetMeshInputFilePath() - { - return meshInputFilePath; - } - public bool IsNavMeshInputTrigerred() { return navMeshInputTrigerred; diff --git a/src/DotRecast.Recast.DemoTool/Tools/ConvexVolumeToolImpl.cs b/src/DotRecast.Recast.DemoTool/Tools/ConvexVolumeToolImpl.cs index 628d866..be1f296 100644 --- a/src/DotRecast.Recast.DemoTool/Tools/ConvexVolumeToolImpl.cs +++ b/src/DotRecast.Recast.DemoTool/Tools/ConvexVolumeToolImpl.cs @@ -2,13 +2,13 @@ { public class ConvexVolumeToolImpl : ISampleTool { + private Sample _sample; public string GetName() { return "Create Convex Volumes"; } - private Sample _sample; public void SetSample(Sample sample) { _sample = sample;