forked from bit/DotRecastNetSim
remove FindPolysAroundResult
This commit is contained in:
parent
36ad2e1498
commit
40229226dc
|
@ -575,7 +575,7 @@ namespace DotRecast.Detour
|
||||||
nearestRef = 0;
|
nearestRef = 0;
|
||||||
nearestPt = center;
|
nearestPt = center;
|
||||||
isOverPoly = false;
|
isOverPoly = false;
|
||||||
|
|
||||||
// Get nearby polygons from proximity grid.
|
// Get nearby polygons from proximity grid.
|
||||||
DtFindNearestPolyQuery query = new DtFindNearestPolyQuery(this, center);
|
DtFindNearestPolyQuery query = new DtFindNearestPolyQuery(this, center);
|
||||||
DtStatus status = QueryPolygons(center, halfExtents, filter, query);
|
DtStatus status = QueryPolygons(center, halfExtents, filter, query);
|
||||||
|
@ -2416,35 +2416,36 @@ namespace DotRecast.Detour
|
||||||
/// If the result arrays are to small to hold the entire result set, they will be
|
/// If the result arrays are to small to hold the entire result set, they will be
|
||||||
/// filled to capacity.
|
/// filled to capacity.
|
||||||
///
|
///
|
||||||
/// @}
|
///@}
|
||||||
/// @name Dijkstra Search Functions
|
/// @name Dijkstra Search Functions
|
||||||
/// @{
|
/// @{
|
||||||
/// Finds the polygons along the navigation graph that touch the specified circle.
|
/// Finds the polygons along the navigation graph that touch the specified circle.
|
||||||
/// @param[in] startRef The reference id of the polygon where the search starts.
|
/// @param[in] startRef The reference id of the polygon where the search starts.
|
||||||
/// @param[in] centerPos The center of the search circle. [(x, y, z)]
|
/// @param[in] centerPos The center of the search circle. [(x, y, z)]
|
||||||
/// @param[in] radius The radius of the search circle.
|
/// @param[in] radius The radius of the search circle.
|
||||||
/// @param[in] filter The polygon filter to apply to the query.
|
/// @param[in] filter The polygon filter to apply to the query.
|
||||||
/// @param[out] resultRef The reference ids of the polygons touched by the circle. [opt]
|
/// @param[out] resultRef The reference ids of the polygons touched by the circle. [opt]
|
||||||
/// @param[out] resultParent The reference ids of the parent polygons for each result.
|
/// @param[out] resultParent The reference ids of the parent polygons for each result.
|
||||||
/// Zero if a result polygon has no parent. [opt]
|
/// Zero if a result polygon has no parent. [opt]
|
||||||
/// @param[out] resultCost The search cost from @p centerPos to the polygon. [opt]
|
/// @param[out] resultCost The search cost from @p centerPos to the polygon. [opt]
|
||||||
/// @param[out] resultCount The number of polygons found. [opt]
|
/// @param[out] resultCount The number of polygons found. [opt]
|
||||||
/// @param[in] maxResult The maximum number of polygons the result arrays can hold.
|
/// @param[in] maxResult The maximum number of polygons the result arrays can hold.
|
||||||
/// @returns The status flags for the query.
|
/// @returns The status flags for the query.
|
||||||
public Result<FindPolysAroundResult> FindPolysAroundCircle(long startRef, RcVec3f centerPos, float radius, IDtQueryFilter filter)
|
public DtStatus FindPolysAroundCircle(long startRef, RcVec3f centerPos, float radius, IDtQueryFilter filter,
|
||||||
|
out List<long> resultRef, out List<long> resultParent, out List<float> resultCost)
|
||||||
{
|
{
|
||||||
// Validate input
|
// TODO : check performance
|
||||||
|
resultRef = new List<long>();
|
||||||
|
resultParent = new List<long>();
|
||||||
|
resultCost = new List<float>();
|
||||||
|
|
||||||
|
// Validate input
|
||||||
if (!m_nav.IsValidPolyRef(startRef) || !RcVec3f.IsFinite(centerPos) || radius < 0
|
if (!m_nav.IsValidPolyRef(startRef) || !RcVec3f.IsFinite(centerPos) || radius < 0
|
||||||
|| !float.IsFinite(radius) || null == filter)
|
|| !float.IsFinite(radius) || null == filter)
|
||||||
{
|
{
|
||||||
return Results.InvalidParam<FindPolysAroundResult>();
|
return DtStatus.DT_FAILURE | DtStatus.DT_INVALID_PARAM;
|
||||||
}
|
}
|
||||||
|
|
||||||
List<long> resultRef = new List<long>();
|
|
||||||
List<long> resultParent = new List<long>();
|
|
||||||
List<float> resultCost = new List<float>();
|
|
||||||
|
|
||||||
m_nodePool.Clear();
|
m_nodePool.Clear();
|
||||||
m_openList.Clear();
|
m_openList.Clear();
|
||||||
|
|
||||||
|
@ -2564,57 +2565,58 @@ namespace DotRecast.Detour
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return Results.Success(new FindPolysAroundResult(resultRef, resultParent, resultCost));
|
return DtStatus.DT_SUCCSESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// @par
|
/// @par
|
||||||
///
|
///
|
||||||
/// The order of the result set is from least to highest cost.
|
/// The order of the result set is from least to highest cost.
|
||||||
///
|
///
|
||||||
/// At least one result array must be provided.
|
/// At least one result array must be provided.
|
||||||
///
|
///
|
||||||
/// A common use case for this method is to perform Dijkstra searches.
|
/// A common use case for this method is to perform Dijkstra searches.
|
||||||
/// Candidate polygons are found by searching the graph beginning at the start
|
/// Candidate polygons are found by searching the graph beginning at the start
|
||||||
/// polygon.
|
/// polygon.
|
||||||
///
|
///
|
||||||
/// The same intersection test restrictions that apply to FindPolysAroundCircle()
|
/// The same intersection test restrictions that apply to findPolysAroundCircle()
|
||||||
/// method apply to this method.
|
/// method apply to this method.
|
||||||
///
|
///
|
||||||
/// The 3D centroid of the search polygon is used as the start position for cost
|
/// The 3D centroid of the search polygon is used as the start position for cost
|
||||||
/// calculations.
|
/// calculations.
|
||||||
///
|
///
|
||||||
/// Intersection tests occur in 2D. All polygons are projected onto the
|
/// Intersection tests occur in 2D. All polygons are projected onto the
|
||||||
/// xz-plane. So the y-values of the vertices do not effect intersection tests.
|
/// xz-plane. So the y-values of the vertices do not effect intersection tests.
|
||||||
///
|
///
|
||||||
/// If the result arrays are is too small to hold the entire result set, they will
|
/// If the result arrays are is too small to hold the entire result set, they will
|
||||||
/// be filled to capacity.
|
/// be filled to capacity.
|
||||||
///
|
///
|
||||||
/// Finds the polygons along the naviation graph that touch the specified convex polygon.
|
/// Finds the polygons along the naviation graph that touch the specified convex polygon.
|
||||||
/// @param[in] startRef The reference id of the polygon where the search starts.
|
/// @param[in] startRef The reference id of the polygon where the search starts.
|
||||||
/// @param[in] verts The vertices describing the convex polygon. (CCW)
|
/// @param[in] verts The vertices describing the convex polygon. (CCW)
|
||||||
/// [(x, y, z) * @p nverts]
|
/// [(x, y, z) * @p nverts]
|
||||||
/// @param[in] nverts The number of vertices in the polygon.
|
/// @param[in] nverts The number of vertices in the polygon.
|
||||||
/// @param[in] filter The polygon filter to apply to the query.
|
/// @param[in] filter The polygon filter to apply to the query.
|
||||||
/// @param[out] resultRef The reference ids of the polygons touched by the search polygon. [opt]
|
/// @param[out] resultRef The reference ids of the polygons touched by the search polygon. [opt]
|
||||||
/// @param[out] resultParent The reference ids of the parent polygons for each result. Zero if a
|
/// @param[out] resultParent The reference ids of the parent polygons for each result. Zero if a
|
||||||
/// result polygon has no parent. [opt]
|
/// result polygon has no parent. [opt]
|
||||||
/// @param[out] resultCost The search cost from the centroid point to the polygon. [opt]
|
/// @param[out] resultCost The search cost from the centroid point to the polygon. [opt]
|
||||||
/// @param[out] resultCount The number of polygons found.
|
/// @param[out] resultCount The number of polygons found.
|
||||||
/// @param[in] maxResult The maximum number of polygons the result arrays can hold.
|
/// @param[in] maxResult The maximum number of polygons the result arrays can hold.
|
||||||
/// @returns The status flags for the query.
|
/// @returns The status flags for the query.
|
||||||
public Result<FindPolysAroundResult> FindPolysAroundShape(long startRef, float[] verts, IDtQueryFilter filter)
|
public DtStatus FindPolysAroundShape(long startRef, float[] verts, IDtQueryFilter filter,
|
||||||
|
out List<long> resultRef, out List<long> resultParent, out List<float> resultCost)
|
||||||
{
|
{
|
||||||
|
resultRef = new List<long>();
|
||||||
|
resultParent = new List<long>();
|
||||||
|
resultCost = new List<float>();
|
||||||
|
|
||||||
// Validate input
|
// Validate input
|
||||||
int nverts = verts.Length / 3;
|
int nverts = verts.Length / 3;
|
||||||
if (!m_nav.IsValidPolyRef(startRef) || null == verts || nverts < 3 || null == filter)
|
if (!m_nav.IsValidPolyRef(startRef) || null == verts || nverts < 3 || null == filter)
|
||||||
{
|
{
|
||||||
return Results.InvalidParam<FindPolysAroundResult>();
|
return DtStatus.DT_FAILURE | DtStatus.DT_INVALID_PARAM;
|
||||||
}
|
}
|
||||||
|
|
||||||
List<long> resultRef = new List<long>();
|
|
||||||
List<long> resultParent = new List<long>();
|
|
||||||
List<float> resultCost = new List<float>();
|
|
||||||
|
|
||||||
m_nodePool.Clear();
|
m_nodePool.Clear();
|
||||||
m_openList.Clear();
|
m_openList.Clear();
|
||||||
|
|
||||||
|
@ -2751,7 +2753,7 @@ namespace DotRecast.Detour
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return Results.Success(new FindPolysAroundResult(resultRef, resultParent, resultCost));
|
return DtStatus.DT_SUCCSESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// @par
|
/// @par
|
||||||
|
|
|
@ -1,54 +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 System.Collections.Generic;
|
|
||||||
|
|
||||||
namespace DotRecast.Detour.QueryResults
|
|
||||||
{
|
|
||||||
// TODO: (PP) Add comments
|
|
||||||
public class FindPolysAroundResult
|
|
||||||
{
|
|
||||||
private readonly List<long> refs;
|
|
||||||
private readonly List<long> parentRefs;
|
|
||||||
private readonly List<float> costs;
|
|
||||||
|
|
||||||
public FindPolysAroundResult(List<long> refs, List<long> parentRefs, List<float> costs)
|
|
||||||
{
|
|
||||||
this.@refs = refs;
|
|
||||||
this.parentRefs = parentRefs;
|
|
||||||
this.costs = costs;
|
|
||||||
}
|
|
||||||
|
|
||||||
public List<long> GetRefs()
|
|
||||||
{
|
|
||||||
return refs;
|
|
||||||
}
|
|
||||||
|
|
||||||
public List<long> GetParentRefs()
|
|
||||||
{
|
|
||||||
return parentRefs;
|
|
||||||
}
|
|
||||||
|
|
||||||
public List<float> GetCosts()
|
|
||||||
{
|
|
||||||
return costs;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -425,12 +425,11 @@ public class TestNavmeshTool : ITool
|
||||||
float dx = m_epos.x - m_spos.x;
|
float dx = m_epos.x - m_spos.x;
|
||||||
float dz = m_epos.z - m_spos.z;
|
float dz = m_epos.z - m_spos.z;
|
||||||
float dist = (float)Math.Sqrt(dx * dx + dz * dz);
|
float dist = (float)Math.Sqrt(dx * dx + dz * dz);
|
||||||
Result<FindPolysAroundResult> result = m_navQuery.FindPolysAroundCircle(m_startRef, m_spos, dist,
|
var status = m_navQuery.FindPolysAroundCircle(m_startRef, m_spos, dist, m_filter, out var refs, out var parentRefs, out var costs);
|
||||||
m_filter);
|
if (status.Succeeded())
|
||||||
if (result.Succeeded())
|
|
||||||
{
|
{
|
||||||
m_polys = result.result.GetRefs();
|
m_polys = refs;
|
||||||
m_parent = result.result.GetParentRefs();
|
m_parent = parentRefs;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -458,11 +457,11 @@ public class TestNavmeshTool : ITool
|
||||||
m_queryPoly[10] = m_epos.y + agentHeight / 2;
|
m_queryPoly[10] = m_epos.y + agentHeight / 2;
|
||||||
m_queryPoly[11] = m_epos.z + nz;
|
m_queryPoly[11] = m_epos.z + nz;
|
||||||
|
|
||||||
Result<FindPolysAroundResult> result = m_navQuery.FindPolysAroundShape(m_startRef, m_queryPoly, m_filter);
|
var status = m_navQuery.FindPolysAroundShape(m_startRef, m_queryPoly, m_filter, out var refs, out var parentRefs, out var costs);
|
||||||
if (result.Succeeded())
|
if (status.Succeeded())
|
||||||
{
|
{
|
||||||
m_polys = result.result.GetRefs();
|
m_polys = refs;
|
||||||
m_parent = result.result.GetParentRefs();
|
m_parent = parentRefs;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -106,19 +106,19 @@ public class FindPolysAroundCircleTest : AbstractDetourTest
|
||||||
{
|
{
|
||||||
long startRef = startRefs[i];
|
long startRef = startRefs[i];
|
||||||
RcVec3f startPos = startPoss[i];
|
RcVec3f startPos = startPoss[i];
|
||||||
Result<FindPolysAroundResult> result = query.FindPolysAroundCircle(startRef, startPos, 7.5f, filter);
|
var status = query.FindPolysAroundCircle(startRef, startPos, 7.5f, filter, out var refs, out var parentRefs, out var costs);
|
||||||
Assert.That(result.Succeeded(), Is.True);
|
Assert.That(status.Succeeded(), Is.True);
|
||||||
FindPolysAroundResult polys = result.result;
|
|
||||||
Assert.That(polys.GetRefs().Count, Is.EqualTo(REFS[i].Length));
|
Assert.That(refs.Count, Is.EqualTo(REFS[i].Length));
|
||||||
for (int v = 0; v < REFS[i].Length; v++)
|
for (int v = 0; v < REFS[i].Length; v++)
|
||||||
{
|
{
|
||||||
bool found = false;
|
bool found = false;
|
||||||
for (int w = 0; w < REFS[i].Length; w++)
|
for (int w = 0; w < REFS[i].Length; w++)
|
||||||
{
|
{
|
||||||
if (REFS[i][v] == polys.GetRefs()[w])
|
if (REFS[i][v] == refs[w])
|
||||||
{
|
{
|
||||||
Assert.That(polys.GetParentRefs()[w], Is.EqualTo(PARENT_REFS[i][v]));
|
Assert.That(parentRefs[w], Is.EqualTo(PARENT_REFS[i][v]));
|
||||||
Assert.That(polys.GetCosts()[w], Is.EqualTo(COSTS[i][v]).Within(0.01f));
|
Assert.That(costs[w], Is.EqualTo(COSTS[i][v]).Within(0.01f));
|
||||||
found = true;
|
found = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -133,17 +133,17 @@ public class FindPolysAroundShapeTest : AbstractDetourTest
|
||||||
{
|
{
|
||||||
long startRef = startRefs[i];
|
long startRef = startRefs[i];
|
||||||
RcVec3f startPos = startPoss[i];
|
RcVec3f startPos = startPoss[i];
|
||||||
Result<FindPolysAroundResult> polys = query.FindPolysAroundShape(startRef, GetQueryPoly(startPos, endPoss[i]), filter);
|
query.FindPolysAroundShape(startRef, GetQueryPoly(startPos, endPoss[i]), filter, out var refs, out var parentRefs, out var costs);
|
||||||
Assert.That(polys.result.GetRefs().Count, Is.EqualTo(REFS[i].Length));
|
Assert.That(refs.Count, Is.EqualTo(REFS[i].Length));
|
||||||
for (int v = 0; v < REFS[i].Length; v++)
|
for (int v = 0; v < REFS[i].Length; v++)
|
||||||
{
|
{
|
||||||
bool found = false;
|
bool found = false;
|
||||||
for (int w = 0; w < REFS[i].Length; w++)
|
for (int w = 0; w < REFS[i].Length; w++)
|
||||||
{
|
{
|
||||||
if (REFS[i][v] == polys.result.GetRefs()[w])
|
if (REFS[i][v] == refs[w])
|
||||||
{
|
{
|
||||||
Assert.That(polys.result.GetParentRefs()[w], Is.EqualTo(PARENT_REFS[i][v]));
|
Assert.That(parentRefs[w], Is.EqualTo(PARENT_REFS[i][v]));
|
||||||
Assert.That(polys.result.GetCosts()[w], Is.EqualTo(COSTS[i][v]).Within(0.01f));
|
Assert.That(costs[w], Is.EqualTo(COSTS[i][v]).Within(0.01f));
|
||||||
found = true;
|
found = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -177,4 +177,4 @@ public class FindPolysAroundShapeTest : AbstractDetourTest
|
||||||
m_queryPoly[11] = m_epos.z + nz;
|
m_queryPoly[11] = m_epos.z + nz;
|
||||||
return m_queryPoly;
|
return m_queryPoly;
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue