forked from bit/DotRecastNetSim
added check tile building
This commit is contained in:
parent
d21cbfb46d
commit
5b16338447
|
@ -58,7 +58,9 @@ namespace DotRecast.Detour
|
||||||
|
|
||||||
/// < Origin of the tile (0,0)
|
/// < Origin of the tile (0,0)
|
||||||
// float m_orig[3]; ///< Origin of the tile (0,0)
|
// float m_orig[3]; ///< Origin of the tile (0,0)
|
||||||
float m_tileWidth, m_tileHeight;
|
private float m_tileWidth;
|
||||||
|
|
||||||
|
private float m_tileHeight;
|
||||||
|
|
||||||
/// < Dimensions of each tile.
|
/// < Dimensions of each tile.
|
||||||
int m_maxTiles;
|
int m_maxTiles;
|
||||||
|
@ -78,6 +80,43 @@ namespace DotRecast.Detour
|
||||||
|
|
||||||
private int m_tileCount;
|
private int m_tileCount;
|
||||||
|
|
||||||
|
public DtNavMesh(DtMeshData data, int maxVertsPerPoly, int flags)
|
||||||
|
: this(GetNavMeshParams(data), maxVertsPerPoly)
|
||||||
|
{
|
||||||
|
AddTile(data, flags, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
public DtNavMesh(DtNavMeshParams option, int maxVertsPerPoly)
|
||||||
|
{
|
||||||
|
m_params = option;
|
||||||
|
m_orig = option.orig;
|
||||||
|
m_tileWidth = option.tileWidth;
|
||||||
|
m_tileHeight = option.tileHeight;
|
||||||
|
// Init tiles
|
||||||
|
m_maxTiles = option.maxTiles;
|
||||||
|
m_maxVertPerPoly = maxVertsPerPoly;
|
||||||
|
m_tileLutMask = Math.Max(1, DetourCommon.NextPow2(option.maxTiles)) - 1;
|
||||||
|
m_tiles = new DtMeshTile[m_maxTiles];
|
||||||
|
for (int i = 0; i < m_maxTiles; i++)
|
||||||
|
{
|
||||||
|
m_tiles[i] = new DtMeshTile(i);
|
||||||
|
m_tiles[i].salt = 1;
|
||||||
|
availableTiles.AddLast(m_tiles[i]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static DtNavMeshParams GetNavMeshParams(DtMeshData data)
|
||||||
|
{
|
||||||
|
DtNavMeshParams option = new DtNavMeshParams();
|
||||||
|
option.orig = data.header.bmin;
|
||||||
|
option.tileWidth = data.header.bmax.x - data.header.bmin.x;
|
||||||
|
option.tileHeight = data.header.bmax.z - data.header.bmin.z;
|
||||||
|
option.maxTiles = 1;
|
||||||
|
option.maxPolys = data.header.polyCount;
|
||||||
|
return option;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The maximum number of tiles supported by the navigation mesh.
|
* The maximum number of tiles supported by the navigation mesh.
|
||||||
*
|
*
|
||||||
|
@ -290,41 +329,6 @@ namespace DotRecast.Detour
|
||||||
return m_params;
|
return m_params;
|
||||||
}
|
}
|
||||||
|
|
||||||
public DtNavMesh(DtMeshData data, int maxVertsPerPoly, int flags)
|
|
||||||
: this(GetNavMeshParams(data), maxVertsPerPoly)
|
|
||||||
{
|
|
||||||
AddTile(data, flags, 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
public DtNavMesh(DtNavMeshParams option, int maxVertsPerPoly)
|
|
||||||
{
|
|
||||||
m_params = option;
|
|
||||||
m_orig = option.orig;
|
|
||||||
m_tileWidth = option.tileWidth;
|
|
||||||
m_tileHeight = option.tileHeight;
|
|
||||||
// Init tiles
|
|
||||||
m_maxTiles = option.maxTiles;
|
|
||||||
m_maxVertPerPoly = maxVertsPerPoly;
|
|
||||||
m_tileLutMask = Math.Max(1, DetourCommon.NextPow2(option.maxTiles)) - 1;
|
|
||||||
m_tiles = new DtMeshTile[m_maxTiles];
|
|
||||||
for (int i = 0; i < m_maxTiles; i++)
|
|
||||||
{
|
|
||||||
m_tiles[i] = new DtMeshTile(i);
|
|
||||||
m_tiles[i].salt = 1;
|
|
||||||
availableTiles.AddLast(m_tiles[i]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private static DtNavMeshParams GetNavMeshParams(DtMeshData data)
|
|
||||||
{
|
|
||||||
DtNavMeshParams option = new DtNavMeshParams();
|
|
||||||
option.orig = data.header.bmin;
|
|
||||||
option.tileWidth = data.header.bmax.x - data.header.bmin.x;
|
|
||||||
option.tileHeight = data.header.bmax.z - data.header.bmin.z;
|
|
||||||
option.maxTiles = 1;
|
|
||||||
option.maxPolys = data.header.polyCount;
|
|
||||||
return option;
|
|
||||||
}
|
|
||||||
|
|
||||||
// TODO: These methods are duplicates from dtNavMeshQuery, but are needed
|
// TODO: These methods are duplicates from dtNavMeshQuery, but are needed
|
||||||
// for off-mesh connection finding.
|
// for off-mesh connection finding.
|
||||||
|
@ -1580,6 +1584,11 @@ namespace DotRecast.Detour
|
||||||
return m_tileCount;
|
return m_tileCount;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public int GetAvailableTileCount()
|
||||||
|
{
|
||||||
|
return availableTiles.Count;
|
||||||
|
}
|
||||||
|
|
||||||
public DtStatus SetPolyFlags(long refs, int flags)
|
public DtStatus SetPolyFlags(long refs, int flags)
|
||||||
{
|
{
|
||||||
if (refs == 0)
|
if (refs == 0)
|
||||||
|
@ -1760,7 +1769,5 @@ namespace DotRecast.Detour
|
||||||
|
|
||||||
return tiles;
|
return tiles;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -59,10 +59,17 @@ public class TileTool : IRcTool
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
_impl.BuildTile(_hitPos, out var tileBuildTicks, out var tileTriCount, out var tileMemUsage);
|
bool built = _impl.BuildTile(_hitPos, out var tileBuildTicks, out var tileTriCount, out var tileMemUsage);
|
||||||
|
if (!built)
|
||||||
|
{
|
||||||
|
Logger.Error($"failed to build tile - check!");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
Logger.Information($"{tileBuildTicks / (float)TimeSpan.TicksPerMillisecond}ms / {tileTriCount}Tris / {tileMemUsage}kB ");
|
Logger.Information($"{tileBuildTicks / (float)TimeSpan.TicksPerMillisecond}ms / {tileTriCount}Tris / {tileMemUsage}kB ");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public void HandleRender(NavMeshRenderer renderer)
|
public void HandleRender(NavMeshRenderer renderer)
|
||||||
{
|
{
|
||||||
|
|
|
@ -89,6 +89,12 @@ namespace DotRecast.Recast.DemoTool.Tools
|
||||||
var geom = _sample.GetInputGeom();
|
var geom = _sample.GetInputGeom();
|
||||||
var navMesh = _sample.GetNavMesh();
|
var navMesh = _sample.GetNavMesh();
|
||||||
|
|
||||||
|
var availableTileCount = navMesh.GetAvailableTileCount();
|
||||||
|
if (0 >= availableTileCount)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
RcVec3f bmin = geom.GetMeshBoundsMin();
|
RcVec3f bmin = geom.GetMeshBoundsMin();
|
||||||
RcVec3f bmax = geom.GetMeshBoundsMax();
|
RcVec3f bmax = geom.GetMeshBoundsMax();
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue