forked from mirror/DotRecast
fix: bidir
This commit is contained in:
parent
4f3804ae3d
commit
4f3580d3f4
|
@ -33,13 +33,23 @@ public class JumpLinkBuilderSampleTool : ISampleTool
|
|||
private static readonly ILogger Logger = Log.ForContext<JumpLinkBuilderSampleTool>();
|
||||
private DemoSample _sample;
|
||||
|
||||
public const int DRAW_WALKABLE_SURFACE = 1 << 0;
|
||||
public const int DRAW_WALKABLE_BORDER = 1 << 1;
|
||||
public const int DRAW_SELECTED_EDGE = 1 << 2;
|
||||
public const int DRAW_ANIM_TRAJECTORY = 1 << 3;
|
||||
public const int DRAW_LAND_SAMPLES = 1 << 4;
|
||||
public const int DRAW_COLLISION_SLICES = 1 << 5;
|
||||
public const int DRAW_ANNOTATIONS = 1 << 6;
|
||||
|
||||
private int _drawFlags = DRAW_WALKABLE_SURFACE | DRAW_WALKABLE_BORDER | DRAW_SELECTED_EDGE | DRAW_ANIM_TRAJECTORY | DRAW_LAND_SAMPLES | DRAW_ANNOTATIONS;
|
||||
|
||||
private readonly RcJumpLinkBuilderTool _tool;
|
||||
private readonly RcJumpLinkBuilderToolOption _option;
|
||||
private readonly RcJumpLinkBuilderToolConfig _cfg;
|
||||
|
||||
public JumpLinkBuilderSampleTool()
|
||||
{
|
||||
_tool = new();
|
||||
_option = new();
|
||||
_cfg = new();
|
||||
}
|
||||
|
||||
public void Layout()
|
||||
|
@ -49,32 +59,33 @@ public class JumpLinkBuilderSampleTool : ISampleTool
|
|||
|
||||
ImGui.Text("Options");
|
||||
ImGui.Separator();
|
||||
ImGui.SliderFloat("Ground Tolerance", ref _option.groundTolerance, 0f, 2f, "%.2f");
|
||||
ImGui.SliderFloat("Ground Tolerance", ref _cfg.groundTolerance, 0f, 2f, "%.2f");
|
||||
ImGui.NewLine();
|
||||
|
||||
ImGui.Text("Climb Down");
|
||||
ImGui.Separator();
|
||||
ImGui.SliderFloat("Distance", ref _option.climbDownDistance, 0f, 5f, "%.2f");
|
||||
ImGui.SliderFloat("Min Cliff Height", ref _option.climbDownMinHeight, 0f, 10f, "%.2f");
|
||||
ImGui.SliderFloat("Max Cliff Height", ref _option.climbDownMaxHeight, 0f, 10f, "%.2f");
|
||||
ImGui.SliderFloat("Distance", ref _cfg.climbDownDistance, 0f, 5f, "%.2f");
|
||||
ImGui.SliderFloat("Min Cliff Height", ref _cfg.climbDownMinHeight, 0f, 10f, "%.2f");
|
||||
ImGui.SliderFloat("Max Cliff Height", ref _cfg.climbDownMaxHeight, 0f, 10f, "%.2f");
|
||||
ImGui.NewLine();
|
||||
|
||||
ImGui.Text("Jump Down");
|
||||
ImGui.Separator();
|
||||
ImGui.SliderFloat("Max Distance", ref _option.edgeJumpEndDistance, 0f, 10f, "%.2f");
|
||||
ImGui.SliderFloat("Jump Height", ref _option.edgeJumpHeight, 0f, 10f, "%.2f");
|
||||
ImGui.SliderFloat("Max Jump Down", ref _option.edgeJumpDownMaxHeight, 0f, 10f, "%.2f");
|
||||
ImGui.SliderFloat("Max Jump Up", ref _option.edgeJumpUpMaxHeight, 0f, 10f, "%.2f");
|
||||
ImGui.SliderFloat("Max Distance", ref _cfg.edgeJumpEndDistance, 0f, 10f, "%.2f");
|
||||
ImGui.SliderFloat("Jump Height", ref _cfg.edgeJumpHeight, 0f, 10f, "%.2f");
|
||||
ImGui.SliderFloat("Max Jump Down", ref _cfg.edgeJumpDownMaxHeight, 0f, 10f, "%.2f");
|
||||
ImGui.SliderFloat("Max Jump Up", ref _cfg.edgeJumpUpMaxHeight, 0f, 10f, "%.2f");
|
||||
ImGui.NewLine();
|
||||
|
||||
ImGui.Text("Mode");
|
||||
ImGui.Separator();
|
||||
//int buildTypes = 0;
|
||||
ImGui.CheckboxFlags("Climb Down", ref _option.buildTypes, JumpLinkType.EDGE_CLIMB_DOWN.Bit);
|
||||
ImGui.CheckboxFlags("Edge Jump", ref _option.buildTypes, JumpLinkType.EDGE_JUMP.Bit);
|
||||
ImGui.CheckboxFlags("Climb Down", ref _cfg.buildTypes, JumpLinkType.EDGE_CLIMB_DOWN.Bit);
|
||||
ImGui.CheckboxFlags("Edge Jump", ref _cfg.buildTypes, JumpLinkType.EDGE_JUMP.Bit);
|
||||
//option.buildTypes = buildTypes;
|
||||
|
||||
bool build = false;
|
||||
bool buildOffMeshConnections = false;
|
||||
_cfg.buildOffMeshConnections = false;
|
||||
if (ImGui.Button("Build Jump Link"))
|
||||
{
|
||||
build = true;
|
||||
|
@ -82,37 +93,25 @@ public class JumpLinkBuilderSampleTool : ISampleTool
|
|||
|
||||
if (ImGui.Button("Build Off-Mesh Links"))
|
||||
{
|
||||
buildOffMeshConnections = true;
|
||||
_cfg.buildOffMeshConnections = true;
|
||||
}
|
||||
|
||||
if (build || buildOffMeshConnections)
|
||||
if (build || _cfg.buildOffMeshConnections)
|
||||
{
|
||||
var geom = _sample.GetInputGeom();
|
||||
var settings = _sample.GetSettings();
|
||||
|
||||
_tool.Build(
|
||||
geom, settings, _sample.GetRecastResults(),
|
||||
buildOffMeshConnections,
|
||||
_option.buildTypes,
|
||||
_option.groundTolerance,
|
||||
_option.climbDownDistance,
|
||||
_option.climbDownMaxHeight,
|
||||
_option.climbDownMinHeight,
|
||||
_option.edgeJumpEndDistance,
|
||||
_option.edgeJumpHeight,
|
||||
_option.edgeJumpDownMaxHeight,
|
||||
_option.edgeJumpUpMaxHeight
|
||||
);
|
||||
_tool.Build(geom, settings, _sample.GetRecastResults(), _cfg);
|
||||
}
|
||||
|
||||
ImGui.Text("Debug Draw Options");
|
||||
ImGui.Separator();
|
||||
//int newFlags = 0;
|
||||
ImGui.CheckboxFlags("Walkable Border", ref _option.flags, RcJumpLinkBuilderToolOption.DRAW_WALKABLE_BORDER);
|
||||
ImGui.CheckboxFlags("Selected Edge", ref _option.flags, RcJumpLinkBuilderToolOption.DRAW_SELECTED_EDGE);
|
||||
ImGui.CheckboxFlags("Anim Trajectory", ref _option.flags, RcJumpLinkBuilderToolOption.DRAW_ANIM_TRAJECTORY);
|
||||
ImGui.CheckboxFlags("Land Samples", ref _option.flags, RcJumpLinkBuilderToolOption.DRAW_LAND_SAMPLES);
|
||||
ImGui.CheckboxFlags("All Annotations", ref _option.flags, RcJumpLinkBuilderToolOption.DRAW_ANNOTATIONS);
|
||||
ImGui.CheckboxFlags("Walkable Border", ref _drawFlags, DRAW_WALKABLE_BORDER);
|
||||
ImGui.CheckboxFlags("Selected Edge", ref _drawFlags, DRAW_SELECTED_EDGE);
|
||||
ImGui.CheckboxFlags("Anim Trajectory", ref _drawFlags, DRAW_ANIM_TRAJECTORY);
|
||||
ImGui.CheckboxFlags("Land Samples", ref _drawFlags, DRAW_LAND_SAMPLES);
|
||||
ImGui.CheckboxFlags("All Annotations", ref _drawFlags, DRAW_ANNOTATIONS);
|
||||
//option.flags = newFlags;
|
||||
}
|
||||
|
||||
|
@ -125,7 +124,7 @@ public class JumpLinkBuilderSampleTool : ISampleTool
|
|||
|
||||
var annotationBuilder = _tool.GetAnnotationBuilder();
|
||||
|
||||
if ((_option.flags & RcJumpLinkBuilderToolOption.DRAW_WALKABLE_BORDER) != 0)
|
||||
if ((_drawFlags & DRAW_WALKABLE_BORDER) != 0)
|
||||
{
|
||||
if (annotationBuilder != null)
|
||||
{
|
||||
|
@ -183,7 +182,7 @@ public class JumpLinkBuilderSampleTool : ISampleTool
|
|||
}
|
||||
}
|
||||
|
||||
if ((_option.flags & RcJumpLinkBuilderToolOption.DRAW_ANNOTATIONS) != 0)
|
||||
if ((_drawFlags & DRAW_ANNOTATIONS) != 0)
|
||||
{
|
||||
dd.Begin(QUADS);
|
||||
foreach (JumpLink link in _tool.GetLinks())
|
||||
|
@ -228,7 +227,7 @@ public class JumpLinkBuilderSampleTool : ISampleTool
|
|||
{
|
||||
foreach (JumpLink link in _tool.GetLinks())
|
||||
{
|
||||
if ((_option.flags & RcJumpLinkBuilderToolOption.DRAW_ANIM_TRAJECTORY) != 0)
|
||||
if ((_drawFlags & DRAW_ANIM_TRAJECTORY) != 0)
|
||||
{
|
||||
float r = link.start.height;
|
||||
|
||||
|
@ -293,7 +292,7 @@ public class JumpLinkBuilderSampleTool : ISampleTool
|
|||
dd.End();
|
||||
}
|
||||
|
||||
if ((_option.flags & RcJumpLinkBuilderToolOption.DRAW_LAND_SAMPLES) != 0)
|
||||
if ((_drawFlags & DRAW_LAND_SAMPLES) != 0)
|
||||
{
|
||||
dd.Begin(POINTS, 8.0f);
|
||||
for (int i = 0; i < link.start.gsamples.Length; ++i)
|
||||
|
|
|
@ -37,6 +37,8 @@ public class OffMeshConnectionSampleTool : ISampleTool
|
|||
private DemoSample _sample;
|
||||
|
||||
private readonly RcOffMeshConnectionTool _tool;
|
||||
|
||||
public int bidir;
|
||||
private bool hitPosSet;
|
||||
private RcVec3f hitPos;
|
||||
|
||||
|
@ -47,9 +49,8 @@ public class OffMeshConnectionSampleTool : ISampleTool
|
|||
|
||||
public void Layout()
|
||||
{
|
||||
var options = _tool.GetOption();
|
||||
ImGui.RadioButton("One Way", ref options.bidir, 0);
|
||||
ImGui.RadioButton("Bidirectional", ref options.bidir, 1);
|
||||
ImGui.RadioButton("One Way", ref bidir, 0);
|
||||
ImGui.RadioButton("Bidirectional", ref bidir, 1);
|
||||
}
|
||||
|
||||
public void HandleRender(NavMeshRenderer renderer)
|
||||
|
@ -111,7 +112,7 @@ public class OffMeshConnectionSampleTool : ISampleTool
|
|||
}
|
||||
else
|
||||
{
|
||||
_tool.Add(geom, settings, hitPos, p);
|
||||
_tool.Add(geom, settings, hitPos, p, 1 == bidir);
|
||||
hitPosSet = false;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -44,10 +44,7 @@ namespace DotRecast.Recast.Toolset.Tools
|
|||
return _links;
|
||||
}
|
||||
|
||||
public void Build(IInputGeomProvider geom, RcNavMeshBuildSettings settings, IList<RecastBuilderResult> results,
|
||||
bool buildOffMeshConnections, int buildTypes,
|
||||
float groundTolerance, float climbDownDistance, float climbDownMaxHeight, float climbDownMinHeight,
|
||||
float edgeJumpEndDistance, float edgeJumpHeight, float edgeJumpDownMaxHeight, float edgeJumpUpMaxHeight)
|
||||
public void Build(IInputGeomProvider geom, RcNavMeshBuildSettings settings, IList<RecastBuilderResult> results, RcJumpLinkBuilderToolConfig cfg)
|
||||
{
|
||||
if (_annotationBuilder == null)
|
||||
{
|
||||
|
@ -66,7 +63,7 @@ namespace DotRecast.Recast.Toolset.Tools
|
|||
float agentClimb = settings.agentMaxClimb;
|
||||
float cellHeight = settings.cellHeight;
|
||||
|
||||
if ((buildTypes & JumpLinkType.EDGE_CLIMB_DOWN.Bit) != 0)
|
||||
if ((cfg.buildTypes & JumpLinkType.EDGE_CLIMB_DOWN.Bit) != 0)
|
||||
{
|
||||
JumpLinkBuilderConfig config = new JumpLinkBuilderConfig(
|
||||
cellSize,
|
||||
|
@ -74,17 +71,17 @@ namespace DotRecast.Recast.Toolset.Tools
|
|||
agentRadius,
|
||||
agentHeight,
|
||||
agentClimb,
|
||||
groundTolerance,
|
||||
cfg.groundTolerance,
|
||||
-agentRadius * 0.2f,
|
||||
cellSize + 2 * agentRadius + climbDownDistance,
|
||||
-climbDownMaxHeight,
|
||||
-climbDownMinHeight,
|
||||
cellSize + 2 * agentRadius + cfg.climbDownDistance,
|
||||
-cfg.climbDownMaxHeight,
|
||||
-cfg.climbDownMinHeight,
|
||||
0
|
||||
);
|
||||
_links.AddRange(_annotationBuilder.Build(config, JumpLinkType.EDGE_CLIMB_DOWN));
|
||||
}
|
||||
|
||||
if ((buildTypes & JumpLinkType.EDGE_JUMP.Bit) != 0)
|
||||
if ((cfg.buildTypes & JumpLinkType.EDGE_JUMP.Bit) != 0)
|
||||
{
|
||||
JumpLinkBuilderConfig config = new JumpLinkBuilderConfig(
|
||||
cellSize,
|
||||
|
@ -92,17 +89,17 @@ namespace DotRecast.Recast.Toolset.Tools
|
|||
agentRadius,
|
||||
agentHeight,
|
||||
agentClimb,
|
||||
groundTolerance,
|
||||
cfg.groundTolerance,
|
||||
-agentRadius * 0.2f,
|
||||
edgeJumpEndDistance,
|
||||
-edgeJumpDownMaxHeight,
|
||||
edgeJumpUpMaxHeight,
|
||||
edgeJumpHeight
|
||||
cfg.edgeJumpEndDistance,
|
||||
-cfg.edgeJumpDownMaxHeight,
|
||||
cfg.edgeJumpUpMaxHeight,
|
||||
cfg.edgeJumpHeight
|
||||
);
|
||||
_links.AddRange(_annotationBuilder.Build(config, JumpLinkType.EDGE_JUMP));
|
||||
}
|
||||
|
||||
if (buildOffMeshConnections)
|
||||
if (cfg.buildOffMeshConnections)
|
||||
{
|
||||
int area = SampleAreaModifications.SAMPLE_POLYAREA_TYPE_JUMP_AUTO;
|
||||
geom.RemoveOffMeshConnections(c => c.area == area);
|
||||
|
|
|
@ -20,17 +20,11 @@ using DotRecast.Detour.Extras.Jumplink;
|
|||
|
||||
namespace DotRecast.Recast.Toolset.Tools
|
||||
{
|
||||
public class RcJumpLinkBuilderToolOption
|
||||
public class RcJumpLinkBuilderToolConfig
|
||||
{
|
||||
public const int DRAW_WALKABLE_SURFACE = 1 << 0;
|
||||
public const int DRAW_WALKABLE_BORDER = 1 << 1;
|
||||
public const int DRAW_SELECTED_EDGE = 1 << 2;
|
||||
public const int DRAW_ANIM_TRAJECTORY = 1 << 3;
|
||||
public const int DRAW_LAND_SAMPLES = 1 << 4;
|
||||
public const int DRAW_COLLISION_SLICES = 1 << 5;
|
||||
public const int DRAW_ANNOTATIONS = 1 << 6;
|
||||
public int buildTypes = JumpLinkType.EDGE_CLIMB_DOWN.Bit | JumpLinkType.EDGE_JUMP.Bit;
|
||||
public bool buildOffMeshConnections = false;
|
||||
|
||||
public int flags = DRAW_WALKABLE_SURFACE | DRAW_WALKABLE_BORDER | DRAW_SELECTED_EDGE | DRAW_ANIM_TRAJECTORY | DRAW_LAND_SAMPLES | DRAW_ANNOTATIONS;
|
||||
public float groundTolerance = 0.3f;
|
||||
public float climbDownDistance = 0.4f;
|
||||
public float climbDownMaxHeight = 3.2f;
|
||||
|
@ -39,6 +33,5 @@ namespace DotRecast.Recast.Toolset.Tools
|
|||
public float edgeJumpHeight = 0.4f;
|
||||
public float edgeJumpDownMaxHeight = 2.5f;
|
||||
public float edgeJumpUpMaxHeight = 0.3f;
|
||||
public int buildTypes = JumpLinkType.EDGE_CLIMB_DOWN.Bit | JumpLinkType.EDGE_JUMP.Bit;
|
||||
}
|
||||
}
|
|
@ -7,11 +7,8 @@ namespace DotRecast.Recast.Toolset.Tools
|
|||
{
|
||||
public class RcOffMeshConnectionTool : IRcToolable
|
||||
{
|
||||
private readonly RcOffMeshConnectionToolOption _option;
|
||||
|
||||
public RcOffMeshConnectionTool()
|
||||
{
|
||||
_option = new RcOffMeshConnectionToolOption();
|
||||
}
|
||||
|
||||
public string GetName()
|
||||
|
@ -19,19 +16,14 @@ namespace DotRecast.Recast.Toolset.Tools
|
|||
return "Off-Mesh Links";
|
||||
}
|
||||
|
||||
public RcOffMeshConnectionToolOption GetOption()
|
||||
{
|
||||
return _option;
|
||||
}
|
||||
|
||||
public void Add(IInputGeomProvider geom, RcNavMeshBuildSettings settings, RcVec3f start, RcVec3f end)
|
||||
public void Add(IInputGeomProvider geom, RcNavMeshBuildSettings settings, RcVec3f start, RcVec3f end, bool bidir)
|
||||
{
|
||||
if (null == geom)
|
||||
return;
|
||||
|
||||
int area = SampleAreaModifications.SAMPLE_POLYAREA_TYPE_JUMP;
|
||||
int flags = SampleAreaModifications.SAMPLE_POLYFLAGS_JUMP;
|
||||
geom.AddOffMeshConnection(start, end, settings.agentRadius, 0 == _option.bidir, area, flags);
|
||||
geom.AddOffMeshConnection(start, end, settings.agentRadius, bidir, area, flags);
|
||||
}
|
||||
|
||||
public void Remove(IInputGeomProvider geom, RcNavMeshBuildSettings settings, RcVec3f p)
|
||||
|
|
|
@ -1,7 +0,0 @@
|
|||
namespace DotRecast.Recast.Toolset.Tools
|
||||
{
|
||||
public class RcOffMeshConnectionToolOption
|
||||
{
|
||||
public int bidir;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue