Core/Recast: Updated to latest recast version.
This commit is contained in:
@@ -71,7 +71,7 @@ namespace Framework.Constants
|
|||||||
public const uint MapLiquidMagic = 0x51494C4D; //"MLIQ";
|
public const uint MapLiquidMagic = 0x51494C4D; //"MLIQ";
|
||||||
|
|
||||||
public const uint mmapMagic = 0x4D4D4150; // 'MMAP'
|
public const uint mmapMagic = 0x4D4D4150; // 'MMAP'
|
||||||
public const int mmapVersion = 9;
|
public const int mmapVersion = 10;
|
||||||
|
|
||||||
public const string VMapMagic = "VMAP_4.9";
|
public const string VMapMagic = "VMAP_4.9";
|
||||||
public const float VMAPInvalidHeightValue = -200000.0f;
|
public const float VMAPInvalidHeightValue = -200000.0f;
|
||||||
|
|||||||
@@ -358,8 +358,8 @@ public static partial class Detour
|
|||||||
// Find sub triangle weighted by area.
|
// Find sub triangle weighted by area.
|
||||||
float thr = s * areasum;
|
float thr = s * areasum;
|
||||||
float acc = 0.0f;
|
float acc = 0.0f;
|
||||||
float u = 0.0f;
|
float u = 1.0f;
|
||||||
int tri = 0;
|
int tri = npts - 1;
|
||||||
for (int i = 2; i < npts; i++)
|
for (int i = 2; i < npts; i++)
|
||||||
{
|
{
|
||||||
float dacc = areas[i];
|
float dacc = areas[i];
|
||||||
|
|||||||
@@ -570,13 +570,13 @@ public static partial class Detour
|
|||||||
if (targetPoly.firstLink == DT_NULL_LINK)
|
if (targetPoly.firstLink == DT_NULL_LINK)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
float[] ext = new float[] { targetCon.rad, target.header.walkableClimb, targetCon.rad };
|
float[] halfExtents = new float[] { targetCon.rad, target.header.walkableClimb, targetCon.rad };
|
||||||
|
|
||||||
// Find polygon to connect to.
|
// Find polygon to connect to.
|
||||||
//const float* p = &targetCon.pos[3];
|
//const float* p = &targetCon.pos[3];
|
||||||
int pIndex = 3;
|
int pIndex = 3;
|
||||||
float[] nearestPt = new float[3];
|
float[] nearestPt = new float[3];
|
||||||
dtPolyRef polyRef = findNearestPolyInTile(tile, targetCon.pos, pIndex, ext, nearestPt);
|
dtPolyRef polyRef = findNearestPolyInTile(tile, targetCon.pos, pIndex, halfExtents, nearestPt);
|
||||||
if (polyRef == 0)
|
if (polyRef == 0)
|
||||||
continue;
|
continue;
|
||||||
// findNearestPoly may return too optimistic results, further check to make sure.
|
// findNearestPoly may return too optimistic results, further check to make sure.
|
||||||
@@ -676,13 +676,13 @@ public static partial class Detour
|
|||||||
dtOffMeshConnection con = tile.offMeshCons[i];
|
dtOffMeshConnection con = tile.offMeshCons[i];
|
||||||
dtPoly poly = tile.polys[con.poly];
|
dtPoly poly = tile.polys[con.poly];
|
||||||
|
|
||||||
float[] ext = new float[] { con.rad, tile.header.walkableClimb, con.rad };
|
float[] halfExtents = new float[] { con.rad, tile.header.walkableClimb, con.rad };
|
||||||
|
|
||||||
// Find polygon to connect to.
|
// Find polygon to connect to.
|
||||||
//const float* p = &con.pos[0]; // First vertex
|
//const float* p = &con.pos[0]; // First vertex
|
||||||
|
|
||||||
float[] nearestPt = new float[3];
|
float[] nearestPt = new float[3];
|
||||||
dtPolyRef polyRef = findNearestPolyInTile(tile, con.pos, 0, ext, nearestPt);
|
dtPolyRef polyRef = findNearestPolyInTile(tile, con.pos, 0, halfExtents, nearestPt);
|
||||||
if (polyRef == 0)
|
if (polyRef == 0)
|
||||||
continue;
|
continue;
|
||||||
// findNearestPoly may return too optimistic results, further check to make sure.
|
// findNearestPoly may return too optimistic results, further check to make sure.
|
||||||
@@ -812,7 +812,7 @@ public static partial class Detour
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
float h = .0f;
|
float h = .0f;
|
||||||
if (dtClosestHeightPointTriangle(pos, posStart, vArrays[0], vIndices[0], vArrays[1], vIndices[1], vArrays[2], vIndices[2], ref h))
|
if (dtClosestHeightPointTriangle(closest, posStart, vArrays[0], vIndices[0], vArrays[1], vIndices[1], vArrays[2], vIndices[2], ref h))
|
||||||
{
|
{
|
||||||
closest[1] = h;
|
closest[1] = h;
|
||||||
break;
|
break;
|
||||||
@@ -820,12 +820,12 @@ public static partial class Detour
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public dtPolyRef findNearestPolyInTile(dtMeshTile tile, float[] center, int centerStart, float[] extents, float[] nearestPt)
|
public dtPolyRef findNearestPolyInTile(dtMeshTile tile, float[] center, int centerStart, float[] halfExtents, float[] nearestPt)
|
||||||
{
|
{
|
||||||
float[] bmin = new float[3];//, bmax[3];
|
float[] bmin = new float[3];//, bmax[3];
|
||||||
float[] bmax = new float[3];
|
float[] bmax = new float[3];
|
||||||
dtVsub(bmin, 0, center, centerStart, extents, 0);
|
dtVsub(bmin, 0, center, centerStart, halfExtents, 0);
|
||||||
dtVadd(bmax, 0, center, centerStart, extents, 0);
|
dtVadd(bmax, 0, center, centerStart, halfExtents, 0);
|
||||||
|
|
||||||
// Get nearby polygons from proximity grid.
|
// Get nearby polygons from proximity grid.
|
||||||
dtPolyRef[] polys = new dtPolyRef[128];
|
dtPolyRef[] polys = new dtPolyRef[128];
|
||||||
|
|||||||
@@ -906,28 +906,56 @@ public static partial class Detour
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static int createBVTree(ushort[] verts, int nverts, ushort[] polys, int npolys, int nvp, float cs, float ch, int nnodes, dtBVNode[] nodes)
|
public static int createBVTree(dtNavMeshCreateParams createParams, dtBVNode[] nodes, int nnodes)
|
||||||
{
|
{
|
||||||
// Build tree
|
// Build tree
|
||||||
BVItem[] items = new BVItem[npolys];//(BVItem*)dtAlloc(sizeof(BVItem)*npolys, DT_ALLOC_TEMP);
|
float quantFactor = 1 / createParams.cs;
|
||||||
|
BVItem[] items = new BVItem[createParams.polyCount];//(BVItem*)dtAlloc(sizeof(BVItem)*npolys, DT_ALLOC_TEMP);
|
||||||
dtcsArrayItemsCreate(items);
|
dtcsArrayItemsCreate(items);
|
||||||
for (int i = 0; i < npolys; i++)
|
for (int i = 0; i < createParams.polyCount; i++)
|
||||||
{
|
{
|
||||||
BVItem it = items[i];
|
BVItem it = items[i];
|
||||||
it.i = i;
|
it.i = i;
|
||||||
// Calc polygon bounds.
|
// Calc polygon bounds. Use detail meshes if available.
|
||||||
//const ushort* p = &polys[i*nvp*2];
|
if (createParams.detailMeshes != null)
|
||||||
int pIndex = i * nvp * 2;
|
|
||||||
it.bmin[0] = it.bmax[0] = verts[polys[pIndex + 0] * 3 + 0];
|
|
||||||
it.bmin[1] = it.bmax[1] = verts[polys[pIndex + 0] * 3 + 1];
|
|
||||||
it.bmin[2] = it.bmax[2] = verts[polys[pIndex + 0] * 3 + 2];
|
|
||||||
|
|
||||||
for (int j = 1; j < nvp; ++j)
|
|
||||||
{
|
{
|
||||||
if (polys[pIndex + j] == MESH_NULL_IDX) break;
|
int vb = (int)createParams.detailMeshes[i * 4 + 0];
|
||||||
ushort x = verts[polys[pIndex + j] * 3 + 0];
|
int ndv = (int)createParams.detailMeshes[i * 4 + 1];
|
||||||
ushort y = verts[polys[pIndex + j] * 3 + 1];
|
float[] bmin = new float[3];
|
||||||
ushort z = verts[polys[pIndex + j] * 3 + 2];
|
float[] bmax = new float[3];
|
||||||
|
|
||||||
|
float[] dv = createParams.detailVerts[(vb * 3)..];
|
||||||
|
dtVcopy(bmin, dv);
|
||||||
|
dtVcopy(bmax, dv);
|
||||||
|
|
||||||
|
for (int j = 1; j < ndv; j++)
|
||||||
|
{
|
||||||
|
dtVmin(bmin, dv[(j * 3)..]);
|
||||||
|
dtVmax(bmax, dv[(j * 3)..]);
|
||||||
|
}
|
||||||
|
|
||||||
|
// BV-tree uses cs for all dimensions
|
||||||
|
it.bmin[0] = (ushort)dtClamp((int)((bmin[0] - createParams.bmin[0]) * quantFactor), 0, 0xffff);
|
||||||
|
it.bmin[1] = (ushort)dtClamp((int)((bmin[1] - createParams.bmin[1]) * quantFactor), 0, 0xffff);
|
||||||
|
it.bmin[2] = (ushort)dtClamp((int)((bmin[2] - createParams.bmin[2]) * quantFactor), 0, 0xffff);
|
||||||
|
|
||||||
|
it.bmax[0] = (ushort)dtClamp((int)((bmax[0] - createParams.bmin[0]) * quantFactor), 0, 0xffff);
|
||||||
|
it.bmax[1] = (ushort)dtClamp((int)((bmax[1] - createParams.bmin[1]) * quantFactor), 0, 0xffff);
|
||||||
|
it.bmax[2] = (ushort)dtClamp((int)((bmax[2] - createParams.bmin[2]) * quantFactor), 0, 0xffff);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
ushort[] p = createParams.polys[(i * createParams.nvp * 2)..];
|
||||||
|
it.bmin[0] = it.bmax[0] = createParams.verts[p[0] * 3 + 0];
|
||||||
|
it.bmin[1] = it.bmax[1] = createParams.verts[p[0] * 3 + 1];
|
||||||
|
it.bmin[2] = it.bmax[2] = createParams.verts[p[0] * 3 + 2];
|
||||||
|
|
||||||
|
for (int j = 1; j < createParams.nvp; ++j)
|
||||||
|
{
|
||||||
|
if (p[j] == MESH_NULL_IDX) break;
|
||||||
|
ushort x = createParams.verts[p[j] * 3 + 0];
|
||||||
|
ushort y = createParams.verts[p[j] * 3 + 1];
|
||||||
|
ushort z = createParams.verts[p[j] * 3 + 2];
|
||||||
|
|
||||||
if (x < it.bmin[0]) it.bmin[0] = x;
|
if (x < it.bmin[0]) it.bmin[0] = x;
|
||||||
if (y < it.bmin[1]) it.bmin[1] = y;
|
if (y < it.bmin[1]) it.bmin[1] = y;
|
||||||
@@ -938,12 +966,13 @@ public static partial class Detour
|
|||||||
if (z > it.bmax[2]) it.bmax[2] = z;
|
if (z > it.bmax[2]) it.bmax[2] = z;
|
||||||
}
|
}
|
||||||
// Remap y
|
// Remap y
|
||||||
it.bmin[1] = (ushort)Math.Floor((float)it.bmin[1] * ch / cs);
|
it.bmin[1] = (ushort)MathF.Floor((float)it.bmin[1] * createParams.ch / createParams.cs);
|
||||||
it.bmax[1] = (ushort)Math.Ceiling((float)it.bmax[1] * ch / cs);
|
it.bmax[1] = (ushort)MathF.Ceiling((float)it.bmax[1] * createParams.ch / createParams.cs);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int curNode = 0;
|
int curNode = 0;
|
||||||
subdivide(items, npolys, 0, npolys, ref curNode, nodes);
|
subdivide(items, createParams.polyCount, 0, createParams.polyCount, ref curNode, nodes);
|
||||||
|
|
||||||
//dtFree(items);
|
//dtFree(items);
|
||||||
|
|
||||||
@@ -1412,8 +1441,7 @@ public static partial class Detour
|
|||||||
// TODO: take detail mesh into account! use byte per bbox extent?
|
// TODO: take detail mesh into account! use byte per bbox extent?
|
||||||
if (createParams.buildBvTree)
|
if (createParams.buildBvTree)
|
||||||
{
|
{
|
||||||
createBVTree(createParams.verts, createParams.vertCount, createParams.polys, createParams.polyCount,
|
createBVTree(createParams, navBvtree, createParams.polyCount * 2);
|
||||||
nvp, createParams.cs, createParams.ch, createParams.polyCount * 2, navBvtree);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Store Off-Mesh connections.
|
// Store Off-Mesh connections.
|
||||||
|
|||||||
@@ -709,7 +709,7 @@ public static partial class Detour
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
float h = .0f;
|
float h = .0f;
|
||||||
if (dtClosestHeightPointTriangle(pos, 0, vSrc[0], vStarts[0], vSrc[1], vStarts[1], vSrc[2], vStarts[2], ref h))
|
if (dtClosestHeightPointTriangle(closest, 0, vSrc[0], vStarts[0], vSrc[1], vStarts[1], vSrc[2], vStarts[2], ref h))
|
||||||
{
|
{
|
||||||
closest[1] = h;
|
closest[1] = h;
|
||||||
break;
|
break;
|
||||||
@@ -864,7 +864,7 @@ public static partial class Detour
|
|||||||
|
|
||||||
/// Finds the polygon nearest to the specified center point.
|
/// Finds the polygon nearest to the specified center point.
|
||||||
/// @param[in] center The center of the search box. [(x, y, z)]
|
/// @param[in] center The center of the search box. [(x, y, z)]
|
||||||
/// @param[in] extents The search distance along each axis. [(x, y, z)]
|
/// @param[in] halfExtents The search distance along each axis. [(x, y, z)]
|
||||||
/// @param[in] filter The polygon filter to apply to the query.
|
/// @param[in] filter The polygon filter to apply to the query.
|
||||||
/// @param[out] nearestRef The reference id of the nearest polygon.
|
/// @param[out] nearestRef The reference id of the nearest polygon.
|
||||||
/// @param[out] nearestPt The nearest point on the polygon. [opt] [(x, y, z)]
|
/// @param[out] nearestPt The nearest point on the polygon. [opt] [(x, y, z)]
|
||||||
@@ -878,7 +878,7 @@ public static partial class Detour
|
|||||||
// @warning This function is not suitable for large area searches. If the search
|
// @warning This function is not suitable for large area searches. If the search
|
||||||
/// extents overlaps more than 128 polygons it may return an invalid result.
|
/// extents overlaps more than 128 polygons it may return an invalid result.
|
||||||
///
|
///
|
||||||
public dtStatus findNearestPoly(float[] center, float[] extents, dtQueryFilter filter, ref dtPolyRef nearestRef, ref float[] nearestPt)
|
public dtStatus findNearestPoly(float[] center, float[] halfExtents, dtQueryFilter filter, ref dtPolyRef nearestRef, ref float[] nearestPt)
|
||||||
{
|
{
|
||||||
Debug.Assert(m_nav != null);
|
Debug.Assert(m_nav != null);
|
||||||
|
|
||||||
@@ -886,7 +886,7 @@ public static partial class Detour
|
|||||||
|
|
||||||
dtFindNearestPolyQuery query = new dtFindNearestPolyQuery(this, center);
|
dtFindNearestPolyQuery query = new dtFindNearestPolyQuery(this, center);
|
||||||
|
|
||||||
dtStatus status = queryPolygons(center, extents, filter, query);
|
dtStatus status = queryPolygons(center, halfExtents, filter, query);
|
||||||
if (dtStatusFailed(status))
|
if (dtStatusFailed(status))
|
||||||
return status;
|
return status;
|
||||||
|
|
||||||
@@ -1030,7 +1030,7 @@ public static partial class Detour
|
|||||||
|
|
||||||
/// Finds polygons that overlap the search box.
|
/// Finds polygons that overlap the search box.
|
||||||
/// @param[in] center The center of the search box. [(x, y, z)]
|
/// @param[in] center The center of the search box. [(x, y, z)]
|
||||||
/// @param[in] extents The search distance along each axis. [(x, y, z)]
|
/// @param[in] halfExtents The search distance along each axis. [(x, y, z)]
|
||||||
/// @param[in] filter The polygon filter to apply to the query.
|
/// @param[in] filter The polygon filter to apply to the query.
|
||||||
/// @param[out] polys The reference ids of the polygons that overlap the query box.
|
/// @param[out] polys The reference ids of the polygons that overlap the query box.
|
||||||
/// @param[out] polyCount The number of polygons in the search result.
|
/// @param[out] polyCount The number of polygons in the search result.
|
||||||
@@ -1045,14 +1045,14 @@ public static partial class Detour
|
|||||||
/// be filled to capacity. The method of choosing which polygons from the
|
/// be filled to capacity. The method of choosing which polygons from the
|
||||||
/// full set are included in the partial result set is undefined.
|
/// full set are included in the partial result set is undefined.
|
||||||
///
|
///
|
||||||
public dtStatus queryPolygons(float[] center, float[] extents, dtQueryFilter filter, dtFindNearestPolyQuery query)
|
public dtStatus queryPolygons(float[] center, float[] halfExtents, dtQueryFilter filter, dtFindNearestPolyQuery query)
|
||||||
{
|
{
|
||||||
Debug.Assert(m_nav != null);
|
Debug.Assert(m_nav != null);
|
||||||
|
|
||||||
float[] bmin = new float[3];
|
float[] bmin = new float[3];
|
||||||
float[] bmax = new float[3];
|
float[] bmax = new float[3];
|
||||||
dtVsub(bmin, center, extents);
|
dtVsub(bmin, center, halfExtents);
|
||||||
dtVadd(bmax, center, extents);
|
dtVadd(bmax, center, halfExtents);
|
||||||
|
|
||||||
// Find tiles the query touches.
|
// Find tiles the query touches.
|
||||||
int minx = 0, miny = 0, maxx = 0, maxy = 0;
|
int minx = 0, miny = 0, maxx = 0, maxy = 0;
|
||||||
|
|||||||
Reference in New Issue
Block a user