mirror of
https://github.com/TorqueGameEngines/Torque3D.git
synced 2026-04-29 16:25:42 +00:00
make sure tilesize is in world units
tilesize now stays the same size as the world units provided
This commit is contained in:
parent
d4d552e8e0
commit
ab83ecb591
3 changed files with 24 additions and 66 deletions
|
|
@ -51,7 +51,7 @@ duDebugDrawTorque::~duDebugDrawTorque()
|
||||||
|
|
||||||
void duDebugDrawTorque::depthMask(bool state)
|
void duDebugDrawTorque::depthMask(bool state)
|
||||||
{
|
{
|
||||||
mDesc.setZReadWrite(state, false);
|
mDesc.setZReadWrite(state);
|
||||||
}
|
}
|
||||||
|
|
||||||
void duDebugDrawTorque::texture(bool state)
|
void duDebugDrawTorque::texture(bool state)
|
||||||
|
|
@ -95,7 +95,8 @@ void duDebugDrawTorque::begin(duDebugDrawPrimitives prim, float size)
|
||||||
}
|
}
|
||||||
|
|
||||||
mDesc.setCullMode(GFXCullCW);
|
mDesc.setCullMode(GFXCullCW);
|
||||||
mDesc.setBlend(true);
|
mDesc.setBlend(false);
|
||||||
|
mDesc.setZReadWrite(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Submit a vertex
|
/// Submit a vertex
|
||||||
|
|
|
||||||
|
|
@ -187,10 +187,11 @@ NavMesh::NavMesh()
|
||||||
mSaveIntermediates = false;
|
mSaveIntermediates = false;
|
||||||
nm = NULL;
|
nm = NULL;
|
||||||
ctx = NULL;
|
ctx = NULL;
|
||||||
|
m_geo = NULL;
|
||||||
|
|
||||||
mWaterMethod = Ignore;
|
mWaterMethod = Ignore;
|
||||||
|
|
||||||
mCellSize = mCellHeight = 0.01f;
|
mCellSize = mCellHeight = 0.2f;
|
||||||
mWalkableHeight = 2.0f;
|
mWalkableHeight = 2.0f;
|
||||||
mWalkableClimb = 0.3f;
|
mWalkableClimb = 0.3f;
|
||||||
mWalkableRadius = 0.5f;
|
mWalkableRadius = 0.5f;
|
||||||
|
|
@ -664,12 +665,12 @@ bool NavMesh::build(bool background, bool saveIntermediates)
|
||||||
Box3F rc_box = DTStoRC(getWorldBox());
|
Box3F rc_box = DTStoRC(getWorldBox());
|
||||||
S32 gw = 0, gh = 0;
|
S32 gw = 0, gh = 0;
|
||||||
rcCalcGridSize(rc_box.minExtents, rc_box.maxExtents, mCellSize, &gw, &gh);
|
rcCalcGridSize(rc_box.minExtents, rc_box.maxExtents, mCellSize, &gw, &gh);
|
||||||
const S32 ts = (S32)mTileSize;
|
const S32 ts = (S32)(mTileSize / mCellSize);
|
||||||
const S32 tw = (gw + ts - 1) / ts;
|
const S32 tw = (gw + ts - 1) / ts;
|
||||||
const S32 th = (gh + ts - 1) / ts;
|
const S32 th = (gh + ts - 1) / ts;
|
||||||
Con::printf("NavMesh::Build - Tiles %d x %d", tw, th);
|
Con::printf("NavMesh::Build - Tiles %d x %d", tw, th);
|
||||||
|
|
||||||
U32 tileBits = mMin(getNextBinLog2(tw * th), 14);
|
U32 tileBits = mMin(getBinLog2(getNextPow2(tw * th)), 14);
|
||||||
if (tileBits > 14) tileBits = 14;
|
if (tileBits > 14) tileBits = 14;
|
||||||
U32 maxTiles = 1 << tileBits;
|
U32 maxTiles = 1 << tileBits;
|
||||||
U32 polyBits = 22 - tileBits;
|
U32 polyBits = 22 - tileBits;
|
||||||
|
|
@ -678,8 +679,8 @@ bool NavMesh::build(bool background, bool saveIntermediates)
|
||||||
// Build navmesh parameters from console members.
|
// Build navmesh parameters from console members.
|
||||||
dtNavMeshParams params;
|
dtNavMeshParams params;
|
||||||
rcVcopy(params.orig, rc_box.minExtents);
|
rcVcopy(params.orig, rc_box.minExtents);
|
||||||
params.tileWidth = mTileSize * mCellSize;
|
params.tileWidth = mTileSize;
|
||||||
params.tileHeight = mTileSize * mCellSize;
|
params.tileHeight = mTileSize;
|
||||||
params.maxTiles = maxTiles;
|
params.maxTiles = maxTiles;
|
||||||
params.maxPolys = mMaxPolysPerTile;
|
params.maxPolys = mMaxPolysPerTile;
|
||||||
|
|
||||||
|
|
@ -822,7 +823,6 @@ void NavMesh::updateTiles(bool dirty)
|
||||||
}
|
}
|
||||||
|
|
||||||
mTiles.clear();
|
mTiles.clear();
|
||||||
mTileData.clear();
|
|
||||||
mDirtyTiles.clear();
|
mDirtyTiles.clear();
|
||||||
|
|
||||||
const Box3F &box = DTStoRC(getWorldBox());
|
const Box3F &box = DTStoRC(getWorldBox());
|
||||||
|
|
@ -837,7 +837,7 @@ void NavMesh::updateTiles(bool dirty)
|
||||||
const S32 ts = (S32)mTileSize;
|
const S32 ts = (S32)mTileSize;
|
||||||
const S32 tw = (gw + ts - 1) / ts;
|
const S32 tw = (gw + ts - 1) / ts;
|
||||||
const S32 th = (gh + ts - 1) / ts;
|
const S32 th = (gh + ts - 1) / ts;
|
||||||
const F32 tcs = mTileSize * mCellSize;
|
const F32 tcs = mTileSize;
|
||||||
|
|
||||||
// Iterate over tiles.
|
// Iterate over tiles.
|
||||||
F32 tileBmin[3], tileBmax[3];
|
F32 tileBmin[3], tileBmax[3];
|
||||||
|
|
@ -860,9 +860,6 @@ void NavMesh::updateTiles(bool dirty)
|
||||||
|
|
||||||
if(dirty)
|
if(dirty)
|
||||||
mDirtyTiles.push_back_unique(mTiles.size() - 1);
|
mDirtyTiles.push_back_unique(mTiles.size() - 1);
|
||||||
|
|
||||||
if(mSaveIntermediates)
|
|
||||||
mTileData.increment();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -881,16 +878,13 @@ void NavMesh::buildNextTile()
|
||||||
U32 i = mDirtyTiles.front();
|
U32 i = mDirtyTiles.front();
|
||||||
mDirtyTiles.pop_front();
|
mDirtyTiles.pop_front();
|
||||||
const Tile &tile = mTiles[i];
|
const Tile &tile = mTiles[i];
|
||||||
// Intermediate data for tile build.
|
|
||||||
TileData tempdata;
|
|
||||||
TileData &tdata = mSaveIntermediates ? mTileData[i] : tempdata;
|
|
||||||
|
|
||||||
// Remove any previous data.
|
// Remove any previous data.
|
||||||
nm->removeTile(nm->getTileRefAt(tile.x, tile.y, 0), 0, 0);
|
nm->removeTile(nm->getTileRefAt(tile.x, tile.y, 0), 0, 0);
|
||||||
|
|
||||||
// Generate navmesh for this tile.
|
// Generate navmesh for this tile.
|
||||||
U32 dataSize = 0;
|
U32 dataSize = 0;
|
||||||
unsigned char* data = buildTileData(tile, tdata, dataSize);
|
unsigned char* data = buildTileData(tile, dataSize);
|
||||||
if(data)
|
if(data)
|
||||||
{
|
{
|
||||||
// Add new data (navmesh owns and deletes the data).
|
// Add new data (navmesh owns and deletes the data).
|
||||||
|
|
@ -929,7 +923,7 @@ void NavMesh::buildNextTile()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned char *NavMesh::buildTileData(const Tile &tile, TileData &data, U32 &dataSize)
|
unsigned char *NavMesh::buildTileData(const Tile &tile, U32 &dataSize)
|
||||||
{
|
{
|
||||||
|
|
||||||
cleanup();
|
cleanup();
|
||||||
|
|
@ -953,7 +947,7 @@ unsigned char *NavMesh::buildTileData(const Tile &tile, TileData &data, U32 &dat
|
||||||
m_cfg.minRegionArea = (S32)mSquared((F32)mMinRegionArea);
|
m_cfg.minRegionArea = (S32)mSquared((F32)mMinRegionArea);
|
||||||
m_cfg.mergeRegionArea = (S32)mSquared((F32)mMergeRegionArea);
|
m_cfg.mergeRegionArea = (S32)mSquared((F32)mMergeRegionArea);
|
||||||
m_cfg.maxVertsPerPoly = (S32)mMaxVertsPerPoly;
|
m_cfg.maxVertsPerPoly = (S32)mMaxVertsPerPoly;
|
||||||
m_cfg.tileSize = (S32)mTileSize;
|
m_cfg.tileSize = (S32)(mTileSize / mCellSize);
|
||||||
m_cfg.borderSize = mMax(m_cfg.walkableRadius + 3, mBorderSize); // use the border size if it is bigger.
|
m_cfg.borderSize = mMax(m_cfg.walkableRadius + 3, mBorderSize); // use the border size if it is bigger.
|
||||||
m_cfg.width = m_cfg.tileSize + m_cfg.borderSize * 2;
|
m_cfg.width = m_cfg.tileSize + m_cfg.borderSize * 2;
|
||||||
m_cfg.height = m_cfg.tileSize + m_cfg.borderSize * 2;
|
m_cfg.height = m_cfg.tileSize + m_cfg.borderSize * 2;
|
||||||
|
|
@ -1572,21 +1566,22 @@ void NavMesh::renderLinks(duDebugDraw &dd)
|
||||||
|
|
||||||
void NavMesh::renderTileData(duDebugDrawTorque &dd, U32 tile)
|
void NavMesh::renderTileData(duDebugDrawTorque &dd, U32 tile)
|
||||||
{
|
{
|
||||||
if(tile >= mTileData.size())
|
|
||||||
return;
|
|
||||||
if(nm)
|
if(nm)
|
||||||
{
|
{
|
||||||
duDebugDrawNavMesh(&dd, *nm, 0);
|
duDebugDrawNavMesh(&dd, *nm, 0);
|
||||||
if(mTileData[tile].chf)
|
if(m_chf)
|
||||||
duDebugDrawCompactHeightfieldSolid(&dd, *mTileData[tile].chf);
|
duDebugDrawCompactHeightfieldSolid(&dd, *m_chf);
|
||||||
|
|
||||||
duDebugDrawNavMeshPortals(&dd, *nm);
|
duDebugDrawNavMeshPortals(&dd, *nm);
|
||||||
|
|
||||||
|
if (!m_geo)
|
||||||
|
return;
|
||||||
|
|
||||||
int col = duRGBA(255, 0, 255, 255);
|
int col = duRGBA(255, 0, 255, 255);
|
||||||
RecastPolyList &in = mTileData[tile].geom;
|
|
||||||
dd.begin(DU_DRAW_LINES);
|
dd.begin(DU_DRAW_LINES);
|
||||||
const F32 *verts = in.getVerts();
|
const F32 *verts = m_geo->getVerts();
|
||||||
const S32 *tris = in.getTris();
|
const S32 *tris = m_geo->getTris();
|
||||||
for(U32 t = 0; t < in.getTriCount(); t++)
|
for(U32 t = 0; t < m_geo->getTriCount(); t++)
|
||||||
{
|
{
|
||||||
dd.vertex(&verts[tris[t*3]*3], col);
|
dd.vertex(&verts[tris[t*3]*3], col);
|
||||||
dd.vertex(&verts[tris[t*3+1]*3], col);
|
dd.vertex(&verts[tris[t*3+1]*3], col);
|
||||||
|
|
|
||||||
|
|
@ -254,10 +254,6 @@ protected:
|
||||||
dtNavMesh const* getNavMesh() { return nm; }
|
dtNavMesh const* getNavMesh() { return nm; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
/// Generates a navigation mesh for the collection of objects in this
|
|
||||||
/// mesh. Returns true if successful. Stores the created mesh in tnm.
|
|
||||||
bool generateMesh();
|
|
||||||
|
|
||||||
/// Builds the next tile in the dirty list.
|
/// Builds the next tile in the dirty list.
|
||||||
void buildNextTile();
|
void buildNextTile();
|
||||||
|
|
||||||
|
|
@ -288,43 +284,9 @@ private:
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
/// Intermediate data for tile creation.
|
|
||||||
struct TileData {
|
|
||||||
RecastPolyList geom;
|
|
||||||
rcHeightfield *hf;
|
|
||||||
rcCompactHeightfield *chf;
|
|
||||||
rcContourSet *cs;
|
|
||||||
rcPolyMesh *pm;
|
|
||||||
rcPolyMeshDetail *pmd;
|
|
||||||
TileData()
|
|
||||||
{
|
|
||||||
hf = NULL;
|
|
||||||
chf = NULL;
|
|
||||||
cs = NULL;
|
|
||||||
pm = NULL;
|
|
||||||
pmd = NULL;
|
|
||||||
}
|
|
||||||
void freeAll()
|
|
||||||
{
|
|
||||||
geom.clear();
|
|
||||||
rcFreeHeightField(hf);
|
|
||||||
rcFreeCompactHeightfield(chf);
|
|
||||||
rcFreeContourSet(cs);
|
|
||||||
rcFreePolyMesh(pm);
|
|
||||||
rcFreePolyMeshDetail(pmd);
|
|
||||||
}
|
|
||||||
~TileData()
|
|
||||||
{
|
|
||||||
freeAll();
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
/// List of tiles.
|
/// List of tiles.
|
||||||
Vector<Tile> mTiles;
|
Vector<Tile> mTiles;
|
||||||
|
|
||||||
/// List of tile intermediate data.
|
|
||||||
Vector<TileData> mTileData;
|
|
||||||
|
|
||||||
/// List of indices to the tile array which are dirty.
|
/// List of indices to the tile array which are dirty.
|
||||||
Vector<U32> mDirtyTiles;
|
Vector<U32> mDirtyTiles;
|
||||||
|
|
||||||
|
|
@ -332,7 +294,7 @@ private:
|
||||||
void updateTiles(bool dirty = false);
|
void updateTiles(bool dirty = false);
|
||||||
|
|
||||||
/// Generates navmesh data for a single tile.
|
/// Generates navmesh data for a single tile.
|
||||||
unsigned char *buildTileData(const Tile &tile, TileData &data, U32 &dataSize);
|
unsigned char *buildTileData(const Tile &tile, U32 &dataSize);
|
||||||
|
|
||||||
/// @}
|
/// @}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue