ready obstacle tool

This commit is contained in:
ikpil 2023-08-20 14:12:23 +09:00
parent e98ff8bec7
commit 356a4c4e0d
10 changed files with 89 additions and 67 deletions

View File

@ -436,7 +436,7 @@ namespace DotRecast.Detour.TileCache
return o;
}
List<long> QueryTiles(RcVec3f bmin, RcVec3f bmax)
private List<long> QueryTiles(RcVec3f bmin, RcVec3f bmax)
{
List<long> results = new List<long>();
float tw = m_params.width * m_params.cs;

View File

@ -39,7 +39,7 @@ public class ConvexVolumeSampleTool : ISampleTool
private static readonly ILogger Logger = Log.ForContext<ConvexVolumeSampleTool>();
private DemoSample _sample;
private readonly RcConvexVolumeTool _impl;
private readonly RcConvexVolumeTool _tool;
private int areaTypeValue = SampleAreaModifications.SAMPLE_AREAMOD_GRASS.Value;
private RcAreaModification areaType = SampleAreaModifications.SAMPLE_AREAMOD_GRASS;
@ -51,12 +51,12 @@ public class ConvexVolumeSampleTool : ISampleTool
public ConvexVolumeSampleTool()
{
_impl = new RcConvexVolumeTool();
_tool = new RcConvexVolumeTool();
}
public IRcToolable GetTool()
{
return _impl;
return _tool;
}
public void SetSample(DemoSample sample)
@ -78,7 +78,7 @@ public class ConvexVolumeSampleTool : ISampleTool
if (shift)
{
_impl.RemoveByPos(geom, p);
_tool.RemoveByPos(geom, p);
}
else
{
@ -90,7 +90,7 @@ public class ConvexVolumeSampleTool : ISampleTool
var vol = RcConvexVolumeTool.CreateConvexVolume(pts, hull, areaType, boxDescent, boxHeight, polyOffset);
if (null != vol)
{
_impl.Add(geom, vol);
_tool.Add(geom, vol);
}
pts.Clear();

View File

@ -40,7 +40,7 @@ public class CrowdSampleTool : ISampleTool
private static readonly ILogger Logger = Log.ForContext<CrowdSampleTool>();
private DemoSample _sample;
private readonly RcCrowdTool _impl;
private readonly RcCrowdTool _tool;
private readonly CrowdToolParams toolParams = new CrowdToolParams();
private DtNavMesh m_nav;
private DtCrowd crowd;
@ -58,12 +58,12 @@ public class CrowdSampleTool : ISampleTool
{
m_agentDebug.vod = new DtObstacleAvoidanceDebugData(2048);
profilingTool = new CrowdProfilingTool(GetAgentParams);
_impl = new();
_tool = new();
}
public IRcToolable GetTool()
{
return _impl;
return _tool;
}
public void SetSample(DemoSample sample)

View File

@ -45,7 +45,7 @@ public class DynamicUpdateSampleTool : ISampleTool
private static readonly ILogger Logger = Log.ForContext<DynamicUpdateSampleTool>();
private DemoSample _sample;
private readonly RcDynamicUpdateTool _impl;
private readonly RcDynamicUpdateTool _tool;
private int toolModeIdx = DynamicUpdateToolMode.BUILD.Idx;
private DynamicUpdateToolMode mode = DynamicUpdateToolMode.BUILD;
private float cellSize = 0.3f;
@ -91,7 +91,7 @@ public class DynamicUpdateSampleTool : ISampleTool
public DynamicUpdateSampleTool()
{
_impl = new();
_tool = new();
executor = Task.Factory;
bridgeGeom = DemoObjImporter.Load(Loader.ToBytes("bridge.obj"));
houseGeom = DemoObjImporter.Load(Loader.ToBytes("house.obj"));
@ -100,7 +100,7 @@ public class DynamicUpdateSampleTool : ISampleTool
public IRcToolable GetTool()
{
return _impl;
return _tool;
}
public void SetSample(DemoSample sample)

View File

@ -33,18 +33,18 @@ public class JumpLinkBuilderSampleTool : ISampleTool
private static readonly ILogger Logger = Log.ForContext<JumpLinkBuilderSampleTool>();
private DemoSample _sample;
private readonly RcJumpLinkBuilderTool _impl;
private readonly RcJumpLinkBuilderTool _tool;
private readonly RcJumpLinkBuilderToolOption _option;
public JumpLinkBuilderSampleTool()
{
_impl = new();
_tool = new();
_option = new();
}
public IRcToolable GetTool()
{
return _impl;
return _tool;
}
public void SetSample(DemoSample sample)
@ -54,7 +54,7 @@ public class JumpLinkBuilderSampleTool : ISampleTool
public void OnSampleChanged()
{
_impl.Clear();
_tool.Clear();
}
@ -69,13 +69,13 @@ public class JumpLinkBuilderSampleTool : ISampleTool
RecastDebugDraw dd = renderer.GetDebugDraw();
dd.DepthMask(false);
var annotationBuilder = _impl.GetAnnotationBuilder();
var annotationBuilder = _tool.GetAnnotationBuilder();
if ((_option.flags & RcJumpLinkBuilderToolOption.DRAW_WALKABLE_BORDER) != 0)
{
if (annotationBuilder != null)
{
var selEdge = _impl.GetSelEdge();
var selEdge = _tool.GetSelEdge();
foreach (JumpEdge[] edges in annotationBuilder.GetEdges())
{
@ -132,7 +132,7 @@ public class JumpLinkBuilderSampleTool : ISampleTool
if ((_option.flags & RcJumpLinkBuilderToolOption.DRAW_ANNOTATIONS) != 0)
{
dd.Begin(QUADS);
foreach (JumpLink link in _impl.GetLinks())
foreach (JumpLink link in _tool.GetLinks())
{
for (int j = 0; j < link.nspine - 1; ++j)
{
@ -149,7 +149,7 @@ public class JumpLinkBuilderSampleTool : ISampleTool
dd.End();
dd.Begin(LINES, 3.0f);
foreach (JumpLink link in _impl.GetLinks())
foreach (JumpLink link in _tool.GetLinks())
{
for (int j = 0; j < link.nspine - 1; ++j)
{
@ -178,7 +178,7 @@ public class JumpLinkBuilderSampleTool : ISampleTool
if (annotationBuilder != null)
{
foreach (JumpLink link in _impl.GetLinks())
foreach (JumpLink link in _tool.GetLinks())
{
if ((_option.flags & RcJumpLinkBuilderToolOption.DRAW_ANIM_TRAJECTORY) != 0)
{
@ -389,7 +389,7 @@ public class JumpLinkBuilderSampleTool : ISampleTool
var geom = _sample.GetInputGeom();
var settings = _sample.GetSettings();
_impl.Build(
_tool.Build(
geom, settings, _sample.GetRecastResults(),
buildOffMeshConnections,
_option.buildTypes,

View File

@ -14,18 +14,18 @@ public class ObstacleSampleTool : ISampleTool
private DemoSample _sample;
private readonly RcObstacleTool _impl;
private readonly RcObstacleTool _tool;
private bool _hitPosSet;
private RcVec3f _hitPos;
public ObstacleSampleTool()
{
_impl = new(DtTileCacheCompressorFactory.Shared);
_tool = new(DtTileCacheCompressorFactory.Shared);
}
public IRcToolable GetTool()
{
return _impl;
return _tool;
}
public void SetSample(DemoSample sample)
@ -39,9 +39,17 @@ public class ObstacleSampleTool : ISampleTool
public void Layout()
{
if (ImGui.Button("Build Tile Cache"))
{
var geom = _sample.GetInputGeom();
var settings = _sample.GetSettings();
_tool.Build(geom, settings, RcByteOrder.LITTLE_ENDIAN, true);
}
if (ImGui.Button("Remove All Temp Obstacles"))
{
_impl.ClearAllTempObstacles();
_tool.ClearAllTempObstacles();
}
ImGui.Separator();
@ -57,11 +65,11 @@ public class ObstacleSampleTool : ISampleTool
if (shift)
{
_impl.RemoveTempObstacle(s, p);
_tool.RemoveTempObstacle(s, p);
}
else
{
_impl.AddTempObstacle(_hitPos);
_tool.AddTempObstacle(_hitPos);
}
}

View File

@ -36,18 +36,18 @@ public class OffMeshConnectionSampleTool : ISampleTool
private DemoSample _sample;
private readonly RcOffMeshConnectionTool _impl;
private readonly RcOffMeshConnectionTool _tool;
private bool hitPosSet;
private RcVec3f hitPos;
public OffMeshConnectionSampleTool()
{
_impl = new();
_tool = new();
}
public IRcToolable GetTool()
{
return _impl;
return _tool;
}
public void SetSample(DemoSample sample)
@ -72,7 +72,7 @@ public class OffMeshConnectionSampleTool : ISampleTool
if (shift)
{
_impl.Remove(geom, settings, p);
_tool.Remove(geom, settings, p);
}
else
{
@ -84,7 +84,7 @@ public class OffMeshConnectionSampleTool : ISampleTool
}
else
{
_impl.Add(geom, settings, hitPos, p);
_tool.Add(geom, settings, hitPos, p);
hitPosSet = false;
}
}
@ -111,7 +111,7 @@ public class OffMeshConnectionSampleTool : ISampleTool
public void Layout()
{
var options = _impl.GetOption();
var options = _tool.GetOption();
ImGui.RadioButton("One Way", ref options.bidir, 0);
ImGui.RadioButton("Bidirectional", ref options.bidir, 1);
}

View File

@ -20,7 +20,7 @@ public class TestNavmeshSampleTool : ISampleTool
private const int MAX_POLYS = 256;
private DemoSample _sample;
private readonly RcTestNavMeshTool _impl;
private readonly RcTestNavMeshTool _tool;
private bool m_sposSet;
private bool m_eposSet;
@ -49,7 +49,7 @@ public class TestNavmeshSampleTool : ISampleTool
public TestNavmeshSampleTool()
{
_impl = new();
_tool = new();
m_filter = new DtQueryDefaultFilter(
SampleAreaModifications.SAMPLE_POLYFLAGS_ALL,
SampleAreaModifications.SAMPLE_POLYFLAGS_DISABLED,
@ -59,7 +59,7 @@ public class TestNavmeshSampleTool : ISampleTool
public IRcToolable GetTool()
{
return _impl;
return _tool;
}
public void SetSample(DemoSample sample)
@ -91,7 +91,7 @@ public class TestNavmeshSampleTool : ISampleTool
public void Layout()
{
var option = _impl.GetOption();
var option = _tool.GetOption();
var previousToolMode = option.mode;
int previousStraightPathOptions = option.straightPathOptions;
int previousIncludeFlags = m_filter.GetIncludeFlags();
@ -197,7 +197,7 @@ public class TestNavmeshSampleTool : ISampleTool
m_endRef = 0;
}
var option = _impl.GetOption();
var option = _tool.GetOption();
if (option.mode == RcTestNavmeshToolMode.PATHFIND_FOLLOW)
{
@ -206,7 +206,7 @@ public class TestNavmeshSampleTool : ISampleTool
var polys = new List<long>();
var smoothPath = new List<RcVec3f>();
var status = _impl.FindFollowPath(navMesh, navQuery, m_startRef, m_endRef, m_spos, m_epos, m_filter, option.enableRaycast,
var status = _tool.FindFollowPath(navMesh, navQuery, m_startRef, m_endRef, m_spos, m_epos, m_filter, option.enableRaycast,
ref polys, ref smoothPath);
if (status.Succeeded())
@ -227,7 +227,7 @@ public class TestNavmeshSampleTool : ISampleTool
{
var polys = new List<long>();
var straightPath = new List<StraightPathItem>();
var status = _impl.FindStraightPath(navQuery, m_startRef, m_endRef, m_spos, m_epos, m_filter, option.enableRaycast,
var status = _tool.FindStraightPath(navQuery, m_startRef, m_endRef, m_spos, m_epos, m_filter, option.enableRaycast,
ref polys, ref straightPath, option.straightPathOptions);
if (status.Succeeded())
@ -248,7 +248,7 @@ public class TestNavmeshSampleTool : ISampleTool
if (m_sposSet && m_eposSet && m_startRef != 0 && m_endRef != 0)
{
m_pathFindStatus = _impl.InitSlicedFindPath(navQuery, m_startRef, m_endRef, m_spos, m_epos, m_filter, option.enableRaycast);
m_pathFindStatus = _tool.InitSlicedFindPath(navQuery, m_startRef, m_endRef, m_spos, m_epos, m_filter, option.enableRaycast);
}
}
else if (option.mode == RcTestNavmeshToolMode.RAYCAST)
@ -258,7 +258,7 @@ public class TestNavmeshSampleTool : ISampleTool
{
var polys = new List<long>();
var straightPath = new List<StraightPathItem>();
var status = _impl.Raycast(navQuery, m_startRef, m_spos, m_epos, m_filter,
var status = _tool.Raycast(navQuery, m_startRef, m_spos, m_epos, m_filter,
ref polys, ref straightPath, out var hitPos, out var hitNormal, out var hitResult);
if (status.Succeeded())
@ -292,7 +292,7 @@ public class TestNavmeshSampleTool : ISampleTool
List<long> refs = new();
List<long> parentRefs = new();
var status = _impl.FindPolysAroundCircle(navQuery, m_startRef, m_spos, m_epos, m_filter, ref refs, ref parentRefs);
var status = _tool.FindPolysAroundCircle(navQuery, m_startRef, m_spos, m_epos, m_filter, ref refs, ref parentRefs);
if (status.Succeeded())
{
m_polys = refs;
@ -307,7 +307,7 @@ public class TestNavmeshSampleTool : ISampleTool
var refs = new List<long>();
var parentRefs = new List<long>();
var status = _impl.FindPolysAroundShape(navQuery, settings, m_startRef, m_spos, m_epos, m_filter, ref refs, ref parentRefs, out var queryPoly);
var status = _tool.FindPolysAroundShape(navQuery, settings, m_startRef, m_spos, m_epos, m_filter, ref refs, ref parentRefs, out var queryPoly);
if (status.Succeeded())
{
m_queryPoly = queryPoly;
@ -337,7 +337,7 @@ public class TestNavmeshSampleTool : ISampleTool
if (m_sposSet && m_startRef != 0 && m_eposSet)
{
var points = new List<RcVec3f>();
_impl.FindRandomPointAroundCircle(navQuery, m_startRef, m_spos, m_epos, m_filter, option.constrainByCircle, 500, ref points);
_tool.FindRandomPointAroundCircle(navQuery, m_startRef, m_spos, m_epos, m_filter, option.constrainByCircle, 500, ref points);
randomPoints.AddRange(points);
}
}
@ -373,7 +373,7 @@ public class TestNavmeshSampleTool : ISampleTool
return;
}
var option = _impl.GetOption();
var option = _tool.GetOption();
if (option.mode == RcTestNavmeshToolMode.PATHFIND_FOLLOW)
{
dd.DebugDrawNavMeshPoly(m_navMesh, m_startRef, startCol);
@ -791,7 +791,7 @@ public class TestNavmeshSampleTool : ISampleTool
public void HandleUpdate(float dt)
{
// TODO Auto-generated method stub
var option = _impl.GetOption();
var option = _tool.GetOption();
if (option.mode == RcTestNavmeshToolMode.PATHFIND_SLICED)
{
DtNavMeshQuery m_navQuery = _sample.GetNavMeshQuery();

View File

@ -15,19 +15,19 @@ public class TileSampleTool : ISampleTool
private static readonly ILogger Logger = Log.ForContext<TileSampleTool>();
private DemoSample _sample;
private readonly RcTileTool _impl;
private readonly RcTileTool _tool;
private bool _hitPosSet;
private RcVec3f _hitPos;
public TileSampleTool()
{
_impl = new();
_tool = new();
}
public IRcToolable GetTool()
{
return _impl;
return _tool;
}
public void SetSample(DemoSample sample)
@ -47,12 +47,12 @@ public class TileSampleTool : ISampleTool
if (ImGui.Button("Create All Tile"))
{
_impl.BuildAllTiles(geom, settings, navMesh);
_tool.BuildAllTiles(geom, settings, navMesh);
}
if (ImGui.Button("Remove All Tile"))
{
_impl.RemoveAllTiles(geom, settings, navMesh);
_tool.RemoveAllTiles(geom, settings, navMesh);
}
}
@ -67,11 +67,11 @@ public class TileSampleTool : ISampleTool
if (shift)
{
_impl.RemoveTile(geom, settings, navMesh, _hitPos);
_tool.RemoveTile(geom, settings, navMesh, _hitPos);
}
else
{
bool built = _impl.BuildTile(geom, settings, navMesh, _hitPos, out var tileBuildTicks, out var tileTriCount, out var tileMemUsage);
bool built = _tool.BuildTile(geom, settings, navMesh, _hitPos, out var tileBuildTicks, out var tileTriCount, out var tileMemUsage);
if (!built)
{
Logger.Error($"failed to build tile - check!");

View File

@ -24,19 +24,33 @@ namespace DotRecast.Recast.Toolset.Tools
return "Create Temp Obstacles";
}
public void Build(IInputGeomProvider geom, RcNavMeshBuildSettings setting, RcByteOrder order, bool cCompatibility)
{
_tc = CreateTileCache(geom, setting, order, cCompatibility);
}
public void ClearAllTempObstacles()
{
if (null == _tc)
return;
}
public void RemoveTempObstacle(RcVec3f sp, RcVec3f sq)
{
// ..
if (null == _tc)
return;
//DtObstacleRef refs = hitTestObstacle(m_tileCache, sp, sq);
//_tc.RemoveObstacle(refs);
}
public void AddTempObstacle(RcVec3f pos)
public void AddTempObstacle(RcVec3f p)
{
//p[1] -= 0.5f;
//m_tileCache->addObstacle(p, 1.0f, 2.0f, 0);
if (null == _tc)
return;
p.y -= 0.5f;
_tc.AddObstacle(p, 1.0f, 2.0f);
}
public DtTileCache CreateTileCache(IInputGeomProvider geom, RcNavMeshBuildSettings setting, RcByteOrder order, bool cCompatibility)