prepare tool <- control < view

This commit is contained in:
ikpil 2023-06-11 14:58:37 +09:00
parent 40229226dc
commit 5e1d4cd02a
13 changed files with 69 additions and 71 deletions

View File

@ -54,7 +54,7 @@ public class RecastDemo
private GL _gl; private GL _gl;
private IInputContext _input; private IInputContext _input;
private ImGuiController _imgui; private ImGuiController _imgui;
private RecastDemoCanvas _canvas; private RcCanvas _canvas;
private int width = 1000; private int width = 1000;
private int height = 900; private int height = 900;
@ -109,9 +109,9 @@ public class RecastDemo
private bool markerPositionSet; private bool markerPositionSet;
private RcVec3f markerPosition = new RcVec3f(); private RcVec3f markerPosition = new RcVec3f();
private ToolsView toolsUI; private RcToolsetView toolsetView;
private RcSettingsView settingsUI; private RcSettingsView settingsView;
private RcLogView logUI; private RcLogView logView;
private long prevFrameTime; private long prevFrameTime;
private RecastDebugDraw dd; private RecastDebugDraw dd;
@ -300,8 +300,8 @@ 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, settingsUI, dd); sample = new Sample(geom, ImmutableArray<RecastBuilderResult>.Empty, null, settingsView, dd);
toolsUI.SetEnabled(true); toolsetView.SetEnabled(true);
return geom; return geom;
} }
@ -325,7 +325,7 @@ public class RecastDemo
if (mesh != null) if (mesh != null)
{ {
//sample = new Sample(null, ImmutableArray<RecastBuilderResult>.Empty, mesh, settingsUI, dd); //sample = new Sample(null, ImmutableArray<RecastBuilderResult>.Empty, mesh, settingsUI, dd);
toolsUI.SetEnabled(true); toolsetView.SetEnabled(true);
} }
} }
@ -368,8 +368,8 @@ public class RecastDemo
_imgui = new ImGuiController(_gl, window, _input); _imgui = new ImGuiController(_gl, window, _input);
settingsUI = new RcSettingsView(); settingsView = new RcSettingsView();
toolsUI = new ToolsView( toolsetView = new RcToolsetView(
new TestNavmeshTool(), new TestNavmeshTool(),
new OffMeshConnectionTool(), new OffMeshConnectionTool(),
new ConvexVolumeTool(), new ConvexVolumeTool(),
@ -377,9 +377,9 @@ public class RecastDemo
new JumpLinkBuilderTool(), new JumpLinkBuilderTool(),
new DynamicUpdateTool() new DynamicUpdateTool()
); );
logUI = new RcLogView(); logView = new RcLogView();
_canvas = new RecastDemoCanvas(window, settingsUI, toolsUI, logUI); _canvas = new RcCanvas(window, settingsView, toolsetView, logView);
var vendor = _gl.GetStringS(GLEnum.Vendor); var vendor = _gl.GetStringS(GLEnum.Vendor);
var version = _gl.GetStringS(GLEnum.Version); var version = _gl.GetStringS(GLEnum.Version);
@ -395,7 +395,7 @@ public class RecastDemo
DemoInputGeomProvider geom = LoadInputMesh(Loader.ToBytes("nav_test.obj")); DemoInputGeomProvider geom = LoadInputMesh(Loader.ToBytes("nav_test.obj"));
sample = new Sample(geom, ImmutableArray<RecastBuilderResult>.Empty, null, settingsUI, dd); sample = new Sample(geom, ImmutableArray<RecastBuilderResult>.Empty, null, settingsView, dd);
} }
private void UpdateKeyboard(float dt) private void UpdateKeyboard(float dt)
@ -432,11 +432,11 @@ public class RecastDemo
{ {
RcVec3f bmin = sample.GetInputGeom().GetMeshBoundsMin(); RcVec3f bmin = sample.GetInputGeom().GetMeshBoundsMin();
RcVec3f bmax = sample.GetInputGeom().GetMeshBoundsMax(); RcVec3f bmax = sample.GetInputGeom().GetMeshBoundsMax();
Recast.CalcGridSize(bmin, bmax, settingsUI.GetCellSize(), out var gw, out var gh); Recast.CalcGridSize(bmin, bmax, settingsView.GetCellSize(), out var gw, out var gh);
settingsUI.SetVoxels(gw, gh); settingsView.SetVoxels(gw, gh);
settingsUI.SetTiles(tileNavMeshBuilder.GetTiles(sample.GetInputGeom(), settingsUI.GetCellSize(), settingsUI.GetTileSize())); settingsView.SetTiles(tileNavMeshBuilder.GetTiles(sample.GetInputGeom(), settingsView.GetCellSize(), settingsView.GetTileSize()));
settingsUI.SetMaxTiles(tileNavMeshBuilder.GetMaxTiles(sample.GetInputGeom(), settingsUI.GetCellSize(), settingsUI.GetTileSize())); settingsView.SetMaxTiles(tileNavMeshBuilder.GetMaxTiles(sample.GetInputGeom(), settingsView.GetCellSize(), settingsView.GetTileSize()));
settingsUI.SetMaxPolys(tileNavMeshBuilder.GetMaxPolysPerTile(sample.GetInputGeom(), settingsUI.GetCellSize(), settingsUI.GetTileSize())); settingsView.SetMaxPolys(tileNavMeshBuilder.GetMaxPolysPerTile(sample.GetInputGeom(), settingsView.GetCellSize(), settingsView.GetTileSize()));
} }
UpdateKeyboard((float)dt); UpdateKeyboard((float)dt);
@ -475,18 +475,18 @@ public class RecastDemo
timeAcc -= DELTA_TIME; timeAcc -= DELTA_TIME;
if (simIter < 5 && sample != null) if (simIter < 5 && sample != null)
{ {
toolsUI.HandleUpdate(DELTA_TIME); toolsetView.HandleUpdate(DELTA_TIME);
} }
simIter++; simIter++;
} }
if (settingsUI.IsMeshInputTrigerred()) if (settingsView.IsMeshInputTrigerred())
{ {
var bytes = Loader.ToBytes(settingsUI.GetMeshInputFilePath()); var bytes = Loader.ToBytes(settingsView.GetMeshInputFilePath());
sample.Update(LoadInputMesh(bytes), null, null); sample.Update(LoadInputMesh(bytes), null, null);
} }
else if (settingsUI.IsNavMeshInputTrigerred()) else if (settingsView.IsNavMeshInputTrigerred())
{ {
// try (MemoryStack stack = StackPush()) { // try (MemoryStack stack = StackPush()) {
// PointerBuffer aFilterPatterns = stack.MallocPointer(4); // PointerBuffer aFilterPatterns = stack.MallocPointer(4);
@ -511,51 +511,51 @@ public class RecastDemo
// } // }
} }
if (settingsUI.IsBuildTriggered() && sample.GetInputGeom() != null) if (settingsView.IsBuildTriggered() && sample.GetInputGeom() != null)
{ {
if (!building) if (!building)
{ {
float m_cellSize = settingsUI.GetCellSize(); float m_cellSize = settingsView.GetCellSize();
float m_cellHeight = settingsUI.GetCellHeight(); float m_cellHeight = settingsView.GetCellHeight();
float m_agentHeight = settingsUI.GetAgentHeight(); float m_agentHeight = settingsView.GetAgentHeight();
float m_agentRadius = settingsUI.GetAgentRadius(); float m_agentRadius = settingsView.GetAgentRadius();
float m_agentMaxClimb = settingsUI.GetAgentMaxClimb(); float m_agentMaxClimb = settingsView.GetAgentMaxClimb();
float m_agentMaxSlope = settingsUI.GetAgentMaxSlope(); float m_agentMaxSlope = settingsView.GetAgentMaxSlope();
int m_regionMinSize = settingsUI.GetMinRegionSize(); int m_regionMinSize = settingsView.GetMinRegionSize();
int m_regionMergeSize = settingsUI.GetMergedRegionSize(); int m_regionMergeSize = settingsView.GetMergedRegionSize();
float m_edgeMaxLen = settingsUI.GetEdgeMaxLen(); float m_edgeMaxLen = settingsView.GetEdgeMaxLen();
float m_edgeMaxError = settingsUI.GetEdgeMaxError(); float m_edgeMaxError = settingsView.GetEdgeMaxError();
int m_vertsPerPoly = settingsUI.GetVertsPerPoly(); int m_vertsPerPoly = settingsView.GetVertsPerPoly();
float m_detailSampleDist = settingsUI.GetDetailSampleDist(); float m_detailSampleDist = settingsView.GetDetailSampleDist();
float m_detailSampleMaxError = settingsUI.GetDetailSampleMaxError(); float m_detailSampleMaxError = settingsView.GetDetailSampleMaxError();
int m_tileSize = settingsUI.GetTileSize(); int m_tileSize = settingsView.GetTileSize();
long t = RcFrequency.Ticks; long t = RcFrequency.Ticks;
Logger.Information($"build"); Logger.Information($"build");
Tuple<IList<RecastBuilderResult>, DtNavMesh> buildResult; Tuple<IList<RecastBuilderResult>, DtNavMesh> buildResult;
if (settingsUI.IsTiled()) if (settingsView.IsTiled())
{ {
buildResult = tileNavMeshBuilder.Build(sample.GetInputGeom(), settingsUI.GetPartitioning(), m_cellSize, buildResult = tileNavMeshBuilder.Build(sample.GetInputGeom(), settingsView.GetPartitioning(), m_cellSize,
m_cellHeight, m_agentHeight, m_agentRadius, m_agentMaxClimb, m_agentMaxSlope, m_regionMinSize, m_cellHeight, m_agentHeight, m_agentRadius, m_agentMaxClimb, m_agentMaxSlope, m_regionMinSize,
m_regionMergeSize, m_edgeMaxLen, m_edgeMaxError, m_vertsPerPoly, m_detailSampleDist, m_regionMergeSize, m_edgeMaxLen, m_edgeMaxError, m_vertsPerPoly, m_detailSampleDist,
m_detailSampleMaxError, settingsUI.IsFilterLowHangingObstacles(), settingsUI.IsFilterLedgeSpans(), m_detailSampleMaxError, settingsView.IsFilterLowHangingObstacles(), settingsView.IsFilterLedgeSpans(),
settingsUI.IsFilterWalkableLowHeightSpans(), m_tileSize); settingsView.IsFilterWalkableLowHeightSpans(), m_tileSize);
} }
else else
{ {
buildResult = soloNavMeshBuilder.Build(sample.GetInputGeom(), settingsUI.GetPartitioning(), m_cellSize, buildResult = soloNavMeshBuilder.Build(sample.GetInputGeom(), settingsView.GetPartitioning(), m_cellSize,
m_cellHeight, m_agentHeight, m_agentRadius, m_agentMaxClimb, m_agentMaxSlope, m_regionMinSize, m_cellHeight, m_agentHeight, m_agentRadius, m_agentMaxClimb, m_agentMaxSlope, m_regionMinSize,
m_regionMergeSize, m_edgeMaxLen, m_edgeMaxError, m_vertsPerPoly, m_detailSampleDist, m_regionMergeSize, m_edgeMaxLen, m_edgeMaxError, m_vertsPerPoly, m_detailSampleDist,
m_detailSampleMaxError, settingsUI.IsFilterLowHangingObstacles(), settingsUI.IsFilterLedgeSpans(), m_detailSampleMaxError, settingsView.IsFilterLowHangingObstacles(), settingsView.IsFilterLedgeSpans(),
settingsUI.IsFilterWalkableLowHeightSpans()); settingsView.IsFilterWalkableLowHeightSpans());
} }
sample.Update(sample.GetInputGeom(), buildResult.Item1, buildResult.Item2); sample.Update(sample.GetInputGeom(), buildResult.Item1, buildResult.Item2);
sample.SetChanged(false); sample.SetChanged(false);
settingsUI.SetBuildTime((RcFrequency.Ticks - t) / TimeSpan.TicksPerMillisecond); settingsView.SetBuildTime((RcFrequency.Ticks - t) / TimeSpan.TicksPerMillisecond);
//settingsUI.SetBuildTelemetry(buildResult.Item1.Select(x => x.GetTelemetry()).ToList()); //settingsUI.SetBuildTelemetry(buildResult.Item1.Select(x => x.GetTelemetry()).ToList());
toolsUI.SetSample(sample); toolsetView.SetSample(sample);
Logger.Information($"build times"); Logger.Information($"build times");
Logger.Information($"-----------------------------------------"); Logger.Information($"-----------------------------------------");
@ -602,7 +602,7 @@ public class RecastDemo
} }
RcVec3f rayDir = RcVec3f.Of(rayEnd.x - rayStart.x, rayEnd.y - rayStart.y, rayEnd.z - rayStart.z); RcVec3f rayDir = RcVec3f.Of(rayEnd.x - rayStart.x, rayEnd.y - rayStart.y, rayEnd.z - rayStart.z);
ITool rayTool = toolsUI.GetTool(); IRcTool rayTool = toolsetView.GetTool();
rayDir.Normalize(); rayDir.Normalize();
if (rayTool != null) if (rayTool != null)
{ {
@ -704,7 +704,7 @@ public class RecastDemo
} }
sample.SetChanged(false); sample.SetChanged(false);
toolsUI.SetSample(sample); toolsetView.SetSample(sample);
} }
@ -727,7 +727,7 @@ public class RecastDemo
dd.Fog(camr * 0.1f, camr * 1.25f); dd.Fog(camr * 0.1f, camr * 1.25f);
renderer.Render(sample); renderer.Render(sample);
ITool tool = toolsUI.GetTool(); IRcTool tool = toolsetView.GetTool();
if (tool != null) if (tool != null)
{ {
tool.HandleRender(renderer); tool.HandleRender(renderer);

View File

@ -30,7 +30,7 @@ using static DotRecast.Recast.Demo.Draw.DebugDrawPrimitives;
namespace DotRecast.Recast.Demo.Tools; namespace DotRecast.Recast.Demo.Tools;
public class ConvexVolumeTool : ITool public class ConvexVolumeTool : IRcTool
{ {
private Sample sample; private Sample sample;
private int areaTypeValue = SampleAreaModifications.SAMPLE_AREAMOD_GRASS.Value; private int areaTypeValue = SampleAreaModifications.SAMPLE_AREAMOD_GRASS.Value;

View File

@ -34,7 +34,7 @@ using static DotRecast.Recast.Demo.Draw.DebugDrawPrimitives;
namespace DotRecast.Recast.Demo.Tools; namespace DotRecast.Recast.Demo.Tools;
public class CrowdTool : ITool public class CrowdTool : IRcTool
{ {
private readonly CrowdToolParams toolParams = new CrowdToolParams(); private readonly CrowdToolParams toolParams = new CrowdToolParams();
private Sample sample; private Sample sample;

View File

@ -37,7 +37,7 @@ using static DotRecast.Recast.Demo.Draw.DebugDrawPrimitives;
namespace DotRecast.Recast.Demo.Tools; namespace DotRecast.Recast.Demo.Tools;
public class DynamicUpdateTool : ITool public class DynamicUpdateTool : IRcTool
{ {
private Sample sample; private Sample sample;
private int toolModeIdx = DynamicUpdateToolMode.BUILD.Idx; private int toolModeIdx = DynamicUpdateToolMode.BUILD.Idx;

View File

@ -23,7 +23,7 @@ using DotRecast.Recast.Demo.Draw;
namespace DotRecast.Recast.Demo.Tools; namespace DotRecast.Recast.Demo.Tools;
public interface ITool public interface IRcTool
{ {
string GetName(); string GetName();
void Layout(); void Layout();

View File

@ -29,7 +29,7 @@ using static DotRecast.Recast.Demo.Draw.DebugDrawPrimitives;
namespace DotRecast.Recast.Demo.Tools; namespace DotRecast.Recast.Demo.Tools;
public class JumpLinkBuilderTool : ITool public class JumpLinkBuilderTool : IRcTool
{ {
private readonly List<JumpLink> links = new(); private readonly List<JumpLink> links = new();
private Sample sample; private Sample sample;

View File

@ -28,7 +28,7 @@ using static DotRecast.Recast.Demo.Draw.DebugDraw;
namespace DotRecast.Recast.Demo.Tools; namespace DotRecast.Recast.Demo.Tools;
public class OffMeshConnectionTool : ITool public class OffMeshConnectionTool : IRcTool
{ {
private Sample sample; private Sample sample;
private bool hitPosSet; private bool hitPosSet;

View File

@ -12,7 +12,7 @@ using static DotRecast.Recast.Demo.Draw.DebugDrawPrimitives;
namespace DotRecast.Recast.Demo.Tools; namespace DotRecast.Recast.Demo.Tools;
public class TestNavmeshTool : ITool public class TestNavmeshTool : IRcTool
{ {
private const int MAX_POLYS = 256; private const int MAX_POLYS = 256;
private const int MAX_SMOOTH = 2048; private const int MAX_SMOOTH = 2048;

View File

@ -20,7 +20,7 @@ namespace DotRecast.Recast.Demo.UI;
public interface IRcView public interface IRcView
{ {
void Bind(RecastDemoCanvas canvas); void Bind(RcCanvas canvas);
bool IsMouseInside(); bool IsMouseInside();
void Update(double dt); void Update(double dt);
void Draw(double dt); void Draw(double dt);

View File

@ -27,7 +27,7 @@ using Silk.NET.Windowing;
namespace DotRecast.Recast.Demo.UI; namespace DotRecast.Recast.Demo.UI;
public class RecastDemoCanvas public class RcCanvas
{ {
private static readonly ILogger Logger = Log.ForContext<RecastDemo>(); private static readonly ILogger Logger = Log.ForContext<RecastDemo>();
@ -38,7 +38,7 @@ public class RecastDemoCanvas
public Vector2D<int> Size => _window.Size; public Vector2D<int> Size => _window.Size;
public RecastDemoCanvas(IWindow window, params IRcView[] views) public RcCanvas(IWindow window, params IRcView[] views)
{ {
_window = window; _window = window;
_views = views; _views = views;

View File

@ -13,7 +13,7 @@ namespace DotRecast.Recast.Demo.UI;
public class RcLogView : IRcView public class RcLogView : IRcView
{ {
private RecastDemoCanvas _canvas; private RcCanvas _canvas;
private bool _mouseInside; private bool _mouseInside;
private readonly List<LogMessageItem> _lines; private readonly List<LogMessageItem> _lines;
@ -42,7 +42,7 @@ public class RcLogView : IRcView
_lines.Clear(); _lines.Clear();
} }
public void Bind(RecastDemoCanvas canvas) public void Bind(RcCanvas canvas)
{ {
_canvas = canvas; _canvas = canvas;
} }

View File

@ -23,9 +23,7 @@ using System.Linq;
using System.Numerics; using System.Numerics;
using DotRecast.Core; using DotRecast.Core;
using DotRecast.Recast.Demo.Draw; using DotRecast.Recast.Demo.Draw;
using DotRecast.Recast.Demo.UI;
using ImGuiNET; using ImGuiNET;
using Silk.NET.Windowing;
namespace DotRecast.Recast.Demo.UI; namespace DotRecast.Recast.Demo.UI;
@ -78,9 +76,9 @@ public class RcSettingsView : IRcView
private bool _mouseInside; private bool _mouseInside;
public bool IsMouseInside() => _mouseInside; public bool IsMouseInside() => _mouseInside;
private RecastDemoCanvas _canvas; private RcCanvas _canvas;
public void Bind(RecastDemoCanvas canvas) public void Bind(RcCanvas canvas)
{ {
_canvas = canvas; _canvas = canvas;
} }

View File

@ -26,24 +26,24 @@ using ImGuiNET;
namespace DotRecast.Recast.Demo.UI; namespace DotRecast.Recast.Demo.UI;
public class ToolsView : IRcView public class RcToolsetView : IRcView
{ {
//private readonly NkColor white = NkColor.Create(); //private readonly NkColor white = NkColor.Create();
private int _currentToolIdx = 0; private int _currentToolIdx = 0;
private ITool currentTool; private IRcTool currentTool;
private bool enabled; private bool enabled;
private readonly ITool[] tools; private readonly IRcTool[] tools;
private bool _mouseInside; private bool _mouseInside;
public bool IsMouseInside() => _mouseInside; public bool IsMouseInside() => _mouseInside;
private RecastDemoCanvas _canvas; private RcCanvas _canvas;
public ToolsView(params ITool[] tools) public RcToolsetView(params IRcTool[] tools)
{ {
this.tools = tools; this.tools = tools;
} }
public void Bind(RecastDemoCanvas canvas) public void Bind(RcCanvas canvas)
{ {
_canvas = canvas; _canvas = canvas;
} }
@ -87,7 +87,7 @@ public class ToolsView : IRcView
this.enabled = enabled; this.enabled = enabled;
} }
public ITool GetTool() public IRcTool GetTool()
{ {
return currentTool; return currentTool;
} }