prepare model <- vm or ctrl <- view

This commit is contained in:
ikpil 2023-06-09 00:06:04 +09:00
parent 474ca92c1c
commit fc553e2753
10 changed files with 89 additions and 68 deletions

View File

@ -304,4 +304,4 @@ public class NavMeshRenderer
debugDraw.DepthMask(true); debugDraw.DepthMask(true);
} }
} }

View File

@ -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);
Tool rayTool = toolsUI.GetTool(); ITool rayTool = toolsUI.GetTool();
rayDir.Normalize(); rayDir.Normalize();
if (rayTool != null) if (rayTool != null)
{ {
@ -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);
Tool tool = toolsUI.GetTool(); ITool tool = toolsUI.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 : Tool public class ConvexVolumeTool : ITool
{ {
private Sample sample; private Sample sample;
private int areaTypeValue = SampleAreaModifications.SAMPLE_AREAMOD_GRASS.Value; private int areaTypeValue = SampleAreaModifications.SAMPLE_AREAMOD_GRASS.Value;
@ -41,12 +41,12 @@ public class ConvexVolumeTool : Tool
private readonly List<float> pts = new(); private readonly List<float> pts = new();
private readonly List<int> hull = new(); private readonly List<int> hull = new();
public override void SetSample(Sample m_sample) public void SetSample(Sample m_sample)
{ {
sample = m_sample; sample = m_sample;
} }
public override void HandleClick(RcVec3f s, RcVec3f p, bool shift) public void HandleClick(RcVec3f s, RcVec3f p, bool shift)
{ {
DemoInputGeomProvider geom = sample.GetInputGeom(); DemoInputGeomProvider geom = sample.GetInputGeom();
if (geom == null) if (geom == null)
@ -139,7 +139,7 @@ public class ConvexVolumeTool : Tool
} }
} }
public override void HandleRender(NavMeshRenderer renderer) public void HandleRender(NavMeshRenderer renderer)
{ {
RecastDebugDraw dd = renderer.GetDebugDraw(); RecastDebugDraw dd = renderer.GetDebugDraw();
// Find height extent of the shape. // Find height extent of the shape.
@ -182,7 +182,7 @@ public class ConvexVolumeTool : Tool
dd.End(); dd.End();
} }
public override void Layout() public void Layout()
{ {
ImGui.SliderFloat("Shape Height", ref boxHeight, 0.1f, 20f, "%.1f"); ImGui.SliderFloat("Shape Height", ref boxHeight, 0.1f, 20f, "%.1f");
ImGui.SliderFloat("Shape Descent", ref boxDescent, 0.1f, 20f, "%.1f"); ImGui.SliderFloat("Shape Descent", ref boxDescent, 0.1f, 20f, "%.1f");
@ -224,13 +224,19 @@ public class ConvexVolumeTool : Tool
} }
} }
public override string GetName() public string GetName()
{ {
return "Create Convex Volumes"; return "Create Convex Volumes";
} }
public override void HandleUpdate(float dt) public void HandleUpdate(float dt)
{ {
// TODO Auto-generated method stub // TODO Auto-generated method stub
} }
public void HandleClickRay(RcVec3f start, RcVec3f direction, bool shift)
{
}
} }

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 : Tool public class CrowdTool : ITool
{ {
private readonly CrowdToolParams toolParams = new CrowdToolParams(); private readonly CrowdToolParams toolParams = new CrowdToolParams();
private Sample sample; private Sample sample;
@ -56,7 +56,7 @@ public class CrowdTool : Tool
profilingTool = new CrowdProfilingTool(GetAgentParams); profilingTool = new CrowdProfilingTool(GetAgentParams);
} }
public override void SetSample(Sample psample) public void SetSample(Sample psample)
{ {
if (sample != psample) if (sample != psample)
{ {
@ -111,7 +111,7 @@ public class CrowdTool : Tool
} }
} }
public override void HandleClick(RcVec3f s, RcVec3f p, bool shift) public void HandleClick(RcVec3f s, RcVec3f p, bool shift)
{ {
if (m_mode == CrowdToolMode.PROFILING) if (m_mode == CrowdToolMode.PROFILING)
{ {
@ -313,7 +313,7 @@ public class CrowdTool : Tool
return vel.Scale(speed); return vel.Scale(speed);
} }
public override void HandleRender(NavMeshRenderer renderer) public void HandleRender(NavMeshRenderer renderer)
{ {
if (m_mode == CrowdToolMode.PROFILING) if (m_mode == CrowdToolMode.PROFILING)
{ {
@ -620,7 +620,7 @@ public class CrowdTool : Tool
dd.DepthMask(true); dd.DepthMask(true);
} }
public override void HandleUpdate(float dt) public void HandleUpdate(float dt)
{ {
UpdateTick(dt); UpdateTick(dt);
} }
@ -665,7 +665,7 @@ public class CrowdTool : Tool
m_agentDebug.agent = agent; m_agentDebug.agent = agent;
} }
public override void Layout() public void Layout()
{ {
ImGui.Text($"Crowd Tool Mode"); ImGui.Text($"Crowd Tool Mode");
ImGui.Separator(); ImGui.Separator();
@ -794,8 +794,14 @@ public class CrowdTool : Tool
return updateFlags; return updateFlags;
} }
public override string GetName() public string GetName()
{ {
return "Crowd"; return "Crowd";
} }
public void HandleClickRay(RcVec3f start, RcVec3f direction, bool shift)
{
}
} }

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 : Tool public class DynamicUpdateTool : ITool
{ {
private Sample sample; private Sample sample;
private int toolModeIdx = DynamicUpdateToolMode.BUILD.Idx; private int toolModeIdx = DynamicUpdateToolMode.BUILD.Idx;
@ -92,12 +92,12 @@ public class DynamicUpdateTool : Tool
convexGeom = DemoObjImporter.Load(Loader.ToBytes("convex.obj")); convexGeom = DemoObjImporter.Load(Loader.ToBytes("convex.obj"));
} }
public override void SetSample(Sample sample) public void SetSample(Sample sample)
{ {
this.sample = sample; this.sample = sample;
} }
public override void HandleClick(RcVec3f s, RcVec3f p, bool shift) public void HandleClick(RcVec3f s, RcVec3f p, bool shift)
{ {
if (mode == DynamicUpdateToolMode.COLLIDERS) if (mode == DynamicUpdateToolMode.COLLIDERS)
{ {
@ -342,7 +342,7 @@ public class DynamicUpdateTool : Tool
} }
public override void HandleClickRay(RcVec3f start, RcVec3f dir, bool shift) public void HandleClickRay(RcVec3f start, RcVec3f dir, bool shift)
{ {
if (mode == DynamicUpdateToolMode.COLLIDERS) if (mode == DynamicUpdateToolMode.COLLIDERS)
{ {
@ -390,7 +390,7 @@ public class DynamicUpdateTool : Tool
return disc >= 0.0f; return disc >= 0.0f;
} }
public override void HandleRender(NavMeshRenderer renderer) public void HandleRender(NavMeshRenderer renderer)
{ {
if (mode == DynamicUpdateToolMode.COLLIDERS) if (mode == DynamicUpdateToolMode.COLLIDERS)
{ {
@ -450,7 +450,7 @@ public class DynamicUpdateTool : Tool
dd.DepthMask(true); dd.DepthMask(true);
} }
public override void HandleUpdate(float dt) public void HandleUpdate(float dt)
{ {
if (dynaMesh != null) if (dynaMesh != null)
{ {
@ -477,7 +477,7 @@ public class DynamicUpdateTool : Tool
} }
} }
public override void Layout() public void Layout()
{ {
ImGui.Text($"Dynamic Update Tool Modes"); ImGui.Text($"Dynamic Update Tool Modes");
ImGui.Separator(); ImGui.Separator();
@ -744,7 +744,7 @@ public class DynamicUpdateTool : Tool
filterWalkableLowHeightSpans = dynaMesh.config.filterWalkableLowHeightSpans; filterWalkableLowHeightSpans = dynaMesh.config.filterWalkableLowHeightSpans;
} }
public override string GetName() public string GetName()
{ {
return "Dynamic Updates"; return "Dynamic Updates";
} }

View File

@ -23,21 +23,18 @@ using DotRecast.Recast.Demo.Draw;
namespace DotRecast.Recast.Demo.Tools; namespace DotRecast.Recast.Demo.Tools;
public abstract class Tool public interface ITool
{ {
public abstract string GetName(); string GetName();
public abstract void Layout(); void Layout();
public abstract void SetSample(Sample m_sample); void SetSample(Sample m_sample);
public abstract void HandleClick(RcVec3f s, RcVec3f p, bool shift); void HandleClick(RcVec3f s, RcVec3f p, bool shift);
public abstract void HandleRender(NavMeshRenderer renderer); void HandleRender(NavMeshRenderer renderer);
public abstract void HandleUpdate(float dt); void HandleUpdate(float dt);
public virtual void HandleClickRay(RcVec3f start, RcVec3f direction, bool shift) void HandleClickRay(RcVec3f start, RcVec3f direction, bool shift);
{
// ...
}
} }

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 : Tool public class JumpLinkBuilderTool : ITool
{ {
private readonly List<JumpLink> links = new(); private readonly List<JumpLink> links = new();
private Sample sample; private Sample sample;
@ -37,17 +37,17 @@ public class JumpLinkBuilderTool : Tool
private readonly int selEdge = -1; private readonly int selEdge = -1;
private readonly JumpLinkBuilderToolParams option = new JumpLinkBuilderToolParams(); private readonly JumpLinkBuilderToolParams option = new JumpLinkBuilderToolParams();
public override void SetSample(Sample sample) public void SetSample(Sample sample)
{ {
this.sample = sample; this.sample = sample;
annotationBuilder = null; annotationBuilder = null;
} }
public override void HandleClick(RcVec3f s, RcVec3f p, bool shift) public void HandleClick(RcVec3f s, RcVec3f p, bool shift)
{ {
} }
public override void HandleRender(NavMeshRenderer renderer) public void HandleRender(NavMeshRenderer renderer)
{ {
int col0 = DuLerpCol(DuRGBA(32, 255, 96, 255), DuRGBA(255, 255, 255, 255), 200); int col0 = DuLerpCol(DuRGBA(32, 255, 96, 255), DuRGBA(255, 255, 255, 255), 200);
int col1 = DuRGBA(32, 255, 96, 255); int col1 = DuRGBA(32, 255, 96, 255);
@ -318,11 +318,11 @@ public class JumpLinkBuilderTool : Tool
{ {
} }
public override void HandleUpdate(float dt) public void HandleUpdate(float dt)
{ {
} }
public override void Layout() public void Layout()
{ {
if (0 >= sample.GetRecastResults().Count) if (0 >= sample.GetRecastResults().Count)
return; return;
@ -442,8 +442,12 @@ public class JumpLinkBuilderTool : Tool
} }
} }
public override string GetName() public string GetName()
{ {
return "Annotation Builder"; return "Annotation Builder";
} }
}
public void HandleClickRay(RcVec3f start, RcVec3f direction, bool shift)
{
}
}

View File

@ -28,19 +28,19 @@ using static DotRecast.Recast.Demo.Draw.DebugDraw;
namespace DotRecast.Recast.Demo.Tools; namespace DotRecast.Recast.Demo.Tools;
public class OffMeshConnectionTool : Tool public class OffMeshConnectionTool : ITool
{ {
private Sample sample; private Sample sample;
private bool hitPosSet; private bool hitPosSet;
private RcVec3f hitPos; private RcVec3f hitPos;
private int bidir; private int bidir;
public override void SetSample(Sample m_sample) public void SetSample(Sample m_sample)
{ {
sample = m_sample; sample = m_sample;
} }
public override void HandleClick(RcVec3f s, RcVec3f p, bool shift) public void HandleClick(RcVec3f s, RcVec3f p, bool shift)
{ {
DemoInputGeomProvider geom = sample.GetInputGeom(); DemoInputGeomProvider geom = sample.GetInputGeom();
if (geom == null) if (geom == null)
@ -87,7 +87,7 @@ public class OffMeshConnectionTool : Tool
} }
} }
public override void HandleRender(NavMeshRenderer renderer) public void HandleRender(NavMeshRenderer renderer)
{ {
if (sample == null) if (sample == null)
{ {
@ -109,19 +109,25 @@ public class OffMeshConnectionTool : Tool
} }
} }
public override void Layout() public void Layout()
{ {
ImGui.RadioButton("One Way", ref bidir, 0); ImGui.RadioButton("One Way", ref bidir, 0);
ImGui.RadioButton("Bidirectional", ref bidir, 1); ImGui.RadioButton("Bidirectional", ref bidir, 1);
} }
public override string GetName() public string GetName()
{ {
return "Create Off-Mesh Links"; return "Create Off-Mesh Links";
} }
public override void HandleUpdate(float dt) public void HandleUpdate(float dt)
{ {
// TODO Auto-generated method stub // TODO Auto-generated method stub
} }
public void HandleClickRay(RcVec3f start, RcVec3f direction, bool shift)
{
}
} }

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 : Tool public class TestNavmeshTool : ITool
{ {
private const int MAX_POLYS = 256; private const int MAX_POLYS = 256;
private const int MAX_SMOOTH = 2048; private const int MAX_SMOOTH = 2048;
@ -54,12 +54,12 @@ public class TestNavmeshTool : Tool
SampleAreaModifications.SAMPLE_POLYFLAGS_DISABLED, new float[] { 1f, 1f, 1f, 1f, 2f, 1.5f }); SampleAreaModifications.SAMPLE_POLYFLAGS_DISABLED, new float[] { 1f, 1f, 1f, 1f, 2f, 1.5f });
} }
public override void SetSample(Sample m_sample) public void SetSample(Sample m_sample)
{ {
this.m_sample = m_sample; this.m_sample = m_sample;
} }
public override void HandleClick(RcVec3f s, RcVec3f p, bool shift) public void HandleClick(RcVec3f s, RcVec3f p, bool shift)
{ {
if (shift) if (shift)
{ {
@ -75,7 +75,7 @@ public class TestNavmeshTool : Tool
Recalc(); Recalc();
} }
public override void Layout() public void Layout()
{ {
var previousToolMode = m_toolMode; var previousToolMode = m_toolMode;
int previousStraightPathOptions = m_straightPathOptions; int previousStraightPathOptions = m_straightPathOptions;
@ -153,7 +153,7 @@ public class TestNavmeshTool : Tool
} }
} }
public override string GetName() public string GetName()
{ {
return "Test Navmesh"; return "Test Navmesh";
} }
@ -505,7 +505,7 @@ public class TestNavmeshTool : Tool
} }
} }
public override void HandleRender(NavMeshRenderer renderer) public void HandleRender(NavMeshRenderer renderer)
{ {
if (m_sample == null) if (m_sample == null)
{ {
@ -973,7 +973,7 @@ public class TestNavmeshTool : Tool
return center; return center;
} }
public override void HandleUpdate(float dt) public void HandleUpdate(float dt)
{ {
// TODO Auto-generated method stub // TODO Auto-generated method stub
if (m_toolMode == TestNavmeshToolMode.PATHFIND_SLICED) if (m_toolMode == TestNavmeshToolMode.PATHFIND_SLICED)
@ -1017,4 +1017,8 @@ public class TestNavmeshTool : Tool
} }
} }
} }
public void HandleClickRay(RcVec3f start, RcVec3f direction, bool shift)
{
}
} }

View File

@ -30,20 +30,19 @@ public class ToolsView : IRcView
{ {
//private readonly NkColor white = NkColor.Create(); //private readonly NkColor white = NkColor.Create();
private int _currentToolIdx = 0; private int _currentToolIdx = 0;
private Tool currentTool; private ITool currentTool;
private bool enabled; private bool enabled;
private readonly Tool[] tools; private readonly ITool[] tools;
public ToolsView(params Tool[] tools)
{
this.tools = tools;
}
private bool _mouseInside; private bool _mouseInside;
public bool IsMouseInside() => _mouseInside; public bool IsMouseInside() => _mouseInside;
private RecastDemoCanvas _canvas; private RecastDemoCanvas _canvas;
public ToolsView(params ITool[] tools)
{
this.tools = tools;
}
public void Bind(RecastDemoCanvas canvas) public void Bind(RecastDemoCanvas canvas)
{ {
_canvas = canvas; _canvas = canvas;
@ -51,7 +50,6 @@ public class ToolsView : IRcView
public void Update(double dt) public void Update(double dt)
{ {
} }
public void Draw(double dt) public void Draw(double dt)
@ -89,7 +87,7 @@ public class ToolsView : IRcView
this.enabled = enabled; this.enabled = enabled;
} }
public Tool GetTool() public ITool GetTool()
{ {
return currentTool; return currentTool;
} }