forked from bit/DotRecastNetSim
add recast demo message
This commit is contained in:
parent
a6b1cc1d5a
commit
5335c133e9
|
@ -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
|
||||
|
|
|
@ -0,0 +1,6 @@
|
|||
namespace DotRecast.Recast.Demo.Messages;
|
||||
|
||||
public interface IRecastDemoChannel
|
||||
{
|
||||
void SendMessage(IRecastDemoMessage message);
|
||||
}
|
|
@ -0,0 +1,6 @@
|
|||
namespace DotRecast.Recast.Demo.Messages;
|
||||
|
||||
public class IRecastDemoMessage
|
||||
{
|
||||
|
||||
}
|
|
@ -0,0 +1,6 @@
|
|||
namespace DotRecast.Recast.Demo.Messages;
|
||||
|
||||
public class SourceGeomSelected : IRecastDemoMessage
|
||||
{
|
||||
public required string FilePath { get; init; }
|
||||
}
|
|
@ -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<RecastDemo>();
|
||||
|
||||
|
@ -117,9 +118,11 @@ public class RecastDemo
|
|||
|
||||
private long prevFrameTime;
|
||||
private RecastDebugDraw dd;
|
||||
private Queue<IRecastDemoMessage> _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<RecastBuilderResult>.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<RecastBuilderResult>.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<RecastBuilderResult>.Empty, null);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -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<RecastDemo>();
|
||||
private static readonly ILogger Logger = Log.ForContext<RcSettingsView>();
|
||||
|
||||
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,8 +191,9 @@ public class RcSettingsView : IRcView
|
|||
ImGui.Text($"Build Time: {buildTime} ms");
|
||||
|
||||
ImGui.Separator();
|
||||
buildTriggered = ImGui.Button("Build Nav Mesh");
|
||||
const string strLoadNavMesh = "Load Nav Mesh...";
|
||||
buildTriggered = ImGui.Button("Build NavMesh");
|
||||
{
|
||||
const string strLoadNavMesh = "Load NavMesh";
|
||||
if (ImGui.Button(strLoadNavMesh))
|
||||
{
|
||||
ImGui.OpenPopup(strLoadNavMesh);
|
||||
|
@ -205,12 +205,22 @@ public class RcSettingsView : IRcView
|
|||
var picker = ImFilePicker.GetFilePicker(strLoadNavMesh, Path.Combine(Environment.CurrentDirectory));
|
||||
if (picker.Draw())
|
||||
{
|
||||
Console.WriteLine(picker.SelectedFile);
|
||||
Logger.Information(picker.SelectedFile);
|
||||
ImFilePicker.RemoveFilePicker(strLoadNavMesh);
|
||||
}
|
||||
|
||||
ImGui.EndPopup();
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
const string strSaveNavMesh = "Save NavMesh";
|
||||
if (ImGui.Button(strSaveNavMesh))
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
ImGui.NewLine();
|
||||
|
||||
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Reference in New Issue