forked from mirror/DotRecast
remove FindNearestPolyResult ok
This commit is contained in:
parent
64315ca56e
commit
36ad2e1498
|
@ -245,14 +245,14 @@ namespace DotRecast.Detour.Crowd
|
|||
UpdateAgentParameters(ag, option);
|
||||
|
||||
// Find nearest position on navmesh and place the agent there.
|
||||
var status = _navQuery.FindNearestPoly(pos, _ext, _filters[ag.option.queryFilterType], out var refs, out var nearest, out var _);
|
||||
var status = _navQuery.FindNearestPoly(pos, _ext, _filters[ag.option.queryFilterType], out var refs, out var nearestPt, out var _);
|
||||
if (status.Failed())
|
||||
{
|
||||
nearest = pos;
|
||||
nearestPt = pos;
|
||||
refs = 0;
|
||||
}
|
||||
|
||||
ag.corridor.Reset(refs, nearest);
|
||||
ag.corridor.Reset(refs, nearestPt);
|
||||
ag.boundary.Reset();
|
||||
ag.partial = false;
|
||||
|
||||
|
@ -262,7 +262,7 @@ namespace DotRecast.Detour.Crowd
|
|||
ag.dvel = RcVec3f.Zero;
|
||||
ag.nvel = RcVec3f.Zero;
|
||||
ag.vel = RcVec3f.Zero;
|
||||
ag.npos = nearest;
|
||||
ag.npos = nearestPt;
|
||||
|
||||
ag.desiredSpeed = 0;
|
||||
|
||||
|
@ -465,8 +465,8 @@ namespace DotRecast.Detour.Crowd
|
|||
{
|
||||
// Current location is not valid, try to reposition.
|
||||
// TODO: this can snap agents, how to handle that?
|
||||
_navQuery.FindNearestPoly(ag.npos, _ext, _filters[ag.option.queryFilterType], out agentRef, out var nearest, out var _);
|
||||
agentPos = nearest;
|
||||
_navQuery.FindNearestPoly(ag.npos, _ext, _filters[ag.option.queryFilterType], out agentRef, out var nearestPt, out var _);
|
||||
agentPos = nearestPt;
|
||||
|
||||
if (agentRef == 0)
|
||||
{
|
||||
|
@ -505,8 +505,8 @@ namespace DotRecast.Detour.Crowd
|
|||
if (!_navQuery.IsValidPolyRef(ag.targetRef, _filters[ag.option.queryFilterType]))
|
||||
{
|
||||
// Current target is not valid, try to reposition.
|
||||
_navQuery.FindNearestPoly(ag.targetPos, _ext, _filters[ag.option.queryFilterType], out ag.targetRef, out var nearest, out var _);
|
||||
ag.targetPos = nearest;
|
||||
_navQuery.FindNearestPoly(ag.targetPos, _ext, _filters[ag.option.queryFilterType], out ag.targetRef, out var nearestPt, out var _);
|
||||
ag.targetPos = nearestPt;
|
||||
replan = true;
|
||||
}
|
||||
|
||||
|
|
|
@ -840,14 +840,12 @@ namespace DotRecast.Detour
|
|||
p.x = targetCon.pos[3];
|
||||
p.y = targetCon.pos[4];
|
||||
p.z = targetCon.pos[5];
|
||||
FindNearestPolyResult nearest = FindNearestPolyInTile(tile, p, ext);
|
||||
long refs = nearest.GetNearestRef();
|
||||
var refs = FindNearestPolyInTile(tile, p, ext, out var nearestPt);
|
||||
if (refs == 0)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
var nearestPt = nearest.GetNearestPos();
|
||||
// findNearestPoly may return too optimistic results, further check
|
||||
// to make sure.
|
||||
|
||||
|
@ -1070,15 +1068,13 @@ namespace DotRecast.Detour
|
|||
};
|
||||
|
||||
// Find polygon to connect to.
|
||||
FindNearestPolyResult nearestPoly = FindNearestPolyInTile(tile, RcVec3f.Of(con.pos), ext);
|
||||
long refs = nearestPoly.GetNearestRef();
|
||||
var refs = FindNearestPolyInTile(tile, RcVec3f.Of(con.pos), ext, out var nearestPt);
|
||||
if (refs == 0)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
float[] p = con.pos; // First vertex
|
||||
RcVec3f nearestPt = nearestPoly.GetNearestPos();
|
||||
// findNearestPoly may return too optimistic results, further check
|
||||
// to make sure.
|
||||
if (Sqr(nearestPt.x - p[0]) + Sqr(nearestPt.z - p[2]) > Sqr(con.rad))
|
||||
|
@ -1343,12 +1339,14 @@ namespace DotRecast.Detour
|
|||
closest = ClosestPointOnDetailEdges(tile, poly, pos, true);
|
||||
}
|
||||
|
||||
FindNearestPolyResult FindNearestPolyInTile(DtMeshTile tile, RcVec3f center, RcVec3f extents)
|
||||
/// Find nearest polygon within a tile.
|
||||
private long FindNearestPolyInTile(DtMeshTile tile, RcVec3f center, RcVec3f halfExtents, out RcVec3f nearestPt)
|
||||
{
|
||||
RcVec3f nearestPt = new RcVec3f();
|
||||
nearestPt = RcVec3f.Zero;
|
||||
|
||||
bool overPoly = false;
|
||||
RcVec3f bmin = center.Subtract(extents);
|
||||
RcVec3f bmax = center.Add(extents);
|
||||
RcVec3f bmin = center.Subtract(halfExtents);
|
||||
RcVec3f bmax = center.Add(halfExtents);
|
||||
|
||||
// Get nearby polygons from proximity grid.
|
||||
List<long> polys = QueryPolygonsInTile(tile, bmin, bmax);
|
||||
|
@ -1384,7 +1382,7 @@ namespace DotRecast.Detour
|
|||
}
|
||||
}
|
||||
|
||||
return new FindNearestPolyResult(nearest, nearestPt, overPoly);
|
||||
return nearest;
|
||||
}
|
||||
|
||||
DtMeshTile GetTileAt(int x, int y, int layer)
|
||||
|
|
|
@ -1,55 +0,0 @@
|
|||
/*
|
||||
Copyright (c) 2009-2010 Mikko Mononen memon@inside.org
|
||||
recast4j copyright (c) 2015-2019 Piotr Piastucki piotr@jtilia.org
|
||||
DotRecast Copyright (c) 2023 Choi Ikpil ikpil@naver.com
|
||||
|
||||
This software is provided 'as-is', without any express or implied
|
||||
warranty. In no event will the authors be held liable for any damages
|
||||
arising from the use of this software.
|
||||
Permission is granted to anyone to use this software for any purpose,
|
||||
including commercial applications, and to alter it and redistribute it
|
||||
freely, subject to the following restrictions:
|
||||
1. The origin of this software must not be misrepresented; you must not
|
||||
claim that you wrote the original software. If you use this software
|
||||
in a product, an acknowledgment in the product documentation would be
|
||||
appreciated but is not required.
|
||||
2. Altered source versions must be plainly marked as such, and must not be
|
||||
misrepresented as being the original software.
|
||||
3. This notice may not be removed or altered from any source distribution.
|
||||
*/
|
||||
|
||||
using DotRecast.Core;
|
||||
|
||||
namespace DotRecast.Detour.QueryResults
|
||||
{
|
||||
public class FindNearestPolyResult
|
||||
{
|
||||
private readonly long nearestRef;
|
||||
private readonly RcVec3f nearestPos;
|
||||
private readonly bool overPoly;
|
||||
|
||||
public FindNearestPolyResult(long nearestRef, RcVec3f nearestPos, bool overPoly)
|
||||
{
|
||||
this.nearestRef = nearestRef;
|
||||
this.nearestPos = nearestPos;
|
||||
this.overPoly = overPoly;
|
||||
}
|
||||
|
||||
/** Returns the reference id of the nearest polygon. 0 if no polygon is found. */
|
||||
public long GetNearestRef()
|
||||
{
|
||||
return nearestRef;
|
||||
}
|
||||
|
||||
/** Returns the nearest point on the polygon. [opt] [(x, y, z)]. Unchanged if no polygon is found. */
|
||||
public RcVec3f GetNearestPos()
|
||||
{
|
||||
return nearestPos;
|
||||
}
|
||||
|
||||
public bool IsOverPoly()
|
||||
{
|
||||
return overPoly;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -279,7 +279,7 @@ public class CrowdProfilingTool
|
|||
private void MoveMob(DtNavMeshQuery navquery, IDtQueryFilter filter, DtCrowdAgent ag, CrowdAgentData crowAgentData)
|
||||
{
|
||||
// Move somewhere
|
||||
var status = navquery.FindNearestPoly(ag.npos, crowd.GetQueryExtents(), filter, out var nearestRef, out var nearest, out var _);
|
||||
var status = navquery.FindNearestPoly(ag.npos, crowd.GetQueryExtents(), filter, out var nearestRef, out var nearestPt, out var _);
|
||||
if (status.Succeeded())
|
||||
{
|
||||
status = navquery.FindRandomPointAroundCircle(nearestRef, crowAgentData.home, zoneRadius * 2f, filter, rnd,
|
||||
|
@ -294,7 +294,7 @@ public class CrowdProfilingTool
|
|||
private void MoveVillager(DtNavMeshQuery navquery, IDtQueryFilter filter, DtCrowdAgent ag, CrowdAgentData crowAgentData)
|
||||
{
|
||||
// Move somewhere close
|
||||
var status = navquery.FindNearestPoly(ag.npos, crowd.GetQueryExtents(), filter, out var nearestRef, out var nearest, out var _);
|
||||
var status = navquery.FindNearestPoly(ag.npos, crowd.GetQueryExtents(), filter, out var nearestRef, out var nearestPt, out var _);
|
||||
if (status.Succeeded())
|
||||
{
|
||||
status = navquery.FindRandomPointAroundCircle(nearestRef, crowAgentData.home, zoneRadius * 0.2f, filter, rnd,
|
||||
|
|
|
@ -158,7 +158,7 @@ public class CrowdTool : ITool
|
|||
{
|
||||
IDtQueryFilter filter = new DtQueryDefaultFilter();
|
||||
RcVec3f halfExtents = crowd.GetQueryExtents();
|
||||
navquery.FindNearestPoly(p, halfExtents, filter, out var refs, out var nearest, out var _);
|
||||
navquery.FindNearestPoly(p, halfExtents, filter, out var refs, out var nearestPt, out var _);
|
||||
if (refs != 0)
|
||||
{
|
||||
Result<int> flags = nav.GetPolyFlags(refs);
|
||||
|
|
|
@ -143,10 +143,10 @@ public class AbstractCrowdTest
|
|||
}
|
||||
else
|
||||
{
|
||||
query.FindNearestPoly(pos, ext, filter, out var refs, out var nearest, out var _);
|
||||
query.FindNearestPoly(pos, ext, filter, out var nearestRef, out var nearestPt, out var _);
|
||||
foreach (DtCrowdAgent ag in crowd.GetActiveAgents())
|
||||
{
|
||||
crowd.RequestMoveTarget(ag, refs, nearest);
|
||||
crowd.RequestMoveTarget(ag, nearestRef, nearestPt);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -109,11 +109,11 @@ public class UnityAStarPathfindingImporterTest
|
|||
for (int i = 0; i < results.Length; i++)
|
||||
{
|
||||
RcVec3f position = positions[i];
|
||||
var status = query.FindNearestPoly(position, extents, filter, out var nearestRef, out var nearest, out var _);
|
||||
var status = query.FindNearestPoly(position, extents, filter, out var nearestRef, out var nearestPt, out var _);
|
||||
Assert.That(status.Succeeded(), Is.True);
|
||||
Assert.That(nearest, Is.Not.EqualTo(RcVec3f.Zero), "Nearest start position is null!");
|
||||
Assert.That(nearestPt, Is.Not.EqualTo(RcVec3f.Zero), "Nearest start position is null!");
|
||||
|
||||
results[i] = new DtPolyPoint(nearestRef, nearest);
|
||||
results[i] = new DtPolyPoint(nearestRef, nearestPt);
|
||||
}
|
||||
|
||||
return results;
|
||||
|
|
|
@ -42,12 +42,12 @@ public class FindNearestPolyTest : AbstractDetourTest
|
|||
for (int i = 0; i < startRefs.Length; i++)
|
||||
{
|
||||
RcVec3f startPos = startPoss[i];
|
||||
var status = query.FindNearestPoly(startPos, extents, filter, out var nearestRef, out var nearest, out var _);
|
||||
var status = query.FindNearestPoly(startPos, extents, filter, out var nearestRef, out var nearestPt, out var _);
|
||||
Assert.That(status.Succeeded(), Is.True);
|
||||
Assert.That(nearestRef, Is.EqualTo(POLY_REFS[i]));
|
||||
for (int v = 0; v < POLY_POS[i].Length; v++)
|
||||
{
|
||||
Assert.That(nearest[v], Is.EqualTo(POLY_POS[i][v]).Within(0.001f));
|
||||
Assert.That(nearestPt[v], Is.EqualTo(POLY_POS[i][v]).Within(0.001f));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -61,12 +61,12 @@ public class FindNearestPolyTest : AbstractDetourTest
|
|||
for (int i = 0; i < startRefs.Length; i++)
|
||||
{
|
||||
RcVec3f startPos = startPoss[i];
|
||||
var status = query.FindNearestPoly(startPos, extents, filter, out var nearestRef, out var nearest, out var _);
|
||||
var status = query.FindNearestPoly(startPos, extents, filter, out var nearestRef, out var nearestPt, out var _);
|
||||
Assert.That(status.Succeeded(), Is.True);
|
||||
Assert.That(nearestRef, Is.EqualTo(0L));
|
||||
for (int v = 0; v < POLY_POS[i].Length; v++)
|
||||
{
|
||||
Assert.That(nearest[v], Is.EqualTo(startPos[v]).Within(0.001f));
|
||||
Assert.That(nearestPt[v], Is.EqualTo(startPos[v]).Within(0.001f));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue