diff --git a/src/DotRecast.Recast.Demo/Messages/SourceGeomFileSelectedEvent.cs b/src/DotRecast.Recast.Demo/Messages/GeomLoadBeganEvent.cs similarity index 61% rename from src/DotRecast.Recast.Demo/Messages/SourceGeomFileSelectedEvent.cs rename to src/DotRecast.Recast.Demo/Messages/GeomLoadBeganEvent.cs index 7c6147d..28bf422 100644 --- a/src/DotRecast.Recast.Demo/Messages/SourceGeomFileSelectedEvent.cs +++ b/src/DotRecast.Recast.Demo/Messages/GeomLoadBeganEvent.cs @@ -1,6 +1,6 @@ namespace DotRecast.Recast.Demo.Messages; -public class SourceGeomFileSelectedEvent : IRecastDemoMessage +public class GeomLoadBeganEvent : IRecastDemoMessage { public required string FilePath { get; init; } } \ No newline at end of file diff --git a/src/DotRecast.Recast.Demo/Messages/NavMeshBuildBeganEvent.cs b/src/DotRecast.Recast.Demo/Messages/NavMeshBuildBeganEvent.cs new file mode 100644 index 0000000..96db561 --- /dev/null +++ b/src/DotRecast.Recast.Demo/Messages/NavMeshBuildBeganEvent.cs @@ -0,0 +1,6 @@ +namespace DotRecast.Recast.Demo.Messages; + +public class NavMeshBuildBeganEvent : IRecastDemoMessage +{ + +} \ No newline at end of file diff --git a/src/DotRecast.Recast.Demo/Messages/NavMeshBuildEvent.cs b/src/DotRecast.Recast.Demo/Messages/NavMeshBuildEvent.cs deleted file mode 100644 index 4509271..0000000 --- a/src/DotRecast.Recast.Demo/Messages/NavMeshBuildEvent.cs +++ /dev/null @@ -1,6 +0,0 @@ -namespace DotRecast.Recast.Demo.Messages; - -public class NavMeshBuildEvent : IRecastDemoMessage -{ - -} \ No newline at end of file diff --git a/src/DotRecast.Recast.Demo/Messages/NavMeshLoadBeganEvent.cs b/src/DotRecast.Recast.Demo/Messages/NavMeshLoadBeganEvent.cs new file mode 100644 index 0000000..3895b32 --- /dev/null +++ b/src/DotRecast.Recast.Demo/Messages/NavMeshLoadBeganEvent.cs @@ -0,0 +1,6 @@ +namespace DotRecast.Recast.Demo.Messages; + +public class NavMeshLoadBeganEvent : IRecastDemoMessage +{ + public required string FilePath { get; init; } +} \ No newline at end of file diff --git a/src/DotRecast.Recast.Demo/Messages/NavMeshSaveBeganEvent.cs b/src/DotRecast.Recast.Demo/Messages/NavMeshSaveBeganEvent.cs new file mode 100644 index 0000000..b9ea7d1 --- /dev/null +++ b/src/DotRecast.Recast.Demo/Messages/NavMeshSaveBeganEvent.cs @@ -0,0 +1,6 @@ +namespace DotRecast.Recast.Demo.Messages; + +public class NavMeshSaveBeganEvent : IRecastDemoMessage +{ + +} \ No newline at end of file diff --git a/src/DotRecast.Recast.Demo/RecastDemo.cs b/src/DotRecast.Recast.Demo/RecastDemo.cs index b839059..19aa185 100644 --- a/src/DotRecast.Recast.Demo/RecastDemo.cs +++ b/src/DotRecast.Recast.Demo/RecastDemo.cs @@ -493,31 +493,6 @@ public class RecastDemo : IRecastDemoChannel simIter++; } - if (settingsView.IsNavMeshInputTrigerred()) - { - // try (MemoryStack stack = StackPush()) { - // PointerBuffer aFilterPatterns = stack.MallocPointer(4); - // aFilterPatterns.Put(stack.UTF8("*.bin")); - // aFilterPatterns.Put(stack.UTF8("*.zip")); - // aFilterPatterns.Put(stack.UTF8("*.bytes")); - // aFilterPatterns.Put(stack.UTF8("*.navmesh")); - // aFilterPatterns.Flip(); - // string filename = TinyFileDialogs.Tinyfd_openFileDialog("Open Nav Mesh File", "", aFilterPatterns, - // "Nav Mesh File", false); - // if (filename != null) { - // File file = new File(filename); - // if (file.Exists()) { - // try { - // LoadNavMesh(file, filename); - // geom = null; - // } catch (Exception e) { - // Console.WriteLine(e); - // } - // } - // } - // } - } - if (!_mouseOverMenu) { GLU.GlhUnProjectf(mousePos[0], viewport[3] - 1 - mousePos[1], 0.0f, modelviewMatrix, projectionMatrix, viewport, ref rayStart); @@ -700,17 +675,25 @@ public class RecastDemo : IRecastDemoChannel private void OnMessage(IRecastDemoMessage message) { - if (message is SourceGeomFileSelectedEvent args) + if (message is GeomLoadBeganEvent args) { - OnSourceGeomFileSelected(args); + OnGeomLoadBegan(args); } - else if (message is NavMeshBuildEvent args2) + else if (message is NavMeshBuildBeganEvent args2) { - OnNavMeshBuild(args2); + OnNavMeshBuildBegan(args2); + } + else if (message is NavMeshSaveBeganEvent args3) + { + OnNavMeshSaveBegan(args3); + } + else if (message is NavMeshLoadBeganEvent args4) + { + OnNavMeshLoadBegan(args4); } } - private void OnSourceGeomFileSelected(SourceGeomFileSelectedEvent args) + private void OnGeomLoadBegan(GeomLoadBeganEvent args) { var bytes = Loader.ToBytes(args.FilePath); var geom = LoadInputMesh(bytes); @@ -718,7 +701,7 @@ public class RecastDemo : IRecastDemoChannel sample.Update(geom, ImmutableArray.Empty, null); } - private void OnNavMeshBuild(NavMeshBuildEvent args) + private void OnNavMeshBuildBegan(NavMeshBuildBeganEvent args) { if (null == sample.GetInputGeom()) { @@ -818,4 +801,34 @@ public class RecastDemo : IRecastDemoChannel Logger.Information($"{key}: {millis} ms"); } } + + private void OnNavMeshSaveBegan(NavMeshSaveBeganEvent args) + { + + } + + private void OnNavMeshLoadBegan(NavMeshLoadBeganEvent args) + { + // try (MemoryStack stack = StackPush()) { + // PointerBuffer aFilterPatterns = stack.MallocPointer(4); + // aFilterPatterns.Put(stack.UTF8("*.bin")); + // aFilterPatterns.Put(stack.UTF8("*.zip")); + // aFilterPatterns.Put(stack.UTF8("*.bytes")); + // aFilterPatterns.Put(stack.UTF8("*.navmesh")); + // aFilterPatterns.Flip(); + // string filename = TinyFileDialogs.Tinyfd_openFileDialog("Open Nav Mesh File", "", aFilterPatterns, + // "Nav Mesh File", false); + // if (filename != null) { + // File file = new File(filename); + // if (file.Exists()) { + // try { + // LoadNavMesh(file, filename); + // geom = null; + // } catch (Exception e) { + // Console.WriteLine(e); + // } + // } + // } + // } + } } \ 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 de28d83..0431c21 100644 --- a/src/DotRecast.Recast.Demo/UI/RcSettingsView.cs +++ b/src/DotRecast.Recast.Demo/UI/RcSettingsView.cs @@ -44,8 +44,6 @@ public class RcSettingsView : IRcView private int drawMode = DrawMode.DRAWMODE_NAVMESH.Idx; - private bool navMeshInputTrigerred; - private bool _isHovered; public bool IsHovered() => _isHovered; @@ -76,7 +74,7 @@ public class RcSettingsView : IRcView var settings = _sample.GetSettings(); ImGui.Begin("Properties"); - + // size reset var size = ImGui.GetItemRectSize(); if (32 >= size.X && 32 >= size.Y) @@ -104,7 +102,7 @@ public class RcSettingsView : IRcView var picker = ImFilePicker.GetFilePicker(strLoadSourceGeom, Path.Combine(Environment.CurrentDirectory), ".obj"); if (picker.Draw()) { - _channel.SendMessage(new SourceGeomFileSelectedEvent() + _channel.SendMessage(new GeomLoadBeganEvent() { FilePath = picker.SelectedFile, }); @@ -192,9 +190,9 @@ public class RcSettingsView : IRcView ImGui.Separator(); if (ImGui.Button("Build NavMesh")) { - _channel.SendMessage(new NavMeshBuildEvent()); + _channel.SendMessage(new NavMeshBuildBeganEvent()); } - + { const string strLoadNavMesh = "Load NavMesh"; if (ImGui.Button(strLoadNavMesh)) @@ -208,7 +206,10 @@ public class RcSettingsView : IRcView var picker = ImFilePicker.GetFilePicker(strLoadNavMesh, Path.Combine(Environment.CurrentDirectory)); if (picker.Draw()) { - Logger.Information(picker.SelectedFile); + _channel.SendMessage(new NavMeshLoadBeganEvent() + { + FilePath = picker.SelectedFile, + }); ImFilePicker.RemoveFilePicker(strLoadNavMesh); } @@ -216,12 +217,9 @@ public class RcSettingsView : IRcView } } + if (ImGui.Button("Save NavMesh")) { - const string strSaveNavMesh = "Save NavMesh"; - if (ImGui.Button(strSaveNavMesh)) - { - - } + _channel.SendMessage(new NavMeshSaveBeganEvent()); } @@ -267,9 +265,4 @@ public class RcSettingsView : IRcView { this.maxPolys = maxPolys; } - - public bool IsNavMeshInputTrigerred() - { - return navMeshInputTrigerred; - } } \ No newline at end of file