Removed stat and tile navmeshes. Fixed examples.
This commit is contained in:
parent
6a00efb936
commit
e4239a3bdf
@ -19,18 +19,10 @@
|
|||||||
#ifndef DETOURDEBUGDRAW_H
|
#ifndef DETOURDEBUGDRAW_H
|
||||||
#define DETOURDEBUGDRAW_H
|
#define DETOURDEBUGDRAW_H
|
||||||
|
|
||||||
#include "DetourStatNavMesh.h"
|
|
||||||
#include "DetourTileNavMesh.h"
|
|
||||||
#include "DetourNavMesh.h"
|
#include "DetourNavMesh.h"
|
||||||
|
|
||||||
void dtDebugDrawStatNavMeshPoly(const dtStatNavMesh* mesh, dtStatPolyRef ref, const float* col);
|
|
||||||
void dtDebugDrawStatNavMeshBVTree(const dtStatNavMesh* mesh);
|
|
||||||
void dtDebugDrawStatNavMesh(const dtStatNavMesh* mesh, bool drawClosedList = false);
|
|
||||||
|
|
||||||
void dtDebugDrawTiledNavMesh(const dtTiledNavMesh* mesh);
|
|
||||||
void dtDebugDrawTiledNavMeshPoly(const dtTiledNavMesh* mesh, dtTilePolyRef ref, const float* col);
|
|
||||||
|
|
||||||
void dtDebugDrawNavMesh(const dtNavMesh* mesh, bool drawClosedList = false);
|
void dtDebugDrawNavMesh(const dtNavMesh* mesh, bool drawClosedList = false);
|
||||||
|
void dtDebugDrawNavMeshBVTree(const dtNavMesh* mesh);
|
||||||
void dtDebugDrawNavMeshPoly(const dtNavMesh* mesh, dtPolyRef ref, const float* col);
|
void dtDebugDrawNavMeshPoly(const dtNavMesh* mesh, dtPolyRef ref, const float* col);
|
||||||
|
|
||||||
#endif // DETOURDEBUGDRAW_H
|
#endif // DETOURDEBUGDRAW_H
|
@ -1,237 +0,0 @@
|
|||||||
//
|
|
||||||
// Copyright (c) 2009 Mikko Mononen memon@inside.org
|
|
||||||
//
|
|
||||||
// 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.
|
|
||||||
//
|
|
||||||
|
|
||||||
#ifndef DETOURSTATNAVMESH_H
|
|
||||||
#define DETOURSTATNAVMESH_H
|
|
||||||
|
|
||||||
// Reference to navigation polygon.
|
|
||||||
typedef unsigned short dtStatPolyRef;
|
|
||||||
|
|
||||||
// Maximum number of vertices per navigation polygon.
|
|
||||||
static const int DT_STAT_VERTS_PER_POLYGON = 6;
|
|
||||||
|
|
||||||
// Structure holding the navigation polygon data.
|
|
||||||
struct dtStatPoly
|
|
||||||
{
|
|
||||||
unsigned short v[DT_STAT_VERTS_PER_POLYGON]; // Indices to vertices of the poly.
|
|
||||||
dtStatPolyRef n[DT_STAT_VERTS_PER_POLYGON]; // Refs to neighbours of the poly.
|
|
||||||
unsigned char nv; // Number of vertices.
|
|
||||||
unsigned char flags; // Flags (not used).
|
|
||||||
};
|
|
||||||
|
|
||||||
struct dtStatPolyDetail
|
|
||||||
{
|
|
||||||
unsigned short vbase; // Offset to detail vertex array.
|
|
||||||
unsigned short nverts; // Number of vertices in the detail mesh.
|
|
||||||
unsigned short tbase; // Offset to detail triangle array.
|
|
||||||
unsigned short ntris; // Number of triangles.
|
|
||||||
};
|
|
||||||
|
|
||||||
const int DT_STAT_NAVMESH_MAGIC = 'NAVM';
|
|
||||||
const int DT_STAT_NAVMESH_VERSION = 3;
|
|
||||||
|
|
||||||
struct dtStatBVNode
|
|
||||||
{
|
|
||||||
unsigned short bmin[3], bmax[3];
|
|
||||||
int i;
|
|
||||||
};
|
|
||||||
|
|
||||||
struct dtStatNavMeshHeader
|
|
||||||
{
|
|
||||||
int magic;
|
|
||||||
int version;
|
|
||||||
int npolys;
|
|
||||||
int nverts;
|
|
||||||
int nnodes;
|
|
||||||
int ndmeshes;
|
|
||||||
int ndverts;
|
|
||||||
int ndtris;
|
|
||||||
float cs;
|
|
||||||
float bmin[3], bmax[3];
|
|
||||||
dtStatPoly* polys;
|
|
||||||
float* verts;
|
|
||||||
dtStatBVNode* bvtree;
|
|
||||||
dtStatPolyDetail* dmeshes;
|
|
||||||
float* dverts;
|
|
||||||
unsigned char* dtris;
|
|
||||||
};
|
|
||||||
|
|
||||||
class dtStatNavMesh
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
|
|
||||||
dtStatNavMesh();
|
|
||||||
~dtStatNavMesh();
|
|
||||||
|
|
||||||
// Initializes the navmesh with data.
|
|
||||||
// Params:
|
|
||||||
// data - (in) Pointer to navmesh data.
|
|
||||||
// dataSize - (in) size of the navmesh data.
|
|
||||||
// ownsData - (in) Flag indicating if the navmesh should own and delete the data.
|
|
||||||
bool init(unsigned char* data, int dataSize, bool ownsData);
|
|
||||||
|
|
||||||
// Finds the nearest navigation polygon around the center location.
|
|
||||||
// Params:
|
|
||||||
// center - (in) The center of the search box.
|
|
||||||
// extents - (in) The extents of the search box.
|
|
||||||
// Returns: Reference identifier for the polygon, or 0 if no polygons found.
|
|
||||||
dtStatPolyRef findNearestPoly(const float* center, const float* extents);
|
|
||||||
|
|
||||||
// Returns polygons which touch the query box.
|
|
||||||
// Params:
|
|
||||||
// center - (in) the center of the search box.
|
|
||||||
// extents - (in) the extents of the search box.
|
|
||||||
// polys - (out) array holding the search result.
|
|
||||||
// maxPolys - (in) The max number of polygons the polys array can hold.
|
|
||||||
// Returns: Number of polygons in search result array.
|
|
||||||
int queryPolygons(const float* center, const float* extents,
|
|
||||||
dtStatPolyRef* polys, const int maxPolys);
|
|
||||||
|
|
||||||
// Finds path from start polygon to end polygon.
|
|
||||||
// If target polygon canno be reached through the navigation graph,
|
|
||||||
// the last node on the array is nearest node to the end polygon.
|
|
||||||
// Params:
|
|
||||||
// startRef - (in) ref to path start polygon.
|
|
||||||
// endRef - (in) ref to path end polygon.
|
|
||||||
// path - (out) array holding the search result.
|
|
||||||
// maxPathSize - (in) The max number of polygons the path array can hold.
|
|
||||||
// Returns: Number of polygons in search result array.
|
|
||||||
int findPath(dtStatPolyRef startRef, dtStatPolyRef endRef,
|
|
||||||
const float* startPos, const float* endPos,
|
|
||||||
dtStatPolyRef* path, const int maxPathSize);
|
|
||||||
|
|
||||||
// Finds a straight path from start to end locations within the corridor
|
|
||||||
// described by the path polygons.
|
|
||||||
// Start and end locations will be clamped on the corridor.
|
|
||||||
// Params:
|
|
||||||
// startPos - (in) Path start location.
|
|
||||||
// endPos - (in) Path end location.
|
|
||||||
// path - (in) Array of connected polygons describing the corridor.
|
|
||||||
// pathSize - (in) Number of polygons in path array.
|
|
||||||
// straightPath - (out) Points describing the straight path.
|
|
||||||
// maxStraightPathSize - (in) The max number of points the straight path array can hold.
|
|
||||||
// Returns: Number of points in the path.
|
|
||||||
int findStraightPath(const float* startPos, const float* endPos,
|
|
||||||
const dtStatPolyRef* path, const int pathSize,
|
|
||||||
float* straightPath, const int maxStraightPathSize);
|
|
||||||
|
|
||||||
// Finds intersection againts walls starting from start pos.
|
|
||||||
// Params:
|
|
||||||
// startRef - (in) ref to the polygon where the start lies.
|
|
||||||
// startPos - (in) start position of the query.
|
|
||||||
// endPos - (in) end position of the query.
|
|
||||||
// t - (out) hit parameter along the segment, 0 if no hit.
|
|
||||||
// endRef - (out) ref to the last polygon which was processed.
|
|
||||||
// Returns: Number of polygons in path or 0 if failed.
|
|
||||||
int raycast(dtStatPolyRef startRef, const float* startPos, const float* endPos,
|
|
||||||
float& t, dtStatPolyRef* path, const int pathSize);
|
|
||||||
|
|
||||||
// Returns distance to nearest wall from the specified location.
|
|
||||||
// Params:
|
|
||||||
// centerRef - (in) ref to the polygon where the center lies.
|
|
||||||
// centerPos - (in) center if the query circle.
|
|
||||||
// maxRadius - (in) max search radius.
|
|
||||||
// hitPos - (out) location of the nearest hit.
|
|
||||||
// hitNormal - (out) normal of the nearest hit.
|
|
||||||
// Returns: Distance to nearest wall from the test location.
|
|
||||||
float findDistanceToWall(dtStatPolyRef centerRef, const float* centerPos, float maxRadius,
|
|
||||||
float* hitPos, float* hitNormal);
|
|
||||||
|
|
||||||
// Finds polygons found along the navigation graph which touch the specified circle.
|
|
||||||
// Params:
|
|
||||||
// centerRef - (in) ref to the polygon where the center lies.
|
|
||||||
// centerPos - (in) center if the query circle
|
|
||||||
// radius - (in) radius of the query circle
|
|
||||||
// resultRef - (out, opt) refs to the polygons touched by the circle.
|
|
||||||
// resultParent - (out, opt) parent of each result polygon.
|
|
||||||
// resultCost - (out, opt) search cost at each result polygon.
|
|
||||||
// maxResult - (int) maximum capacity of search results.
|
|
||||||
// Returns: Number of results.
|
|
||||||
int findPolysAround(dtStatPolyRef centerRef, const float* centerPos, float radius,
|
|
||||||
dtStatPolyRef* resultRef, dtStatPolyRef* resultParent, float* resultCost,
|
|
||||||
const int maxResult);
|
|
||||||
|
|
||||||
// Returns closest point on navigation polygon.
|
|
||||||
// Params:
|
|
||||||
// ref - (in) ref to the polygon.
|
|
||||||
// pos - (in) the point to check.
|
|
||||||
// closest - (out) closest point.
|
|
||||||
// Returns: true if closest point found.
|
|
||||||
bool closestPointToPoly(dtStatPolyRef ref, const float* pos, float* closest) const;
|
|
||||||
|
|
||||||
// Returns height of the polygon at specified location.
|
|
||||||
// Params:
|
|
||||||
// ref - (in) ref to the polygon.
|
|
||||||
// pos - (in) the point where to locate the height.
|
|
||||||
// height - (out) height at the location.
|
|
||||||
// Returns: true if oer polygon.
|
|
||||||
bool getPolyHeight(dtStatPolyRef ref, const float* pos, float* height) const;
|
|
||||||
|
|
||||||
int moveAlongPath(const float* startPos, const float* endPos, float* resultPos,
|
|
||||||
const dtStatPolyRef* path, const int pathSize);
|
|
||||||
|
|
||||||
// Returns pointer to a polygon based on ref.
|
|
||||||
const dtStatPoly* getPolyByRef(dtStatPolyRef ref) const;
|
|
||||||
// Returns polygon index based on ref, or -1 if failed.
|
|
||||||
int getPolyIndexByRef(dtStatPolyRef ref) const;
|
|
||||||
// Returns number of navigation polygons.
|
|
||||||
inline int getPolyCount() const { return m_header ? m_header->npolys : 0; }
|
|
||||||
// Rerturns pointer to specified navigation polygon.
|
|
||||||
inline const dtStatPoly* getPoly(int i) const { return &m_header->polys[i]; }
|
|
||||||
// Returns number of vertices.
|
|
||||||
inline int getVertexCount() const { return m_header ? m_header->nverts : 0; }
|
|
||||||
// Returns pointer to specified vertex.
|
|
||||||
inline const float* getVertex(int i) const { return &m_header->verts[i*3]; }
|
|
||||||
// Returns number of navigation polygons details.
|
|
||||||
inline int getPolyDetailCount() const { return m_header ? m_header->ndmeshes : 0; }
|
|
||||||
// Rerturns pointer to specified navigation polygon detail.
|
|
||||||
const dtStatPolyDetail* getPolyDetail(int i) const { return &m_header->dmeshes[i]; }
|
|
||||||
// Returns pointer to specified vertex.
|
|
||||||
inline const float* getDetailVertex(int i) const { return &m_header->dverts[i*3]; }
|
|
||||||
// Returns pointer to specified vertex.
|
|
||||||
inline const unsigned char* getDetailTri(int i) const { return &m_header->dtris[i*4]; }
|
|
||||||
|
|
||||||
bool isInClosedList(dtStatPolyRef ref) const;
|
|
||||||
|
|
||||||
int getMemUsed() const;
|
|
||||||
|
|
||||||
inline unsigned char* getData() const { return m_data; }
|
|
||||||
inline int getDataSize() const { return m_dataSize; }
|
|
||||||
inline const dtStatNavMeshHeader* getHeader() const { return m_header; }
|
|
||||||
inline const dtStatBVNode* getBvTreeNodes() const { return m_header ? m_header->bvtree : 0; }
|
|
||||||
inline int getBvTreeNodeCount() const { return m_header ? m_header->nnodes : 0; }
|
|
||||||
|
|
||||||
private:
|
|
||||||
|
|
||||||
// Copies the locations of vertices of a polygon to an array.
|
|
||||||
int getPolyVerts(dtStatPolyRef ref, float* verts) const;
|
|
||||||
// Returns portal points between two polygons.
|
|
||||||
bool getPortalPoints(dtStatPolyRef from, dtStatPolyRef to, float* left, float* right) const;
|
|
||||||
// Returns edge mid point between two polygons.
|
|
||||||
bool getEdgeMidPoint(dtStatPolyRef from, dtStatPolyRef to, float* mid) const;
|
|
||||||
|
|
||||||
unsigned char* m_data;
|
|
||||||
int m_dataSize;
|
|
||||||
|
|
||||||
dtStatNavMeshHeader* m_header;
|
|
||||||
|
|
||||||
class dtNodePool* m_nodePool;
|
|
||||||
class dtNodeQueue* m_openList;
|
|
||||||
};
|
|
||||||
|
|
||||||
#endif // DETOURSTATNAVMESH_H
|
|
@ -1,29 +0,0 @@
|
|||||||
//
|
|
||||||
// Copyright (c) 2009 Mikko Mononen memon@inside.org
|
|
||||||
//
|
|
||||||
// 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.
|
|
||||||
//
|
|
||||||
|
|
||||||
#ifndef DETOURSTATNAVMESHBUILDER_H
|
|
||||||
#define DETOURSTATNAVMESHBUILDER_H
|
|
||||||
|
|
||||||
bool dtCreateNavMeshData(const unsigned short* verts, const int nverts,
|
|
||||||
const unsigned short* polys, const int npolys, const int nvp,
|
|
||||||
const float* bmin, const float* bmax, float cs, float ch,
|
|
||||||
const unsigned short* dmeshes, const float* dverts, const int ndverts,
|
|
||||||
const unsigned char* dtris, const int ndtris,
|
|
||||||
unsigned char** outData, int* outDataSize);
|
|
||||||
|
|
||||||
#endif // DETOURSTATNAVMESHBUILDER_H
|
|
@ -1,315 +0,0 @@
|
|||||||
//
|
|
||||||
// Copyright (c) 2009 Mikko Mononen memon@inside.org
|
|
||||||
//
|
|
||||||
// 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.
|
|
||||||
//
|
|
||||||
|
|
||||||
#ifndef DETOURTILENAVMESH_H
|
|
||||||
#define DETOURTILENAVMESH_H
|
|
||||||
|
|
||||||
// Reference to navigation polygon.
|
|
||||||
typedef unsigned int dtTilePolyRef;
|
|
||||||
|
|
||||||
// The bits used in the poly ref.
|
|
||||||
static const int DT_TILE_REF_SALT_BITS = 12;
|
|
||||||
static const int DT_TILE_REF_TILE_BITS = 12;
|
|
||||||
static const int DT_TILE_REF_POLY_BITS = 8;
|
|
||||||
static const int DT_TILE_REF_SALT_MASK = (1<<DT_TILE_REF_SALT_BITS)-1;
|
|
||||||
static const int DT_TILE_REF_TILE_MASK = (1<<DT_TILE_REF_TILE_BITS)-1;
|
|
||||||
static const int DT_TILE_REF_POLY_MASK = (1<<DT_TILE_REF_POLY_BITS)-1;
|
|
||||||
|
|
||||||
// Maximum number of vertices per navigation polygon.
|
|
||||||
static const int DT_TILE_VERTS_PER_POLYGON = 6;
|
|
||||||
|
|
||||||
static const int DT_MAX_TILES = 1 << DT_TILE_REF_TILE_BITS;
|
|
||||||
static const int DT_MAX_POLYGONS = 1 << DT_TILE_REF_POLY_BITS;
|
|
||||||
|
|
||||||
static const int DT_TILE_NAVMESH_MAGIC = 'NAVT';
|
|
||||||
static const int DT_TILE_NAVMESH_VERSION = 2;
|
|
||||||
|
|
||||||
// Structure holding the navigation polygon data.
|
|
||||||
struct dtTilePoly
|
|
||||||
{
|
|
||||||
unsigned short v[DT_TILE_VERTS_PER_POLYGON]; // Indices to vertices of the poly.
|
|
||||||
unsigned short n[DT_TILE_VERTS_PER_POLYGON]; // Refs to neighbours of the poly.
|
|
||||||
unsigned short links; // Base index to header 'links' array.
|
|
||||||
unsigned char nlinks; // Number of links for
|
|
||||||
unsigned char nv; // Number of vertices.
|
|
||||||
unsigned char flags; // Flags (not used).
|
|
||||||
};
|
|
||||||
|
|
||||||
struct dtTilePolyDetail
|
|
||||||
{
|
|
||||||
unsigned short vbase; // Offset to detail vertex array.
|
|
||||||
unsigned short nverts; // Number of vertices in the detail mesh.
|
|
||||||
unsigned short tbase; // Offset to detail triangle array.
|
|
||||||
unsigned short ntris; // Number of triangles.
|
|
||||||
};
|
|
||||||
|
|
||||||
// Stucture holding a link to another polygon.
|
|
||||||
struct dtTileLink
|
|
||||||
{
|
|
||||||
dtTilePolyRef ref; // Neighbour reference.
|
|
||||||
unsigned short p; // Index to polygon which owns this link.
|
|
||||||
unsigned char e; // Index to polygon edge which owns this link.
|
|
||||||
unsigned char side; // If boundary link, defines on which side the link is.
|
|
||||||
unsigned char bmin, bmax; // If boundary link, defines the sub edge area.
|
|
||||||
};
|
|
||||||
|
|
||||||
struct dtTileHeader
|
|
||||||
{
|
|
||||||
int magic; // Magic number, used to identify the data.
|
|
||||||
int version; // Data version number.
|
|
||||||
int npolys; // Number of polygons in the tile.
|
|
||||||
int nverts; // Number of vertices in the tile.
|
|
||||||
int nlinks; // Number of links in the tile (will be updated when tile is added).
|
|
||||||
int maxlinks; // Number of allocated links.
|
|
||||||
int ndmeshes;
|
|
||||||
int ndverts;
|
|
||||||
int ndtris;
|
|
||||||
float bmin[3], bmax[3]; // Bounding box of the tile.
|
|
||||||
dtTilePoly* polys; // Pointer to the polygons (will be updated when tile is added).
|
|
||||||
float* verts; // Pointer to the vertices (will be updated when tile added).
|
|
||||||
dtTileLink* links; // Pointer to the links (will be updated when tile added).
|
|
||||||
dtTilePolyDetail* dmeshes;
|
|
||||||
float* dverts;
|
|
||||||
unsigned char* dtris;
|
|
||||||
};
|
|
||||||
|
|
||||||
struct dtTile
|
|
||||||
{
|
|
||||||
int salt; // Counter describing modifications to the tile.
|
|
||||||
int x,y; // Grid location of the tile.
|
|
||||||
dtTileHeader* header; // Pointer to tile header.
|
|
||||||
unsigned char* data; // Pointer to tile data.
|
|
||||||
int dataSize; // Size of the tile data.
|
|
||||||
bool ownsData; // Flag indicating of the navmesh should release the data.
|
|
||||||
dtTile* next; // Next free tile or, next tile in spatial grid.
|
|
||||||
};
|
|
||||||
|
|
||||||
// Encodes a tile id.
|
|
||||||
inline dtTilePolyRef dtEncodeTileId(unsigned int salt, unsigned int it, unsigned int ip)
|
|
||||||
{
|
|
||||||
return (salt << (DT_TILE_REF_POLY_BITS+DT_TILE_REF_TILE_BITS)) | ((it+1) << DT_TILE_REF_POLY_BITS) | ip;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Decodes a tile id.
|
|
||||||
inline void dtDecodeTileId(dtTilePolyRef ref, unsigned int& salt, unsigned int& it, unsigned int& ip)
|
|
||||||
{
|
|
||||||
salt = (ref >> (DT_TILE_REF_POLY_BITS+DT_TILE_REF_TILE_BITS)) & DT_TILE_REF_SALT_MASK;
|
|
||||||
it = ((ref >> DT_TILE_REF_POLY_BITS) & DT_TILE_REF_TILE_MASK) - 1;
|
|
||||||
ip = ref & DT_TILE_REF_POLY_MASK;
|
|
||||||
}
|
|
||||||
|
|
||||||
static const int DT_TILE_LOOKUP_SIZE = DT_MAX_TILES/4;
|
|
||||||
|
|
||||||
class dtTiledNavMesh
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
dtTiledNavMesh();
|
|
||||||
~dtTiledNavMesh();
|
|
||||||
|
|
||||||
// Initializes the nav mesh.
|
|
||||||
// Params:
|
|
||||||
// orig - (in) origin of the nav mesh tile space.
|
|
||||||
// tileSiz - (in) size of a tile.
|
|
||||||
// portalheight - (in) height of the portal region between tiles.
|
|
||||||
// Returns: True if succeed, else false.
|
|
||||||
bool init(const float* orig, float tileSize, float portalHeight);
|
|
||||||
|
|
||||||
// Adds new tile into the navmesh.
|
|
||||||
// The add will fail if the data is in wrong format,
|
|
||||||
// there is not enough tiles left, or if there is a tile already at the location.
|
|
||||||
// Params:
|
|
||||||
// x,y - (in) Location of the new tile.
|
|
||||||
// data - (in) Data of the new tile mesh.
|
|
||||||
// dataSize - (in) Data size of the new tile mesh.
|
|
||||||
// ownsData - (in) Flag indicating if the navmesh should own and delete the data.
|
|
||||||
// Returns: True if tile was added, else false.
|
|
||||||
bool addTileAt(int x, int y, unsigned char* data, int dataSize, bool ownsData);
|
|
||||||
|
|
||||||
// Removes tile at specified location.
|
|
||||||
// Params:
|
|
||||||
// x,y - (in) Location of the tile to remove.
|
|
||||||
// data - (out) Data associated with deleted tile.
|
|
||||||
// dataSize - (out) Size of the data associated with deleted tile.
|
|
||||||
// Returns: True if remove suceed, else false.
|
|
||||||
bool removeTileAt(int x, int y, unsigned char** data, int* dataSize);
|
|
||||||
|
|
||||||
// Returns pointer to tile at specified location.
|
|
||||||
// Params:
|
|
||||||
// x,y - (in) Location of the tile to get.
|
|
||||||
// Returns: pointer to tile if tile exists or 0 tile does not exists.
|
|
||||||
dtTile* getTileAt(int x, int y);
|
|
||||||
|
|
||||||
// Returns pointer to tile in the tile array.
|
|
||||||
// Params:
|
|
||||||
// i - (in) Index to the tile to retrieve, must be in range [0,DT_MAX_TILES[
|
|
||||||
// Returns: Pointer to specified tile.
|
|
||||||
dtTile* getTile(int i);
|
|
||||||
const dtTile* getTile(int i) const;
|
|
||||||
|
|
||||||
// Finds the nearest navigation polygon around the center location.
|
|
||||||
// Params:
|
|
||||||
// center - (in) The center of the search box.
|
|
||||||
// extents - (in) The extents of the search box.
|
|
||||||
// Returns: Reference identifier for the polygon, or 0 if no polygons found.
|
|
||||||
dtTilePolyRef findNearestPoly(const float* center, const float* extents);
|
|
||||||
|
|
||||||
// Returns polygons which touch the query box.
|
|
||||||
// Params:
|
|
||||||
// center - (in) the center of the search box.
|
|
||||||
// extents - (in) the extents of the search box.
|
|
||||||
// polys - (out) array holding the search result.
|
|
||||||
// maxPolys - (in) The max number of polygons the polys array can hold.
|
|
||||||
// Returns: Number of polygons in search result array.
|
|
||||||
int queryPolygons(const float* center, const float* extents,
|
|
||||||
dtTilePolyRef* polys, const int maxPolys);
|
|
||||||
|
|
||||||
// Finds path from start polygon to end polygon.
|
|
||||||
// If target polygon canno be reached through the navigation graph,
|
|
||||||
// the last node on the array is nearest node to the end polygon.
|
|
||||||
// Params:
|
|
||||||
// startRef - (in) ref to path start polygon.
|
|
||||||
// endRef - (in) ref to path end polygon.
|
|
||||||
// path - (out) array holding the search result.
|
|
||||||
// maxPathSize - (in) The max number of polygons the path array can hold.
|
|
||||||
// Returns: Number of polygons in search result array.
|
|
||||||
int findPath(dtTilePolyRef startRef, dtTilePolyRef endRef,
|
|
||||||
const float* startPos, const float* endPos,
|
|
||||||
dtTilePolyRef* path, const int maxPathSize);
|
|
||||||
|
|
||||||
// Finds a straight path from start to end locations within the corridor
|
|
||||||
// described by the path polygons.
|
|
||||||
// Start and end locations will be clamped on the corridor.
|
|
||||||
// Params:
|
|
||||||
// startPos - (in) Path start location.
|
|
||||||
// endPos - (in) Path end location.
|
|
||||||
// path - (in) Array of connected polygons describing the corridor.
|
|
||||||
// pathSize - (in) Number of polygons in path array.
|
|
||||||
// straightPath - (out) Points describing the straight path.
|
|
||||||
// maxStraightPathSize - (in) The max number of points the straight path array can hold.
|
|
||||||
// Returns: Number of points in the path.
|
|
||||||
int findStraightPath(const float* startPos, const float* endPos,
|
|
||||||
const dtTilePolyRef* path, const int pathSize,
|
|
||||||
float* straightPath, const int maxStraightPathSize);
|
|
||||||
|
|
||||||
// Finds intersection againts walls starting from start pos.
|
|
||||||
// Params:
|
|
||||||
// startRef - (in) ref to the polygon where the start lies.
|
|
||||||
// startPos - (in) start position of the query.
|
|
||||||
// endPos - (in) end position of the query.
|
|
||||||
// t - (out) hit parameter along the segment, 0 if no hit.
|
|
||||||
// endRef - (out) ref to the last polygon which was processed.
|
|
||||||
// Returns: Number of polygons in path or 0 if failed.
|
|
||||||
int raycast(dtTilePolyRef startRef, const float* startPos, const float* endPos,
|
|
||||||
float& t, dtTilePolyRef* path, const int pathSize);
|
|
||||||
|
|
||||||
// Returns distance to nearest wall from the specified location.
|
|
||||||
// Params:
|
|
||||||
// centerRef - (in) ref to the polygon where the center lies.
|
|
||||||
// centerPos - (in) center if the query circle.
|
|
||||||
// maxRadius - (in) max search radius.
|
|
||||||
// hitPos - (out) location of the nearest hit.
|
|
||||||
// hitNormal - (out) normal of the nearest hit.
|
|
||||||
// Returns: Distance to nearest wall from the test location.
|
|
||||||
float findDistanceToWall(dtTilePolyRef centerRef, const float* centerPos, float maxRadius,
|
|
||||||
float* hitPos, float* hitNormal);
|
|
||||||
|
|
||||||
// Finds polygons found along the navigation graph which touch the specified circle.
|
|
||||||
// Params:
|
|
||||||
// centerRef - (in) ref to the polygon where the center lies.
|
|
||||||
// centerPos - (in) center if the query circle
|
|
||||||
// radius - (in) radius of the query circle
|
|
||||||
// resultRef - (out, opt) refs to the polygons touched by the circle.
|
|
||||||
// resultParent - (out, opt) parent of each result polygon.
|
|
||||||
// resultCost - (out, opt) search cost at each result polygon.
|
|
||||||
// maxResult - (int) maximum capacity of search results.
|
|
||||||
// Returns: Number of results.
|
|
||||||
int findPolysAround(dtTilePolyRef centerRef, const float* centerPos, float radius,
|
|
||||||
dtTilePolyRef* resultRef, dtTilePolyRef* resultParent, float* resultCost,
|
|
||||||
const int maxResult);
|
|
||||||
|
|
||||||
// Returns closest point on navigation polygon.
|
|
||||||
// Params:
|
|
||||||
// ref - (in) ref to the polygon.
|
|
||||||
// pos - (in) the point to check.
|
|
||||||
// closest - (out) closest point.
|
|
||||||
// Returns: true if closest point found.
|
|
||||||
bool closestPointToPoly(dtTilePolyRef ref, const float* pos, float* closest) const;
|
|
||||||
|
|
||||||
// Returns height of the polygon at specified location.
|
|
||||||
// Params:
|
|
||||||
// ref - (in) ref to the polygon.
|
|
||||||
// pos - (in) the point where to locate the height.
|
|
||||||
// height - (out) height at the location.
|
|
||||||
// Returns: true if over polygon.
|
|
||||||
bool getPolyHeight(dtTilePolyRef ref, const float* pos, float* height) const;
|
|
||||||
|
|
||||||
// Returns pointer to a polygon based on ref.
|
|
||||||
const dtTilePoly* getPolyByRef(dtTilePolyRef ref) const;
|
|
||||||
|
|
||||||
// Returns pointer to a polygon vertices based on ref.
|
|
||||||
const float* getPolyVertsByRef(dtTilePolyRef ref) const;
|
|
||||||
|
|
||||||
// Returns pointer to a polygon link based on ref.
|
|
||||||
const dtTileLink* getPolyLinksByRef(dtTilePolyRef ref) const;
|
|
||||||
|
|
||||||
private:
|
|
||||||
|
|
||||||
// Returns base id for the tile.
|
|
||||||
dtTilePolyRef getTileId(dtTile* tile);
|
|
||||||
// Returns neighbour tile based on side.
|
|
||||||
dtTile* getNeighbourTileAt(int x, int y, int side);
|
|
||||||
// Returns all polygons in neighbour tile based on portal defined by the segment.
|
|
||||||
int findConnectingPolys(const float* va, const float* vb,
|
|
||||||
dtTile* tile, int side,
|
|
||||||
dtTilePolyRef* con, float* conarea, int maxcon);
|
|
||||||
// Builds internal polygons links for a tile.
|
|
||||||
void buildIntLinks(dtTile* tile);
|
|
||||||
// Builds external polygon links for a tile.
|
|
||||||
void buildExtLinks(dtTile* tile, dtTile* target, int side);
|
|
||||||
// Removes external links at specified side.
|
|
||||||
void removeExtLinks(dtTile* tile, int side);
|
|
||||||
// Queries polygons within a tile.
|
|
||||||
int queryTilePolygons(dtTile* tile, const float* qmin, const float* qmax,
|
|
||||||
dtTilePolyRef* polys, const int maxPolys);
|
|
||||||
|
|
||||||
float getCost(dtTilePolyRef prev, dtTilePolyRef from, dtTilePolyRef to) const;
|
|
||||||
float getFirstCost(const float* pos, dtTilePolyRef from, dtTilePolyRef to) const;
|
|
||||||
float getLastCost(dtTilePolyRef from, dtTilePolyRef to, const float* pos) const;
|
|
||||||
float getHeuristic(const float* from, const float* to) const;
|
|
||||||
|
|
||||||
// Returns portal points between two polygons.
|
|
||||||
bool getPortalPoints(dtTilePolyRef from, dtTilePolyRef to, float* left, float* right) const;
|
|
||||||
// Returns edge mid point between two polygons.
|
|
||||||
bool getEdgeMidPoint(dtTilePolyRef from, dtTilePolyRef to, float* mid) const;
|
|
||||||
|
|
||||||
float m_orig[3];
|
|
||||||
float m_tileSize;
|
|
||||||
float m_portalHeight;
|
|
||||||
|
|
||||||
dtTile* m_posLookup[DT_TILE_LOOKUP_SIZE];
|
|
||||||
dtTile* m_nextFree;
|
|
||||||
dtTile m_tiles[DT_MAX_TILES];
|
|
||||||
|
|
||||||
dtTileLink* m_tmpLinks;
|
|
||||||
int m_ntmpLinks;
|
|
||||||
|
|
||||||
class dtNodePool* m_nodePool;
|
|
||||||
class dtNodeQueue* m_openList;
|
|
||||||
};
|
|
||||||
|
|
||||||
#endif // DETOURTILENAVMESH_H
|
|
@ -1,29 +0,0 @@
|
|||||||
//
|
|
||||||
// Copyright (c) 2009 Mikko Mononen memon@inside.org
|
|
||||||
//
|
|
||||||
// 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.
|
|
||||||
//
|
|
||||||
|
|
||||||
#ifndef DETOURTILEDNAVMESHBUILDER_H
|
|
||||||
#define DETOURTILEDNAVMESHBUILDER_H
|
|
||||||
|
|
||||||
bool dtCreateNavMeshTileData(const unsigned short* verts, const int nverts,
|
|
||||||
const unsigned short* polys, const int npolys, const int nvp,
|
|
||||||
const unsigned short* dmeshes, const float* dverts, const int ndverts,
|
|
||||||
const unsigned char* dtris, const int ndtris,
|
|
||||||
const float* bmin, const float* bmax, float cs, float ch, int tileSize, int walkableClimb,
|
|
||||||
unsigned char** outData, int* outDataSize);
|
|
||||||
|
|
||||||
#endif // DETOURTILEDNAVMESHBUILDER_H
|
|
@ -17,57 +17,10 @@
|
|||||||
//
|
//
|
||||||
|
|
||||||
#include "DetourDebugDraw.h"
|
#include "DetourDebugDraw.h"
|
||||||
#include "DetourStatNavMesh.h"
|
|
||||||
#include "DetourTileNavMesh.h"
|
|
||||||
#include "DetourNavMesh.h"
|
#include "DetourNavMesh.h"
|
||||||
#include "SDL.h"
|
#include "SDL.h"
|
||||||
#include "SDL_opengl.h"
|
#include "SDL_opengl.h"
|
||||||
|
|
||||||
void dtDebugDrawStatNavMeshPoly(const dtStatNavMesh* mesh, dtStatPolyRef ref, const float* col)
|
|
||||||
{
|
|
||||||
int idx = mesh->getPolyIndexByRef(ref);
|
|
||||||
if (idx == -1) return;
|
|
||||||
|
|
||||||
glColor4f(col[0],col[1],col[2],0.25f);
|
|
||||||
|
|
||||||
if (mesh->getPolyDetailCount())
|
|
||||||
{
|
|
||||||
const dtStatPoly* p = mesh->getPoly(idx);
|
|
||||||
const dtStatPolyDetail* pd = mesh->getPolyDetail(idx);
|
|
||||||
glBegin(GL_TRIANGLES);
|
|
||||||
for (int j = 0; j < pd->ntris; ++j)
|
|
||||||
{
|
|
||||||
const unsigned char* t = mesh->getDetailTri(pd->tbase+j);
|
|
||||||
for (int k = 0; k < 3; ++k)
|
|
||||||
{
|
|
||||||
if (t[k] < p->nv)
|
|
||||||
glVertex3fv(mesh->getVertex(p->v[t[k]]));
|
|
||||||
else
|
|
||||||
glVertex3fv(mesh->getDetailVertex(pd->vbase+(t[k]-p->nv)));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
glEnd();
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
const dtStatPoly* p = mesh->getPoly(idx);
|
|
||||||
glBegin(GL_TRIANGLES);
|
|
||||||
unsigned short vi[3];
|
|
||||||
for (int j = 2; j < (int)p->nv; ++j)
|
|
||||||
{
|
|
||||||
vi[0] = p->v[0];
|
|
||||||
vi[1] = p->v[j-1];
|
|
||||||
vi[2] = p->v[j];
|
|
||||||
for (int k = 0; k < 3; ++k)
|
|
||||||
{
|
|
||||||
const float* v = mesh->getVertex(vi[k]);
|
|
||||||
glVertex3f(v[0], v[1]+0.2f, v[2]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
glEnd();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static void drawBoxWire(float minx, float miny, float minz, float maxx, float maxy, float maxz, const float* col)
|
static void drawBoxWire(float minx, float miny, float minz, float maxx, float maxy, float maxz, const float* col)
|
||||||
{
|
{
|
||||||
glColor4fv(col);
|
glColor4fv(col);
|
||||||
@ -103,32 +56,6 @@ static void drawBoxWire(float minx, float miny, float minz, float maxx, float ma
|
|||||||
glVertex3f(minx, maxy, maxz);
|
glVertex3f(minx, maxy, maxz);
|
||||||
}
|
}
|
||||||
|
|
||||||
void dtDebugDrawStatNavMeshBVTree(const dtStatNavMesh* mesh)
|
|
||||||
{
|
|
||||||
const float col[] = { 1,1,1,0.5f };
|
|
||||||
const dtStatNavMeshHeader* hdr = mesh->getHeader();
|
|
||||||
|
|
||||||
const dtStatBVNode* nodes = mesh->getBvTreeNodes();
|
|
||||||
int nnodes = mesh->getBvTreeNodeCount();
|
|
||||||
|
|
||||||
glBegin(GL_LINES);
|
|
||||||
|
|
||||||
for (int i = 0; i < nnodes; ++i)
|
|
||||||
{
|
|
||||||
const dtStatBVNode* n = &nodes[i];
|
|
||||||
if (n->i < 0) // Leaf indices are positive.
|
|
||||||
continue;
|
|
||||||
drawBoxWire(hdr->bmin[0] + n->bmin[0]*hdr->cs,
|
|
||||||
hdr->bmin[1] + n->bmin[1]*hdr->cs,
|
|
||||||
hdr->bmin[2] + n->bmin[2]*hdr->cs,
|
|
||||||
hdr->bmin[0] + n->bmax[0]*hdr->cs,
|
|
||||||
hdr->bmin[1] + n->bmax[1]*hdr->cs,
|
|
||||||
hdr->bmin[2] + n->bmax[2]*hdr->cs, col);
|
|
||||||
}
|
|
||||||
glEnd();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
static float distancePtLine2d(const float* pt, const float* p, const float* q)
|
static float distancePtLine2d(const float* pt, const float* p, const float* q)
|
||||||
{
|
{
|
||||||
float pqx = q[0] - p[0];
|
float pqx = q[0] - p[0];
|
||||||
@ -143,363 +70,6 @@ static float distancePtLine2d(const float* pt, const float* p, const float* q)
|
|||||||
return dx*dx + dz*dz;
|
return dx*dx + dz*dz;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void drawStatMeshPolyBoundaries(const dtStatNavMesh* mesh, bool inner)
|
|
||||||
{
|
|
||||||
static const float thr = 0.01f*0.01f;
|
|
||||||
|
|
||||||
glBegin(GL_LINES);
|
|
||||||
for (int i = 0; i < mesh->getPolyCount(); ++i)
|
|
||||||
{
|
|
||||||
const dtStatPoly* p = mesh->getPoly(i);
|
|
||||||
const dtStatPolyDetail* pd = mesh->getPolyDetail(i);
|
|
||||||
|
|
||||||
for (int j = 0, nj = (int)p->nv; j < nj; ++j)
|
|
||||||
{
|
|
||||||
if (inner)
|
|
||||||
{
|
|
||||||
// Skip non-connected edges.
|
|
||||||
if (p->n[j] == 0) continue;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
// Skip connected edges.
|
|
||||||
if (p->n[j] != 0) continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
const float* v0 = mesh->getVertex(p->v[j]);
|
|
||||||
const float* v1 = mesh->getVertex(p->v[(j+1) % nj]);
|
|
||||||
|
|
||||||
// Draw detail mesh edges which align with the actual poly edge.
|
|
||||||
// This is really slow.
|
|
||||||
for (int k = 0; k < pd->ntris; ++k)
|
|
||||||
{
|
|
||||||
const unsigned char* t = mesh->getDetailTri(pd->tbase+k);
|
|
||||||
const float* tv[3];
|
|
||||||
for (int m = 0; m < 3; ++m)
|
|
||||||
{
|
|
||||||
if (t[m] < p->nv)
|
|
||||||
tv[m] = mesh->getVertex(p->v[t[m]]);
|
|
||||||
else
|
|
||||||
tv[m] = mesh->getDetailVertex(pd->vbase+(t[m]-p->nv));
|
|
||||||
}
|
|
||||||
for (int m = 0, n = 2; m < 3; n=m++)
|
|
||||||
{
|
|
||||||
if (((t[3] >> (n*2)) & 0x3) == 0) continue; // Skip inner edges.
|
|
||||||
if (distancePtLine2d(tv[n],v0,v1) < thr &&
|
|
||||||
distancePtLine2d(tv[m],v0,v1) < thr)
|
|
||||||
{
|
|
||||||
glVertex3fv(tv[n]);
|
|
||||||
glVertex3fv(tv[m]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
glEnd();
|
|
||||||
}
|
|
||||||
|
|
||||||
void dtDebugDrawStatNavMesh(const dtStatNavMesh* mesh, bool drawClosedList)
|
|
||||||
{
|
|
||||||
glBegin(GL_TRIANGLES);
|
|
||||||
for (int i = 0; i < mesh->getPolyDetailCount(); ++i)
|
|
||||||
{
|
|
||||||
const dtStatPoly* p = mesh->getPoly(i);
|
|
||||||
const dtStatPolyDetail* pd = mesh->getPolyDetail(i);
|
|
||||||
|
|
||||||
if (drawClosedList && mesh->isInClosedList(i+1))
|
|
||||||
glColor4ub(255,196,0,64);
|
|
||||||
else
|
|
||||||
glColor4ub(0,196,255,64);
|
|
||||||
|
|
||||||
for (int j = 0; j < pd->ntris; ++j)
|
|
||||||
{
|
|
||||||
const unsigned char* t = mesh->getDetailTri(pd->tbase+j);
|
|
||||||
for (int k = 0; k < 3; ++k)
|
|
||||||
{
|
|
||||||
if (t[k] < p->nv)
|
|
||||||
glVertex3fv(mesh->getVertex(p->v[t[k]]));
|
|
||||||
else
|
|
||||||
glVertex3fv(mesh->getDetailVertex(pd->vbase+(t[k]-p->nv)));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
glEnd();
|
|
||||||
|
|
||||||
// Draw inter poly boundaries
|
|
||||||
glColor4ub(0,48,64,32);
|
|
||||||
glLineWidth(1.5f);
|
|
||||||
drawStatMeshPolyBoundaries(mesh, true);
|
|
||||||
|
|
||||||
// Draw outer poly boundaries
|
|
||||||
glLineWidth(2.5f);
|
|
||||||
glColor4ub(0,48,64,220);
|
|
||||||
drawStatMeshPolyBoundaries(mesh, false);
|
|
||||||
|
|
||||||
glLineWidth(1.0f);
|
|
||||||
|
|
||||||
glPointSize(3.0f);
|
|
||||||
glColor4ub(0,0,0,196);
|
|
||||||
glBegin(GL_POINTS);
|
|
||||||
for (int i = 0; i < mesh->getVertexCount(); ++i)
|
|
||||||
{
|
|
||||||
const float* v = mesh->getVertex(i);
|
|
||||||
glVertex3f(v[0], v[1], v[2]);
|
|
||||||
}
|
|
||||||
glEnd();
|
|
||||||
glPointSize(1.0f);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
static void drawTilePolyBoundaries(const dtTileHeader* header, bool inner)
|
|
||||||
{
|
|
||||||
static const float thr = 0.01f*0.01f;
|
|
||||||
|
|
||||||
glBegin(GL_LINES);
|
|
||||||
for (int i = 0; i < header->npolys; ++i)
|
|
||||||
{
|
|
||||||
const dtTilePoly* p = &header->polys[i];
|
|
||||||
const dtTilePolyDetail* pd = &header->dmeshes[i];
|
|
||||||
|
|
||||||
for (int j = 0, nj = (int)p->nv; j < nj; ++j)
|
|
||||||
{
|
|
||||||
if (inner)
|
|
||||||
{
|
|
||||||
if (p->n[j] == 0) continue;
|
|
||||||
if (p->n[j] & 0x8000)
|
|
||||||
{
|
|
||||||
bool con = false;
|
|
||||||
for (int k = 0; k < p->nlinks; ++k)
|
|
||||||
{
|
|
||||||
if (header->links[p->links+k].e == j)
|
|
||||||
{
|
|
||||||
con = true;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (con)
|
|
||||||
glColor4ub(255,255,255,128);
|
|
||||||
else
|
|
||||||
glColor4ub(0,0,0,128);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
glColor4ub(0,48,64,32);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
if (p->n[j] != 0) continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
const float* v0 = &header->verts[p->v[j]*3];
|
|
||||||
const float* v1 = &header->verts[p->v[(j+1)%nj]*3];
|
|
||||||
|
|
||||||
// Draw detail mesh edges which align with the actual poly edge.
|
|
||||||
// This is really slow.
|
|
||||||
for (int k = 0; k < pd->ntris; ++k)
|
|
||||||
{
|
|
||||||
const unsigned char* t = &header->dtris[(pd->tbase+k)*4];
|
|
||||||
const float* tv[3];
|
|
||||||
for (int m = 0; m < 3; ++m)
|
|
||||||
{
|
|
||||||
if (t[m] < p->nv)
|
|
||||||
tv[m] = &header->verts[p->v[t[m]]*3];
|
|
||||||
else
|
|
||||||
tv[m] = &header->dverts[(pd->vbase+(t[m]-p->nv))*3];
|
|
||||||
}
|
|
||||||
for (int m = 0, n = 2; m < 3; n=m++)
|
|
||||||
{
|
|
||||||
if (((t[3] >> (n*2)) & 0x3) == 0) continue; // Skip inner detail edges.
|
|
||||||
if (distancePtLine2d(tv[n],v0,v1) < thr &&
|
|
||||||
distancePtLine2d(tv[m],v0,v1) < thr)
|
|
||||||
{
|
|
||||||
glVertex3fv(tv[n]);
|
|
||||||
glVertex3fv(tv[m]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
glEnd();
|
|
||||||
}
|
|
||||||
|
|
||||||
static void drawTile(const dtTileHeader* header)
|
|
||||||
{
|
|
||||||
glBegin(GL_TRIANGLES);
|
|
||||||
for (int i = 0; i < header->npolys; ++i)
|
|
||||||
{
|
|
||||||
const dtTilePoly* p = &header->polys[i];
|
|
||||||
const dtTilePolyDetail* pd = &header->dmeshes[i];
|
|
||||||
|
|
||||||
glColor4ub(0,196,255,64);
|
|
||||||
|
|
||||||
for (int j = 0; j < pd->ntris; ++j)
|
|
||||||
{
|
|
||||||
const unsigned char* t = &header->dtris[(pd->tbase+j)*4];
|
|
||||||
for (int k = 0; k < 3; ++k)
|
|
||||||
{
|
|
||||||
if (t[k] < p->nv)
|
|
||||||
glVertex3fv(&header->verts[p->v[t[k]]*3]);
|
|
||||||
else
|
|
||||||
glVertex3fv(&header->dverts[(pd->vbase+t[k]-p->nv)*3]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
glEnd();
|
|
||||||
|
|
||||||
// Draw inter poly boundaries
|
|
||||||
glColor4ub(0,48,64,32);
|
|
||||||
glLineWidth(1.5f);
|
|
||||||
|
|
||||||
drawTilePolyBoundaries(header, true);
|
|
||||||
|
|
||||||
// Draw outer poly boundaries
|
|
||||||
glLineWidth(2.5f);
|
|
||||||
glColor4ub(0,48,64,220);
|
|
||||||
|
|
||||||
drawTilePolyBoundaries(header, false);
|
|
||||||
|
|
||||||
glLineWidth(1.0f);
|
|
||||||
|
|
||||||
glPointSize(3.0f);
|
|
||||||
glColor4ub(0,0,0,196);
|
|
||||||
glBegin(GL_POINTS);
|
|
||||||
for (int i = 0; i < header->nverts; ++i)
|
|
||||||
{
|
|
||||||
const float* v = &header->verts[i*3];
|
|
||||||
glVertex3f(v[0], v[1], v[2]);
|
|
||||||
}
|
|
||||||
glEnd();
|
|
||||||
glPointSize(1.0f);
|
|
||||||
|
|
||||||
// Draw portals
|
|
||||||
/* glBegin(GL_LINES);
|
|
||||||
|
|
||||||
for (int i = 0; i < header->nportals[0]; ++i)
|
|
||||||
{
|
|
||||||
const dtTilePortal* p = &header->portals[0][i];
|
|
||||||
if (p->ncon)
|
|
||||||
glColor4ub(255,255,255,192);
|
|
||||||
else
|
|
||||||
glColor4ub(255,0,0,64);
|
|
||||||
glVertex3f(header->bmax[0]-0.1f, p->bmin[1], p->bmin[0]);
|
|
||||||
glVertex3f(header->bmax[0]-0.1f, p->bmax[1], p->bmin[0]);
|
|
||||||
|
|
||||||
glVertex3f(header->bmax[0]-0.1f, p->bmax[1], p->bmin[0]);
|
|
||||||
glVertex3f(header->bmax[0]-0.1f, p->bmax[1], p->bmax[0]);
|
|
||||||
|
|
||||||
glVertex3f(header->bmax[0]-0.1f, p->bmax[1], p->bmax[0]);
|
|
||||||
glVertex3f(header->bmax[0]-0.1f, p->bmin[1], p->bmax[0]);
|
|
||||||
|
|
||||||
glVertex3f(header->bmax[0]-0.1f, p->bmin[1], p->bmax[0]);
|
|
||||||
glVertex3f(header->bmax[0]-0.1f, p->bmin[1], p->bmin[0]);
|
|
||||||
}
|
|
||||||
for (int i = 0; i < header->nportals[1]; ++i)
|
|
||||||
{
|
|
||||||
const dtTilePortal* p = &header->portals[1][i];
|
|
||||||
if (p->ncon)
|
|
||||||
glColor4ub(255,255,255,192);
|
|
||||||
else
|
|
||||||
glColor4ub(255,0,0,64);
|
|
||||||
glVertex3f(p->bmin[0], p->bmin[1], header->bmax[2]-0.1f);
|
|
||||||
glVertex3f(p->bmin[0], p->bmax[1], header->bmax[2]-0.1f);
|
|
||||||
|
|
||||||
glVertex3f(p->bmin[0], p->bmax[1], header->bmax[2]-0.1f);
|
|
||||||
glVertex3f(p->bmax[0], p->bmax[1], header->bmax[2]-0.1f);
|
|
||||||
|
|
||||||
glVertex3f(p->bmax[0], p->bmax[1], header->bmax[2]-0.1f);
|
|
||||||
glVertex3f(p->bmax[0], p->bmin[1], header->bmax[2]-0.1f);
|
|
||||||
|
|
||||||
glVertex3f(p->bmax[0], p->bmin[1], header->bmax[2]-0.1f);
|
|
||||||
glVertex3f(p->bmin[0], p->bmin[1], header->bmax[2]-0.1f);
|
|
||||||
}
|
|
||||||
for (int i = 0; i < header->nportals[2]; ++i)
|
|
||||||
{
|
|
||||||
const dtTilePortal* p = &header->portals[2][i];
|
|
||||||
if (p->ncon)
|
|
||||||
glColor4ub(255,255,255,192);
|
|
||||||
else
|
|
||||||
glColor4ub(255,0,0,64);
|
|
||||||
glVertex3f(header->bmin[0]+0.1f, p->bmin[1], p->bmin[0]);
|
|
||||||
glVertex3f(header->bmin[0]+0.1f, p->bmax[1], p->bmin[0]);
|
|
||||||
|
|
||||||
glVertex3f(header->bmin[0]+0.1f, p->bmax[1], p->bmin[0]);
|
|
||||||
glVertex3f(header->bmin[0]+0.1f, p->bmax[1], p->bmax[0]);
|
|
||||||
|
|
||||||
glVertex3f(header->bmin[0]+0.1f, p->bmax[1], p->bmax[0]);
|
|
||||||
glVertex3f(header->bmin[0]+0.1f, p->bmin[1], p->bmax[0]);
|
|
||||||
|
|
||||||
glVertex3f(header->bmin[0]+0.1f, p->bmin[1], p->bmax[0]);
|
|
||||||
glVertex3f(header->bmin[0]+0.1f, p->bmin[1], p->bmin[0]);
|
|
||||||
}
|
|
||||||
for (int i = 0; i < header->nportals[3]; ++i)
|
|
||||||
{
|
|
||||||
const dtTilePortal* p = &header->portals[3][i];
|
|
||||||
if (p->ncon)
|
|
||||||
glColor4ub(255,255,255,192);
|
|
||||||
else
|
|
||||||
glColor4ub(255,0,0,64);
|
|
||||||
glVertex3f(p->bmin[0], p->bmin[1], header->bmin[2]+0.1f);
|
|
||||||
glVertex3f(p->bmin[0], p->bmax[1], header->bmin[2]+0.1f);
|
|
||||||
|
|
||||||
glVertex3f(p->bmin[0], p->bmax[1], header->bmin[2]+0.1f);
|
|
||||||
glVertex3f(p->bmax[0], p->bmax[1], header->bmin[2]+0.1f);
|
|
||||||
|
|
||||||
glVertex3f(p->bmax[0], p->bmax[1], header->bmin[2]+0.1f);
|
|
||||||
glVertex3f(p->bmax[0], p->bmin[1], header->bmin[2]+0.1f);
|
|
||||||
|
|
||||||
glVertex3f(p->bmax[0], p->bmin[1], header->bmin[2]+0.1f);
|
|
||||||
glVertex3f(p->bmin[0], p->bmin[1], header->bmin[2]+0.1f);
|
|
||||||
}
|
|
||||||
glEnd();*/
|
|
||||||
}
|
|
||||||
|
|
||||||
void dtDebugDrawTiledNavMesh(const dtTiledNavMesh* mesh)
|
|
||||||
{
|
|
||||||
if (!mesh) return;
|
|
||||||
|
|
||||||
for (int i = 0; i < DT_MAX_TILES; ++i)
|
|
||||||
{
|
|
||||||
const dtTile* tile = mesh->getTile(i);
|
|
||||||
if (!tile->header) continue;
|
|
||||||
|
|
||||||
drawTile(tile->header);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void dtDebugDrawTiledNavMeshPoly(const dtTiledNavMesh* mesh, dtTilePolyRef ref, const float* col)
|
|
||||||
{
|
|
||||||
unsigned int salt, it, ip;
|
|
||||||
dtDecodeTileId(ref, salt, it, ip);
|
|
||||||
if (it >= DT_MAX_TILES) return;
|
|
||||||
const dtTile* tile = mesh->getTile(it);
|
|
||||||
if (tile->salt != salt || tile->header == 0) return;
|
|
||||||
const dtTileHeader* header = tile->header;
|
|
||||||
|
|
||||||
if (ip >= (unsigned int)header->npolys) return;
|
|
||||||
|
|
||||||
glColor4f(col[0],col[1],col[2],0.25f);
|
|
||||||
|
|
||||||
const dtTilePoly* p = &header->polys[ip];
|
|
||||||
const dtTilePolyDetail* pd = &header->dmeshes[ip];
|
|
||||||
|
|
||||||
glBegin(GL_TRIANGLES);
|
|
||||||
for (int i = 0; i < pd->ntris; ++i)
|
|
||||||
{
|
|
||||||
const unsigned char* t = &header->dtris[(pd->tbase+i)*4];
|
|
||||||
for (int j = 0; j < 3; ++j)
|
|
||||||
{
|
|
||||||
if (t[j] < p->nv)
|
|
||||||
glVertex3fv(&header->verts[p->v[t[j]]*3]);
|
|
||||||
else
|
|
||||||
glVertex3fv(&header->dverts[(pd->vbase+t[j]-p->nv)*3]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
glEnd();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
static void drawPolyBoundaries(const dtMeshHeader* header, bool inner)
|
static void drawPolyBoundaries(const dtMeshHeader* header, bool inner)
|
||||||
{
|
{
|
||||||
static const float thr = 0.01f*0.01f;
|
static const float thr = 0.01f*0.01f;
|
||||||
@ -626,26 +196,6 @@ static void drawMeshTile(const dtNavMesh* mesh, const dtMeshTile* tile, bool dra
|
|||||||
glEnd();
|
glEnd();
|
||||||
glPointSize(1.0f);
|
glPointSize(1.0f);
|
||||||
|
|
||||||
/*
|
|
||||||
// Draw BV nodes.
|
|
||||||
const float col[] = { 1,1,1,0.5f };
|
|
||||||
const float cs = 1.0f / header->bvquant;
|
|
||||||
glBegin(GL_LINES);
|
|
||||||
for (int i = 0; i < header->nbvtree; ++i)
|
|
||||||
{
|
|
||||||
const dtBVNode* n = &header->bvtree[i];
|
|
||||||
if (n->i < 0) // Leaf indices are positive.
|
|
||||||
continue;
|
|
||||||
drawBoxWire(header->bmin[0] + n->bmin[0]*cs,
|
|
||||||
header->bmin[1] + n->bmin[1]*cs,
|
|
||||||
header->bmin[2] + n->bmin[2]*cs,
|
|
||||||
header->bmin[0] + n->bmax[0]*cs,
|
|
||||||
header->bmin[1] + n->bmax[1]*cs,
|
|
||||||
header->bmin[2] + n->bmax[2]*cs, col);
|
|
||||||
}
|
|
||||||
glEnd();
|
|
||||||
*/
|
|
||||||
|
|
||||||
// Draw portals
|
// Draw portals
|
||||||
/* glBegin(GL_LINES);
|
/* glBegin(GL_LINES);
|
||||||
|
|
||||||
@ -741,6 +291,121 @@ void dtDebugDrawNavMesh(const dtNavMesh* mesh, bool drawClosedList)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static void drawMeshTileBVTree(const dtNavMesh* mesh, const dtMeshTile* tile)
|
||||||
|
{
|
||||||
|
const dtMeshHeader* header = tile->header;
|
||||||
|
|
||||||
|
// Draw BV nodes.
|
||||||
|
const float col[] = { 1,1,1,0.5f };
|
||||||
|
const float cs = 1.0f / header->bvquant;
|
||||||
|
glBegin(GL_LINES);
|
||||||
|
for (int i = 0; i < header->nbvtree; ++i)
|
||||||
|
{
|
||||||
|
const dtBVNode* n = &header->bvtree[i];
|
||||||
|
if (n->i < 0) // Leaf indices are positive.
|
||||||
|
continue;
|
||||||
|
drawBoxWire(header->bmin[0] + n->bmin[0]*cs,
|
||||||
|
header->bmin[1] + n->bmin[1]*cs,
|
||||||
|
header->bmin[2] + n->bmin[2]*cs,
|
||||||
|
header->bmin[0] + n->bmax[0]*cs,
|
||||||
|
header->bmin[1] + n->bmax[1]*cs,
|
||||||
|
header->bmin[2] + n->bmax[2]*cs, col);
|
||||||
|
}
|
||||||
|
glEnd();
|
||||||
|
|
||||||
|
// Draw portals
|
||||||
|
/* glBegin(GL_LINES);
|
||||||
|
|
||||||
|
for (int i = 0; i < header->nportals[0]; ++i)
|
||||||
|
{
|
||||||
|
const dtTilePortal* p = &header->portals[0][i];
|
||||||
|
if (p->ncon)
|
||||||
|
glColor4ub(255,255,255,192);
|
||||||
|
else
|
||||||
|
glColor4ub(255,0,0,64);
|
||||||
|
glVertex3f(header->bmax[0]-0.1f, p->bmin[1], p->bmin[0]);
|
||||||
|
glVertex3f(header->bmax[0]-0.1f, p->bmax[1], p->bmin[0]);
|
||||||
|
|
||||||
|
glVertex3f(header->bmax[0]-0.1f, p->bmax[1], p->bmin[0]);
|
||||||
|
glVertex3f(header->bmax[0]-0.1f, p->bmax[1], p->bmax[0]);
|
||||||
|
|
||||||
|
glVertex3f(header->bmax[0]-0.1f, p->bmax[1], p->bmax[0]);
|
||||||
|
glVertex3f(header->bmax[0]-0.1f, p->bmin[1], p->bmax[0]);
|
||||||
|
|
||||||
|
glVertex3f(header->bmax[0]-0.1f, p->bmin[1], p->bmax[0]);
|
||||||
|
glVertex3f(header->bmax[0]-0.1f, p->bmin[1], p->bmin[0]);
|
||||||
|
}
|
||||||
|
for (int i = 0; i < header->nportals[1]; ++i)
|
||||||
|
{
|
||||||
|
const dtTilePortal* p = &header->portals[1][i];
|
||||||
|
if (p->ncon)
|
||||||
|
glColor4ub(255,255,255,192);
|
||||||
|
else
|
||||||
|
glColor4ub(255,0,0,64);
|
||||||
|
glVertex3f(p->bmin[0], p->bmin[1], header->bmax[2]-0.1f);
|
||||||
|
glVertex3f(p->bmin[0], p->bmax[1], header->bmax[2]-0.1f);
|
||||||
|
|
||||||
|
glVertex3f(p->bmin[0], p->bmax[1], header->bmax[2]-0.1f);
|
||||||
|
glVertex3f(p->bmax[0], p->bmax[1], header->bmax[2]-0.1f);
|
||||||
|
|
||||||
|
glVertex3f(p->bmax[0], p->bmax[1], header->bmax[2]-0.1f);
|
||||||
|
glVertex3f(p->bmax[0], p->bmin[1], header->bmax[2]-0.1f);
|
||||||
|
|
||||||
|
glVertex3f(p->bmax[0], p->bmin[1], header->bmax[2]-0.1f);
|
||||||
|
glVertex3f(p->bmin[0], p->bmin[1], header->bmax[2]-0.1f);
|
||||||
|
}
|
||||||
|
for (int i = 0; i < header->nportals[2]; ++i)
|
||||||
|
{
|
||||||
|
const dtTilePortal* p = &header->portals[2][i];
|
||||||
|
if (p->ncon)
|
||||||
|
glColor4ub(255,255,255,192);
|
||||||
|
else
|
||||||
|
glColor4ub(255,0,0,64);
|
||||||
|
glVertex3f(header->bmin[0]+0.1f, p->bmin[1], p->bmin[0]);
|
||||||
|
glVertex3f(header->bmin[0]+0.1f, p->bmax[1], p->bmin[0]);
|
||||||
|
|
||||||
|
glVertex3f(header->bmin[0]+0.1f, p->bmax[1], p->bmin[0]);
|
||||||
|
glVertex3f(header->bmin[0]+0.1f, p->bmax[1], p->bmax[0]);
|
||||||
|
|
||||||
|
glVertex3f(header->bmin[0]+0.1f, p->bmax[1], p->bmax[0]);
|
||||||
|
glVertex3f(header->bmin[0]+0.1f, p->bmin[1], p->bmax[0]);
|
||||||
|
|
||||||
|
glVertex3f(header->bmin[0]+0.1f, p->bmin[1], p->bmax[0]);
|
||||||
|
glVertex3f(header->bmin[0]+0.1f, p->bmin[1], p->bmin[0]);
|
||||||
|
}
|
||||||
|
for (int i = 0; i < header->nportals[3]; ++i)
|
||||||
|
{
|
||||||
|
const dtTilePortal* p = &header->portals[3][i];
|
||||||
|
if (p->ncon)
|
||||||
|
glColor4ub(255,255,255,192);
|
||||||
|
else
|
||||||
|
glColor4ub(255,0,0,64);
|
||||||
|
glVertex3f(p->bmin[0], p->bmin[1], header->bmin[2]+0.1f);
|
||||||
|
glVertex3f(p->bmin[0], p->bmax[1], header->bmin[2]+0.1f);
|
||||||
|
|
||||||
|
glVertex3f(p->bmin[0], p->bmax[1], header->bmin[2]+0.1f);
|
||||||
|
glVertex3f(p->bmax[0], p->bmax[1], header->bmin[2]+0.1f);
|
||||||
|
|
||||||
|
glVertex3f(p->bmax[0], p->bmax[1], header->bmin[2]+0.1f);
|
||||||
|
glVertex3f(p->bmax[0], p->bmin[1], header->bmin[2]+0.1f);
|
||||||
|
|
||||||
|
glVertex3f(p->bmax[0], p->bmin[1], header->bmin[2]+0.1f);
|
||||||
|
glVertex3f(p->bmin[0], p->bmin[1], header->bmin[2]+0.1f);
|
||||||
|
}
|
||||||
|
glEnd();*/
|
||||||
|
}
|
||||||
|
|
||||||
|
void dtDebugDrawNavMeshBVTree(const dtNavMesh* mesh)
|
||||||
|
{
|
||||||
|
if (!mesh) return;
|
||||||
|
|
||||||
|
for (int i = 0; i < mesh->getMaxTiles(); ++i)
|
||||||
|
{
|
||||||
|
const dtMeshTile* tile = mesh->getTile(i);
|
||||||
|
if (!tile->header) continue;
|
||||||
|
drawMeshTileBVTree(mesh, tile);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void dtDebugDrawNavMeshPoly(const dtNavMesh* mesh, dtPolyRef ref, const float* col)
|
void dtDebugDrawNavMeshPoly(const dtNavMesh* mesh, dtPolyRef ref, const float* col)
|
||||||
{
|
{
|
||||||
|
@ -76,19 +76,30 @@ inline int computeTileHash(int x, int y, const int mask)
|
|||||||
return (int)(n & mask);
|
return (int)(n & mask);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////////////////////
|
||||||
dtNavMesh::dtNavMesh() :
|
dtNavMesh::dtNavMesh() :
|
||||||
m_tileWidth(0),
|
m_tileWidth(0),
|
||||||
m_tileHeight(0),
|
m_tileHeight(0),
|
||||||
m_portalHeight(0),
|
m_portalHeight(0),
|
||||||
|
m_maxTiles(0),
|
||||||
|
m_tileLutSize(0),
|
||||||
|
m_tileLutMask(0),
|
||||||
|
m_posLookup(0),
|
||||||
m_nextFree(0),
|
m_nextFree(0),
|
||||||
|
m_tiles(0),
|
||||||
m_tmpLinks(0),
|
m_tmpLinks(0),
|
||||||
m_ntmpLinks(0),
|
m_ntmpLinks(0),
|
||||||
|
m_saltBits(0),
|
||||||
|
m_tileBits(0),
|
||||||
|
m_polyBits(0),
|
||||||
m_nodePool(0),
|
m_nodePool(0),
|
||||||
m_openList(0),
|
m_openList(0)
|
||||||
m_posLookup(0),
|
|
||||||
m_tiles(0)
|
|
||||||
{
|
{
|
||||||
|
m_orig[0] = 0;
|
||||||
|
m_orig[1] = 0;
|
||||||
|
m_orig[2] = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
dtNavMesh::~dtNavMesh()
|
dtNavMesh::~dtNavMesh()
|
||||||
|
@ -1,953 +0,0 @@
|
|||||||
//
|
|
||||||
// Copyright (c) 2009 Mikko Mononen memon@inside.org
|
|
||||||
//
|
|
||||||
// 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.
|
|
||||||
//
|
|
||||||
|
|
||||||
#include <math.h>
|
|
||||||
#include <float.h>
|
|
||||||
#include <string.h>
|
|
||||||
#include <stdio.h>
|
|
||||||
#include "DetourStatNavMesh.h"
|
|
||||||
#include "DetourNode.h"
|
|
||||||
#include "DetourCommon.h"
|
|
||||||
|
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////////////////////
|
|
||||||
dtStatNavMesh::dtStatNavMesh() :
|
|
||||||
m_data(0),
|
|
||||||
m_dataSize(0),
|
|
||||||
m_header(0),
|
|
||||||
m_nodePool(0),
|
|
||||||
m_openList(0)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
dtStatNavMesh::~dtStatNavMesh()
|
|
||||||
{
|
|
||||||
delete m_nodePool;
|
|
||||||
delete m_openList;
|
|
||||||
if (m_data)
|
|
||||||
delete [] m_data;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool dtStatNavMesh::init(unsigned char* data, int dataSize, bool ownsData)
|
|
||||||
{
|
|
||||||
dtStatNavMeshHeader* header = (dtStatNavMeshHeader*)data;
|
|
||||||
|
|
||||||
if (header->magic != DT_STAT_NAVMESH_MAGIC)
|
|
||||||
return false;
|
|
||||||
if (header->version != DT_STAT_NAVMESH_VERSION)
|
|
||||||
return false;
|
|
||||||
|
|
||||||
const int headerSize = align4(sizeof(dtStatNavMeshHeader));
|
|
||||||
const int vertsSize = align4(sizeof(float)*3*header->nverts);
|
|
||||||
const int polysSize = align4(sizeof(dtStatPoly)*header->npolys);
|
|
||||||
const int nodesSize = align4(sizeof(dtStatBVNode)*header->npolys*2);
|
|
||||||
const int detailMeshesSize = align4(sizeof(dtStatPolyDetail)*header->ndmeshes);
|
|
||||||
const int detailVertsSize = align4(sizeof(float)*3*header->ndverts);
|
|
||||||
const int detailTrisSize = align4(sizeof(unsigned char)*4*header->ndtris);
|
|
||||||
|
|
||||||
|
|
||||||
unsigned char* d = data + headerSize;
|
|
||||||
header->verts = (float*)d; d += vertsSize;
|
|
||||||
header->polys = (dtStatPoly*)d; d += polysSize;
|
|
||||||
header->bvtree = (dtStatBVNode*)d; d += nodesSize;
|
|
||||||
header->dmeshes = (dtStatPolyDetail*)d; d += detailMeshesSize;
|
|
||||||
header->dverts = (float*)d; d += detailVertsSize;
|
|
||||||
header->dtris = (unsigned char*)d; d += detailTrisSize;
|
|
||||||
|
|
||||||
m_nodePool = new dtNodePool(2048, 256);
|
|
||||||
if (!m_nodePool)
|
|
||||||
return false;
|
|
||||||
|
|
||||||
m_openList = new dtNodeQueue(2048);
|
|
||||||
if (!m_openList)
|
|
||||||
return false;
|
|
||||||
|
|
||||||
if (ownsData)
|
|
||||||
{
|
|
||||||
m_data = data;
|
|
||||||
m_dataSize = dataSize;
|
|
||||||
}
|
|
||||||
|
|
||||||
m_header = header;
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
const dtStatPoly* dtStatNavMesh::getPolyByRef(dtStatPolyRef ref) const
|
|
||||||
{
|
|
||||||
if (!m_header || ref == 0 || (int)ref > m_header->npolys) return 0;
|
|
||||||
return &m_header->polys[ref-1];
|
|
||||||
}
|
|
||||||
|
|
||||||
int dtStatNavMesh::getPolyIndexByRef(dtStatPolyRef ref) const
|
|
||||||
{
|
|
||||||
if (!m_header || ref == 0 || (int)ref > m_header->npolys) return -1;
|
|
||||||
return (int)ref-1;
|
|
||||||
}
|
|
||||||
|
|
||||||
int dtStatNavMesh::findPath(dtStatPolyRef startRef, dtStatPolyRef endRef,
|
|
||||||
const float* startPos, const float* endPos,
|
|
||||||
dtStatPolyRef* path, const int maxPathSize)
|
|
||||||
{
|
|
||||||
if (!m_header) return 0;
|
|
||||||
|
|
||||||
if (!startRef || !endRef)
|
|
||||||
return 0;
|
|
||||||
|
|
||||||
if (!maxPathSize)
|
|
||||||
return 0;
|
|
||||||
|
|
||||||
if (startRef == endRef)
|
|
||||||
{
|
|
||||||
path[0] = startRef;
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
m_nodePool->clear();
|
|
||||||
m_openList->clear();
|
|
||||||
|
|
||||||
static const float H_SCALE = 1.1f; // Heuristic scale.
|
|
||||||
|
|
||||||
dtNode* startNode = m_nodePool->getNode(startRef);
|
|
||||||
startNode->pidx = 0;
|
|
||||||
startNode->cost = 0;
|
|
||||||
startNode->total = vdist(startPos, endPos) * H_SCALE;
|
|
||||||
startNode->id = startRef;
|
|
||||||
startNode->flags = DT_NODE_OPEN;
|
|
||||||
m_openList->push(startNode);
|
|
||||||
|
|
||||||
dtNode* lastBestNode = startNode;
|
|
||||||
float lastBestNodeCost = startNode->total;
|
|
||||||
while (!m_openList->empty())
|
|
||||||
{
|
|
||||||
dtNode* bestNode = m_openList->pop();
|
|
||||||
|
|
||||||
if (bestNode->id == endRef)
|
|
||||||
{
|
|
||||||
lastBestNode = bestNode;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
const dtStatPoly* poly = getPoly(bestNode->id-1);
|
|
||||||
for (int i = 0; i < (int)poly->nv; ++i)
|
|
||||||
{
|
|
||||||
dtStatPolyRef neighbour = poly->n[i];
|
|
||||||
if (neighbour)
|
|
||||||
{
|
|
||||||
// Skip parent node.
|
|
||||||
if (bestNode->pidx && m_nodePool->getNodeAtIdx(bestNode->pidx)->id == neighbour)
|
|
||||||
continue;
|
|
||||||
|
|
||||||
dtNode* parent = bestNode;
|
|
||||||
dtNode newNode;
|
|
||||||
newNode.pidx = m_nodePool->getNodeIdx(parent);
|
|
||||||
newNode.id = neighbour;
|
|
||||||
|
|
||||||
// Calculate cost.
|
|
||||||
float p0[3], p1[3];
|
|
||||||
if (!parent->pidx)
|
|
||||||
vcopy(p0, startPos);
|
|
||||||
else
|
|
||||||
getEdgeMidPoint(m_nodePool->getNodeAtIdx(parent->pidx)->id, parent->id, p0);
|
|
||||||
getEdgeMidPoint(parent->id, newNode.id, p1);
|
|
||||||
newNode.cost = parent->cost + vdist(p0,p1);
|
|
||||||
// Special case for last node.
|
|
||||||
if (newNode.id == endRef)
|
|
||||||
newNode.cost += vdist(p1, endPos);
|
|
||||||
|
|
||||||
// Heuristic
|
|
||||||
const float h = vdist(p1,endPos)*H_SCALE;
|
|
||||||
newNode.total = newNode.cost + h;
|
|
||||||
|
|
||||||
dtNode* actualNode = m_nodePool->getNode(newNode.id);
|
|
||||||
if (!actualNode)
|
|
||||||
continue;
|
|
||||||
|
|
||||||
if (!((actualNode->flags & DT_NODE_OPEN) && newNode.total > actualNode->total) &&
|
|
||||||
!((actualNode->flags & DT_NODE_CLOSED) && newNode.total > actualNode->total))
|
|
||||||
{
|
|
||||||
actualNode->flags &= ~DT_NODE_CLOSED;
|
|
||||||
actualNode->pidx = newNode.pidx;
|
|
||||||
actualNode->cost = newNode.cost;
|
|
||||||
actualNode->total = newNode.total;
|
|
||||||
|
|
||||||
if (h < lastBestNodeCost)
|
|
||||||
{
|
|
||||||
lastBestNodeCost = h;
|
|
||||||
lastBestNode = actualNode;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (actualNode->flags & DT_NODE_OPEN)
|
|
||||||
{
|
|
||||||
m_openList->modify(actualNode);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
actualNode->flags |= DT_NODE_OPEN;
|
|
||||||
m_openList->push(actualNode);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
bestNode->flags |= DT_NODE_CLOSED;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Reverse the path.
|
|
||||||
dtNode* prev = 0;
|
|
||||||
dtNode* node = lastBestNode;
|
|
||||||
do
|
|
||||||
{
|
|
||||||
dtNode* next = m_nodePool->getNodeAtIdx(node->pidx);
|
|
||||||
node->pidx = m_nodePool->getNodeIdx(prev);
|
|
||||||
prev = node;
|
|
||||||
node = next;
|
|
||||||
}
|
|
||||||
while (node);
|
|
||||||
|
|
||||||
// Store path
|
|
||||||
node = prev;
|
|
||||||
int n = 0;
|
|
||||||
do
|
|
||||||
{
|
|
||||||
path[n++] = node->id;
|
|
||||||
node = m_nodePool->getNodeAtIdx(node->pidx);
|
|
||||||
}
|
|
||||||
while (node && n < maxPathSize);
|
|
||||||
|
|
||||||
return n;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool dtStatNavMesh::closestPointToPoly(dtStatPolyRef ref, const float* pos, float* closest) const
|
|
||||||
{
|
|
||||||
int idx = getPolyIndexByRef(ref);
|
|
||||||
if (idx == -1)
|
|
||||||
return false;
|
|
||||||
|
|
||||||
float closestDistSqr = FLT_MAX;
|
|
||||||
const dtStatPoly* p = getPoly(idx);
|
|
||||||
const dtStatPolyDetail* pd = getPolyDetail(idx);
|
|
||||||
|
|
||||||
for (int j = 0; j < pd->ntris; ++j)
|
|
||||||
{
|
|
||||||
const unsigned char* t = getDetailTri(pd->tbase+j);
|
|
||||||
const float* v[3];
|
|
||||||
for (int k = 0; k < 3; ++k)
|
|
||||||
{
|
|
||||||
if (t[k] < p->nv)
|
|
||||||
v[k] = getVertex(p->v[t[k]]);
|
|
||||||
else
|
|
||||||
v[k] = getDetailVertex(pd->vbase+(t[k]-p->nv));
|
|
||||||
}
|
|
||||||
float pt[3];
|
|
||||||
closestPtPointTriangle(pt, pos, v[0], v[1], v[2]);
|
|
||||||
float d = vdistSqr(pos, pt);
|
|
||||||
if (d < closestDistSqr)
|
|
||||||
{
|
|
||||||
vcopy(closest, pt);
|
|
||||||
closestDistSqr = d;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool dtStatNavMesh::getPolyHeight(dtStatPolyRef ref, const float* pos, float* height) const
|
|
||||||
{
|
|
||||||
int idx = getPolyIndexByRef(ref);
|
|
||||||
if (idx == -1)
|
|
||||||
return false;
|
|
||||||
|
|
||||||
const dtStatPoly* p = getPoly(idx);
|
|
||||||
const dtStatPolyDetail* pd = getPolyDetail(idx);
|
|
||||||
|
|
||||||
for (int i = 0; i < pd->ntris; ++i)
|
|
||||||
{
|
|
||||||
const unsigned char* t = getDetailTri(pd->tbase+i);
|
|
||||||
const float* v[3];
|
|
||||||
for (int j = 0; j < 3; ++j)
|
|
||||||
{
|
|
||||||
if (t[j] < p->nv)
|
|
||||||
v[j] = getVertex(p->v[t[j]]);
|
|
||||||
else
|
|
||||||
v[j] = getDetailVertex(pd->vbase+(t[j]-p->nv));
|
|
||||||
}
|
|
||||||
float h;
|
|
||||||
if (closestHeightPointTriangle(pos, v[0], v[1], v[2], h))
|
|
||||||
{
|
|
||||||
if (height)
|
|
||||||
*height = h;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
int dtStatNavMesh::findStraightPath(const float* startPos, const float* endPos,
|
|
||||||
const dtStatPolyRef* path, const int pathSize,
|
|
||||||
float* straightPath, const int maxStraightPathSize)
|
|
||||||
{
|
|
||||||
if (!m_header) return 0;
|
|
||||||
|
|
||||||
if (!maxStraightPathSize)
|
|
||||||
return 0;
|
|
||||||
|
|
||||||
if (!path[0])
|
|
||||||
return 0;
|
|
||||||
|
|
||||||
int straightPathSize = 0;
|
|
||||||
|
|
||||||
float closestStartPos[3];
|
|
||||||
if (!closestPointToPoly(path[0], startPos, closestStartPos))
|
|
||||||
return 0;
|
|
||||||
|
|
||||||
// Add start point.
|
|
||||||
vcopy(&straightPath[straightPathSize*3], closestStartPos);
|
|
||||||
straightPathSize++;
|
|
||||||
if (straightPathSize >= maxStraightPathSize)
|
|
||||||
return straightPathSize;
|
|
||||||
|
|
||||||
float closestEndPos[3];
|
|
||||||
if (!closestPointToPoly(path[pathSize-1], endPos, closestEndPos))
|
|
||||||
return 0;
|
|
||||||
|
|
||||||
float portalApex[3], portalLeft[3], portalRight[3];
|
|
||||||
|
|
||||||
if (pathSize > 1)
|
|
||||||
{
|
|
||||||
vcopy(portalApex, closestStartPos);
|
|
||||||
vcopy(portalLeft, portalApex);
|
|
||||||
vcopy(portalRight, portalApex);
|
|
||||||
int apexIndex = 0;
|
|
||||||
int leftIndex = 0;
|
|
||||||
int rightIndex = 0;
|
|
||||||
|
|
||||||
for (int i = 0; i < pathSize; ++i)
|
|
||||||
{
|
|
||||||
float left[3], right[3];
|
|
||||||
if (i < pathSize-1)
|
|
||||||
{
|
|
||||||
// Next portal.
|
|
||||||
getPortalPoints(path[i], path[i+1], left, right);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
// End of the path.
|
|
||||||
vcopy(left, closestEndPos);
|
|
||||||
vcopy(right, closestEndPos);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Right vertex.
|
|
||||||
if (vequal(portalApex, portalRight))
|
|
||||||
{
|
|
||||||
vcopy(portalRight, right);
|
|
||||||
rightIndex = i;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
if (triArea2D(portalApex, portalRight, right) <= 0.0f)
|
|
||||||
{
|
|
||||||
if (triArea2D(portalApex, portalLeft, right) > 0.0f)
|
|
||||||
{
|
|
||||||
vcopy(portalRight, right);
|
|
||||||
rightIndex = i;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
vcopy(portalApex, portalLeft);
|
|
||||||
apexIndex = leftIndex;
|
|
||||||
|
|
||||||
if (!vequal(&straightPath[(straightPathSize-1)*3], portalApex))
|
|
||||||
{
|
|
||||||
vcopy(&straightPath[straightPathSize*3], portalApex);
|
|
||||||
straightPathSize++;
|
|
||||||
if (straightPathSize >= maxStraightPathSize)
|
|
||||||
return straightPathSize;
|
|
||||||
}
|
|
||||||
|
|
||||||
vcopy(portalLeft, portalApex);
|
|
||||||
vcopy(portalRight, portalApex);
|
|
||||||
leftIndex = apexIndex;
|
|
||||||
rightIndex = apexIndex;
|
|
||||||
|
|
||||||
// Restart
|
|
||||||
i = apexIndex;
|
|
||||||
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Left vertex.
|
|
||||||
if (vequal(portalApex, portalLeft))
|
|
||||||
{
|
|
||||||
vcopy(portalLeft, left);
|
|
||||||
leftIndex = i;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
if (triArea2D(portalApex, portalLeft, left) >= 0.0f)
|
|
||||||
{
|
|
||||||
if (triArea2D(portalApex, portalRight, left) < 0.0f)
|
|
||||||
{
|
|
||||||
vcopy(portalLeft, left);
|
|
||||||
leftIndex = i;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
vcopy(portalApex, portalRight);
|
|
||||||
apexIndex = rightIndex;
|
|
||||||
|
|
||||||
if (!vequal(&straightPath[(straightPathSize-1)*3], portalApex))
|
|
||||||
{
|
|
||||||
vcopy(&straightPath[straightPathSize*3], portalApex);
|
|
||||||
straightPathSize++;
|
|
||||||
if (straightPathSize >= maxStraightPathSize)
|
|
||||||
return straightPathSize;
|
|
||||||
}
|
|
||||||
|
|
||||||
vcopy(portalLeft, portalApex);
|
|
||||||
vcopy(portalRight, portalApex);
|
|
||||||
leftIndex = apexIndex;
|
|
||||||
rightIndex = apexIndex;
|
|
||||||
|
|
||||||
// Restart
|
|
||||||
i = apexIndex;
|
|
||||||
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Add end point.
|
|
||||||
vcopy(&straightPath[straightPathSize*3], closestEndPos);
|
|
||||||
straightPathSize++;
|
|
||||||
|
|
||||||
return straightPathSize;
|
|
||||||
}
|
|
||||||
|
|
||||||
static bool pointInPoly(int nvert, const float* verts, const float* p)
|
|
||||||
{
|
|
||||||
|
|
||||||
int i, j, c = 0;
|
|
||||||
for (i = 0, j = nvert-1; i < nvert; j = i++)
|
|
||||||
{
|
|
||||||
const float* vi = &verts[i*3];
|
|
||||||
const float* vj = &verts[j*3];
|
|
||||||
if (((vi[2] > p[2]) != (vj[2] > p[2])) &&
|
|
||||||
(p[0] < (vj[0]-vi[0]) * (p[2]-vi[2]) / (vj[2]-vi[2]) + vi[0]) )
|
|
||||||
c = !c;
|
|
||||||
}
|
|
||||||
return c != 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
int dtStatNavMesh::moveAlongPath(const float* startPos, const float* endPos, float* resultPos,
|
|
||||||
const dtStatPolyRef* path, const int pathSize)
|
|
||||||
{
|
|
||||||
static const float SLOP = 0.01f;
|
|
||||||
float verts[DT_STAT_VERTS_PER_POLYGON*3];
|
|
||||||
int n = 0, prevn = 0;
|
|
||||||
|
|
||||||
vcopy(resultPos, startPos);
|
|
||||||
|
|
||||||
while (n < pathSize)
|
|
||||||
{
|
|
||||||
// Cast ray against current polygon.
|
|
||||||
int nv = getPolyVerts(path[n], verts);
|
|
||||||
if (nv < 3)
|
|
||||||
{
|
|
||||||
return prevn;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (pointInPoly(nv, verts, endPos))
|
|
||||||
{
|
|
||||||
vcopy(resultPos, endPos);
|
|
||||||
return n;
|
|
||||||
}
|
|
||||||
|
|
||||||
float tmin, tmax;
|
|
||||||
int segMin, segMax;
|
|
||||||
if (!intersectSegmentPoly2D(startPos, endPos, verts, nv, tmin, tmax, segMin, segMax))
|
|
||||||
{
|
|
||||||
// Could not a polygon
|
|
||||||
return prevn;
|
|
||||||
}
|
|
||||||
|
|
||||||
resultPos[0] = startPos[0] + (endPos[0] - startPos[0])*tmax;
|
|
||||||
resultPos[1] = startPos[1] + (endPos[1] - startPos[1])*tmax;
|
|
||||||
resultPos[2] = startPos[2] + (endPos[2] - startPos[2])*tmax;
|
|
||||||
|
|
||||||
// Check if the hitpos is on the exit segment.
|
|
||||||
float p0[3], p1[3];
|
|
||||||
if (!getPortalPoints(path[n], path[n+1], p0, p1))
|
|
||||||
return 0;
|
|
||||||
float segt;
|
|
||||||
float distToPortalSqr = distancePtSegSqr2D(resultPos, p0, p1, segt);
|
|
||||||
if (distToPortalSqr > SLOP*SLOP)
|
|
||||||
{
|
|
||||||
// Hit wall, return pos so far.
|
|
||||||
return n;
|
|
||||||
}
|
|
||||||
|
|
||||||
prevn = n;
|
|
||||||
n++;
|
|
||||||
}
|
|
||||||
|
|
||||||
return n;
|
|
||||||
|
|
||||||
/* // Check the neighbour of this polygon.
|
|
||||||
const dtStatPoly* poly = getPolyByRef(curRef);
|
|
||||||
dtStatPolyRef nextRef = poly->n[segMax];
|
|
||||||
if (!nextRef)*/
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
int dtStatNavMesh::getPolyVerts(dtStatPolyRef ref, float* verts) const
|
|
||||||
{
|
|
||||||
if (!m_header) return 0;
|
|
||||||
const dtStatPoly* poly = getPolyByRef(ref);
|
|
||||||
if (!poly) return 0;
|
|
||||||
float* v = verts;
|
|
||||||
for (int i = 0; i < (int)poly->nv; ++i)
|
|
||||||
{
|
|
||||||
const float* cv = &m_header->verts[poly->v[i]*3];
|
|
||||||
*v++ = cv[0];
|
|
||||||
*v++ = cv[1];
|
|
||||||
*v++ = cv[2];
|
|
||||||
}
|
|
||||||
return (int)poly->nv;
|
|
||||||
}
|
|
||||||
|
|
||||||
int dtStatNavMesh::raycast(dtStatPolyRef centerRef, const float* startPos, const float* endPos,
|
|
||||||
float& t, dtStatPolyRef* path, const int pathSize)
|
|
||||||
{
|
|
||||||
if (!m_header) return 0;
|
|
||||||
if (!centerRef) return 0;
|
|
||||||
|
|
||||||
dtStatPolyRef prevRef = centerRef;
|
|
||||||
dtStatPolyRef curRef = centerRef;
|
|
||||||
t = 0;
|
|
||||||
|
|
||||||
float verts[DT_STAT_VERTS_PER_POLYGON*3];
|
|
||||||
int n = 0;
|
|
||||||
|
|
||||||
while (curRef)
|
|
||||||
{
|
|
||||||
// Cast ray against current polygon.
|
|
||||||
int nv = getPolyVerts(curRef, verts);
|
|
||||||
if (nv < 3)
|
|
||||||
{
|
|
||||||
// Hit bad polygon, report hit.
|
|
||||||
return n;
|
|
||||||
}
|
|
||||||
|
|
||||||
float tmin, tmax;
|
|
||||||
int segMin, segMax;
|
|
||||||
if (!intersectSegmentPoly2D(startPos, endPos, verts, nv, tmin, tmax, segMin, segMax))
|
|
||||||
{
|
|
||||||
// Could not a polygon, keep the old t and report hit.
|
|
||||||
return n;
|
|
||||||
}
|
|
||||||
// Keep track of furthest t so far.
|
|
||||||
if (tmax > t)
|
|
||||||
t = tmax;
|
|
||||||
|
|
||||||
if (n < pathSize)
|
|
||||||
path[n++] = curRef;
|
|
||||||
|
|
||||||
// Check the neighbour of this polygon.
|
|
||||||
const dtStatPoly* poly = getPolyByRef(curRef);
|
|
||||||
dtStatPolyRef nextRef = poly->n[segMax];
|
|
||||||
if (!nextRef)
|
|
||||||
{
|
|
||||||
// No neighbour, we hit a wall.
|
|
||||||
return n;
|
|
||||||
}
|
|
||||||
|
|
||||||
// No hit, advance to neighbour polygon.
|
|
||||||
prevRef = curRef;
|
|
||||||
curRef = nextRef;
|
|
||||||
}
|
|
||||||
|
|
||||||
return n;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
float dtStatNavMesh::findDistanceToWall(dtStatPolyRef centerRef, const float* centerPos, float maxRadius,
|
|
||||||
float* hitPos, float* hitNormal)
|
|
||||||
{
|
|
||||||
if (!m_header) return 0;
|
|
||||||
if (!centerRef) return 0;
|
|
||||||
|
|
||||||
m_nodePool->clear();
|
|
||||||
m_openList->clear();
|
|
||||||
|
|
||||||
dtNode* startNode = m_nodePool->getNode(centerRef);
|
|
||||||
startNode->pidx = 0;
|
|
||||||
startNode->cost = 0;
|
|
||||||
startNode->total = 0;
|
|
||||||
startNode->id = centerRef;
|
|
||||||
startNode->flags = DT_NODE_OPEN;
|
|
||||||
m_openList->push(startNode);
|
|
||||||
|
|
||||||
float radiusSqr = sqr(maxRadius);
|
|
||||||
|
|
||||||
hitNormal[0] = 1;
|
|
||||||
hitNormal[1] = 0;
|
|
||||||
hitNormal[2] = 0;
|
|
||||||
|
|
||||||
while (!m_openList->empty())
|
|
||||||
{
|
|
||||||
dtNode* bestNode = m_openList->pop();
|
|
||||||
const dtStatPoly* poly = getPoly(bestNode->id-1);
|
|
||||||
|
|
||||||
// Hit test walls.
|
|
||||||
for (int i = 0, j = (int)poly->nv-1; i < (int)poly->nv; j = i++)
|
|
||||||
{
|
|
||||||
// Skip non-solid edges.
|
|
||||||
if (poly->n[j]) continue;
|
|
||||||
|
|
||||||
// Calc distance to the edge.
|
|
||||||
const float* vj = getVertex(poly->v[j]);
|
|
||||||
const float* vi = getVertex(poly->v[i]);
|
|
||||||
float tseg;
|
|
||||||
float distSqr = distancePtSegSqr2D(centerPos, vj, vi, tseg);
|
|
||||||
|
|
||||||
// Edge is too far, skip.
|
|
||||||
if (distSqr > radiusSqr)
|
|
||||||
continue;
|
|
||||||
|
|
||||||
// Hit wall, update radius.
|
|
||||||
radiusSqr = distSqr;
|
|
||||||
// Calculate hit pos.
|
|
||||||
hitPos[0] = vj[0] + (vi[0] - vj[0])*tseg;
|
|
||||||
hitPos[1] = vj[1] + (vi[1] - vj[1])*tseg;
|
|
||||||
hitPos[2] = vj[2] + (vi[2] - vj[2])*tseg;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Check to see if teh circle expands to one of the neighbours and expand.
|
|
||||||
for (int i = 0, j = (int)poly->nv-1; i < (int)poly->nv; j = i++)
|
|
||||||
{
|
|
||||||
// Skip solid edges.
|
|
||||||
if (!poly->n[j]) continue;
|
|
||||||
|
|
||||||
// Expand to neighbour if not visited yet.
|
|
||||||
dtStatPolyRef neighbour = poly->n[j];
|
|
||||||
|
|
||||||
// Skip parent node.
|
|
||||||
if (bestNode->pidx && m_nodePool->getNodeAtIdx(bestNode->pidx)->id == neighbour)
|
|
||||||
continue;
|
|
||||||
|
|
||||||
// Calc distance to the edge.
|
|
||||||
const float* vj = getVertex(poly->v[j]);
|
|
||||||
const float* vi = getVertex(poly->v[i]);
|
|
||||||
float tseg;
|
|
||||||
float distSqr = distancePtSegSqr2D(centerPos, vj, vi, tseg);
|
|
||||||
|
|
||||||
// Edge is too far, skip.
|
|
||||||
if (distSqr > radiusSqr)
|
|
||||||
continue;
|
|
||||||
|
|
||||||
dtNode* parent = bestNode;
|
|
||||||
dtNode newNode;
|
|
||||||
newNode.pidx = m_nodePool->getNodeIdx(parent);
|
|
||||||
newNode.id = neighbour;
|
|
||||||
|
|
||||||
// Cost
|
|
||||||
float p0[3], p1[3];
|
|
||||||
if (!parent->pidx)
|
|
||||||
vcopy(p0, centerPos);
|
|
||||||
else
|
|
||||||
getEdgeMidPoint(m_nodePool->getNodeAtIdx(parent->pidx)->id, parent->id, p0);
|
|
||||||
getEdgeMidPoint(parent->id, newNode.id, p1);
|
|
||||||
newNode.total = parent->total + vdist(p0,p1);
|
|
||||||
|
|
||||||
dtNode* actualNode = m_nodePool->getNode(newNode.id);
|
|
||||||
if (!actualNode)
|
|
||||||
continue;
|
|
||||||
|
|
||||||
if (!((actualNode->flags & DT_NODE_OPEN) && newNode.total > actualNode->total) &&
|
|
||||||
!((actualNode->flags & DT_NODE_CLOSED) && newNode.total > actualNode->total))
|
|
||||||
{
|
|
||||||
actualNode->flags &= ~DT_NODE_CLOSED;
|
|
||||||
actualNode->pidx = newNode.pidx;
|
|
||||||
actualNode->total = newNode.total;
|
|
||||||
|
|
||||||
if (actualNode->flags & DT_NODE_OPEN)
|
|
||||||
{
|
|
||||||
m_openList->modify(actualNode);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
actualNode->flags |= DT_NODE_OPEN;
|
|
||||||
m_openList->push(actualNode);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
bestNode->flags |= DT_NODE_CLOSED;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Calc hit normal.
|
|
||||||
vsub(hitNormal, centerPos, hitPos);
|
|
||||||
vnormalize(hitNormal);
|
|
||||||
|
|
||||||
return sqrtf(radiusSqr);
|
|
||||||
}
|
|
||||||
|
|
||||||
int dtStatNavMesh::findPolysAround(dtStatPolyRef centerRef, const float* centerPos, float radius,
|
|
||||||
dtStatPolyRef* resultRef, dtStatPolyRef* resultParent, float* resultCost,
|
|
||||||
const int maxResult)
|
|
||||||
{
|
|
||||||
if (!m_header) return 0;
|
|
||||||
if (!centerRef) return 0;
|
|
||||||
|
|
||||||
m_nodePool->clear();
|
|
||||||
m_openList->clear();
|
|
||||||
|
|
||||||
dtNode* startNode = m_nodePool->getNode(centerRef);
|
|
||||||
startNode->pidx = 0;
|
|
||||||
startNode->cost = 0;
|
|
||||||
startNode->total = 0;
|
|
||||||
startNode->id = centerRef;
|
|
||||||
startNode->flags = DT_NODE_OPEN;
|
|
||||||
m_openList->push(startNode);
|
|
||||||
|
|
||||||
int n = 0;
|
|
||||||
if (n < maxResult)
|
|
||||||
{
|
|
||||||
if (resultRef)
|
|
||||||
resultRef[n] = startNode->id;
|
|
||||||
if (resultParent)
|
|
||||||
resultParent[n] = 0;
|
|
||||||
if (resultCost)
|
|
||||||
resultCost[n] = 0;
|
|
||||||
++n;
|
|
||||||
}
|
|
||||||
|
|
||||||
const float radiusSqr = sqr(radius);
|
|
||||||
|
|
||||||
while (!m_openList->empty())
|
|
||||||
{
|
|
||||||
dtNode* bestNode = m_openList->pop();
|
|
||||||
const dtStatPoly* poly = getPoly(bestNode->id-1);
|
|
||||||
for (unsigned i = 0, j = (int)poly->nv-1; i < (int)poly->nv; j=i++)
|
|
||||||
{
|
|
||||||
dtStatPolyRef neighbour = poly->n[j];
|
|
||||||
|
|
||||||
if (neighbour)
|
|
||||||
{
|
|
||||||
// Skip parent node.
|
|
||||||
if (bestNode->pidx && m_nodePool->getNodeAtIdx(bestNode->pidx)->id == neighbour)
|
|
||||||
continue;
|
|
||||||
|
|
||||||
// Calc distance to the edge.
|
|
||||||
const float* vj = getVertex(poly->v[j]);
|
|
||||||
const float* vi = getVertex(poly->v[i]);
|
|
||||||
float tseg;
|
|
||||||
float distSqr = distancePtSegSqr2D(centerPos, vj, vi, tseg);
|
|
||||||
|
|
||||||
// If the circle is not touching the next polygon, skip it.
|
|
||||||
if (distSqr > radiusSqr)
|
|
||||||
continue;
|
|
||||||
|
|
||||||
dtNode* parent = bestNode;
|
|
||||||
dtNode newNode;
|
|
||||||
newNode.pidx = m_nodePool->getNodeIdx(parent);
|
|
||||||
newNode.id = neighbour;
|
|
||||||
|
|
||||||
// Cost
|
|
||||||
float p0[3], p1[3];
|
|
||||||
if (!parent->pidx)
|
|
||||||
vcopy(p0, centerPos);
|
|
||||||
else
|
|
||||||
getEdgeMidPoint(m_nodePool->getNodeAtIdx(parent->pidx)->id, parent->id, p0);
|
|
||||||
getEdgeMidPoint(parent->id, newNode.id, p1);
|
|
||||||
newNode.total = parent->total + vdist(p0,p1);
|
|
||||||
|
|
||||||
dtNode* actualNode = m_nodePool->getNode(newNode.id);
|
|
||||||
if (!actualNode)
|
|
||||||
continue;
|
|
||||||
|
|
||||||
if (!((actualNode->flags & DT_NODE_OPEN) && newNode.total > actualNode->total) &&
|
|
||||||
!((actualNode->flags & DT_NODE_CLOSED) && newNode.total > actualNode->total))
|
|
||||||
{
|
|
||||||
actualNode->flags &= ~DT_NODE_CLOSED;
|
|
||||||
actualNode->pidx = newNode.pidx;
|
|
||||||
actualNode->total = newNode.total;
|
|
||||||
|
|
||||||
if (actualNode->flags & DT_NODE_OPEN)
|
|
||||||
{
|
|
||||||
m_openList->modify(actualNode);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
if (n < maxResult)
|
|
||||||
{
|
|
||||||
if (resultRef)
|
|
||||||
resultRef[n] = actualNode->id;
|
|
||||||
if (resultParent)
|
|
||||||
resultParent[n] = m_nodePool->getNodeAtIdx(actualNode->pidx)->id;
|
|
||||||
if (resultCost)
|
|
||||||
resultCost[n] = actualNode->total;
|
|
||||||
++n;
|
|
||||||
}
|
|
||||||
actualNode->flags |= DT_NODE_OPEN;
|
|
||||||
m_openList->push(actualNode);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
bestNode->flags |= DT_NODE_CLOSED;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
return n;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Returns polygons which are withing certain radius from the query location.
|
|
||||||
int dtStatNavMesh::queryPolygons(const float* center, const float* extents,
|
|
||||||
dtStatPolyRef* polys, const int maxIds)
|
|
||||||
{
|
|
||||||
if (!m_header) return 0;
|
|
||||||
|
|
||||||
const dtStatBVNode* node = &m_header->bvtree[0];
|
|
||||||
const dtStatBVNode* end = &m_header->bvtree[m_header->nnodes];
|
|
||||||
|
|
||||||
// Calculate quantized box
|
|
||||||
const float ics = 1.0f / m_header->cs;
|
|
||||||
unsigned short bmin[3], bmax[3];
|
|
||||||
// Clamp query box to world box.
|
|
||||||
float minx = clamp(center[0] - extents[0], m_header->bmin[0], m_header->bmax[0]) - m_header->bmin[0];
|
|
||||||
float miny = clamp(center[1] - extents[1], m_header->bmin[1], m_header->bmax[1]) - m_header->bmin[1];
|
|
||||||
float minz = clamp(center[2] - extents[2], m_header->bmin[2], m_header->bmax[2]) - m_header->bmin[2];
|
|
||||||
float maxx = clamp(center[0] + extents[0], m_header->bmin[0], m_header->bmax[0]) - m_header->bmin[0];
|
|
||||||
float maxy = clamp(center[1] + extents[1], m_header->bmin[1], m_header->bmax[1]) - m_header->bmin[1];
|
|
||||||
float maxz = clamp(center[2] + extents[2], m_header->bmin[2], m_header->bmax[2]) - m_header->bmin[2];
|
|
||||||
// Quantize
|
|
||||||
bmin[0] = (unsigned short)(ics * minx) & 0xfffe;
|
|
||||||
bmin[1] = (unsigned short)(ics * miny) & 0xfffe;
|
|
||||||
bmin[2] = (unsigned short)(ics * minz) & 0xfffe;
|
|
||||||
bmax[0] = (unsigned short)(ics * maxx + 1) | 1;
|
|
||||||
bmax[1] = (unsigned short)(ics * maxy + 1) | 1;
|
|
||||||
bmax[2] = (unsigned short)(ics * maxz + 1) | 1;
|
|
||||||
|
|
||||||
// Traverse tree
|
|
||||||
int n = 0;
|
|
||||||
while (node < end)
|
|
||||||
{
|
|
||||||
bool overlap = checkOverlapBox(bmin, bmax, node->bmin, node->bmax);
|
|
||||||
bool isLeafNode = node->i >= 0;
|
|
||||||
|
|
||||||
if (isLeafNode && overlap)
|
|
||||||
{
|
|
||||||
if (n < maxIds)
|
|
||||||
{
|
|
||||||
polys[n] = (dtStatPolyRef)node->i;
|
|
||||||
n++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (overlap || isLeafNode)
|
|
||||||
node++;
|
|
||||||
else
|
|
||||||
{
|
|
||||||
const int escapeIndex = -node->i;
|
|
||||||
node += escapeIndex;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return n;
|
|
||||||
}
|
|
||||||
|
|
||||||
dtStatPolyRef dtStatNavMesh::findNearestPoly(const float* center, const float* extents)
|
|
||||||
{
|
|
||||||
if (!m_header) return 0;
|
|
||||||
|
|
||||||
// Get nearby polygons from proximity grid.
|
|
||||||
dtStatPolyRef polys[128];
|
|
||||||
int npolys = queryPolygons(center, extents, polys, 128);
|
|
||||||
|
|
||||||
// Find nearest polygon amongst the nearby polygons.
|
|
||||||
dtStatPolyRef nearest = 0;
|
|
||||||
float nearestDistanceSqr = FLT_MAX;
|
|
||||||
for (int i = 0; i < npolys; ++i)
|
|
||||||
{
|
|
||||||
dtStatPolyRef ref = polys[i];
|
|
||||||
float closest[3];
|
|
||||||
if (!closestPointToPoly(ref, center, closest))
|
|
||||||
continue;
|
|
||||||
float d = vdistSqr(center, closest);
|
|
||||||
if (d < nearestDistanceSqr)
|
|
||||||
{
|
|
||||||
nearestDistanceSqr = d;
|
|
||||||
nearest = ref;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return nearest;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool dtStatNavMesh::getPortalPoints(dtStatPolyRef from, dtStatPolyRef to, float* left, float* right) const
|
|
||||||
{
|
|
||||||
const dtStatPoly* fromPoly = getPolyByRef(from);
|
|
||||||
if (!fromPoly)
|
|
||||||
return false;
|
|
||||||
|
|
||||||
// Find common edge between the polygons and returns the segment end points.
|
|
||||||
for (unsigned i = 0, j = (int)fromPoly->nv - 1; i < (int)fromPoly->nv; j = i++)
|
|
||||||
{
|
|
||||||
unsigned short neighbour = fromPoly->n[j];
|
|
||||||
if (neighbour == to)
|
|
||||||
{
|
|
||||||
vcopy(left, getVertex(fromPoly->v[j]));
|
|
||||||
vcopy(right, getVertex(fromPoly->v[i]));
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool dtStatNavMesh::getEdgeMidPoint(dtStatPolyRef from, dtStatPolyRef to, float* mid) const
|
|
||||||
{
|
|
||||||
float left[3], right[3];
|
|
||||||
if (!getPortalPoints(from, to, left,right)) return false;
|
|
||||||
mid[0] = (left[0]+right[0])*0.5f;
|
|
||||||
mid[1] = (left[1]+right[1])*0.5f;
|
|
||||||
mid[2] = (left[2]+right[2])*0.5f;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool dtStatNavMesh::isInClosedList(dtStatPolyRef ref) const
|
|
||||||
{
|
|
||||||
if (!m_nodePool) return false;
|
|
||||||
const dtNode* node = m_nodePool->findNode(ref);
|
|
||||||
return node && node->flags & DT_NODE_CLOSED;
|
|
||||||
}
|
|
||||||
|
|
||||||
int dtStatNavMesh::getMemUsed() const
|
|
||||||
{
|
|
||||||
if (!m_nodePool || ! m_openList)
|
|
||||||
return 0;
|
|
||||||
return sizeof(*this) + m_dataSize +
|
|
||||||
m_nodePool->getMemUsed() +
|
|
||||||
m_openList->getMemUsed();
|
|
||||||
}
|
|
@ -1,347 +0,0 @@
|
|||||||
//
|
|
||||||
// Copyright (c) 2009 Mikko Mononen memon@inside.org
|
|
||||||
//
|
|
||||||
// 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.
|
|
||||||
//
|
|
||||||
|
|
||||||
#include <math.h>
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include <string.h>
|
|
||||||
#include "DetourCommon.h"
|
|
||||||
#include "DetourStatNavMesh.h"
|
|
||||||
|
|
||||||
struct BVItem
|
|
||||||
{
|
|
||||||
unsigned short bmin[3];
|
|
||||||
unsigned short bmax[3];
|
|
||||||
int i;
|
|
||||||
};
|
|
||||||
|
|
||||||
static int compareItemX(const void* va, const void* vb)
|
|
||||||
{
|
|
||||||
const BVItem* a = (const BVItem*)va;
|
|
||||||
const BVItem* b = (const BVItem*)vb;
|
|
||||||
if (a->bmin[0] < b->bmin[0])
|
|
||||||
return -1;
|
|
||||||
if (a->bmin[0] > b->bmin[0])
|
|
||||||
return 1;
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
static int compareItemY(const void* va, const void* vb)
|
|
||||||
{
|
|
||||||
const BVItem* a = (const BVItem*)va;
|
|
||||||
const BVItem* b = (const BVItem*)vb;
|
|
||||||
if (a->bmin[1] < b->bmin[1])
|
|
||||||
return -1;
|
|
||||||
if (a->bmin[1] > b->bmin[1])
|
|
||||||
return 1;
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
static int compareItemZ(const void* va, const void* vb)
|
|
||||||
{
|
|
||||||
const BVItem* a = (const BVItem*)va;
|
|
||||||
const BVItem* b = (const BVItem*)vb;
|
|
||||||
if (a->bmin[2] < b->bmin[2])
|
|
||||||
return -1;
|
|
||||||
if (a->bmin[2] > b->bmin[2])
|
|
||||||
return 1;
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void calcExtends(BVItem* items, int nitems, int imin, int imax,
|
|
||||||
unsigned short* bmin, unsigned short* bmax)
|
|
||||||
{
|
|
||||||
bmin[0] = items[imin].bmin[0];
|
|
||||||
bmin[1] = items[imin].bmin[1];
|
|
||||||
bmin[2] = items[imin].bmin[2];
|
|
||||||
|
|
||||||
bmax[0] = items[imin].bmax[0];
|
|
||||||
bmax[1] = items[imin].bmax[1];
|
|
||||||
bmax[2] = items[imin].bmax[2];
|
|
||||||
|
|
||||||
for (int i = imin+1; i < imax; ++i)
|
|
||||||
{
|
|
||||||
const BVItem& it = items[i];
|
|
||||||
if (it.bmin[0] < bmin[0]) bmin[0] = it.bmin[0];
|
|
||||||
if (it.bmin[1] < bmin[1]) bmin[1] = it.bmin[1];
|
|
||||||
if (it.bmin[2] < bmin[2]) bmin[2] = it.bmin[2];
|
|
||||||
|
|
||||||
if (it.bmax[0] > bmax[0]) bmax[0] = it.bmax[0];
|
|
||||||
if (it.bmax[1] > bmax[1]) bmax[1] = it.bmax[1];
|
|
||||||
if (it.bmax[2] > bmax[2]) bmax[2] = it.bmax[2];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
inline int longestAxis(unsigned short x, unsigned short y, unsigned short z)
|
|
||||||
{
|
|
||||||
int axis = 0;
|
|
||||||
unsigned short maxVal = x;
|
|
||||||
if (y > maxVal)
|
|
||||||
{
|
|
||||||
axis = 1;
|
|
||||||
maxVal = y;
|
|
||||||
}
|
|
||||||
if (z > maxVal)
|
|
||||||
{
|
|
||||||
axis = 2;
|
|
||||||
maxVal = z;
|
|
||||||
}
|
|
||||||
return axis;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void subdivide(BVItem* items, int nitems, int imin, int imax, int& curNode, dtStatBVNode* nodes)
|
|
||||||
{
|
|
||||||
int inum = imax - imin;
|
|
||||||
int icur = curNode;
|
|
||||||
|
|
||||||
dtStatBVNode& node = nodes[curNode++];
|
|
||||||
|
|
||||||
if (inum == 1)
|
|
||||||
{
|
|
||||||
// Leaf
|
|
||||||
node.bmin[0] = items[imin].bmin[0];
|
|
||||||
node.bmin[1] = items[imin].bmin[1];
|
|
||||||
node.bmin[2] = items[imin].bmin[2];
|
|
||||||
|
|
||||||
node.bmax[0] = items[imin].bmax[0];
|
|
||||||
node.bmax[1] = items[imin].bmax[1];
|
|
||||||
node.bmax[2] = items[imin].bmax[2];
|
|
||||||
|
|
||||||
node.i = items[imin].i;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
// Split
|
|
||||||
calcExtends(items, nitems, imin, imax, node.bmin, node.bmax);
|
|
||||||
|
|
||||||
int axis = longestAxis(node.bmax[0] - node.bmin[0],
|
|
||||||
node.bmax[1] - node.bmin[1],
|
|
||||||
node.bmax[2] - node.bmin[2]);
|
|
||||||
|
|
||||||
if (axis == 0)
|
|
||||||
{
|
|
||||||
// Sort along x-axis
|
|
||||||
qsort(items+imin, inum, sizeof(BVItem), compareItemX);
|
|
||||||
}
|
|
||||||
else if (axis == 1)
|
|
||||||
{
|
|
||||||
// Sort along y-axis
|
|
||||||
qsort(items+imin, inum, sizeof(BVItem), compareItemY);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
// Sort along z-axis
|
|
||||||
qsort(items+imin, inum, sizeof(BVItem), compareItemZ);
|
|
||||||
}
|
|
||||||
|
|
||||||
int isplit = imin+inum/2;
|
|
||||||
|
|
||||||
// Left
|
|
||||||
subdivide(items, nitems, imin, isplit, curNode, nodes);
|
|
||||||
// Right
|
|
||||||
subdivide(items, nitems, isplit, imax, curNode, nodes);
|
|
||||||
|
|
||||||
int iescape = curNode - icur;
|
|
||||||
// Negative index means escape.
|
|
||||||
node.i = -iescape;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static int createBVTree(const unsigned short* verts, const int nverts,
|
|
||||||
const unsigned short* polys, const int npolys, const int nvp,
|
|
||||||
float cs, float ch,
|
|
||||||
int nnodes, dtStatBVNode* nodes)
|
|
||||||
{
|
|
||||||
// Build tree
|
|
||||||
BVItem* items = new BVItem[npolys];
|
|
||||||
for (int i = 0; i < npolys; i++)
|
|
||||||
{
|
|
||||||
BVItem& it = items[i];
|
|
||||||
it.i = i+1;
|
|
||||||
// Calc polygon bounds.
|
|
||||||
const unsigned short* p = &polys[i*nvp*2];
|
|
||||||
it.bmin[0] = it.bmax[0] = verts[p[0]*3+0];
|
|
||||||
it.bmin[1] = it.bmax[1] = verts[p[0]*3+1];
|
|
||||||
it.bmin[2] = it.bmax[2] = verts[p[0]*3+2];
|
|
||||||
|
|
||||||
for (int j = 1; j < nvp; ++j)
|
|
||||||
{
|
|
||||||
if (p[j] == 0xffff) break;
|
|
||||||
unsigned short x = verts[p[j]*3+0];
|
|
||||||
unsigned short y = verts[p[j]*3+1];
|
|
||||||
unsigned short z = verts[p[j]*3+2];
|
|
||||||
|
|
||||||
if (x < it.bmin[0]) it.bmin[0] = x;
|
|
||||||
if (y < it.bmin[1]) it.bmin[1] = y;
|
|
||||||
if (z < it.bmin[2]) it.bmin[2] = z;
|
|
||||||
|
|
||||||
if (x > it.bmax[0]) it.bmax[0] = x;
|
|
||||||
if (y > it.bmax[1]) it.bmax[1] = y;
|
|
||||||
if (z > it.bmax[2]) it.bmax[2] = z;
|
|
||||||
}
|
|
||||||
// Remap y
|
|
||||||
it.bmin[1] = (unsigned short)floorf((float)it.bmin[1]*ch/cs);
|
|
||||||
it.bmax[1] = (unsigned short)ceilf((float)it.bmax[1]*ch/cs);
|
|
||||||
}
|
|
||||||
|
|
||||||
int curNode = 0;
|
|
||||||
subdivide(items, npolys, 0, npolys, curNode, nodes);
|
|
||||||
|
|
||||||
delete [] items;
|
|
||||||
|
|
||||||
return curNode;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
bool dtCreateNavMeshData(const unsigned short* verts, const int nverts,
|
|
||||||
const unsigned short* polys, const int npolys, const int nvp,
|
|
||||||
const float* bmin, const float* bmax, float cs, float ch,
|
|
||||||
const unsigned short* dmeshes, const float* dverts, const int ndverts,
|
|
||||||
const unsigned char* dtris, const int ndtris,
|
|
||||||
unsigned char** outData, int* outDataSize)
|
|
||||||
{
|
|
||||||
if (nvp > DT_STAT_VERTS_PER_POLYGON)
|
|
||||||
return false;
|
|
||||||
if (nverts >= 0xffff)
|
|
||||||
return false;
|
|
||||||
|
|
||||||
if (!nverts)
|
|
||||||
return false;
|
|
||||||
if (!npolys)
|
|
||||||
return false;
|
|
||||||
if (!dmeshes || !dverts || ! dtris)
|
|
||||||
return false;
|
|
||||||
|
|
||||||
// Find unique detail vertices.
|
|
||||||
int uniqueDetailVerts = 0;
|
|
||||||
if (dmeshes)
|
|
||||||
{
|
|
||||||
for (int i = 0; i < npolys; ++i)
|
|
||||||
{
|
|
||||||
const unsigned short* p = &polys[i*nvp*2];
|
|
||||||
int ndv = dmeshes[i*4+1];
|
|
||||||
int nv = 0;
|
|
||||||
for (int j = 0; j < nvp; ++j)
|
|
||||||
{
|
|
||||||
if (p[j] == 0xffff) break;
|
|
||||||
nv++;
|
|
||||||
}
|
|
||||||
ndv -= nv;
|
|
||||||
uniqueDetailVerts += ndv;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Calculate data size
|
|
||||||
const int headerSize = align4(sizeof(dtStatNavMeshHeader));
|
|
||||||
const int vertsSize = align4(sizeof(float)*3*nverts);
|
|
||||||
const int polysSize = align4(sizeof(dtStatPoly)*npolys);
|
|
||||||
const int nodesSize = align4(sizeof(dtStatBVNode)*npolys*2);
|
|
||||||
const int detailMeshesSize = align4(sizeof(dtStatPolyDetail)*npolys);
|
|
||||||
const int detailVertsSize = align4(sizeof(float)*3*uniqueDetailVerts);
|
|
||||||
const int detailTrisSize = align4(sizeof(unsigned char)*4*ndtris);
|
|
||||||
|
|
||||||
const int dataSize = headerSize + vertsSize + polysSize + nodesSize +
|
|
||||||
detailMeshesSize + detailVertsSize + detailTrisSize;
|
|
||||||
unsigned char* data = new unsigned char[dataSize];
|
|
||||||
if (!data)
|
|
||||||
return false;
|
|
||||||
memset(data, 0, dataSize);
|
|
||||||
|
|
||||||
unsigned char* d = data;
|
|
||||||
dtStatNavMeshHeader* header = (dtStatNavMeshHeader*)d; d += headerSize;
|
|
||||||
float* navVerts = (float*)d; d += vertsSize;
|
|
||||||
dtStatPoly* navPolys = (dtStatPoly*)d; d += polysSize;
|
|
||||||
dtStatBVNode* navNodes = (dtStatBVNode*)d; d += nodesSize;
|
|
||||||
dtStatPolyDetail* navDMeshes = (dtStatPolyDetail*)d; d += detailMeshesSize;
|
|
||||||
float* navDVerts = (float*)d; d += detailVertsSize;
|
|
||||||
unsigned char* navDTris = (unsigned char*)d; d += detailTrisSize;
|
|
||||||
|
|
||||||
// Store header
|
|
||||||
header->magic = DT_STAT_NAVMESH_MAGIC;
|
|
||||||
header->version = DT_STAT_NAVMESH_VERSION;
|
|
||||||
header->npolys = npolys;
|
|
||||||
header->nverts = nverts;
|
|
||||||
header->cs = cs;
|
|
||||||
header->bmin[0] = bmin[0];
|
|
||||||
header->bmin[1] = bmin[1];
|
|
||||||
header->bmin[2] = bmin[2];
|
|
||||||
header->bmax[0] = bmax[0];
|
|
||||||
header->bmax[1] = bmax[1];
|
|
||||||
header->bmax[2] = bmax[2];
|
|
||||||
header->ndmeshes = dmeshes ? npolys : 0;
|
|
||||||
header->ndverts = dmeshes ? uniqueDetailVerts : 0;
|
|
||||||
header->ndtris = dmeshes ? ndtris : 0;
|
|
||||||
|
|
||||||
// Store vertices
|
|
||||||
for (int i = 0; i < nverts; ++i)
|
|
||||||
{
|
|
||||||
const unsigned short* iv = &verts[i*3];
|
|
||||||
float* v = &navVerts[i*3];
|
|
||||||
v[0] = bmin[0] + iv[0] * cs;
|
|
||||||
v[1] = bmin[1] + iv[1] * ch;
|
|
||||||
v[2] = bmin[2] + iv[2] * cs;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Store polygons
|
|
||||||
const unsigned short* src = polys;
|
|
||||||
for (int i = 0; i < npolys; ++i)
|
|
||||||
{
|
|
||||||
dtStatPoly* p = &navPolys[i];
|
|
||||||
p->nv = 0;
|
|
||||||
for (int j = 0; j < nvp; ++j)
|
|
||||||
{
|
|
||||||
if (src[j] == 0xffff) break;
|
|
||||||
p->v[j] = src[j];
|
|
||||||
p->n[j] = src[nvp+j]+1;
|
|
||||||
p->nv++;
|
|
||||||
}
|
|
||||||
src += nvp*2;
|
|
||||||
}
|
|
||||||
|
|
||||||
header->nnodes = createBVTree(verts, nverts, polys, npolys, nvp,
|
|
||||||
cs, ch, npolys*2, navNodes);
|
|
||||||
|
|
||||||
|
|
||||||
// Store detail meshes and vertices.
|
|
||||||
// The nav polygon vertices are stored as the first vertices on each mesh.
|
|
||||||
// We compress the mesh data by skipping them and using the navmesh coordinates.
|
|
||||||
unsigned short vbase = 0;
|
|
||||||
for (int i = 0; i < npolys; ++i)
|
|
||||||
{
|
|
||||||
dtStatPolyDetail& dtl = navDMeshes[i];
|
|
||||||
const int vb = dmeshes[i*4+0];
|
|
||||||
const int ndv = dmeshes[i*4+1];
|
|
||||||
const int nv = navPolys[i].nv;
|
|
||||||
dtl.vbase = vbase;
|
|
||||||
dtl.nverts = ndv-nv;
|
|
||||||
dtl.tbase = dmeshes[i*4+2];
|
|
||||||
dtl.ntris = dmeshes[i*4+3];
|
|
||||||
// Copy vertices except the first 'nv' verts which are equal to nav poly verts.
|
|
||||||
if (ndv-nv > 0)
|
|
||||||
{
|
|
||||||
memcpy(&navDVerts[vbase*3], &dverts[(vb+nv)*3], sizeof(float)*3*(ndv-nv));
|
|
||||||
vbase += ndv-nv;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// Store triangles.
|
|
||||||
memcpy(navDTris, dtris, sizeof(unsigned char)*4*ndtris);
|
|
||||||
|
|
||||||
*outData = data;
|
|
||||||
*outDataSize = dataSize;
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
File diff suppressed because it is too large
Load Diff
@ -1,215 +0,0 @@
|
|||||||
//
|
|
||||||
// Copyright (c) 2009 Mikko Mononen memon@inside.org
|
|
||||||
//
|
|
||||||
// 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.
|
|
||||||
//
|
|
||||||
|
|
||||||
#include <math.h>
|
|
||||||
#include <stdio.h>
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include <string.h>
|
|
||||||
#include "DetourTileNavMesh.h"
|
|
||||||
#include "DetourCommon.h"
|
|
||||||
|
|
||||||
bool dtCreateNavMeshTileData(const unsigned short* verts, const int nverts,
|
|
||||||
const unsigned short* polys, const int npolys, const int nvp,
|
|
||||||
const unsigned short* dmeshes, const float* dverts, const int ndverts,
|
|
||||||
const unsigned char* dtris, const int ndtris,
|
|
||||||
const float* bmin, const float* bmax, float cs, float ch, int tileSize, int walkableClimb,
|
|
||||||
unsigned char** outData, int* outDataSize)
|
|
||||||
{
|
|
||||||
if (nvp != DT_TILE_VERTS_PER_POLYGON)
|
|
||||||
return false;
|
|
||||||
if (nverts >= 0xffff)
|
|
||||||
return false;
|
|
||||||
if (npolys > DT_MAX_TILES)
|
|
||||||
return false;
|
|
||||||
|
|
||||||
if (!nverts)
|
|
||||||
return false;
|
|
||||||
if (!npolys)
|
|
||||||
return false;
|
|
||||||
if (!dmeshes || !dverts || ! dtris)
|
|
||||||
return false;
|
|
||||||
|
|
||||||
// Find portal edges which are at tile borders.
|
|
||||||
int nedges = 0;
|
|
||||||
int nportals = 0;
|
|
||||||
for (int i = 0; i < npolys; ++i)
|
|
||||||
{
|
|
||||||
const unsigned short* p = &polys[i*2*nvp];
|
|
||||||
for (int j = 0; j < nvp; ++j)
|
|
||||||
{
|
|
||||||
if (p[j] == 0xffff) break;
|
|
||||||
int nj = j+1;
|
|
||||||
if (nj >= nvp || p[nj] == 0xffff) nj = 0;
|
|
||||||
const unsigned short* va = &verts[p[j]*3];
|
|
||||||
const unsigned short* vb = &verts[p[nj]*3];
|
|
||||||
|
|
||||||
nedges++;
|
|
||||||
|
|
||||||
if (va[0] == tileSize && vb[0] == tileSize)
|
|
||||||
nportals++; // x+
|
|
||||||
else if (va[2] == tileSize && vb[2] == tileSize)
|
|
||||||
nportals++; // z+
|
|
||||||
else if (va[0] == 0 && vb[0] == 0)
|
|
||||||
nportals++; // x-
|
|
||||||
else if (va[2] == 0 && vb[2] == 0)
|
|
||||||
nportals++; // z-
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const int maxLinks = nedges + nportals*2;
|
|
||||||
|
|
||||||
|
|
||||||
// Find unique detail vertices.
|
|
||||||
int uniqueDetailVerts = 0;
|
|
||||||
if (dmeshes)
|
|
||||||
{
|
|
||||||
for (int i = 0; i < npolys; ++i)
|
|
||||||
{
|
|
||||||
const unsigned short* p = &polys[i*nvp*2];
|
|
||||||
int ndv = dmeshes[i*4+1];
|
|
||||||
int nv = 0;
|
|
||||||
for (int j = 0; j < nvp; ++j)
|
|
||||||
{
|
|
||||||
if (p[j] == 0xffff) break;
|
|
||||||
nv++;
|
|
||||||
}
|
|
||||||
ndv -= nv;
|
|
||||||
uniqueDetailVerts += ndv;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Calculate data size
|
|
||||||
const int headerSize = align4(sizeof(dtTileHeader));
|
|
||||||
const int vertsSize = align4(sizeof(float)*3*nverts);
|
|
||||||
const int polysSize = align4(sizeof(dtTilePoly)*npolys);
|
|
||||||
const int linksSize = align4(sizeof(dtTileLink)*maxLinks);
|
|
||||||
const int detailMeshesSize = align4(sizeof(dtTilePolyDetail)*npolys);
|
|
||||||
const int detailVertsSize = align4(sizeof(float)*3*uniqueDetailVerts);
|
|
||||||
const int detailTrisSize = align4(sizeof(unsigned char)*4*ndtris);
|
|
||||||
|
|
||||||
const int dataSize = headerSize + vertsSize + polysSize + linksSize +
|
|
||||||
detailMeshesSize + detailVertsSize + detailTrisSize;
|
|
||||||
unsigned char* data = new unsigned char[dataSize];
|
|
||||||
if (!data)
|
|
||||||
return false;
|
|
||||||
memset(data, 0, dataSize);
|
|
||||||
|
|
||||||
unsigned char* d = data;
|
|
||||||
dtTileHeader* header = (dtTileHeader*)d; d += headerSize;
|
|
||||||
float* navVerts = (float*)d; d += vertsSize;
|
|
||||||
dtTilePoly* navPolys = (dtTilePoly*)d; d += polysSize;
|
|
||||||
d += linksSize;
|
|
||||||
dtTilePolyDetail* navDMeshes = (dtTilePolyDetail*)d; d += detailMeshesSize;
|
|
||||||
float* navDVerts = (float*)d; d += detailVertsSize;
|
|
||||||
unsigned char* navDTris = (unsigned char*)d; d += detailTrisSize;
|
|
||||||
|
|
||||||
|
|
||||||
// Store header
|
|
||||||
header->magic = DT_TILE_NAVMESH_MAGIC;
|
|
||||||
header->version = DT_TILE_NAVMESH_VERSION;
|
|
||||||
header->npolys = npolys;
|
|
||||||
header->nverts = nverts;
|
|
||||||
header->maxlinks = maxLinks;
|
|
||||||
header->bmin[0] = bmin[0];
|
|
||||||
header->bmin[1] = bmin[1];
|
|
||||||
header->bmin[2] = bmin[2];
|
|
||||||
header->bmax[0] = bmax[0];
|
|
||||||
header->bmax[1] = bmax[1];
|
|
||||||
header->bmax[2] = bmax[2];
|
|
||||||
header->ndmeshes = npolys;
|
|
||||||
header->ndverts = uniqueDetailVerts;
|
|
||||||
header->ndtris = ndtris;
|
|
||||||
|
|
||||||
// Store vertices
|
|
||||||
for (int i = 0; i < nverts; ++i)
|
|
||||||
{
|
|
||||||
const unsigned short* iv = &verts[i*3];
|
|
||||||
float* v = &navVerts[i*3];
|
|
||||||
v[0] = bmin[0] + iv[0] * cs;
|
|
||||||
v[1] = bmin[1] + iv[1] * ch;
|
|
||||||
v[2] = bmin[2] + iv[2] * cs;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Store polygons
|
|
||||||
const unsigned short* src = polys;
|
|
||||||
for (int i = 0; i < npolys; ++i)
|
|
||||||
{
|
|
||||||
dtTilePoly* p = &navPolys[i];
|
|
||||||
p->nv = 0;
|
|
||||||
for (int j = 0; j < nvp; ++j)
|
|
||||||
{
|
|
||||||
if (src[j] == 0xffff) break;
|
|
||||||
p->v[j] = src[j];
|
|
||||||
p->n[j] = (src[nvp+j]+1) & 0xffff;
|
|
||||||
p->nv++;
|
|
||||||
}
|
|
||||||
src += nvp*2;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Store portal edges.
|
|
||||||
for (int i = 0; i < npolys; ++i)
|
|
||||||
{
|
|
||||||
dtTilePoly* poly = &navPolys[i];
|
|
||||||
for (int j = 0; j < poly->nv; ++j)
|
|
||||||
{
|
|
||||||
int nj = j+1;
|
|
||||||
if (nj >= poly->nv) nj = 0;
|
|
||||||
|
|
||||||
const unsigned short* va = &verts[poly->v[j]*3];
|
|
||||||
const unsigned short* vb = &verts[poly->v[nj]*3];
|
|
||||||
|
|
||||||
if (va[0] == tileSize && vb[0] == tileSize) // x+
|
|
||||||
poly->n[j] = 0x8000 | 0;
|
|
||||||
else if (va[2] == tileSize && vb[2] == tileSize) // z+
|
|
||||||
poly->n[j] = 0x8000 | 1;
|
|
||||||
else if (va[0] == 0 && vb[0] == 0) // x-
|
|
||||||
poly->n[j] = 0x8000 | 2;
|
|
||||||
else if (va[2] == 0 && vb[2] == 0) // z-
|
|
||||||
poly->n[j] = 0x8000 | 3;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Store detail meshes and vertices.
|
|
||||||
// The nav polygon vertices are stored as the first vertices on each mesh.
|
|
||||||
// We compress the mesh data by skipping them and using the navmesh coordinates.
|
|
||||||
unsigned short vbase = 0;
|
|
||||||
for (int i = 0; i < npolys; ++i)
|
|
||||||
{
|
|
||||||
dtTilePolyDetail& dtl = navDMeshes[i];
|
|
||||||
const int vb = dmeshes[i*4+0];
|
|
||||||
const int ndv = dmeshes[i*4+1];
|
|
||||||
const int nv = navPolys[i].nv;
|
|
||||||
dtl.vbase = vbase;
|
|
||||||
dtl.nverts = ndv-nv;
|
|
||||||
dtl.tbase = dmeshes[i*4+2];
|
|
||||||
dtl.ntris = dmeshes[i*4+3];
|
|
||||||
// Copy vertices except the first 'nv' verts which are equal to nav poly verts.
|
|
||||||
if (ndv-nv)
|
|
||||||
{
|
|
||||||
memcpy(&navDVerts[vbase*3], &dverts[(vb+nv)*3], sizeof(float)*3*(ndv-nv));
|
|
||||||
vbase += ndv-nv;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// Store triangles.
|
|
||||||
memcpy(navDTris, dtris, sizeof(unsigned char)*4*ndtris);
|
|
||||||
|
|
||||||
*outData = data;
|
|
||||||
*outDataSize = dataSize;
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
@ -6,6 +6,8 @@
|
|||||||
<string>English</string>
|
<string>English</string>
|
||||||
<key>CFBundleExecutable</key>
|
<key>CFBundleExecutable</key>
|
||||||
<string>Recast</string>
|
<string>Recast</string>
|
||||||
|
<key>CFBundleIconFile</key>
|
||||||
|
<string>Icon.icns</string>
|
||||||
<key>CFBundleIdentifier</key>
|
<key>CFBundleIdentifier</key>
|
||||||
<string>com.yourcompany.Recast</string>
|
<string>com.yourcompany.Recast</string>
|
||||||
<key>CFBundleInfoDictionaryVersion</key>
|
<key>CFBundleInfoDictionaryVersion</key>
|
||||||
|
Binary file not shown.
Binary file not shown.
File diff suppressed because it is too large
Load Diff
@ -9,7 +9,6 @@
|
|||||||
/* Begin PBXBuildFile section */
|
/* Begin PBXBuildFile section */
|
||||||
1DDD58160DA1D0A300B32029 /* MainMenu.xib in Resources */ = {isa = PBXBuildFile; fileRef = 1DDD58140DA1D0A300B32029 /* MainMenu.xib */; };
|
1DDD58160DA1D0A300B32029 /* MainMenu.xib in Resources */ = {isa = PBXBuildFile; fileRef = 1DDD58140DA1D0A300B32029 /* MainMenu.xib */; };
|
||||||
6B024C0D10060AC600CF7107 /* Icon.icns in Resources */ = {isa = PBXBuildFile; fileRef = 6B024C0C10060AC600CF7107 /* Icon.icns */; };
|
6B024C0D10060AC600CF7107 /* Icon.icns in Resources */ = {isa = PBXBuildFile; fileRef = 6B024C0C10060AC600CF7107 /* Icon.icns */; };
|
||||||
6B092B940FFCC2BD0088D3A5 /* DetourTileNavMeshBuilder.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 6B092B930FFCC2BD0088D3A5 /* DetourTileNavMeshBuilder.cpp */; };
|
|
||||||
6B1185F51006895B0018F96F /* DetourNode.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 6B1185F41006895B0018F96F /* DetourNode.cpp */; };
|
6B1185F51006895B0018F96F /* DetourNode.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 6B1185F41006895B0018F96F /* DetourNode.cpp */; };
|
||||||
6B1185FE10068B150018F96F /* DetourCommon.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 6B1185FD10068B150018F96F /* DetourCommon.cpp */; };
|
6B1185FE10068B150018F96F /* DetourCommon.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 6B1185FD10068B150018F96F /* DetourCommon.cpp */; };
|
||||||
6B137C710F7FCBBB00459200 /* imgui.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 6B137C6C0F7FCBBB00459200 /* imgui.cpp */; };
|
6B137C710F7FCBBB00459200 /* imgui.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 6B137C6C0F7FCBBB00459200 /* imgui.cpp */; };
|
||||||
@ -27,21 +26,17 @@
|
|||||||
6B25B6190FFA62BE004F1BC4 /* Sample.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 6B25B6140FFA62BE004F1BC4 /* Sample.cpp */; };
|
6B25B6190FFA62BE004F1BC4 /* Sample.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 6B25B6140FFA62BE004F1BC4 /* Sample.cpp */; };
|
||||||
6B25B61D0FFA62BE004F1BC4 /* main.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 6B25B6180FFA62BE004F1BC4 /* main.cpp */; };
|
6B25B61D0FFA62BE004F1BC4 /* main.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 6B25B6180FFA62BE004F1BC4 /* main.cpp */; };
|
||||||
6B2AEC530FFB8958005BE9CC /* Sample_TileMesh.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 6B2AEC520FFB8958005BE9CC /* Sample_TileMesh.cpp */; };
|
6B2AEC530FFB8958005BE9CC /* Sample_TileMesh.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 6B2AEC520FFB8958005BE9CC /* Sample_TileMesh.cpp */; };
|
||||||
6B2AEC5A0FFB8A7A005BE9CC /* DetourTileNavMesh.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 6B2AEC590FFB8A7A005BE9CC /* DetourTileNavMesh.cpp */; };
|
|
||||||
6B555DB1100B212E00247EA3 /* imguiRenderGL.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 6B555DB0100B212E00247EA3 /* imguiRenderGL.cpp */; };
|
6B555DB1100B212E00247EA3 /* imguiRenderGL.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 6B555DB0100B212E00247EA3 /* imguiRenderGL.cpp */; };
|
||||||
6B62416A103434880002E346 /* RecastMeshDetail.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 6B624169103434880002E346 /* RecastMeshDetail.cpp */; };
|
6B62416A103434880002E346 /* RecastMeshDetail.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 6B624169103434880002E346 /* RecastMeshDetail.cpp */; };
|
||||||
6B8632DA0F78122C00E2684A /* SDL.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 6B8632D90F78122C00E2684A /* SDL.framework */; };
|
6B8632DA0F78122C00E2684A /* SDL.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 6B8632D90F78122C00E2684A /* SDL.framework */; };
|
||||||
6B8632DC0F78123E00E2684A /* OpenGL.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 6B8632DB0F78123E00E2684A /* OpenGL.framework */; };
|
6B8632DC0F78123E00E2684A /* OpenGL.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 6B8632DB0F78123E00E2684A /* OpenGL.framework */; };
|
||||||
6B8DE88910B69E3E00DF20FB /* DetourNavMesh.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 6B8DE88710B69E3E00DF20FB /* DetourNavMesh.cpp */; };
|
6B8DE88910B69E3E00DF20FB /* DetourNavMesh.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 6B8DE88710B69E3E00DF20FB /* DetourNavMesh.cpp */; };
|
||||||
6B8DE88A10B69E3E00DF20FB /* DetourNavMeshBuilder.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 6B8DE88810B69E3E00DF20FB /* DetourNavMeshBuilder.cpp */; };
|
6B8DE88A10B69E3E00DF20FB /* DetourNavMeshBuilder.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 6B8DE88810B69E3E00DF20FB /* DetourNavMeshBuilder.cpp */; };
|
||||||
6B8DE8F810B6B70E00DF20FB /* Sample_DynMesh.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 6B8DE8F710B6B70E00DF20FB /* Sample_DynMesh.cpp */; };
|
|
||||||
6BA1E88A10C7BFC9008007F6 /* Sample_SoloMesh.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 6BA1E88710C7BFC9008007F6 /* Sample_SoloMesh.cpp */; };
|
6BA1E88A10C7BFC9008007F6 /* Sample_SoloMesh.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 6BA1E88710C7BFC9008007F6 /* Sample_SoloMesh.cpp */; };
|
||||||
6BA1E88B10C7BFC9008007F6 /* Sample_SoloMeshSimple.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 6BA1E88810C7BFC9008007F6 /* Sample_SoloMeshSimple.cpp */; };
|
6BA1E88B10C7BFC9008007F6 /* Sample_SoloMeshSimple.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 6BA1E88810C7BFC9008007F6 /* Sample_SoloMeshSimple.cpp */; };
|
||||||
6BA1E88C10C7BFC9008007F6 /* Sample_SoloMeshTiled.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 6BA1E88910C7BFC9008007F6 /* Sample_SoloMeshTiled.cpp */; };
|
6BA1E88C10C7BFC9008007F6 /* Sample_SoloMeshTiled.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 6BA1E88910C7BFC9008007F6 /* Sample_SoloMeshTiled.cpp */; };
|
||||||
6BB788170FC0472B003C24DB /* ChunkyTriMesh.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 6BB788160FC0472B003C24DB /* ChunkyTriMesh.cpp */; };
|
6BB788170FC0472B003C24DB /* ChunkyTriMesh.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 6BB788160FC0472B003C24DB /* ChunkyTriMesh.cpp */; };
|
||||||
6BDD9E0A0F91113800904EEF /* DetourDebugDraw.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 6BDD9E070F91113800904EEF /* DetourDebugDraw.cpp */; };
|
6BDD9E0A0F91113800904EEF /* DetourDebugDraw.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 6BDD9E070F91113800904EEF /* DetourDebugDraw.cpp */; };
|
||||||
6BDD9E0B0F91113800904EEF /* DetourStatNavMesh.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 6BDD9E080F91113800904EEF /* DetourStatNavMesh.cpp */; };
|
|
||||||
6BDD9E0C0F91113800904EEF /* DetourStatNavMeshBuilder.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 6BDD9E090F91113800904EEF /* DetourStatNavMeshBuilder.cpp */; };
|
|
||||||
8D11072B0486CEB800E47090 /* InfoPlist.strings in Resources */ = {isa = PBXBuildFile; fileRef = 089C165CFE840E0CC02AAC07 /* InfoPlist.strings */; };
|
8D11072B0486CEB800E47090 /* InfoPlist.strings in Resources */ = {isa = PBXBuildFile; fileRef = 089C165CFE840E0CC02AAC07 /* InfoPlist.strings */; };
|
||||||
8D11072F0486CEB800E47090 /* Cocoa.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 1058C7A1FEA54F0111CA2CBB /* Cocoa.framework */; };
|
8D11072F0486CEB800E47090 /* Cocoa.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 1058C7A1FEA54F0111CA2CBB /* Cocoa.framework */; };
|
||||||
/* End PBXBuildFile section */
|
/* End PBXBuildFile section */
|
||||||
@ -55,8 +50,6 @@
|
|||||||
29B97325FDCFA39411CA2CEA /* Foundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Foundation.framework; path = /System/Library/Frameworks/Foundation.framework; sourceTree = "<absolute>"; };
|
29B97325FDCFA39411CA2CEA /* Foundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Foundation.framework; path = /System/Library/Frameworks/Foundation.framework; sourceTree = "<absolute>"; };
|
||||||
32CA4F630368D1EE00C91783 /* Recast_Prefix.pch */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Recast_Prefix.pch; sourceTree = "<group>"; };
|
32CA4F630368D1EE00C91783 /* Recast_Prefix.pch */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Recast_Prefix.pch; sourceTree = "<group>"; };
|
||||||
6B024C0C10060AC600CF7107 /* Icon.icns */ = {isa = PBXFileReference; lastKnownFileType = image.icns; path = Icon.icns; sourceTree = "<group>"; };
|
6B024C0C10060AC600CF7107 /* Icon.icns */ = {isa = PBXFileReference; lastKnownFileType = image.icns; path = Icon.icns; sourceTree = "<group>"; };
|
||||||
6B092B920FFCC2AC0088D3A5 /* DetourTileNavMeshBuilder.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = DetourTileNavMeshBuilder.h; path = ../../../Detour/Include/DetourTileNavMeshBuilder.h; sourceTree = SOURCE_ROOT; };
|
|
||||||
6B092B930FFCC2BD0088D3A5 /* DetourTileNavMeshBuilder.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = DetourTileNavMeshBuilder.cpp; path = ../../../Detour/Source/DetourTileNavMeshBuilder.cpp; sourceTree = SOURCE_ROOT; };
|
|
||||||
6B1185F41006895B0018F96F /* DetourNode.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = DetourNode.cpp; path = ../../../Detour/Source/DetourNode.cpp; sourceTree = SOURCE_ROOT; };
|
6B1185F41006895B0018F96F /* DetourNode.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = DetourNode.cpp; path = ../../../Detour/Source/DetourNode.cpp; sourceTree = SOURCE_ROOT; };
|
||||||
6B1185F61006896B0018F96F /* DetourNode.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = DetourNode.h; path = ../../../Detour/Include/DetourNode.h; sourceTree = SOURCE_ROOT; };
|
6B1185F61006896B0018F96F /* DetourNode.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = DetourNode.h; path = ../../../Detour/Include/DetourNode.h; sourceTree = SOURCE_ROOT; };
|
||||||
6B1185FC10068B040018F96F /* DetourCommon.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = DetourCommon.h; path = ../../../Detour/Include/DetourCommon.h; sourceTree = SOURCE_ROOT; };
|
6B1185FC10068B040018F96F /* DetourCommon.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = DetourCommon.h; path = ../../../Detour/Include/DetourCommon.h; sourceTree = SOURCE_ROOT; };
|
||||||
@ -85,8 +78,6 @@
|
|||||||
6B25B6180FFA62BE004F1BC4 /* main.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = main.cpp; path = ../../Source/main.cpp; sourceTree = SOURCE_ROOT; };
|
6B25B6180FFA62BE004F1BC4 /* main.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = main.cpp; path = ../../Source/main.cpp; sourceTree = SOURCE_ROOT; };
|
||||||
6B2AEC510FFB8946005BE9CC /* Sample_TileMesh.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = Sample_TileMesh.h; path = ../../Include/Sample_TileMesh.h; sourceTree = SOURCE_ROOT; };
|
6B2AEC510FFB8946005BE9CC /* Sample_TileMesh.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = Sample_TileMesh.h; path = ../../Include/Sample_TileMesh.h; sourceTree = SOURCE_ROOT; };
|
||||||
6B2AEC520FFB8958005BE9CC /* Sample_TileMesh.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = Sample_TileMesh.cpp; path = ../../Source/Sample_TileMesh.cpp; sourceTree = SOURCE_ROOT; };
|
6B2AEC520FFB8958005BE9CC /* Sample_TileMesh.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = Sample_TileMesh.cpp; path = ../../Source/Sample_TileMesh.cpp; sourceTree = SOURCE_ROOT; };
|
||||||
6B2AEC580FFB8A68005BE9CC /* DetourTileNavMesh.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = DetourTileNavMesh.h; path = ../../../Detour/Include/DetourTileNavMesh.h; sourceTree = SOURCE_ROOT; };
|
|
||||||
6B2AEC590FFB8A7A005BE9CC /* DetourTileNavMesh.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = DetourTileNavMesh.cpp; path = ../../../Detour/Source/DetourTileNavMesh.cpp; sourceTree = SOURCE_ROOT; };
|
|
||||||
6B555DAE100B211D00247EA3 /* imguiRenderGL.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = imguiRenderGL.h; path = ../../Include/imguiRenderGL.h; sourceTree = SOURCE_ROOT; };
|
6B555DAE100B211D00247EA3 /* imguiRenderGL.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = imguiRenderGL.h; path = ../../Include/imguiRenderGL.h; sourceTree = SOURCE_ROOT; };
|
||||||
6B555DB0100B212E00247EA3 /* imguiRenderGL.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = imguiRenderGL.cpp; path = ../../Source/imguiRenderGL.cpp; sourceTree = SOURCE_ROOT; };
|
6B555DB0100B212E00247EA3 /* imguiRenderGL.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = imguiRenderGL.cpp; path = ../../Source/imguiRenderGL.cpp; sourceTree = SOURCE_ROOT; };
|
||||||
6B555DF6100B273500247EA3 /* stb_truetype.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = stb_truetype.h; path = ../../Contrib/stb_truetype.h; sourceTree = SOURCE_ROOT; };
|
6B555DF6100B273500247EA3 /* stb_truetype.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = stb_truetype.h; path = ../../Contrib/stb_truetype.h; sourceTree = SOURCE_ROOT; };
|
||||||
@ -97,8 +88,6 @@
|
|||||||
6B8DE88810B69E3E00DF20FB /* DetourNavMeshBuilder.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = DetourNavMeshBuilder.cpp; path = ../../../Detour/Source/DetourNavMeshBuilder.cpp; sourceTree = SOURCE_ROOT; };
|
6B8DE88810B69E3E00DF20FB /* DetourNavMeshBuilder.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = DetourNavMeshBuilder.cpp; path = ../../../Detour/Source/DetourNavMeshBuilder.cpp; sourceTree = SOURCE_ROOT; };
|
||||||
6B8DE88B10B69E4C00DF20FB /* DetourNavMesh.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = DetourNavMesh.h; path = ../../../Detour/Include/DetourNavMesh.h; sourceTree = SOURCE_ROOT; };
|
6B8DE88B10B69E4C00DF20FB /* DetourNavMesh.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = DetourNavMesh.h; path = ../../../Detour/Include/DetourNavMesh.h; sourceTree = SOURCE_ROOT; };
|
||||||
6B8DE88C10B69E4C00DF20FB /* DetourNavMeshBuilder.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = DetourNavMeshBuilder.h; path = ../../../Detour/Include/DetourNavMeshBuilder.h; sourceTree = SOURCE_ROOT; };
|
6B8DE88C10B69E4C00DF20FB /* DetourNavMeshBuilder.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = DetourNavMeshBuilder.h; path = ../../../Detour/Include/DetourNavMeshBuilder.h; sourceTree = SOURCE_ROOT; };
|
||||||
6B8DE8F610B6B70100DF20FB /* Sample_DynMesh.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = Sample_DynMesh.h; path = ../../Include/Sample_DynMesh.h; sourceTree = SOURCE_ROOT; };
|
|
||||||
6B8DE8F710B6B70E00DF20FB /* Sample_DynMesh.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = Sample_DynMesh.cpp; path = ../../Source/Sample_DynMesh.cpp; sourceTree = SOURCE_ROOT; };
|
|
||||||
6BA1E88710C7BFC9008007F6 /* Sample_SoloMesh.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = Sample_SoloMesh.cpp; path = ../../Source/Sample_SoloMesh.cpp; sourceTree = SOURCE_ROOT; };
|
6BA1E88710C7BFC9008007F6 /* Sample_SoloMesh.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = Sample_SoloMesh.cpp; path = ../../Source/Sample_SoloMesh.cpp; sourceTree = SOURCE_ROOT; };
|
||||||
6BA1E88810C7BFC9008007F6 /* Sample_SoloMeshSimple.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = Sample_SoloMeshSimple.cpp; path = ../../Source/Sample_SoloMeshSimple.cpp; sourceTree = SOURCE_ROOT; };
|
6BA1E88810C7BFC9008007F6 /* Sample_SoloMeshSimple.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = Sample_SoloMeshSimple.cpp; path = ../../Source/Sample_SoloMeshSimple.cpp; sourceTree = SOURCE_ROOT; };
|
||||||
6BA1E88910C7BFC9008007F6 /* Sample_SoloMeshTiled.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = Sample_SoloMeshTiled.cpp; path = ../../Source/Sample_SoloMeshTiled.cpp; sourceTree = SOURCE_ROOT; };
|
6BA1E88910C7BFC9008007F6 /* Sample_SoloMeshTiled.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = Sample_SoloMeshTiled.cpp; path = ../../Source/Sample_SoloMeshTiled.cpp; sourceTree = SOURCE_ROOT; };
|
||||||
@ -108,11 +97,7 @@
|
|||||||
6BB788160FC0472B003C24DB /* ChunkyTriMesh.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = ChunkyTriMesh.cpp; path = ../../Source/ChunkyTriMesh.cpp; sourceTree = SOURCE_ROOT; };
|
6BB788160FC0472B003C24DB /* ChunkyTriMesh.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = ChunkyTriMesh.cpp; path = ../../Source/ChunkyTriMesh.cpp; sourceTree = SOURCE_ROOT; };
|
||||||
6BB788180FC04753003C24DB /* ChunkyTriMesh.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = ChunkyTriMesh.h; path = ../../Include/ChunkyTriMesh.h; sourceTree = SOURCE_ROOT; };
|
6BB788180FC04753003C24DB /* ChunkyTriMesh.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = ChunkyTriMesh.h; path = ../../Include/ChunkyTriMesh.h; sourceTree = SOURCE_ROOT; };
|
||||||
6BDD9E040F91112200904EEF /* DetourDebugDraw.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = DetourDebugDraw.h; path = ../../../Detour/Include/DetourDebugDraw.h; sourceTree = SOURCE_ROOT; };
|
6BDD9E040F91112200904EEF /* DetourDebugDraw.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = DetourDebugDraw.h; path = ../../../Detour/Include/DetourDebugDraw.h; sourceTree = SOURCE_ROOT; };
|
||||||
6BDD9E050F91112200904EEF /* DetourStatNavMesh.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = DetourStatNavMesh.h; path = ../../../Detour/Include/DetourStatNavMesh.h; sourceTree = SOURCE_ROOT; };
|
|
||||||
6BDD9E060F91112200904EEF /* DetourStatNavMeshBuilder.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = DetourStatNavMeshBuilder.h; path = ../../../Detour/Include/DetourStatNavMeshBuilder.h; sourceTree = SOURCE_ROOT; };
|
|
||||||
6BDD9E070F91113800904EEF /* DetourDebugDraw.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = DetourDebugDraw.cpp; path = ../../../Detour/Source/DetourDebugDraw.cpp; sourceTree = SOURCE_ROOT; };
|
6BDD9E070F91113800904EEF /* DetourDebugDraw.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = DetourDebugDraw.cpp; path = ../../../Detour/Source/DetourDebugDraw.cpp; sourceTree = SOURCE_ROOT; };
|
||||||
6BDD9E080F91113800904EEF /* DetourStatNavMesh.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = DetourStatNavMesh.cpp; path = ../../../Detour/Source/DetourStatNavMesh.cpp; sourceTree = SOURCE_ROOT; };
|
|
||||||
6BDD9E090F91113800904EEF /* DetourStatNavMeshBuilder.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = DetourStatNavMeshBuilder.cpp; path = ../../../Detour/Source/DetourStatNavMeshBuilder.cpp; sourceTree = SOURCE_ROOT; };
|
|
||||||
8D1107310486CEB800E47090 /* Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
|
8D1107310486CEB800E47090 /* Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
|
||||||
8D1107320486CEB800E47090 /* Recast.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = Recast.app; sourceTree = BUILT_PRODUCTS_DIR; };
|
8D1107320486CEB800E47090 /* Recast.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = Recast.app; sourceTree = BUILT_PRODUCTS_DIR; };
|
||||||
/* End PBXFileReference section */
|
/* End PBXFileReference section */
|
||||||
@ -253,8 +238,6 @@
|
|||||||
6BA1E88910C7BFC9008007F6 /* Sample_SoloMeshTiled.cpp */,
|
6BA1E88910C7BFC9008007F6 /* Sample_SoloMeshTiled.cpp */,
|
||||||
6B25B6100FFA62AD004F1BC4 /* Sample.h */,
|
6B25B6100FFA62AD004F1BC4 /* Sample.h */,
|
||||||
6B25B6140FFA62BE004F1BC4 /* Sample.cpp */,
|
6B25B6140FFA62BE004F1BC4 /* Sample.cpp */,
|
||||||
6B8DE8F610B6B70100DF20FB /* Sample_DynMesh.h */,
|
|
||||||
6B8DE8F710B6B70E00DF20FB /* Sample_DynMesh.cpp */,
|
|
||||||
6B2AEC510FFB8946005BE9CC /* Sample_TileMesh.h */,
|
6B2AEC510FFB8946005BE9CC /* Sample_TileMesh.h */,
|
||||||
6B2AEC520FFB8958005BE9CC /* Sample_TileMesh.cpp */,
|
6B2AEC520FFB8958005BE9CC /* Sample_TileMesh.cpp */,
|
||||||
);
|
);
|
||||||
@ -270,14 +253,6 @@
|
|||||||
6B8DE88810B69E3E00DF20FB /* DetourNavMeshBuilder.cpp */,
|
6B8DE88810B69E3E00DF20FB /* DetourNavMeshBuilder.cpp */,
|
||||||
6BDD9E040F91112200904EEF /* DetourDebugDraw.h */,
|
6BDD9E040F91112200904EEF /* DetourDebugDraw.h */,
|
||||||
6BDD9E070F91113800904EEF /* DetourDebugDraw.cpp */,
|
6BDD9E070F91113800904EEF /* DetourDebugDraw.cpp */,
|
||||||
6BDD9E050F91112200904EEF /* DetourStatNavMesh.h */,
|
|
||||||
6BDD9E080F91113800904EEF /* DetourStatNavMesh.cpp */,
|
|
||||||
6BDD9E060F91112200904EEF /* DetourStatNavMeshBuilder.h */,
|
|
||||||
6BDD9E090F91113800904EEF /* DetourStatNavMeshBuilder.cpp */,
|
|
||||||
6B2AEC580FFB8A68005BE9CC /* DetourTileNavMesh.h */,
|
|
||||||
6B2AEC590FFB8A7A005BE9CC /* DetourTileNavMesh.cpp */,
|
|
||||||
6B092B920FFCC2AC0088D3A5 /* DetourTileNavMeshBuilder.h */,
|
|
||||||
6B092B930FFCC2BD0088D3A5 /* DetourTileNavMeshBuilder.cpp */,
|
|
||||||
6B1185F61006896B0018F96F /* DetourNode.h */,
|
6B1185F61006896B0018F96F /* DetourNode.h */,
|
||||||
6B1185F41006895B0018F96F /* DetourNode.cpp */,
|
6B1185F41006895B0018F96F /* DetourNode.cpp */,
|
||||||
6B1185FC10068B040018F96F /* DetourCommon.h */,
|
6B1185FC10068B040018F96F /* DetourCommon.h */,
|
||||||
@ -355,21 +330,16 @@
|
|||||||
6B137C920F7FCC1100459200 /* RecastRegion.cpp in Sources */,
|
6B137C920F7FCC1100459200 /* RecastRegion.cpp in Sources */,
|
||||||
6B137C930F7FCC1100459200 /* RecastTimer.cpp in Sources */,
|
6B137C930F7FCC1100459200 /* RecastTimer.cpp in Sources */,
|
||||||
6BDD9E0A0F91113800904EEF /* DetourDebugDraw.cpp in Sources */,
|
6BDD9E0A0F91113800904EEF /* DetourDebugDraw.cpp in Sources */,
|
||||||
6BDD9E0B0F91113800904EEF /* DetourStatNavMesh.cpp in Sources */,
|
|
||||||
6BDD9E0C0F91113800904EEF /* DetourStatNavMeshBuilder.cpp in Sources */,
|
|
||||||
6BB788170FC0472B003C24DB /* ChunkyTriMesh.cpp in Sources */,
|
6BB788170FC0472B003C24DB /* ChunkyTriMesh.cpp in Sources */,
|
||||||
6B25B6190FFA62BE004F1BC4 /* Sample.cpp in Sources */,
|
6B25B6190FFA62BE004F1BC4 /* Sample.cpp in Sources */,
|
||||||
6B25B61D0FFA62BE004F1BC4 /* main.cpp in Sources */,
|
6B25B61D0FFA62BE004F1BC4 /* main.cpp in Sources */,
|
||||||
6B2AEC530FFB8958005BE9CC /* Sample_TileMesh.cpp in Sources */,
|
6B2AEC530FFB8958005BE9CC /* Sample_TileMesh.cpp in Sources */,
|
||||||
6B2AEC5A0FFB8A7A005BE9CC /* DetourTileNavMesh.cpp in Sources */,
|
|
||||||
6B092B940FFCC2BD0088D3A5 /* DetourTileNavMeshBuilder.cpp in Sources */,
|
|
||||||
6B1185F51006895B0018F96F /* DetourNode.cpp in Sources */,
|
6B1185F51006895B0018F96F /* DetourNode.cpp in Sources */,
|
||||||
6B1185FE10068B150018F96F /* DetourCommon.cpp in Sources */,
|
6B1185FE10068B150018F96F /* DetourCommon.cpp in Sources */,
|
||||||
6B555DB1100B212E00247EA3 /* imguiRenderGL.cpp in Sources */,
|
6B555DB1100B212E00247EA3 /* imguiRenderGL.cpp in Sources */,
|
||||||
6B62416A103434880002E346 /* RecastMeshDetail.cpp in Sources */,
|
6B62416A103434880002E346 /* RecastMeshDetail.cpp in Sources */,
|
||||||
6B8DE88910B69E3E00DF20FB /* DetourNavMesh.cpp in Sources */,
|
6B8DE88910B69E3E00DF20FB /* DetourNavMesh.cpp in Sources */,
|
||||||
6B8DE88A10B69E3E00DF20FB /* DetourNavMeshBuilder.cpp in Sources */,
|
6B8DE88A10B69E3E00DF20FB /* DetourNavMeshBuilder.cpp in Sources */,
|
||||||
6B8DE8F810B6B70E00DF20FB /* Sample_DynMesh.cpp in Sources */,
|
|
||||||
6BA1E88A10C7BFC9008007F6 /* Sample_SoloMesh.cpp in Sources */,
|
6BA1E88A10C7BFC9008007F6 /* Sample_SoloMesh.cpp in Sources */,
|
||||||
6BA1E88B10C7BFC9008007F6 /* Sample_SoloMeshSimple.cpp in Sources */,
|
6BA1E88B10C7BFC9008007F6 /* Sample_SoloMeshSimple.cpp in Sources */,
|
||||||
6BA1E88C10C7BFC9008007F6 /* Sample_SoloMeshTiled.cpp in Sources */,
|
6BA1E88C10C7BFC9008007F6 /* Sample_SoloMeshTiled.cpp in Sources */,
|
||||||
|
@ -1,114 +0,0 @@
|
|||||||
//
|
|
||||||
// Copyright (c) 2009 Mikko Mononen memon@inside.org
|
|
||||||
//
|
|
||||||
// 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.
|
|
||||||
//
|
|
||||||
|
|
||||||
#ifndef RECASTSAMPLEDYNMESH_H
|
|
||||||
#define RECASTSAMPLEDYNMESH_H
|
|
||||||
|
|
||||||
#include "Sample.h"
|
|
||||||
#include "DetourNavMesh.h"
|
|
||||||
#include "Recast.h"
|
|
||||||
#include "RecastLog.h"
|
|
||||||
#include "ChunkyTriMesh.h"
|
|
||||||
|
|
||||||
class Sample_DynMesh : public Sample
|
|
||||||
{
|
|
||||||
protected:
|
|
||||||
|
|
||||||
bool m_keepInterResults;
|
|
||||||
rcBuildTimes m_buildTimes;
|
|
||||||
|
|
||||||
dtNavMesh* m_navMesh;
|
|
||||||
rcChunkyTriMesh* m_chunkyMesh;
|
|
||||||
unsigned char* m_triflags;
|
|
||||||
rcHeightfield* m_solid;
|
|
||||||
rcCompactHeightfield* m_chf;
|
|
||||||
rcContourSet* m_cset;
|
|
||||||
rcPolyMesh* m_pmesh;
|
|
||||||
rcPolyMeshDetail* m_dmesh;
|
|
||||||
rcConfig m_cfg;
|
|
||||||
|
|
||||||
float m_tileSize;
|
|
||||||
|
|
||||||
float m_spos[3];
|
|
||||||
float m_epos[3];
|
|
||||||
bool m_sposSet;
|
|
||||||
bool m_eposSet;
|
|
||||||
|
|
||||||
float m_tileCol[4];
|
|
||||||
float m_tileBmin[3];
|
|
||||||
float m_tileBmax[3];
|
|
||||||
float m_tileBuildTime;
|
|
||||||
float m_tileMemUsage;
|
|
||||||
int m_tileTriCount;
|
|
||||||
|
|
||||||
enum ToolMode
|
|
||||||
{
|
|
||||||
TOOLMODE_CREATE_TILES,
|
|
||||||
TOOLMODE_PATHFIND,
|
|
||||||
TOOLMODE_RAYCAST,
|
|
||||||
TOOLMODE_DISTANCE_TO_WALL,
|
|
||||||
TOOLMODE_FIND_POLYS_AROUND,
|
|
||||||
};
|
|
||||||
|
|
||||||
dtPolyRef m_startRef;
|
|
||||||
dtPolyRef m_endRef;
|
|
||||||
float m_polyPickExt[3];
|
|
||||||
|
|
||||||
static const int MAX_POLYS = 256;
|
|
||||||
|
|
||||||
dtPolyRef m_polys[MAX_POLYS];
|
|
||||||
dtPolyRef m_parent[MAX_POLYS];
|
|
||||||
int m_npolys;
|
|
||||||
float m_straightPath[MAX_POLYS*3];
|
|
||||||
int m_nstraightPath;
|
|
||||||
float m_hitPos[3];
|
|
||||||
float m_hitNormal[3];
|
|
||||||
float m_distanceToWall;
|
|
||||||
|
|
||||||
ToolMode m_toolMode;
|
|
||||||
|
|
||||||
void toolRecalc();
|
|
||||||
|
|
||||||
void buildTile(const float* pos);
|
|
||||||
void removeTile(const float* pos);
|
|
||||||
|
|
||||||
unsigned char* buildTileMesh(const float* bmin, const float* bmax, int& dataSize);
|
|
||||||
|
|
||||||
void cleanup();
|
|
||||||
|
|
||||||
public:
|
|
||||||
Sample_DynMesh();
|
|
||||||
virtual ~Sample_DynMesh();
|
|
||||||
|
|
||||||
virtual void handleSettings();
|
|
||||||
virtual void handleTools();
|
|
||||||
virtual void handleDebugMode();
|
|
||||||
|
|
||||||
virtual void setToolStartPos(const float* p);
|
|
||||||
virtual void setToolEndPos(const float* p);
|
|
||||||
|
|
||||||
virtual void handleRender();
|
|
||||||
virtual void handleRenderOverlay(double* proj, double* model, int* view);
|
|
||||||
virtual void handleMeshChanged(const float* verts, int nverts,
|
|
||||||
const int* tris, const float* trinorms, int ntris,
|
|
||||||
const float* bmin, const float* bmax);
|
|
||||||
virtual bool handleBuild();
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
#endif // RECASTSAMPLEDYNMESH_H
|
|
@ -2,7 +2,7 @@
|
|||||||
#define RECASTSAMPLESOLOMESHSIMPLE_H
|
#define RECASTSAMPLESOLOMESHSIMPLE_H
|
||||||
|
|
||||||
#include "Sample_SoloMesh.h"
|
#include "Sample_SoloMesh.h"
|
||||||
#include "DetourStatNavMesh.h"
|
#include "DetourNavMesh.h"
|
||||||
#include "Recast.h"
|
#include "Recast.h"
|
||||||
#include "RecastLog.h"
|
#include "RecastLog.h"
|
||||||
|
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
#define RECASTSAMPLESOLOMESHTILED_H
|
#define RECASTSAMPLESOLOMESHTILED_H
|
||||||
|
|
||||||
#include "Sample_SoloMesh.h"
|
#include "Sample_SoloMesh.h"
|
||||||
#include "DetourStatNavMesh.h"
|
#include "DetourNavMesh.h"
|
||||||
#include "Recast.h"
|
#include "Recast.h"
|
||||||
#include "RecastLog.h"
|
#include "RecastLog.h"
|
||||||
#include "ChunkyTriMesh.h"
|
#include "ChunkyTriMesh.h"
|
||||||
|
@ -16,11 +16,11 @@
|
|||||||
// 3. This notice may not be removed or altered from any source distribution.
|
// 3. This notice may not be removed or altered from any source distribution.
|
||||||
//
|
//
|
||||||
|
|
||||||
#ifndef RECASTSAMPLETILEDMESH_H
|
#ifndef RECASTSAMPLETILEMESH_H
|
||||||
#define RECASTSAMPLETILEDMESH_H
|
#define RECASTSAMPLETILEMESH_H
|
||||||
|
|
||||||
#include "Sample.h"
|
#include "Sample.h"
|
||||||
#include "DetourTileNavMesh.h"
|
#include "DetourNavMesh.h"
|
||||||
#include "Recast.h"
|
#include "Recast.h"
|
||||||
#include "RecastLog.h"
|
#include "RecastLog.h"
|
||||||
#include "ChunkyTriMesh.h"
|
#include "ChunkyTriMesh.h"
|
||||||
@ -32,7 +32,7 @@ protected:
|
|||||||
bool m_keepInterResults;
|
bool m_keepInterResults;
|
||||||
rcBuildTimes m_buildTimes;
|
rcBuildTimes m_buildTimes;
|
||||||
|
|
||||||
dtTiledNavMesh* m_navMesh;
|
dtNavMesh* m_navMesh;
|
||||||
rcChunkyTriMesh* m_chunkyMesh;
|
rcChunkyTriMesh* m_chunkyMesh;
|
||||||
unsigned char* m_triflags;
|
unsigned char* m_triflags;
|
||||||
rcHeightfield* m_solid;
|
rcHeightfield* m_solid;
|
||||||
@ -42,6 +42,9 @@ protected:
|
|||||||
rcPolyMeshDetail* m_dmesh;
|
rcPolyMeshDetail* m_dmesh;
|
||||||
rcConfig m_cfg;
|
rcConfig m_cfg;
|
||||||
|
|
||||||
|
int m_maxTiles;
|
||||||
|
int m_maxPolysPerTile;
|
||||||
|
|
||||||
float m_tileSize;
|
float m_tileSize;
|
||||||
|
|
||||||
float m_spos[3];
|
float m_spos[3];
|
||||||
@ -65,14 +68,14 @@ protected:
|
|||||||
TOOLMODE_FIND_POLYS_AROUND,
|
TOOLMODE_FIND_POLYS_AROUND,
|
||||||
};
|
};
|
||||||
|
|
||||||
dtTilePolyRef m_startRef;
|
dtPolyRef m_startRef;
|
||||||
dtTilePolyRef m_endRef;
|
dtPolyRef m_endRef;
|
||||||
float m_polyPickExt[3];
|
float m_polyPickExt[3];
|
||||||
|
|
||||||
static const int MAX_POLYS = 256;
|
static const int MAX_POLYS = 256;
|
||||||
|
|
||||||
dtTilePolyRef m_polys[MAX_POLYS];
|
dtPolyRef m_polys[MAX_POLYS];
|
||||||
dtTilePolyRef m_parent[MAX_POLYS];
|
dtPolyRef m_parent[MAX_POLYS];
|
||||||
int m_npolys;
|
int m_npolys;
|
||||||
float m_straightPath[MAX_POLYS*3];
|
float m_straightPath[MAX_POLYS*3];
|
||||||
int m_nstraightPath;
|
int m_nstraightPath;
|
||||||
@ -111,4 +114,4 @@ public:
|
|||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
#endif // RECASTBUILDERTILEDMESH_H
|
#endif // RECASTSAMPLETILEMESH_H
|
||||||
|
@ -1,931 +0,0 @@
|
|||||||
//
|
|
||||||
// Copyright (c) 2009 Mikko Mononen memon@inside.org
|
|
||||||
//
|
|
||||||
// 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.
|
|
||||||
//
|
|
||||||
|
|
||||||
#define _USE_MATH_DEFINES
|
|
||||||
#include <math.h>
|
|
||||||
#include <stdio.h>
|
|
||||||
#include <string.h>
|
|
||||||
#include "SDL.h"
|
|
||||||
#include "SDL_opengl.h"
|
|
||||||
#include "imgui.h"
|
|
||||||
#include "Sample.h"
|
|
||||||
#include "Sample_DynMesh.h"
|
|
||||||
#include "Recast.h"
|
|
||||||
#include "RecastTimer.h"
|
|
||||||
#include "RecastDebugDraw.h"
|
|
||||||
#include "DetourNavMesh.h"
|
|
||||||
#include "DetourNavMeshBuilder.h"
|
|
||||||
#include "DetourDebugDraw.h"
|
|
||||||
|
|
||||||
#ifdef WIN32
|
|
||||||
# define snprintf _snprintf
|
|
||||||
#endif
|
|
||||||
|
|
||||||
|
|
||||||
Sample_DynMesh::Sample_DynMesh() :
|
|
||||||
m_keepInterResults(false),
|
|
||||||
m_navMesh(0),
|
|
||||||
m_chunkyMesh(0),
|
|
||||||
m_triflags(0),
|
|
||||||
m_solid(0),
|
|
||||||
m_chf(0),
|
|
||||||
m_cset(0),
|
|
||||||
m_pmesh(0),
|
|
||||||
m_dmesh(0),
|
|
||||||
m_tileSize(32),
|
|
||||||
m_sposSet(false),
|
|
||||||
m_eposSet(false),
|
|
||||||
m_tileBuildTime(0),
|
|
||||||
m_tileMemUsage(0),
|
|
||||||
m_tileTriCount(0),
|
|
||||||
m_startRef(0),
|
|
||||||
m_endRef(0),
|
|
||||||
m_npolys(0),
|
|
||||||
m_nstraightPath(0),
|
|
||||||
m_distanceToWall(0),
|
|
||||||
m_toolMode(TOOLMODE_CREATE_TILES)
|
|
||||||
{
|
|
||||||
resetCommonSettings();
|
|
||||||
memset(m_tileBmin, 0, sizeof(m_tileBmin));
|
|
||||||
memset(m_tileBmax, 0, sizeof(m_tileBmax));
|
|
||||||
m_polyPickExt[0] = 2;
|
|
||||||
m_polyPickExt[1] = 4;
|
|
||||||
m_polyPickExt[2] = 2;
|
|
||||||
}
|
|
||||||
|
|
||||||
Sample_DynMesh::~Sample_DynMesh()
|
|
||||||
{
|
|
||||||
cleanup();
|
|
||||||
delete m_navMesh;
|
|
||||||
delete m_chunkyMesh;
|
|
||||||
}
|
|
||||||
|
|
||||||
void Sample_DynMesh::cleanup()
|
|
||||||
{
|
|
||||||
delete [] m_triflags;
|
|
||||||
m_triflags = 0;
|
|
||||||
delete m_solid;
|
|
||||||
m_solid = 0;
|
|
||||||
delete m_chf;
|
|
||||||
m_chf = 0;
|
|
||||||
delete m_cset;
|
|
||||||
m_cset = 0;
|
|
||||||
delete m_pmesh;
|
|
||||||
m_pmesh = 0;
|
|
||||||
delete m_dmesh;
|
|
||||||
m_dmesh = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
void Sample_DynMesh::handleSettings()
|
|
||||||
{
|
|
||||||
Sample::handleCommonSettings();
|
|
||||||
|
|
||||||
imguiLabel("Tiling");
|
|
||||||
imguiSlider("TileSize", &m_tileSize, 16.0f, 1024.0f, 16.0f);
|
|
||||||
|
|
||||||
char text[64];
|
|
||||||
int gw = 0, gh = 0;
|
|
||||||
rcCalcGridSize(m_bmin, m_bmax, m_cellSize, &gw, &gh);
|
|
||||||
const int ts = (int)m_tileSize;
|
|
||||||
const int tw = (gw + ts-1) / ts;
|
|
||||||
const int th = (gh + ts-1) / ts;
|
|
||||||
snprintf(text, 64, "Tiles %d x %d", tw, th);
|
|
||||||
imguiValue(text);
|
|
||||||
}
|
|
||||||
|
|
||||||
void Sample_DynMesh::toolRecalc()
|
|
||||||
{
|
|
||||||
m_startRef = 0;
|
|
||||||
if (m_sposSet)
|
|
||||||
m_startRef = m_navMesh->findNearestPoly(m_spos, m_polyPickExt);
|
|
||||||
|
|
||||||
m_endRef = 0;
|
|
||||||
if (m_eposSet)
|
|
||||||
m_endRef = m_navMesh->findNearestPoly(m_epos, m_polyPickExt);
|
|
||||||
|
|
||||||
if (m_toolMode == TOOLMODE_PATHFIND)
|
|
||||||
{
|
|
||||||
if (m_sposSet && m_eposSet && m_startRef && m_endRef)
|
|
||||||
{
|
|
||||||
m_npolys = m_navMesh->findPath(m_startRef, m_endRef, m_spos, m_epos, m_polys, MAX_POLYS);
|
|
||||||
if (m_npolys)
|
|
||||||
m_nstraightPath = m_navMesh->findStraightPath(m_spos, m_epos, m_polys, m_npolys, m_straightPath, MAX_POLYS);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
m_npolys = 0;
|
|
||||||
m_nstraightPath = 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else if (m_toolMode == TOOLMODE_RAYCAST)
|
|
||||||
{
|
|
||||||
m_nstraightPath = 0;
|
|
||||||
if (m_sposSet && m_eposSet && m_startRef)
|
|
||||||
{
|
|
||||||
float t = 0;
|
|
||||||
m_npolys = 0;
|
|
||||||
m_nstraightPath = 2;
|
|
||||||
m_straightPath[0] = m_spos[0];
|
|
||||||
m_straightPath[1] = m_spos[1];
|
|
||||||
m_straightPath[2] = m_spos[2];
|
|
||||||
m_npolys = m_navMesh->raycast(m_startRef, m_spos, m_epos, t, m_polys, MAX_POLYS);
|
|
||||||
if (m_npolys && t < 1)
|
|
||||||
{
|
|
||||||
m_straightPath[3] = m_spos[0] + (m_epos[0] - m_spos[0]) * t;
|
|
||||||
m_straightPath[4] = m_spos[1] + (m_epos[1] - m_spos[1]) * t;
|
|
||||||
m_straightPath[5] = m_spos[2] + (m_epos[2] - m_spos[2]) * t;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
m_straightPath[3] = m_epos[0];
|
|
||||||
m_straightPath[4] = m_epos[1];
|
|
||||||
m_straightPath[5] = m_epos[2];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else if (m_toolMode == TOOLMODE_DISTANCE_TO_WALL)
|
|
||||||
{
|
|
||||||
m_distanceToWall = 0;
|
|
||||||
if (m_sposSet && m_startRef)
|
|
||||||
m_distanceToWall = m_navMesh->findDistanceToWall(m_startRef, m_spos, 100.0f, m_hitPos, m_hitNormal);
|
|
||||||
}
|
|
||||||
else if (m_toolMode == TOOLMODE_FIND_POLYS_AROUND)
|
|
||||||
{
|
|
||||||
if (m_sposSet && m_startRef && m_eposSet)
|
|
||||||
{
|
|
||||||
const float dx = m_epos[0] - m_spos[0];
|
|
||||||
const float dz = m_epos[2] - m_spos[2];
|
|
||||||
float dist = sqrtf(dx*dx + dz*dz);
|
|
||||||
m_npolys = m_navMesh->findPolysAround(m_startRef, m_spos, dist, m_polys, m_parent, 0, MAX_POLYS);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
void Sample_DynMesh::handleTools()
|
|
||||||
{
|
|
||||||
if (imguiCheck("Create Tiles", m_toolMode == TOOLMODE_CREATE_TILES))
|
|
||||||
{
|
|
||||||
m_toolMode = TOOLMODE_CREATE_TILES;
|
|
||||||
toolRecalc();
|
|
||||||
}
|
|
||||||
if (imguiCheck("Pathfind", m_toolMode == TOOLMODE_PATHFIND))
|
|
||||||
{
|
|
||||||
m_toolMode = TOOLMODE_PATHFIND;
|
|
||||||
toolRecalc();
|
|
||||||
}
|
|
||||||
if (imguiCheck("Distance to Wall", m_toolMode == TOOLMODE_DISTANCE_TO_WALL))
|
|
||||||
{
|
|
||||||
m_toolMode = TOOLMODE_DISTANCE_TO_WALL;
|
|
||||||
toolRecalc();
|
|
||||||
}
|
|
||||||
if (imguiCheck("Raycast", m_toolMode == TOOLMODE_RAYCAST))
|
|
||||||
{
|
|
||||||
m_toolMode = TOOLMODE_RAYCAST;
|
|
||||||
toolRecalc();
|
|
||||||
}
|
|
||||||
if (imguiCheck("Find Polys Around", m_toolMode == TOOLMODE_FIND_POLYS_AROUND))
|
|
||||||
{
|
|
||||||
m_toolMode = TOOLMODE_FIND_POLYS_AROUND;
|
|
||||||
toolRecalc();
|
|
||||||
}
|
|
||||||
if (imguiButton("Create All"))
|
|
||||||
{
|
|
||||||
int gw = 0, gh = 0;
|
|
||||||
rcCalcGridSize(m_bmin, m_bmax, m_cellSize, &gw, &gh);
|
|
||||||
const int ts = (int)m_tileSize;
|
|
||||||
const int tw = (gw + ts-1) / ts;
|
|
||||||
const int th = (gh + ts-1) / ts;
|
|
||||||
const float tcs = m_tileSize*m_cellSize;
|
|
||||||
|
|
||||||
for (int y = 0; y < th; ++y)
|
|
||||||
{
|
|
||||||
for (int x = 0; x < tw; ++x)
|
|
||||||
{
|
|
||||||
m_tileBmin[0] = m_bmin[0] + x*tcs;
|
|
||||||
m_tileBmin[1] = m_bmin[1];
|
|
||||||
m_tileBmin[2] = m_bmin[2] + y*tcs;
|
|
||||||
|
|
||||||
m_tileBmax[0] = m_bmin[0] + (x+1)*tcs;
|
|
||||||
m_tileBmax[1] = m_bmax[1];
|
|
||||||
m_tileBmax[2] = m_bmin[2] + (y+1)*tcs;
|
|
||||||
|
|
||||||
int dataSize = 0;
|
|
||||||
unsigned char* data = buildTileMesh(m_tileBmin, m_tileBmax, dataSize);
|
|
||||||
if (data)
|
|
||||||
{
|
|
||||||
// Remove any previous data (navmesh owns and deletes the data).
|
|
||||||
m_navMesh->removeTileAt(x,y,0,0);
|
|
||||||
// Let the navmesh own the data.
|
|
||||||
if (!m_navMesh->addTileAt(x,y,data,dataSize,true))
|
|
||||||
delete [] data;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
toolRecalc();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void Sample_DynMesh::handleDebugMode()
|
|
||||||
{
|
|
||||||
if (m_navMesh)
|
|
||||||
{
|
|
||||||
imguiValue("Navmesh ready.");
|
|
||||||
imguiValue("Use 'Create Tiles' tool to experiment.");
|
|
||||||
imguiValue("LMB: (Re)Create tiles.");
|
|
||||||
imguiValue("LMB+SHIFT: Remove tiles.");
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
static void getPolyCenter(dtNavMesh* navMesh, dtPolyRef ref, float* center)
|
|
||||||
{
|
|
||||||
const dtPoly* p = navMesh->getPolyByRef(ref);
|
|
||||||
if (!p) return;
|
|
||||||
const float* verts = navMesh->getPolyVertsByRef(ref);
|
|
||||||
center[0] = 0;
|
|
||||||
center[1] = 0;
|
|
||||||
center[2] = 0;
|
|
||||||
for (int i = 0; i < (int)p->nv; ++i)
|
|
||||||
{
|
|
||||||
const float* v = &verts[p->v[i]*3];
|
|
||||||
center[0] += v[0];
|
|
||||||
center[1] += v[1];
|
|
||||||
center[2] += v[2];
|
|
||||||
}
|
|
||||||
const float s = 1.0f / p->nv;
|
|
||||||
center[0] *= s;
|
|
||||||
center[1] *= s;
|
|
||||||
center[2] *= s;
|
|
||||||
}
|
|
||||||
|
|
||||||
void Sample_DynMesh::handleRender()
|
|
||||||
{
|
|
||||||
if (!m_verts || !m_tris || !m_trinorms)
|
|
||||||
return;
|
|
||||||
|
|
||||||
DebugDrawGL dd;
|
|
||||||
|
|
||||||
// Draw mesh
|
|
||||||
if (m_navMesh)
|
|
||||||
rcDebugDrawMesh(&dd, m_verts, m_nverts, m_tris, m_trinorms, m_ntris, 0);
|
|
||||||
else
|
|
||||||
rcDebugDrawMeshSlope(&dd, m_verts, m_nverts, m_tris, m_trinorms, m_ntris, m_agentMaxSlope);
|
|
||||||
|
|
||||||
glDepthMask(GL_FALSE);
|
|
||||||
|
|
||||||
// Draw bounds
|
|
||||||
float col[4] = {1,1,1,0.5f};
|
|
||||||
rcDebugDrawBoxWire(&dd, m_bmin[0],m_bmin[1],m_bmin[2], m_bmax[0],m_bmax[1],m_bmax[2], col);
|
|
||||||
|
|
||||||
// Tiling grid.
|
|
||||||
const int ts = (int)m_tileSize;
|
|
||||||
int gw = 0, gh = 0;
|
|
||||||
rcCalcGridSize(m_bmin, m_bmax, m_cellSize, &gw, &gh);
|
|
||||||
int tw = (gw + ts-1) / ts;
|
|
||||||
int th = (gh + ts-1) / ts;
|
|
||||||
const float s = ts*m_cellSize;
|
|
||||||
glBegin(GL_LINES);
|
|
||||||
glColor4ub(0,0,0,64);
|
|
||||||
for (int y = 0; y < th; ++y)
|
|
||||||
{
|
|
||||||
for (int x = 0; x < tw; ++x)
|
|
||||||
{
|
|
||||||
float fx, fy, fz;
|
|
||||||
fx = m_bmin[0] + x*s;
|
|
||||||
fy = m_bmin[1];
|
|
||||||
fz = m_bmin[2] + y*s;
|
|
||||||
|
|
||||||
glVertex3f(fx,fy,fz);
|
|
||||||
glVertex3f(fx+s,fy,fz);
|
|
||||||
glVertex3f(fx,fy,fz);
|
|
||||||
glVertex3f(fx,fy,fz+s);
|
|
||||||
|
|
||||||
if (x+1 >= tw)
|
|
||||||
{
|
|
||||||
glVertex3f(fx+s,fy,fz);
|
|
||||||
glVertex3f(fx+s,fy,fz+s);
|
|
||||||
}
|
|
||||||
if (y+1 >= th)
|
|
||||||
{
|
|
||||||
glVertex3f(fx,fy,fz+s);
|
|
||||||
glVertex3f(fx+s,fy,fz+s);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
glEnd();
|
|
||||||
|
|
||||||
// Draw active tile
|
|
||||||
rcDebugDrawBoxWire(&dd, m_tileBmin[0],m_tileBmin[1],m_tileBmin[2], m_tileBmax[0],m_tileBmax[1],m_tileBmax[2], m_tileCol);
|
|
||||||
|
|
||||||
if (m_navMesh)
|
|
||||||
dtDebugDrawNavMesh(m_navMesh);
|
|
||||||
|
|
||||||
if (m_sposSet)
|
|
||||||
{
|
|
||||||
const float s = 0.5f;
|
|
||||||
glColor4ub(64,16,0,255);
|
|
||||||
glLineWidth(3.0f);
|
|
||||||
glBegin(GL_LINES);
|
|
||||||
glVertex3f(m_spos[0]-s,m_spos[1]+m_cellHeight,m_spos[2]);
|
|
||||||
glVertex3f(m_spos[0]+s,m_spos[1]+m_cellHeight,m_spos[2]);
|
|
||||||
glVertex3f(m_spos[0],m_spos[1]-s+m_cellHeight,m_spos[2]);
|
|
||||||
glVertex3f(m_spos[0],m_spos[1]+s+m_cellHeight,m_spos[2]);
|
|
||||||
glVertex3f(m_spos[0],m_spos[1]+m_cellHeight,m_spos[2]-s);
|
|
||||||
glVertex3f(m_spos[0],m_spos[1]+m_cellHeight,m_spos[2]+s);
|
|
||||||
glEnd();
|
|
||||||
glLineWidth(1.0f);
|
|
||||||
}
|
|
||||||
if (m_eposSet)
|
|
||||||
{
|
|
||||||
const float s = 0.5f;
|
|
||||||
glColor4ub(16,64,0,255);
|
|
||||||
glLineWidth(3.0f);
|
|
||||||
glBegin(GL_LINES);
|
|
||||||
glVertex3f(m_epos[0]-s,m_epos[1]+m_cellHeight,m_epos[2]);
|
|
||||||
glVertex3f(m_epos[0]+s,m_epos[1]+m_cellHeight,m_epos[2]);
|
|
||||||
glVertex3f(m_epos[0],m_epos[1]-s+m_cellHeight,m_epos[2]);
|
|
||||||
glVertex3f(m_epos[0],m_epos[1]+s+m_cellHeight,m_epos[2]);
|
|
||||||
glVertex3f(m_epos[0],m_epos[1]+m_cellHeight,m_epos[2]-s);
|
|
||||||
glVertex3f(m_epos[0],m_epos[1]+m_cellHeight,m_epos[2]+s);
|
|
||||||
glEnd();
|
|
||||||
glLineWidth(1.0f);
|
|
||||||
}
|
|
||||||
|
|
||||||
static const float startCol[4] = { 0.5f, 0.1f, 0.0f, 0.75f };
|
|
||||||
static const float endCol[4] = { 0.2f, 0.4f, 0.0f, 0.75f };
|
|
||||||
static const float pathCol[4] = {0,0,0,0.25f};
|
|
||||||
|
|
||||||
if (m_toolMode == TOOLMODE_PATHFIND)
|
|
||||||
{
|
|
||||||
dtDebugDrawNavMeshPoly(m_navMesh, m_startRef, startCol);
|
|
||||||
dtDebugDrawNavMeshPoly(m_navMesh, m_endRef, endCol);
|
|
||||||
|
|
||||||
if (m_npolys)
|
|
||||||
{
|
|
||||||
for (int i = 1; i < m_npolys-1; ++i)
|
|
||||||
dtDebugDrawNavMeshPoly(m_navMesh, m_polys[i], pathCol);
|
|
||||||
}
|
|
||||||
if (m_nstraightPath)
|
|
||||||
{
|
|
||||||
glColor4ub(64,16,0,220);
|
|
||||||
glLineWidth(3.0f);
|
|
||||||
glBegin(GL_LINE_STRIP);
|
|
||||||
for (int i = 0; i < m_nstraightPath; ++i)
|
|
||||||
glVertex3f(m_straightPath[i*3], m_straightPath[i*3+1]+0.4f, m_straightPath[i*3+2]);
|
|
||||||
glEnd();
|
|
||||||
glLineWidth(1.0f);
|
|
||||||
glPointSize(4.0f);
|
|
||||||
glBegin(GL_POINTS);
|
|
||||||
for (int i = 0; i < m_nstraightPath; ++i)
|
|
||||||
glVertex3f(m_straightPath[i*3], m_straightPath[i*3+1]+0.4f, m_straightPath[i*3+2]);
|
|
||||||
glEnd();
|
|
||||||
glPointSize(1.0f);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else if (m_toolMode == TOOLMODE_RAYCAST)
|
|
||||||
{
|
|
||||||
dtDebugDrawNavMeshPoly(m_navMesh, m_startRef, startCol);
|
|
||||||
|
|
||||||
if (m_nstraightPath)
|
|
||||||
{
|
|
||||||
for (int i = 1; i < m_npolys; ++i)
|
|
||||||
dtDebugDrawNavMeshPoly(m_navMesh, m_polys[i], pathCol);
|
|
||||||
|
|
||||||
glColor4ub(64,16,0,220);
|
|
||||||
glLineWidth(3.0f);
|
|
||||||
glBegin(GL_LINE_STRIP);
|
|
||||||
for (int i = 0; i < m_nstraightPath; ++i)
|
|
||||||
glVertex3f(m_straightPath[i*3], m_straightPath[i*3+1]+0.4f, m_straightPath[i*3+2]);
|
|
||||||
glEnd();
|
|
||||||
glLineWidth(1.0f);
|
|
||||||
glPointSize(4.0f);
|
|
||||||
glBegin(GL_POINTS);
|
|
||||||
for (int i = 0; i < m_nstraightPath; ++i)
|
|
||||||
glVertex3f(m_straightPath[i*3], m_straightPath[i*3+1]+0.4f, m_straightPath[i*3+2]);
|
|
||||||
glEnd();
|
|
||||||
glPointSize(1.0f);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else if (m_toolMode == TOOLMODE_DISTANCE_TO_WALL)
|
|
||||||
{
|
|
||||||
dtDebugDrawNavMeshPoly(m_navMesh, m_startRef, startCol);
|
|
||||||
const float col[4] = {1,1,1,0.5f};
|
|
||||||
rcDebugDrawCylinderWire(&dd, m_spos[0]-m_distanceToWall, m_spos[1]+0.02f, m_spos[2]-m_distanceToWall,
|
|
||||||
m_spos[0]+m_distanceToWall, m_spos[1]+m_agentHeight, m_spos[2]+m_distanceToWall, col);
|
|
||||||
glLineWidth(3.0f);
|
|
||||||
glColor4fv(col);
|
|
||||||
glBegin(GL_LINES);
|
|
||||||
glVertex3f(m_hitPos[0], m_hitPos[1] + 0.02f, m_hitPos[2]);
|
|
||||||
glVertex3f(m_hitPos[0], m_hitPos[1] + m_agentHeight, m_hitPos[2]);
|
|
||||||
glEnd();
|
|
||||||
glLineWidth(1.0f);
|
|
||||||
}
|
|
||||||
else if (m_toolMode == TOOLMODE_FIND_POLYS_AROUND)
|
|
||||||
{
|
|
||||||
const float cola[4] = {0,0,0,0.5f};
|
|
||||||
for (int i = 0; i < m_npolys; ++i)
|
|
||||||
{
|
|
||||||
dtDebugDrawNavMeshPoly(m_navMesh, m_polys[i], pathCol);
|
|
||||||
if (m_parent[i])
|
|
||||||
{
|
|
||||||
float p0[3], p1[3];
|
|
||||||
getPolyCenter(m_navMesh, m_polys[i], p0);
|
|
||||||
getPolyCenter(m_navMesh, m_parent[i], p1);
|
|
||||||
glColor4ub(0,0,0,128);
|
|
||||||
rcDrawArc(&dd, p0, p1, cola, 2.0f);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const float dx = m_epos[0] - m_spos[0];
|
|
||||||
const float dz = m_epos[2] - m_spos[2];
|
|
||||||
float dist = sqrtf(dx*dx + dz*dz);
|
|
||||||
const float col[4] = {1,1,1,0.5f};
|
|
||||||
rcDebugDrawCylinderWire(&dd, m_spos[0]-dist, m_spos[1]+0.02f, m_spos[2]-dist,
|
|
||||||
m_spos[0]+dist, m_spos[1]+m_agentHeight, m_spos[2]+dist, col);
|
|
||||||
}
|
|
||||||
|
|
||||||
glDepthMask(GL_TRUE);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
void Sample_DynMesh::handleRenderOverlay(double* proj, double* model, int* view)
|
|
||||||
{
|
|
||||||
GLdouble x, y, z;
|
|
||||||
|
|
||||||
// Draw start and end point labels
|
|
||||||
if (m_tileBuildTime > 0.0f && gluProject((GLdouble)(m_tileBmin[0]+m_tileBmax[0])/2, (GLdouble)(m_tileBmin[1]+m_tileBmax[1])/2, (GLdouble)(m_tileBmin[2]+m_tileBmax[2])/2,
|
|
||||||
model, proj, view, &x, &y, &z))
|
|
||||||
{
|
|
||||||
char text[32];
|
|
||||||
snprintf(text,32,"%.3fms / %dTris / %.1fkB", m_tileBuildTime, m_tileTriCount, m_tileMemUsage);
|
|
||||||
imguiDrawText((int)x, (int)y-25, IMGUI_ALIGN_CENTER, text, imguiRGBA(0,0,0,220));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void Sample_DynMesh::handleMeshChanged(const float* verts, int nverts,
|
|
||||||
const int* tris, const float* trinorms, int ntris,
|
|
||||||
const float* bmin, const float* bmax)
|
|
||||||
{
|
|
||||||
m_verts = verts;
|
|
||||||
m_nverts = nverts;
|
|
||||||
m_tris = tris;
|
|
||||||
m_trinorms = trinorms;
|
|
||||||
m_ntris = ntris;
|
|
||||||
vcopy(m_bmin, bmin);
|
|
||||||
vcopy(m_bmax, bmax);
|
|
||||||
|
|
||||||
delete m_chunkyMesh;
|
|
||||||
m_chunkyMesh = 0;
|
|
||||||
delete m_navMesh;
|
|
||||||
m_navMesh = 0;
|
|
||||||
cleanup();
|
|
||||||
}
|
|
||||||
|
|
||||||
void Sample_DynMesh::setToolStartPos(const float* p)
|
|
||||||
{
|
|
||||||
m_sposSet = true;
|
|
||||||
vcopy(m_spos, p);
|
|
||||||
|
|
||||||
if (m_toolMode == TOOLMODE_CREATE_TILES)
|
|
||||||
removeTile(m_spos);
|
|
||||||
else
|
|
||||||
toolRecalc();
|
|
||||||
}
|
|
||||||
|
|
||||||
void Sample_DynMesh::setToolEndPos(const float* p)
|
|
||||||
{
|
|
||||||
if (!m_navMesh)
|
|
||||||
return;
|
|
||||||
|
|
||||||
m_eposSet = true;
|
|
||||||
vcopy(m_epos, p);
|
|
||||||
|
|
||||||
if (m_toolMode == TOOLMODE_CREATE_TILES)
|
|
||||||
buildTile(m_epos);
|
|
||||||
else
|
|
||||||
toolRecalc();
|
|
||||||
}
|
|
||||||
|
|
||||||
bool Sample_DynMesh::handleBuild()
|
|
||||||
{
|
|
||||||
if (!m_verts || !m_tris)
|
|
||||||
{
|
|
||||||
printf("No verts or tris\n");
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
delete m_navMesh;
|
|
||||||
m_navMesh = new dtNavMesh;
|
|
||||||
if (!m_navMesh)
|
|
||||||
{
|
|
||||||
printf("Could not allocate navmehs\n");
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
if (!m_navMesh->init(m_bmin, m_tileSize*m_cellSize, m_tileSize*m_cellSize, m_agentMaxClimb*m_cellHeight, 512, 512, 2048))
|
|
||||||
{
|
|
||||||
printf("Could not init navmesh\n");
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Build chunky mesh.
|
|
||||||
delete m_chunkyMesh;
|
|
||||||
m_chunkyMesh = new rcChunkyTriMesh;
|
|
||||||
if (!m_chunkyMesh)
|
|
||||||
{
|
|
||||||
if (rcGetLog())
|
|
||||||
rcGetLog()->log(RC_LOG_ERROR, "buildTiledNavigation: Out of memory 'm_chunkyMesh'.");
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
if (!rcCreateChunkyTriMesh(m_verts, m_tris, m_ntris, 256, m_chunkyMesh))
|
|
||||||
{
|
|
||||||
if (rcGetLog())
|
|
||||||
rcGetLog()->log(RC_LOG_ERROR, "buildTiledNavigation: Could not build chunky mesh.");
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
void Sample_DynMesh::buildTile(const float* pos)
|
|
||||||
{
|
|
||||||
if (!m_navMesh)
|
|
||||||
return;
|
|
||||||
|
|
||||||
const float ts = m_tileSize*m_cellSize;
|
|
||||||
const int tx = (int)floorf((pos[0]-m_bmin[0]) / ts);
|
|
||||||
const int ty = (int)floorf((pos[2]-m_bmin[2]) / ts);
|
|
||||||
if (tx < 0 || ty < 0)
|
|
||||||
return;
|
|
||||||
|
|
||||||
m_tileBmin[0] = m_bmin[0] + tx*ts;
|
|
||||||
m_tileBmin[1] = m_bmin[1];
|
|
||||||
m_tileBmin[2] = m_bmin[2] + ty*ts;
|
|
||||||
|
|
||||||
m_tileBmax[0] = m_bmin[0] + (tx+1)*ts;
|
|
||||||
m_tileBmax[1] = m_bmax[1];
|
|
||||||
m_tileBmax[2] = m_bmin[2] + (ty+1)*ts;
|
|
||||||
|
|
||||||
m_tileCol[0] = 0.3f; m_tileCol[1] = 0.8f; m_tileCol[2] = 0; m_tileCol[3] = 1;
|
|
||||||
|
|
||||||
int dataSize = 0;
|
|
||||||
unsigned char* data = buildTileMesh(m_tileBmin, m_tileBmax, dataSize);
|
|
||||||
|
|
||||||
if (data)
|
|
||||||
{
|
|
||||||
// Remove any previous data (navmesh owns and deletes the data).
|
|
||||||
m_navMesh->removeTileAt(tx,ty,0,0);
|
|
||||||
|
|
||||||
// Let the navmesh own the data.
|
|
||||||
if (!m_navMesh->addTileAt(tx,ty,data,dataSize,true))
|
|
||||||
delete [] data;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void Sample_DynMesh::removeTile(const float* pos)
|
|
||||||
{
|
|
||||||
if (!m_navMesh)
|
|
||||||
return;
|
|
||||||
|
|
||||||
const float ts = m_tileSize*m_cellSize;
|
|
||||||
const int tx = (int)floorf((pos[0]-m_bmin[0]) / ts);
|
|
||||||
const int ty = (int)floorf((pos[2]-m_bmin[2]) / ts);
|
|
||||||
|
|
||||||
m_tileBmin[0] = m_bmin[0] + tx*ts;
|
|
||||||
m_tileBmin[1] = m_bmin[1];
|
|
||||||
m_tileBmin[2] = m_bmin[2] + ty*ts;
|
|
||||||
|
|
||||||
m_tileBmax[0] = m_bmin[0] + (tx+1)*ts;
|
|
||||||
m_tileBmax[1] = m_bmax[1];
|
|
||||||
m_tileBmax[2] = m_bmin[2] + (ty+1)*ts;
|
|
||||||
|
|
||||||
m_tileCol[0] = 0.8f; m_tileCol[1] = 0.1f; m_tileCol[2] = 0; m_tileCol[3] = 1;
|
|
||||||
|
|
||||||
unsigned char* rdata = 0;
|
|
||||||
int rdataSize = 0;
|
|
||||||
if (m_navMesh->removeTileAt(tx,ty,&rdata,&rdataSize))
|
|
||||||
delete [] rdata;
|
|
||||||
}
|
|
||||||
|
|
||||||
unsigned char* Sample_DynMesh::buildTileMesh(const float* bmin, const float* bmax, int& dataSize)
|
|
||||||
{
|
|
||||||
if (!m_verts || ! m_tris)
|
|
||||||
{
|
|
||||||
if (rcGetLog())
|
|
||||||
rcGetLog()->log(RC_LOG_ERROR, "buildNavigation: Input mesh is not specified.");
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
cleanup();
|
|
||||||
|
|
||||||
// Init build configuration from GUI
|
|
||||||
memset(&m_cfg, 0, sizeof(m_cfg));
|
|
||||||
m_cfg.cs = m_cellSize;
|
|
||||||
m_cfg.ch = m_cellHeight;
|
|
||||||
m_cfg.walkableSlopeAngle = m_agentMaxSlope;
|
|
||||||
m_cfg.walkableHeight = (int)ceilf(m_agentHeight / m_cfg.ch);
|
|
||||||
m_cfg.walkableClimb = (int)ceilf(m_agentMaxClimb / m_cfg.ch);
|
|
||||||
m_cfg.walkableRadius = (int)ceilf(m_agentRadius / m_cfg.cs);
|
|
||||||
m_cfg.maxEdgeLen = (int)(m_edgeMaxLen / m_cellSize);
|
|
||||||
m_cfg.maxSimplificationError = m_edgeMaxError;
|
|
||||||
m_cfg.minRegionSize = (int)rcSqr(m_regionMinSize);
|
|
||||||
m_cfg.mergeRegionSize = (int)rcSqr(m_regionMergeSize);
|
|
||||||
m_cfg.maxVertsPerPoly = (int)m_vertsPerPoly;
|
|
||||||
m_cfg.tileSize = (int)m_tileSize;
|
|
||||||
m_cfg.borderSize = m_cfg.walkableRadius + 3; // Reserve enough padding.
|
|
||||||
m_cfg.width = m_cfg.tileSize + m_cfg.borderSize*2;
|
|
||||||
m_cfg.height = m_cfg.tileSize + m_cfg.borderSize*2;
|
|
||||||
m_cfg.detailSampleDist = m_detailSampleDist < 0.9f ? 0 : m_cellSize * m_detailSampleDist;
|
|
||||||
m_cfg.detailSampleMaxError = m_cellHeight * m_detailSampleMaxError;
|
|
||||||
|
|
||||||
vcopy(m_cfg.bmin, bmin);
|
|
||||||
vcopy(m_cfg.bmax, bmax);
|
|
||||||
m_cfg.bmin[0] -= m_cfg.borderSize*m_cfg.cs;
|
|
||||||
m_cfg.bmin[2] -= m_cfg.borderSize*m_cfg.cs;
|
|
||||||
m_cfg.bmax[0] += m_cfg.borderSize*m_cfg.cs;
|
|
||||||
m_cfg.bmax[2] += m_cfg.borderSize*m_cfg.cs;
|
|
||||||
|
|
||||||
// Reset build times gathering.
|
|
||||||
memset(&m_buildTimes, 0, sizeof(m_buildTimes));
|
|
||||||
rcSetBuildTimes(&m_buildTimes);
|
|
||||||
|
|
||||||
// Start the build process.
|
|
||||||
rcTimeVal totStartTime = rcGetPerformanceTimer();
|
|
||||||
|
|
||||||
if (rcGetLog())
|
|
||||||
{
|
|
||||||
rcGetLog()->log(RC_LOG_PROGRESS, "Building navigation:");
|
|
||||||
rcGetLog()->log(RC_LOG_PROGRESS, " - %d x %d cells", m_cfg.width, m_cfg.height);
|
|
||||||
rcGetLog()->log(RC_LOG_PROGRESS, " - %.1fK verts, %.1fK tris", m_nverts/1000.0f, m_ntris/1000.0f);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Allocate voxel heighfield where we rasterize our input data to.
|
|
||||||
m_solid = new rcHeightfield;
|
|
||||||
if (!m_solid)
|
|
||||||
{
|
|
||||||
if (rcGetLog())
|
|
||||||
rcGetLog()->log(RC_LOG_ERROR, "buildNavigation: Out of memory 'solid'.");
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
if (!rcCreateHeightfield(*m_solid, m_cfg.width, m_cfg.height, m_cfg.bmin, m_cfg.bmax, m_cfg.cs, m_cfg.ch))
|
|
||||||
{
|
|
||||||
if (rcGetLog())
|
|
||||||
rcGetLog()->log(RC_LOG_ERROR, "buildNavigation: Could not create solid heightfield.");
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Allocate array that can hold triangle flags.
|
|
||||||
// If you have multiple meshes you need to process, allocate
|
|
||||||
// and array which can hold the max number of triangles you need to process.
|
|
||||||
m_triflags = new unsigned char[m_chunkyMesh->maxTrisPerChunk];
|
|
||||||
if (!m_triflags)
|
|
||||||
{
|
|
||||||
if (rcGetLog())
|
|
||||||
rcGetLog()->log(RC_LOG_ERROR, "buildNavigation: Out of memory 'triangleFlags' (%d).", m_chunkyMesh->maxTrisPerChunk);
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
float tbmin[2], tbmax[2];
|
|
||||||
tbmin[0] = m_cfg.bmin[0];
|
|
||||||
tbmin[1] = m_cfg.bmin[2];
|
|
||||||
tbmax[0] = m_cfg.bmax[0];
|
|
||||||
tbmax[1] = m_cfg.bmax[2];
|
|
||||||
int cid[256];// TODO: Make grow when returning too many items.
|
|
||||||
const int ncid = rcGetChunksInRect(m_chunkyMesh, tbmin, tbmax, cid, 256);
|
|
||||||
if (!ncid)
|
|
||||||
return 0;
|
|
||||||
|
|
||||||
m_tileTriCount = 0;
|
|
||||||
|
|
||||||
for (int i = 0; i < ncid; ++i)
|
|
||||||
{
|
|
||||||
const rcChunkyTriMeshNode& node = m_chunkyMesh->nodes[cid[i]];
|
|
||||||
const int* tris = &m_chunkyMesh->tris[node.i*3];
|
|
||||||
const int ntris = node.n;
|
|
||||||
|
|
||||||
m_tileTriCount += ntris;
|
|
||||||
|
|
||||||
memset(m_triflags, 0, ntris*sizeof(unsigned char));
|
|
||||||
rcMarkWalkableTriangles(m_cfg.walkableSlopeAngle,
|
|
||||||
m_verts, m_nverts, tris, ntris, m_triflags);
|
|
||||||
|
|
||||||
rcRasterizeTriangles(m_verts, m_nverts, tris, m_triflags, ntris, *m_solid);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!m_keepInterResults)
|
|
||||||
{
|
|
||||||
delete [] m_triflags;
|
|
||||||
m_triflags = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Once all geoemtry is rasterized, we do initial pass of filtering to
|
|
||||||
// remove unwanted overhangs caused by the conservative rasterization
|
|
||||||
// as well as filter spans where the character cannot possibly stand.
|
|
||||||
rcFilterLedgeSpans(m_cfg.walkableHeight, m_cfg.walkableClimb, *m_solid);
|
|
||||||
rcFilterWalkableLowHeightSpans(m_cfg.walkableHeight, *m_solid);
|
|
||||||
|
|
||||||
// Compact the heightfield so that it is faster to handle from now on.
|
|
||||||
// This will result more cache coherent data as well as the neighbours
|
|
||||||
// between walkable cells will be calculated.
|
|
||||||
m_chf = new rcCompactHeightfield;
|
|
||||||
if (!m_chf)
|
|
||||||
{
|
|
||||||
if (rcGetLog())
|
|
||||||
rcGetLog()->log(RC_LOG_ERROR, "buildNavigation: Out of memory 'chf'.");
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
if (!rcBuildCompactHeightfield(m_cfg.walkableHeight, m_cfg.walkableClimb, RC_WALKABLE, *m_solid, *m_chf))
|
|
||||||
{
|
|
||||||
if (rcGetLog())
|
|
||||||
rcGetLog()->log(RC_LOG_ERROR, "buildNavigation: Could not build compact data.");
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!m_keepInterResults)
|
|
||||||
{
|
|
||||||
delete m_solid;
|
|
||||||
m_solid = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Prepare for region partitioning, by calculating distance field along the walkable surface.
|
|
||||||
if (!rcBuildDistanceField(*m_chf))
|
|
||||||
{
|
|
||||||
if (rcGetLog())
|
|
||||||
rcGetLog()->log(RC_LOG_ERROR, "buildNavigation: Could not build distance field.");
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Partition the walkable surface into simple regions without holes.
|
|
||||||
if (!rcBuildRegions(*m_chf, m_cfg.walkableRadius, m_cfg.borderSize, m_cfg.minRegionSize, m_cfg.mergeRegionSize))
|
|
||||||
{
|
|
||||||
if (rcGetLog())
|
|
||||||
rcGetLog()->log(RC_LOG_ERROR, "buildNavigation: Could not build regions.");
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Create contours.
|
|
||||||
m_cset = new rcContourSet;
|
|
||||||
if (!m_cset)
|
|
||||||
{
|
|
||||||
if (rcGetLog())
|
|
||||||
rcGetLog()->log(RC_LOG_ERROR, "buildNavigation: Out of memory 'cset'.");
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
if (!rcBuildContours(*m_chf, m_cfg.maxSimplificationError, m_cfg.maxEdgeLen, *m_cset))
|
|
||||||
{
|
|
||||||
if (rcGetLog())
|
|
||||||
rcGetLog()->log(RC_LOG_ERROR, "buildNavigation: Could not create contours.");
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (m_cset->nconts == 0)
|
|
||||||
{
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Build polygon navmesh from the contours.
|
|
||||||
m_pmesh = new rcPolyMesh;
|
|
||||||
if (!m_pmesh)
|
|
||||||
{
|
|
||||||
if (rcGetLog())
|
|
||||||
rcGetLog()->log(RC_LOG_ERROR, "buildNavigation: Out of memory 'pmesh'.");
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
if (!rcBuildPolyMesh(*m_cset, m_cfg.maxVertsPerPoly, *m_pmesh))
|
|
||||||
{
|
|
||||||
if (rcGetLog())
|
|
||||||
rcGetLog()->log(RC_LOG_ERROR, "buildNavigation: Could not triangulate contours.");
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Build detail mesh.
|
|
||||||
m_dmesh = new rcPolyMeshDetail;
|
|
||||||
if (!m_dmesh)
|
|
||||||
{
|
|
||||||
if (rcGetLog())
|
|
||||||
rcGetLog()->log(RC_LOG_ERROR, "buildNavigation: Out of memory 'dmesh'.");
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!rcBuildPolyMeshDetail(*m_pmesh, *m_chf,
|
|
||||||
m_cfg.detailSampleDist, m_cfg.detailSampleMaxError,
|
|
||||||
*m_dmesh))
|
|
||||||
{
|
|
||||||
if (rcGetLog())
|
|
||||||
rcGetLog()->log(RC_LOG_ERROR, "buildNavigation: Could build polymesh detail.");
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!m_keepInterResults)
|
|
||||||
{
|
|
||||||
delete m_chf;
|
|
||||||
m_chf = 0;
|
|
||||||
delete m_cset;
|
|
||||||
m_cset = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
unsigned char* navData = 0;
|
|
||||||
int navDataSize = 0;
|
|
||||||
if (m_cfg.maxVertsPerPoly <= DT_VERTS_PER_POLYGON)
|
|
||||||
{
|
|
||||||
// Remove padding from the polymesh data. TODO: Remove this odditity.
|
|
||||||
for (int i = 0; i < m_pmesh->nverts; ++i)
|
|
||||||
{
|
|
||||||
unsigned short* v = &m_pmesh->verts[i*3];
|
|
||||||
v[0] -= (unsigned short)m_cfg.borderSize;
|
|
||||||
v[2] -= (unsigned short)m_cfg.borderSize;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (m_pmesh->nverts >= 0xffff)
|
|
||||||
{
|
|
||||||
// The vertex indices are ushorts, and cannot point to more than 0xffff vertices.
|
|
||||||
if (rcGetLog())
|
|
||||||
rcGetLog()->log(RC_LOG_ERROR, "Too many vertices per tile %d (max: %d).", m_pmesh->nverts, 0xffff);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
/* if (m_pmesh->npolys > DT_MAX_TILES)
|
|
||||||
{
|
|
||||||
// If you hit this error, you have too many polygons per tile.
|
|
||||||
// You can trade off tile count to poly count by adjusting DT_TILE_REF_TILE_BITS and DT_TILE_REF_POLY_BITS.
|
|
||||||
// The current setup is optimized for large number of tiles and small number of polys per tile.
|
|
||||||
if (rcGetLog())
|
|
||||||
rcGetLog()->log(RC_LOG_ERROR, "Too many polygons per tile %d (max: %d).", m_pmesh->npolys, DT_MAX_TILES);
|
|
||||||
return false;
|
|
||||||
}*/
|
|
||||||
|
|
||||||
if (!dtCreateNavMeshData(m_pmesh->verts, m_pmesh->nverts,
|
|
||||||
m_pmesh->polys, m_pmesh->npolys, m_pmesh->nvp,
|
|
||||||
m_dmesh->meshes, m_dmesh->verts, m_dmesh->nverts, m_dmesh->tris, m_dmesh->ntris,
|
|
||||||
bmin, bmax, m_cfg.cs, m_cfg.ch, m_cfg.tileSize, m_cfg.walkableClimb, &navData, &navDataSize))
|
|
||||||
{
|
|
||||||
if (rcGetLog())
|
|
||||||
rcGetLog()->log(RC_LOG_ERROR, "Could not build Detour navmesh.");
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
m_tileMemUsage = navDataSize/1024.0f;
|
|
||||||
|
|
||||||
rcTimeVal totEndTime = rcGetPerformanceTimer();
|
|
||||||
|
|
||||||
// Show performance stats.
|
|
||||||
if (rcGetLog())
|
|
||||||
{
|
|
||||||
const float pc = 100.0f / rcGetDeltaTimeUsec(totStartTime, totEndTime);
|
|
||||||
|
|
||||||
rcGetLog()->log(RC_LOG_PROGRESS, "Rasterize: %.1fms (%.1f%%)", m_buildTimes.rasterizeTriangles/1000.0f, m_buildTimes.rasterizeTriangles*pc);
|
|
||||||
|
|
||||||
rcGetLog()->log(RC_LOG_PROGRESS, "Build Compact: %.1fms (%.1f%%)", m_buildTimes.buildCompact/1000.0f, m_buildTimes.buildCompact*pc);
|
|
||||||
|
|
||||||
rcGetLog()->log(RC_LOG_PROGRESS, "Filter Border: %.1fms (%.1f%%)", m_buildTimes.filterBorder/1000.0f, m_buildTimes.filterBorder*pc);
|
|
||||||
rcGetLog()->log(RC_LOG_PROGRESS, "Filter Walkable: %.1fms (%.1f%%)", m_buildTimes.filterWalkable/1000.0f, m_buildTimes.filterWalkable*pc);
|
|
||||||
rcGetLog()->log(RC_LOG_PROGRESS, "Filter Reachable: %.1fms (%.1f%%)", m_buildTimes.filterMarkReachable/1000.0f, m_buildTimes.filterMarkReachable*pc);
|
|
||||||
|
|
||||||
rcGetLog()->log(RC_LOG_PROGRESS, "Build Distancefield: %.1fms (%.1f%%)", m_buildTimes.buildDistanceField/1000.0f, m_buildTimes.buildDistanceField*pc);
|
|
||||||
rcGetLog()->log(RC_LOG_PROGRESS, " - distance: %.1fms (%.1f%%)", m_buildTimes.buildDistanceFieldDist/1000.0f, m_buildTimes.buildDistanceFieldDist*pc);
|
|
||||||
rcGetLog()->log(RC_LOG_PROGRESS, " - blur: %.1fms (%.1f%%)", m_buildTimes.buildDistanceFieldBlur/1000.0f, m_buildTimes.buildDistanceFieldBlur*pc);
|
|
||||||
|
|
||||||
rcGetLog()->log(RC_LOG_PROGRESS, "Build Regions: %.1fms (%.1f%%)", m_buildTimes.buildRegions/1000.0f, m_buildTimes.buildRegions*pc);
|
|
||||||
rcGetLog()->log(RC_LOG_PROGRESS, " - watershed: %.1fms (%.1f%%)", m_buildTimes.buildRegionsReg/1000.0f, m_buildTimes.buildRegionsReg*pc);
|
|
||||||
rcGetLog()->log(RC_LOG_PROGRESS, " - expand: %.1fms (%.1f%%)", m_buildTimes.buildRegionsExp/1000.0f, m_buildTimes.buildRegionsExp*pc);
|
|
||||||
rcGetLog()->log(RC_LOG_PROGRESS, " - find catchment basins: %.1fms (%.1f%%)", m_buildTimes.buildRegionsFlood/1000.0f, m_buildTimes.buildRegionsFlood*pc);
|
|
||||||
rcGetLog()->log(RC_LOG_PROGRESS, " - filter: %.1fms (%.1f%%)", m_buildTimes.buildRegionsFilter/1000.0f, m_buildTimes.buildRegionsFilter*pc);
|
|
||||||
|
|
||||||
rcGetLog()->log(RC_LOG_PROGRESS, "Build Contours: %.1fms (%.1f%%)", m_buildTimes.buildContours/1000.0f, m_buildTimes.buildContours*pc);
|
|
||||||
rcGetLog()->log(RC_LOG_PROGRESS, " - trace: %.1fms (%.1f%%)", m_buildTimes.buildContoursTrace/1000.0f, m_buildTimes.buildContoursTrace*pc);
|
|
||||||
rcGetLog()->log(RC_LOG_PROGRESS, " - simplify: %.1fms (%.1f%%)", m_buildTimes.buildContoursSimplify/1000.0f, m_buildTimes.buildContoursSimplify*pc);
|
|
||||||
|
|
||||||
rcGetLog()->log(RC_LOG_PROGRESS, "Build Polymesh: %.1fms (%.1f%%)", m_buildTimes.buildPolymesh/1000.0f, m_buildTimes.buildPolymesh*pc);
|
|
||||||
rcGetLog()->log(RC_LOG_PROGRESS, "Build Polymesh Detail: %.1fms (%.1f%%)", m_buildTimes.buildDetailMesh/1000.0f, m_buildTimes.buildDetailMesh*pc);
|
|
||||||
rcGetLog()->log(RC_LOG_PROGRESS, "Merge Polymeshes: %.1fms (%.1f%%)", m_buildTimes.mergePolyMesh/1000.0f, m_buildTimes.mergePolyMesh*pc);
|
|
||||||
rcGetLog()->log(RC_LOG_PROGRESS, "Merge Polymesh Details: %.1fms (%.1f%%)", m_buildTimes.mergePolyMeshDetail/1000.0f, m_buildTimes.mergePolyMeshDetail*pc);
|
|
||||||
|
|
||||||
|
|
||||||
rcGetLog()->log(RC_LOG_PROGRESS, "Build Polymesh: %.1fms (%.1f%%)", m_buildTimes.buildPolymesh/1000.0f, m_buildTimes.buildPolymesh*pc);
|
|
||||||
|
|
||||||
rcGetLog()->log(RC_LOG_PROGRESS, "Polymesh: Verts:%d Polys:%d", m_pmesh->nverts, m_pmesh->npolys);
|
|
||||||
|
|
||||||
rcGetLog()->log(RC_LOG_PROGRESS, "TOTAL: %.1fms", rcGetDeltaTimeUsec(totStartTime, totEndTime)/1000.0f);
|
|
||||||
}
|
|
||||||
|
|
||||||
m_tileBuildTime = rcGetDeltaTimeUsec(totStartTime, totEndTime)/1000.0f;
|
|
||||||
|
|
||||||
dataSize = navDataSize;
|
|
||||||
return navData;
|
|
||||||
}
|
|
@ -23,7 +23,7 @@ inline bool inRange(const float* v1, const float* v2, const float r, const float
|
|||||||
const float dx = v2[0] - v1[0];
|
const float dx = v2[0] - v1[0];
|
||||||
const float dy = v2[1] - v1[1];
|
const float dy = v2[1] - v1[1];
|
||||||
const float dz = v2[2] - v1[2];
|
const float dz = v2[2] - v1[2];
|
||||||
return (dx*dx + dz*dz) < r*r; // && fabsf(dy) < h;
|
return (dx*dx + dz*dz) < r*r && fabsf(dy) < h;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -293,8 +293,8 @@ void Sample_SoloMesh::toolRender(int flags)
|
|||||||
if (flags & NAVMESH_POLYS)
|
if (flags & NAVMESH_POLYS)
|
||||||
dtDebugDrawNavMesh(m_navMesh, m_toolMode == TOOLMODE_PATHFIND);
|
dtDebugDrawNavMesh(m_navMesh, m_toolMode == TOOLMODE_PATHFIND);
|
||||||
|
|
||||||
/* if (flags & NAVMESH_BVTREE)
|
if (flags & NAVMESH_BVTREE)
|
||||||
dtDebugDrawNavMeshBVTree(m_navMesh);*/
|
dtDebugDrawNavMeshBVTree(m_navMesh);
|
||||||
|
|
||||||
if (flags & NAVMESH_TOOLS)
|
if (flags & NAVMESH_TOOLS)
|
||||||
{
|
{
|
||||||
|
@ -488,7 +488,7 @@ bool Sample_SoloMeshSimple::handleBuild()
|
|||||||
|
|
||||||
// The GUI may allow more max points per polygon than Detour can handle.
|
// The GUI may allow more max points per polygon than Detour can handle.
|
||||||
// Only build the detour navmesh if we do not exceed the limit.
|
// Only build the detour navmesh if we do not exceed the limit.
|
||||||
if (m_cfg.maxVertsPerPoly <= DT_STAT_VERTS_PER_POLYGON)
|
if (m_cfg.maxVertsPerPoly <= DT_VERTS_PER_POLYGON)
|
||||||
{
|
{
|
||||||
unsigned char* navData = 0;
|
unsigned char* navData = 0;
|
||||||
int navDataSize = 0;
|
int navDataSize = 0;
|
||||||
|
@ -905,7 +905,7 @@ bool Sample_SoloMeshTiled::handleBuild()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (m_pmesh && m_cfg.maxVertsPerPoly <= DT_STAT_VERTS_PER_POLYGON)
|
if (m_pmesh && m_cfg.maxVertsPerPoly <= DT_VERTS_PER_POLYGON)
|
||||||
{
|
{
|
||||||
unsigned char* navData = 0;
|
unsigned char* navData = 0;
|
||||||
int navDataSize = 0;
|
int navDataSize = 0;
|
||||||
|
@ -28,8 +28,8 @@
|
|||||||
#include "Recast.h"
|
#include "Recast.h"
|
||||||
#include "RecastTimer.h"
|
#include "RecastTimer.h"
|
||||||
#include "RecastDebugDraw.h"
|
#include "RecastDebugDraw.h"
|
||||||
#include "DetourTileNavMesh.h"
|
#include "DetourNavMesh.h"
|
||||||
#include "DetourTileNavMeshBuilder.h"
|
#include "DetourNavMeshBuilder.h"
|
||||||
#include "DetourDebugDraw.h"
|
#include "DetourDebugDraw.h"
|
||||||
|
|
||||||
#ifdef WIN32
|
#ifdef WIN32
|
||||||
@ -37,6 +37,31 @@
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
inline unsigned int nextPow2(unsigned int v)
|
||||||
|
{
|
||||||
|
v--;
|
||||||
|
v |= v >> 1;
|
||||||
|
v |= v >> 2;
|
||||||
|
v |= v >> 4;
|
||||||
|
v |= v >> 8;
|
||||||
|
v |= v >> 16;
|
||||||
|
v++;
|
||||||
|
return v;
|
||||||
|
}
|
||||||
|
|
||||||
|
inline unsigned int ilog2(unsigned int v)
|
||||||
|
{
|
||||||
|
unsigned int r;
|
||||||
|
unsigned int shift;
|
||||||
|
r = (v > 0xffff) << 4; v >>= r;
|
||||||
|
shift = (v > 0xff) << 3; v >>= shift; r |= shift;
|
||||||
|
shift = (v > 0xf) << 2; v >>= shift; r |= shift;
|
||||||
|
shift = (v > 0x3) << 1; v >>= shift; r |= shift;
|
||||||
|
r |= (v >> 1);
|
||||||
|
return r;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
Sample_TileMesh::Sample_TileMesh() :
|
Sample_TileMesh::Sample_TileMesh() :
|
||||||
m_keepInterResults(false),
|
m_keepInterResults(false),
|
||||||
m_navMesh(0),
|
m_navMesh(0),
|
||||||
@ -47,6 +72,8 @@ Sample_TileMesh::Sample_TileMesh() :
|
|||||||
m_cset(0),
|
m_cset(0),
|
||||||
m_pmesh(0),
|
m_pmesh(0),
|
||||||
m_dmesh(0),
|
m_dmesh(0),
|
||||||
|
m_maxTiles(0),
|
||||||
|
m_maxPolysPerTile(0),
|
||||||
m_tileSize(32),
|
m_tileSize(32),
|
||||||
m_sposSet(false),
|
m_sposSet(false),
|
||||||
m_eposSet(false),
|
m_eposSet(false),
|
||||||
@ -106,6 +133,18 @@ void Sample_TileMesh::handleSettings()
|
|||||||
const int th = (gh + ts-1) / ts;
|
const int th = (gh + ts-1) / ts;
|
||||||
snprintf(text, 64, "Tiles %d x %d", tw, th);
|
snprintf(text, 64, "Tiles %d x %d", tw, th);
|
||||||
imguiValue(text);
|
imguiValue(text);
|
||||||
|
|
||||||
|
// Max tiles and max polys affect how the tile IDs are caculated.
|
||||||
|
// There are 22 bits available for identifying a tile and a polygon.
|
||||||
|
int tileBits = rcMin((int)ilog2(nextPow2(tw*th)), 14);
|
||||||
|
if (tileBits > 14) tileBits = 14;
|
||||||
|
int polyBits = 22 - tileBits;
|
||||||
|
m_maxTiles = 1 << tileBits;
|
||||||
|
m_maxPolysPerTile = 1 << polyBits;
|
||||||
|
snprintf(text, 64, "Max Tiles %d", m_maxTiles);
|
||||||
|
imguiValue(text);
|
||||||
|
snprintf(text, 64, "Max Polys %d", m_maxPolysPerTile);
|
||||||
|
imguiValue(text);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Sample_TileMesh::toolRecalc()
|
void Sample_TileMesh::toolRecalc()
|
||||||
@ -184,6 +223,49 @@ void Sample_TileMesh::handleTools()
|
|||||||
m_toolMode = TOOLMODE_CREATE_TILES;
|
m_toolMode = TOOLMODE_CREATE_TILES;
|
||||||
toolRecalc();
|
toolRecalc();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
imguiIndent();
|
||||||
|
|
||||||
|
if (imguiButton("Create All"))
|
||||||
|
{
|
||||||
|
int gw = 0, gh = 0;
|
||||||
|
rcCalcGridSize(m_bmin, m_bmax, m_cellSize, &gw, &gh);
|
||||||
|
const int ts = (int)m_tileSize;
|
||||||
|
const int tw = (gw + ts-1) / ts;
|
||||||
|
const int th = (gh + ts-1) / ts;
|
||||||
|
const float tcs = m_tileSize*m_cellSize;
|
||||||
|
|
||||||
|
for (int y = 0; y < th; ++y)
|
||||||
|
{
|
||||||
|
for (int x = 0; x < tw; ++x)
|
||||||
|
{
|
||||||
|
m_tileBmin[0] = m_bmin[0] + x*tcs;
|
||||||
|
m_tileBmin[1] = m_bmin[1];
|
||||||
|
m_tileBmin[2] = m_bmin[2] + y*tcs;
|
||||||
|
|
||||||
|
m_tileBmax[0] = m_bmin[0] + (x+1)*tcs;
|
||||||
|
m_tileBmax[1] = m_bmax[1];
|
||||||
|
m_tileBmax[2] = m_bmin[2] + (y+1)*tcs;
|
||||||
|
|
||||||
|
int dataSize = 0;
|
||||||
|
unsigned char* data = buildTileMesh(m_tileBmin, m_tileBmax, dataSize);
|
||||||
|
if (data)
|
||||||
|
{
|
||||||
|
// Remove any previous data (navmesh owns and deletes the data).
|
||||||
|
m_navMesh->removeTileAt(x,y,0,0);
|
||||||
|
// Let the navmesh own the data.
|
||||||
|
if (!m_navMesh->addTileAt(x,y,data,dataSize,true))
|
||||||
|
delete [] data;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
toolRecalc();
|
||||||
|
}
|
||||||
|
imguiUnindent();
|
||||||
|
|
||||||
|
imguiSeparator();
|
||||||
|
|
||||||
if (imguiCheck("Pathfind", m_toolMode == TOOLMODE_PATHFIND))
|
if (imguiCheck("Pathfind", m_toolMode == TOOLMODE_PATHFIND))
|
||||||
{
|
{
|
||||||
m_toolMode = TOOLMODE_PATHFIND;
|
m_toolMode = TOOLMODE_PATHFIND;
|
||||||
@ -215,12 +297,16 @@ void Sample_TileMesh::handleDebugMode()
|
|||||||
imguiValue("LMB: (Re)Create tiles.");
|
imguiValue("LMB: (Re)Create tiles.");
|
||||||
imguiValue("LMB+SHIFT: Remove tiles.");
|
imguiValue("LMB+SHIFT: Remove tiles.");
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
imguiValue("Press [Build] to create tile mesh");
|
||||||
|
imguiValue("with specified parameters.");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void getPolyCenter(dtTiledNavMesh* navMesh, dtTilePolyRef ref, float* center)
|
static void getPolyCenter(dtNavMesh* navMesh, dtPolyRef ref, float* center)
|
||||||
{
|
{
|
||||||
const dtTilePoly* p = navMesh->getPolyByRef(ref);
|
const dtPoly* p = navMesh->getPolyByRef(ref);
|
||||||
if (!p) return;
|
if (!p) return;
|
||||||
const float* verts = navMesh->getPolyVertsByRef(ref);
|
const float* verts = navMesh->getPolyVertsByRef(ref);
|
||||||
center[0] = 0;
|
center[0] = 0;
|
||||||
@ -299,7 +385,7 @@ void Sample_TileMesh::handleRender()
|
|||||||
rcDebugDrawBoxWire(&dd, m_tileBmin[0],m_tileBmin[1],m_tileBmin[2], m_tileBmax[0],m_tileBmax[1],m_tileBmax[2], m_tileCol);
|
rcDebugDrawBoxWire(&dd, m_tileBmin[0],m_tileBmin[1],m_tileBmin[2], m_tileBmax[0],m_tileBmax[1],m_tileBmax[2], m_tileCol);
|
||||||
|
|
||||||
if (m_navMesh)
|
if (m_navMesh)
|
||||||
dtDebugDrawTiledNavMesh(m_navMesh);
|
dtDebugDrawNavMesh(m_navMesh);
|
||||||
|
|
||||||
if (m_sposSet)
|
if (m_sposSet)
|
||||||
{
|
{
|
||||||
@ -338,13 +424,13 @@ void Sample_TileMesh::handleRender()
|
|||||||
|
|
||||||
if (m_toolMode == TOOLMODE_PATHFIND)
|
if (m_toolMode == TOOLMODE_PATHFIND)
|
||||||
{
|
{
|
||||||
dtDebugDrawTiledNavMeshPoly(m_navMesh, m_startRef, startCol);
|
dtDebugDrawNavMeshPoly(m_navMesh, m_startRef, startCol);
|
||||||
dtDebugDrawTiledNavMeshPoly(m_navMesh, m_endRef, endCol);
|
dtDebugDrawNavMeshPoly(m_navMesh, m_endRef, endCol);
|
||||||
|
|
||||||
if (m_npolys)
|
if (m_npolys)
|
||||||
{
|
{
|
||||||
for (int i = 1; i < m_npolys-1; ++i)
|
for (int i = 1; i < m_npolys-1; ++i)
|
||||||
dtDebugDrawTiledNavMeshPoly(m_navMesh, m_polys[i], pathCol);
|
dtDebugDrawNavMeshPoly(m_navMesh, m_polys[i], pathCol);
|
||||||
}
|
}
|
||||||
if (m_nstraightPath)
|
if (m_nstraightPath)
|
||||||
{
|
{
|
||||||
@ -365,12 +451,12 @@ void Sample_TileMesh::handleRender()
|
|||||||
}
|
}
|
||||||
else if (m_toolMode == TOOLMODE_RAYCAST)
|
else if (m_toolMode == TOOLMODE_RAYCAST)
|
||||||
{
|
{
|
||||||
dtDebugDrawTiledNavMeshPoly(m_navMesh, m_startRef, startCol);
|
dtDebugDrawNavMeshPoly(m_navMesh, m_startRef, startCol);
|
||||||
|
|
||||||
if (m_nstraightPath)
|
if (m_nstraightPath)
|
||||||
{
|
{
|
||||||
for (int i = 1; i < m_npolys; ++i)
|
for (int i = 1; i < m_npolys; ++i)
|
||||||
dtDebugDrawTiledNavMeshPoly(m_navMesh, m_polys[i], pathCol);
|
dtDebugDrawNavMeshPoly(m_navMesh, m_polys[i], pathCol);
|
||||||
|
|
||||||
glColor4ub(64,16,0,220);
|
glColor4ub(64,16,0,220);
|
||||||
glLineWidth(3.0f);
|
glLineWidth(3.0f);
|
||||||
@ -389,7 +475,7 @@ void Sample_TileMesh::handleRender()
|
|||||||
}
|
}
|
||||||
else if (m_toolMode == TOOLMODE_DISTANCE_TO_WALL)
|
else if (m_toolMode == TOOLMODE_DISTANCE_TO_WALL)
|
||||||
{
|
{
|
||||||
dtDebugDrawTiledNavMeshPoly(m_navMesh, m_startRef, startCol);
|
dtDebugDrawNavMeshPoly(m_navMesh, m_startRef, startCol);
|
||||||
const float col[4] = {1,1,1,0.5f};
|
const float col[4] = {1,1,1,0.5f};
|
||||||
rcDebugDrawCylinderWire(&dd, m_spos[0]-m_distanceToWall, m_spos[1]+0.02f, m_spos[2]-m_distanceToWall,
|
rcDebugDrawCylinderWire(&dd, m_spos[0]-m_distanceToWall, m_spos[1]+0.02f, m_spos[2]-m_distanceToWall,
|
||||||
m_spos[0]+m_distanceToWall, m_spos[1]+m_agentHeight, m_spos[2]+m_distanceToWall, col);
|
m_spos[0]+m_distanceToWall, m_spos[1]+m_agentHeight, m_spos[2]+m_distanceToWall, col);
|
||||||
@ -406,7 +492,7 @@ void Sample_TileMesh::handleRender()
|
|||||||
const float cola[4] = {0,0,0,0.5f};
|
const float cola[4] = {0,0,0,0.5f};
|
||||||
for (int i = 0; i < m_npolys; ++i)
|
for (int i = 0; i < m_npolys; ++i)
|
||||||
{
|
{
|
||||||
dtDebugDrawTiledNavMeshPoly(m_navMesh, m_polys[i], pathCol);
|
dtDebugDrawNavMeshPoly(m_navMesh, m_polys[i], pathCol);
|
||||||
if (m_parent[i])
|
if (m_parent[i])
|
||||||
{
|
{
|
||||||
float p0[3], p1[3];
|
float p0[3], p1[3];
|
||||||
@ -491,20 +577,23 @@ bool Sample_TileMesh::handleBuild()
|
|||||||
{
|
{
|
||||||
if (!m_verts || !m_tris)
|
if (!m_verts || !m_tris)
|
||||||
{
|
{
|
||||||
printf("No verts or tris\n");
|
if (rcGetLog())
|
||||||
|
rcGetLog()->log(RC_LOG_ERROR, "buildTiledNavigation: No vertices and triangles.");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
delete m_navMesh;
|
delete m_navMesh;
|
||||||
m_navMesh = new dtTiledNavMesh;
|
m_navMesh = new dtNavMesh;
|
||||||
if (!m_navMesh)
|
if (!m_navMesh)
|
||||||
{
|
{
|
||||||
printf("Could not allocate navmehs\n");
|
if (rcGetLog())
|
||||||
|
rcGetLog()->log(RC_LOG_ERROR, "buildTiledNavigation: Could not allocate navmesh.");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (!m_navMesh->init(m_bmin, m_tileSize*m_cellSize, m_agentMaxClimb*m_cellHeight))
|
if (!m_navMesh->init(m_bmin, m_tileSize*m_cellSize, m_tileSize*m_cellSize, m_agentMaxClimb*m_cellHeight, m_maxTiles, m_maxPolysPerTile, 2048))
|
||||||
{
|
{
|
||||||
printf("Could not init navmesh\n");
|
if (rcGetLog())
|
||||||
|
rcGetLog()->log(RC_LOG_ERROR, "buildTiledNavigation: Could not init navmesh.");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -759,6 +848,11 @@ unsigned char* Sample_TileMesh::buildTileMesh(const float* bmin, const float* bm
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (m_cset->nconts == 0)
|
||||||
|
{
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
// Build polygon navmesh from the contours.
|
// Build polygon navmesh from the contours.
|
||||||
m_pmesh = new rcPolyMesh;
|
m_pmesh = new rcPolyMesh;
|
||||||
if (!m_pmesh)
|
if (!m_pmesh)
|
||||||
@ -802,7 +896,7 @@ unsigned char* Sample_TileMesh::buildTileMesh(const float* bmin, const float* bm
|
|||||||
|
|
||||||
unsigned char* navData = 0;
|
unsigned char* navData = 0;
|
||||||
int navDataSize = 0;
|
int navDataSize = 0;
|
||||||
if (m_cfg.maxVertsPerPoly == DT_TILE_VERTS_PER_POLYGON)
|
if (m_cfg.maxVertsPerPoly <= DT_VERTS_PER_POLYGON)
|
||||||
{
|
{
|
||||||
// Remove padding from the polymesh data. TODO: Remove this odditity.
|
// Remove padding from the polymesh data. TODO: Remove this odditity.
|
||||||
for (int i = 0; i < m_pmesh->nverts; ++i)
|
for (int i = 0; i < m_pmesh->nverts; ++i)
|
||||||
@ -819,7 +913,7 @@ unsigned char* Sample_TileMesh::buildTileMesh(const float* bmin, const float* bm
|
|||||||
rcGetLog()->log(RC_LOG_ERROR, "Too many vertices per tile %d (max: %d).", m_pmesh->nverts, 0xffff);
|
rcGetLog()->log(RC_LOG_ERROR, "Too many vertices per tile %d (max: %d).", m_pmesh->nverts, 0xffff);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (m_pmesh->npolys > DT_MAX_TILES)
|
/* if (m_pmesh->npolys > DT_MAX_TILES)
|
||||||
{
|
{
|
||||||
// If you hit this error, you have too many polygons per tile.
|
// If you hit this error, you have too many polygons per tile.
|
||||||
// You can trade off tile count to poly count by adjusting DT_TILE_REF_TILE_BITS and DT_TILE_REF_POLY_BITS.
|
// You can trade off tile count to poly count by adjusting DT_TILE_REF_TILE_BITS and DT_TILE_REF_POLY_BITS.
|
||||||
@ -827,9 +921,9 @@ unsigned char* Sample_TileMesh::buildTileMesh(const float* bmin, const float* bm
|
|||||||
if (rcGetLog())
|
if (rcGetLog())
|
||||||
rcGetLog()->log(RC_LOG_ERROR, "Too many polygons per tile %d (max: %d).", m_pmesh->npolys, DT_MAX_TILES);
|
rcGetLog()->log(RC_LOG_ERROR, "Too many polygons per tile %d (max: %d).", m_pmesh->npolys, DT_MAX_TILES);
|
||||||
return false;
|
return false;
|
||||||
}
|
}*/
|
||||||
|
|
||||||
if (!dtCreateNavMeshTileData(m_pmesh->verts, m_pmesh->nverts,
|
if (!dtCreateNavMeshData(m_pmesh->verts, m_pmesh->nverts,
|
||||||
m_pmesh->polys, m_pmesh->npolys, m_pmesh->nvp,
|
m_pmesh->polys, m_pmesh->npolys, m_pmesh->nvp,
|
||||||
m_dmesh->meshes, m_dmesh->verts, m_dmesh->nverts, m_dmesh->tris, m_dmesh->ntris,
|
m_dmesh->meshes, m_dmesh->verts, m_dmesh->nverts, m_dmesh->tris, m_dmesh->ntris,
|
||||||
bmin, bmax, m_cfg.cs, m_cfg.ch, m_cfg.tileSize, m_cfg.walkableClimb, &navData, &navDataSize))
|
bmin, bmax, m_cfg.cs, m_cfg.ch, m_cfg.tileSize, m_cfg.walkableClimb, &navData, &navDataSize))
|
||||||
|
@ -18,7 +18,6 @@
|
|||||||
#include "Sample_SoloMeshSimple.h"
|
#include "Sample_SoloMeshSimple.h"
|
||||||
#include "Sample_SoloMeshTiled.h"
|
#include "Sample_SoloMeshTiled.h"
|
||||||
#include "Sample_TileMesh.h"
|
#include "Sample_TileMesh.h"
|
||||||
#include "Sample_DynMesh.h"
|
|
||||||
|
|
||||||
#ifdef WIN32
|
#ifdef WIN32
|
||||||
# define snprintf _snprintf
|
# define snprintf _snprintf
|
||||||
@ -198,14 +197,12 @@ struct SampleItem
|
|||||||
Sample* createSoloSimple() { return new Sample_SoloMeshSimple(); }
|
Sample* createSoloSimple() { return new Sample_SoloMeshSimple(); }
|
||||||
Sample* createSoloTiled() { return new Sample_SoloMeshTiled(); }
|
Sample* createSoloTiled() { return new Sample_SoloMeshTiled(); }
|
||||||
Sample* createTile() { return new Sample_TileMesh(); }
|
Sample* createTile() { return new Sample_TileMesh(); }
|
||||||
Sample* createDyn() { return new Sample_DynMesh(); }
|
|
||||||
|
|
||||||
static SampleItem g_samples[] =
|
static SampleItem g_samples[] =
|
||||||
{
|
{
|
||||||
{ createSoloSimple, "Solo Mesh Simple" },
|
{ createSoloSimple, "Solo Mesh Simple" },
|
||||||
{ createSoloTiled, "Solo Mesh Tiled" },
|
{ createSoloTiled, "Solo Mesh Tiled" },
|
||||||
{ createTile, "Tile Mesh" },
|
{ createTile, "Tile Mesh" },
|
||||||
{ createDyn, "Dyn Mesh" },
|
|
||||||
};
|
};
|
||||||
static const int g_nsamples = sizeof(g_samples)/sizeof(SampleItem);
|
static const int g_nsamples = sizeof(g_samples)/sizeof(SampleItem);
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user