Demo: Changed demo "Builders" to "Samples".

Detour: Prefixed static nav with 'dtStat', this includes polys and poly refs too.
imgui: Made imgui code not to use id:s anymore, since there were way too many id clashes.
imgui: Separated the rendering code into its' own file, changed prebaked font to use stb_truetype instead, removed glfont.
imgui: Added 'disabled' property to widgets.
Recast: exposed single triangle rasterization into the recast api.
Demo: Changed the debug draw validation to be "soft", easier to demo now.
This commit is contained in:
Mikko Mononen
2009-07-13 10:30:37 +00:00
parent 20e07146b9
commit d71740036d
30 changed files with 7459 additions and 12722 deletions

View File

@@ -20,9 +20,9 @@
#define DETOURDEBUGDRAW_H
#include "DetourStatNavMesh.h"
#include "DetourTiledNavMesh.h"
#include "DetourTileNavMesh.h"
void dtDebugDrawStatNavMeshPoly(const dtStatNavMesh* mesh, dtPolyRef ref, const float* col);
void dtDebugDrawStatNavMeshPoly(const dtStatNavMesh* mesh, dtStatPolyRef ref, const float* col);
void dtDebugDrawStatNavMeshBVTree(const dtStatNavMesh* mesh);
void dtDebugDrawStatNavMesh(const dtStatNavMesh* mesh);

View File

@@ -20,25 +20,24 @@
#define DETOURSTATNAVMESH_H
// Reference to navigation polygon.
typedef unsigned short dtPolyRef;
typedef unsigned short dtStatPolyRef;
// Maximum number of vertices per navigation polygon.
static const int DT_VERTS_PER_POLYGON = 6;
static const int DT_STAT_VERTS_PER_POLYGON = 6;
// Structure holding the navigation polygon data.
struct dtPoly
struct dtStatPoly
{
unsigned short v[DT_VERTS_PER_POLYGON]; // Indices to vertices of the poly.
dtPolyRef n[DT_VERTS_PER_POLYGON]; // Refs to neighbours of the poly.
unsigned char nv; // Number of vertices.
unsigned char flags; // Flags (not used).
unsigned char pad[2];
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).
};
const int DT_NAVMESH_MAGIC = 'NAVM';
const int DT_NAVMESH_VERSION = 2;
const int DT_STAT_NAVMESH_MAGIC = 'NAVM';
const int DT_STAT_NAVMESH_VERSION = 2;
struct dtBVNode
struct dtStatBVNode
{
unsigned short bmin[3], bmax[3];
int i;
@@ -74,7 +73,7 @@ public:
// 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.
dtPolyRef findNearestPoly(const float* center, const float* extents);
dtStatPolyRef findNearestPoly(const float* center, const float* extents);
// Returns polygons which touch the query box.
// Params:
@@ -84,7 +83,7 @@ public:
// 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,
dtPolyRef* polys, const int maxPolys);
dtStatPolyRef* polys, const int maxPolys);
// Finds path from start polygon to end polygon.
// If target polygon canno be reached through the navigation graph,
@@ -95,8 +94,8 @@ public:
// 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(dtPolyRef startRef, dtPolyRef endRef,
dtPolyRef* path, const int maxPathSize);
int findPath(dtStatPolyRef startRef, dtStatPolyRef endRef,
dtStatPolyRef* path, const int maxPathSize);
// Finds a straight path from start to end locations within the corridor
// described by the path polygons.
@@ -110,7 +109,7 @@ public:
// 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 dtPolyRef* path, const int pathSize,
const dtStatPolyRef* path, const int pathSize,
float* straightPath, const int maxStraightPathSize);
// Finds intersection againts walls starting from start pos.
@@ -118,11 +117,11 @@ public:
// 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, valid only if hit.
// t - (out) hit parameter along the segment, 0 if no hit.
// endRef - (out) ref to the last polygon which was processed.
// Returns: True if hit wall.
// TODO: Return the whole corridor!!
bool raycast(dtPolyRef startRef, const float* startPos, const float* endPos, float& t, dtPolyRef& endRef);
// 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:
@@ -132,7 +131,7 @@ public:
// 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(dtPolyRef centerRef, const float* centerPos, float maxRadius,
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.
@@ -143,12 +142,10 @@ public:
// 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.
// resultDepth - (out, opt) search depth at each result polygon.
// maxResult - (int) maximum capacity of search results.
// Returns: Number of results.
int findPolysAround(dtPolyRef centerRef, const float* centerPos, float radius,
dtPolyRef* resultRef, dtPolyRef* resultParent,
float* resultCost, unsigned short* resultDepth,
int findPolysAround(dtStatPolyRef centerRef, const float* centerPos, float radius,
dtStatPolyRef* resultRef, dtStatPolyRef* resultParent, float* resultCost,
const int maxResult);
// Returns closest point on navigation polygon.
@@ -157,45 +154,45 @@ public:
// pos - (in) the point to check.
// closest - (out) closest point.
// Returns: true if closest point found.
bool closestPointToPoly(dtPolyRef ref, const float* pos, float* closest) const;
bool closestPointToPoly(dtStatPolyRef ref, const float* pos, float* closest) const;
// Returns pointer to a polygon based on ref.
const dtPoly* getPolyByRef(dtPolyRef ref) const;
const dtStatPoly* getPolyByRef(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 dtPoly* getPoly(int i) const { return &m_polys[i]; }
inline const dtStatPoly* getPoly(int i) const { return &m_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_verts[i*3]; }
bool isInOpenList(dtPolyRef ref) const;
bool isInOpenList(dtStatPolyRef ref) const;
int getMemUsed() const;
inline const dtStatNavMeshHeader* getHeader() const { return m_header; }
inline const dtBVNode* getBvTreeNodes() const { return m_bvtree; }
inline const dtStatBVNode* getBvTreeNodes() const { return m_bvtree; }
inline int getBvTreeNodeCount() const { return m_header->nnodes; }
private:
float getCost(dtPolyRef prev, dtPolyRef from, dtPolyRef to) const;
float getHeuristic(dtPolyRef from, dtPolyRef to) const;
float getCost(dtStatPolyRef prev, dtStatPolyRef from, dtStatPolyRef to) const;
float getHeuristic(dtStatPolyRef from, dtStatPolyRef to) const;
// Copies the locations of vertices of a polygon to an array.
int getPolyVerts(dtPolyRef ref, float* verts) const;
int getPolyVerts(dtStatPolyRef ref, float* verts) const;
// Returns portal points between two polygons.
bool getPortalPoints(dtPolyRef from, dtPolyRef to, float* left, float* right) const;
bool getPortalPoints(dtStatPolyRef from, dtStatPolyRef to, float* left, float* right) const;
unsigned char* m_data;
int m_dataSize;
dtStatNavMeshHeader* m_header;
dtPoly* m_polys;
dtStatPoly* m_polys;
float* m_verts;
dtBVNode* m_bvtree;
dtStatBVNode* m_bvtree;
class dtNodePool* m_nodePool;
class dtNodeQueue* m_openList;

View File

@@ -21,9 +21,9 @@
#include "SDL.h"
#include "SDL_Opengl.h"
void dtDebugDrawStatNavMeshPoly(const dtStatNavMesh* mesh, dtPolyRef ref, const float* col)
void dtDebugDrawStatNavMeshPoly(const dtStatNavMesh* mesh, dtStatPolyRef ref, const float* col)
{
const dtPoly* p = mesh->getPolyByRef(ref);
const dtStatPoly* p = mesh->getPolyByRef(ref);
if (!p)
return;
glColor4f(col[0],col[1],col[2],0.25f);
@@ -83,14 +83,14 @@ void dtDebugDrawStatNavMeshBVTree(const dtStatNavMesh* mesh)
const float col[] = { 1,1,1,0.5f };
const dtStatNavMeshHeader* hdr = mesh->getHeader();
const dtBVNode* nodes = mesh->getBvTreeNodes();
const dtStatBVNode* nodes = mesh->getBvTreeNodes();
int nnodes = mesh->getBvTreeNodeCount();
glBegin(GL_LINES);
for (int i = 0; i < nnodes; ++i)
{
const dtBVNode* n = &nodes[i];
const dtStatBVNode* n = &nodes[i];
if (n->i < 0) // Leaf indices are positive.
continue;
drawBoxWire(hdr->bmin[0] + n->bmin[0]*hdr->cs,
@@ -108,7 +108,7 @@ void dtDebugDrawStatNavMesh(const dtStatNavMesh* mesh)
glBegin(GL_TRIANGLES);
for (int i = 0; i < mesh->getPolyCount(); ++i)
{
const dtPoly* p = mesh->getPoly(i);
const dtStatPoly* p = mesh->getPoly(i);
if (mesh->isInOpenList(i+1))
glColor4ub(255,196,0,64);
@@ -136,7 +136,7 @@ void dtDebugDrawStatNavMesh(const dtStatNavMesh* mesh)
glBegin(GL_LINES);
for (int i = 0; i < mesh->getPolyCount(); ++i)
{
const dtPoly* p = mesh->getPoly(i);
const dtStatPoly* p = mesh->getPoly(i);
for (int j = 0, nj = (int)p->nv; j < nj; ++j)
{
if (p->n[j] == 0) continue;
@@ -158,7 +158,7 @@ void dtDebugDrawStatNavMesh(const dtStatNavMesh* mesh)
glBegin(GL_LINES);
for (int i = 0; i < mesh->getPolyCount(); ++i)
{
const dtPoly* p = mesh->getPoly(i);
const dtStatPoly* p = mesh->getPoly(i);
for (int j = 0, nj = (int)p->nv; j < nj; ++j)
{
if (p->n[j] != 0) continue;
@@ -191,10 +191,10 @@ void dtDebugDrawStatNavMesh(const dtStatNavMesh* mesh)
static void drawTile(const dtTileHeader* header)
{
const float col[4] = {0,0,0,0.25f};
glBegin(GL_LINES);
/* glBegin(GL_LINES);
drawBoxWire(header->bmin[0],header->bmin[1],header->bmin[2],
header->bmax[0],header->bmax[1],header->bmax[2], col);
glEnd();
glEnd();*/
glBegin(GL_TRIANGLES);
for (int i = 0; i < header->npolys; ++i)

View File

@@ -102,12 +102,12 @@ inline int longestAxis(unsigned short x, unsigned short y, unsigned short z)
return axis;
}
void subdivide(BVItem* items, int nitems, int imin, int imax, int& curNode, dtBVNode* nodes)
static void subdivide(BVItem* items, int nitems, int imin, int imax, int& curNode, dtStatBVNode* nodes)
{
int inum = imax - imin;
int icur = curNode;
dtBVNode& node = nodes[curNode++];
dtStatBVNode& node = nodes[curNode++];
if (inum == 1)
{
@@ -163,7 +163,7 @@ void subdivide(BVItem* items, int nitems, int imin, int imax, int& curNode, dtBV
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, dtBVNode* nodes)
int nnodes, dtStatBVNode* nodes)
{
// Build tree
BVItem* items = new BVItem[npolys];
@@ -211,7 +211,7 @@ bool dtCreateNavMeshData(const unsigned short* verts, const int nverts,
const float* bmin, const float* bmax, float cs, float ch,
unsigned char** outData, int* outDataSize)
{
if (nvp != DT_VERTS_PER_POLYGON)
if (nvp != DT_STAT_VERTS_PER_POLYGON)
return false;
if (nverts >= 0xffff)
return false;
@@ -224,8 +224,8 @@ bool dtCreateNavMeshData(const unsigned short* verts, const int nverts,
// Calculate data size
const int headerSize = sizeof(dtStatNavMeshHeader);
const int vertsSize = sizeof(float)*3*nverts;
const int polysSize = sizeof(dtPoly)*npolys;
const int nodesSize = sizeof(dtBVNode)*npolys*2;
const int polysSize = sizeof(dtStatPoly)*npolys;
const int nodesSize = sizeof(dtStatBVNode)*npolys*2;
const int dataSize = headerSize + vertsSize + polysSize + nodesSize;
unsigned char* data = new unsigned char[dataSize];
@@ -235,12 +235,12 @@ bool dtCreateNavMeshData(const unsigned short* verts, const int nverts,
dtStatNavMeshHeader* header = (dtStatNavMeshHeader*)(data);
float* navVerts = (float*)(data + headerSize);
dtPoly* navPolys = (dtPoly*)(data + headerSize + vertsSize);
dtBVNode* nodes = (dtBVNode*)(data + headerSize + vertsSize + polysSize);
dtStatPoly* navPolys = (dtStatPoly*)(data + headerSize + vertsSize);
dtStatBVNode* nodes = (dtStatBVNode*)(data + headerSize + vertsSize + polysSize);
// Store header
header->magic = DT_NAVMESH_MAGIC;
header->version = DT_NAVMESH_VERSION;
header->magic = DT_STAT_NAVMESH_MAGIC;
header->version = DT_STAT_NAVMESH_VERSION;
header->npolys = npolys;
header->nverts = nverts;
header->cs = cs;
@@ -265,7 +265,7 @@ bool dtCreateNavMeshData(const unsigned short* verts, const int nverts,
const unsigned short* src = polys;
for (int i = 0; i < npolys; ++i)
{
dtPoly* p = &navPolys[i];
dtStatPoly* p = &navPolys[i];
p->nv = 0;
for (int j = 0; j < nvp; ++j)
{

View File

@@ -291,6 +291,14 @@ void rcMarkWalkableTriangles(const float walkableSlopeAngle,
const int* tris, int nt,
unsigned char* flags);
// Rasterizes a triangle into heightfield spans.
// Params:
// v0,v1,v2 - (in) the vertices of the triangle.
// flags - (in) triangle flags (uses WALKABLE)
// solid - (in) heighfield where the triangle is rasterized
void rcRasterizeTriangle(const float* v0, const float* v1, const float* v2,
unsigned char flags, rcHeightfield& solid);
// Rasterizes the triangles into heightfield spans.
// Params:
// verts - (in) array of vertices

View File

@@ -268,6 +268,21 @@ static void rasterizeTri(const float* v0, const float* v1, const float* v2,
}
}
void rcRasterizeTriangle(const float* v0, const float* v1, const float* v2,
unsigned char flags, rcHeightfield& solid)
{
rcTimeVal startTime = rcGetPerformanceTimer();
const float ics = 1.0f/solid.cs;
const float ich = 1.0f/solid.ch;
rasterizeTri(v0, v1, v2, flags, solid, solid.bmin, solid.bmax, solid.cs, ics, ich);
rcTimeVal endTime = rcGetPerformanceTimer();
if (rcGetBuildTimes())
rcGetBuildTimes()->rasterizeTriangles += rcGetDeltaTimeUsec(startTime, endTime);
}
void rcRasterizeTriangles(const float* verts, int nv,
const int* tris, const unsigned char* flags, int nt,
rcHeightfield& solid)
@@ -287,9 +302,6 @@ void rcRasterizeTriangles(const float* verts, int nv,
}
rcTimeVal endTime = rcGetPerformanceTimer();
// if (rcGetLog())
// rcGetLog()->log(RC_LOG_PROGRESS, "Rasterize: %.3f ms", rcGetDeltaTimeUsec(startTime, endTime)/1000.0f);
if (rcGetBuildTimes())
rcGetBuildTimes()->rasterizeTriangles += rcGetDeltaTimeUsec(startTime, endTime);

BIN
RecastDemo/Bin/DroidSans.ttf Executable file

Binary file not shown.

Binary file not shown.

File diff suppressed because it is too large Load Diff

View File

@@ -268,8 +268,7 @@
<array>
<string>29B97314FDCFA39411CA2CEA</string>
<string>080E96DDFE201D6D7F000001</string>
<string>6BDD9E030F91110C00904EEF</string>
<string>6B137C7D0F7FCBE800459200</string>
<string>6B555DF5100B25FC00247EA3</string>
<string>29B97315FDCFA39411CA2CEA</string>
<string>29B97317FDCFA39411CA2CEA</string>
<string>1C37FBAC04509CD000000102</string>
@@ -278,13 +277,13 @@
<key>PBXSmartGroupTreeModuleOutlineStateSelectionKey</key>
<array>
<array>
<integer>52</integer>
<integer>50</integer>
<integer>16</integer>
<integer>1</integer>
<integer>0</integer>
</array>
</array>
<key>PBXSmartGroupTreeModuleOutlineStateVisibleRectKey</key>
<string>{{0, 492}, {282, 660}}</string>
<string>{{0, 0}, {282, 628}}</string>
</dict>
<key>PBXTopSmartGroupGIDs</key>
<array/>
@@ -294,14 +293,14 @@
<key>GeometryConfiguration</key>
<dict>
<key>Frame</key>
<string>{{0, 0}, {299, 678}}</string>
<string>{{0, 0}, {299, 646}}</string>
<key>GroupTreeTableConfiguration</key>
<array>
<string>MainColumn</string>
<real>282</real>
</array>
<key>RubberWindowFrame</key>
<string>0 59 1280 719 0 0 1280 778 </string>
<string>0 91 1280 687 0 0 1280 778 </string>
</dict>
<key>Module</key>
<string>PBXSmartGroupTreeModule</string>
@@ -312,12 +311,14 @@
<key>Dock</key>
<array>
<dict>
<key>BecomeActive</key>
<true/>
<key>ContentConfiguration</key>
<dict>
<key>PBXProjectModuleGUID</key>
<string>6B8632A30F78115100E2684A</string>
<key>PBXProjectModuleLabel</key>
<string>Info.plist</string>
<string>main.cpp</string>
<key>PBXSplitModuleInNavigatorKey</key>
<dict>
<key>Split0</key>
@@ -325,65 +326,73 @@
<key>PBXProjectModuleGUID</key>
<string>6B8632A40F78115100E2684A</string>
<key>PBXProjectModuleLabel</key>
<string>Info.plist</string>
<string>main.cpp</string>
<key>_historyCapacity</key>
<integer>0</integer>
<key>bookmark</key>
<string>6B024C051006098300CF7107</string>
<string>6B555F02100B431000247EA3</string>
<key>history</key>
<array>
<string>6BB87E0B0F9DE8A300E33F12</string>
<string>6B7707F00FBD90F100D21BAE</string>
<string>6BB7876B0FC03EAD003C24DB</string>
<string>6BB85D3A0FCEAA6300758966</string>
<string>6B8A71F40FDAB52200A0A6FB</string>
<string>6B995BDF0FE0D9B300D5C493</string>
<string>6B6BC6CA0FE7A3A4009E3CB9</string>
<string>6BC745A70FF527E50083A694</string>
<string>6BC745A80FF527E50083A694</string>
<string>6B9B7D9D0FF91AC600A9090F</string>
<string>6B25B3A60FFA124D004F1BC4</string>
<string>6B25B43E0FFA1786004F1BC4</string>
<string>6B25B44B0FFA1968004F1BC4</string>
<string>6B25B4710FFA1FE0004F1BC4</string>
<string>6B25B54F0FFA5899004F1BC4</string>
<string>6B2AEC5C0FFB8AB0005BE9CC</string>
<string>6B2AEC610FFB8AB0005BE9CC</string>
<string>6B2AEC620FFB8AB0005BE9CC</string>
<string>6B2AEC670FFB8AB0005BE9CC</string>
<string>6B2AEC6F0FFB8AB0005BE9CC</string>
<string>6B2AECED0FFB8B41005BE9CC</string>
<string>6B2AECEE0FFB8B41005BE9CC</string>
<string>6B2AECEF0FFB8B41005BE9CC</string>
<string>6B2AECF80FFB9075005BE9CC</string>
<string>6B2AECF90FFB9075005BE9CC</string>
<string>6B2AED8E0FFBA45B005BE9CC</string>
<string>6B2AEDA00FFBA507005BE9CC</string>
<string>6B092B4F0FFCA0A20088D3A5</string>
<string>6B092B500FFCA0A20088D3A5</string>
<string>6B092BB50FFCEC1A0088D3A5</string>
<string>6B092BB70FFCEC1A0088D3A5</string>
<string>6B092C5F0FFCFF790088D3A5</string>
<string>6B092CC10FFE40160088D3A5</string>
<string>6B02497E1003751300CF7107</string>
<string>6B0249821003751300CF7107</string>
<string>6B02499F1003766D00CF7107</string>
<string>6B0249BE1003793900CF7107</string>
<string>6B024ACE1004AC8D00CF7107</string>
<string>6B024B391004CCCC00CF7107</string>
<string>6B024BA81005DC3A00CF7107</string>
<string>6B024BB81005DF5700CF7107</string>
<string>6B024BB91005DF5700CF7107</string>
<string>6B024BCA1005DFAB00CF7107</string>
<string>6B024BD31006059C00CF7107</string>
<string>6B024BD41006059C00CF7107</string>
<string>6B024BD51006059C00CF7107</string>
<string>6B024BD61006059C00CF7107</string>
<string>6B024BD71006059C00CF7107</string>
<string>6B024BEB1006064C00CF7107</string>
<string>6B024C001006098300CF7107</string>
<string>6B024C011006098300CF7107</string>
<string>6B024C021006098300CF7107</string>
<string>6B024C1110060C7600CF7107</string>
<string>6B1186211006945C0018F96F</string>
<string>6B1186231006945C0018F96F</string>
<string>6B1186241006945C0018F96F</string>
<string>6B1186251006945C0018F96F</string>
<string>6B1186A1100698B70018F96F</string>
<string>6B1186CD100699A00018F96F</string>
<string>6B1186CE100699A00018F96F</string>
<string>6B1186CF100699A00018F96F</string>
<string>6B1186D0100699A00018F96F</string>
<string>6B1186D1100699A00018F96F</string>
<string>6B1186D2100699A00018F96F</string>
<string>6B1186E610069E200018F96F</string>
<string>6B7EBB69100721310066EF8C</string>
<string>6B8EF40C1007653C003F8851</string>
<string>6B555D23100B136A00247EA3</string>
<string>6B555D24100B136A00247EA3</string>
<string>6B555D2F100B143200247EA3</string>
<string>6B555D30100B143200247EA3</string>
<string>6B555E01100B285300247EA3</string>
<string>6B555E04100B285300247EA3</string>
<string>6B555E5F100B334900247EA3</string>
<string>6B555E60100B334900247EA3</string>
<string>6B555E79100B350E00247EA3</string>
<string>6B555E7B100B350E00247EA3</string>
<string>6B555E7C100B350E00247EA3</string>
<string>6B555E8A100B35E000247EA3</string>
<string>6B555E9D100B37AB00247EA3</string>
<string>6B555E9E100B37AB00247EA3</string>
<string>6B555E9F100B37AB00247EA3</string>
<string>6B555EA1100B37AB00247EA3</string>
<string>6B555EA2100B37AB00247EA3</string>
<string>6B555EA3100B37AB00247EA3</string>
<string>6B555EA4100B37AB00247EA3</string>
<string>6B555EDE100B39A600247EA3</string>
<string>6B555EF6100B42E600247EA3</string>
<string>6B555EF7100B42E600247EA3</string>
<string>6B555EF8100B42E600247EA3</string>
</array>
<key>prevStack</key>
<array>
@@ -395,7 +404,6 @@
<string>6BB87E0E0F9DE8A300E33F12</string>
<string>6B458EA80FB4540500044EA9</string>
<string>6B7707B90FBD66CF00D21BAE</string>
<string>6B7707F70FBD90F100D21BAE</string>
<string>6B7707F90FBD90F100D21BAE</string>
<string>6B7708F70FBDA96300D21BAE</string>
<string>6BB787C30FC03EAD003C24DB</string>
@@ -414,119 +422,174 @@
<string>6B25B4080FFA13E9004F1BC4</string>
<string>6B25B56D0FFA5899004F1BC4</string>
<string>6B25B6250FFA63C8004F1BC4</string>
<string>6B2AEC730FFB8AB0005BE9CC</string>
<string>6B2AEC740FFB8AB0005BE9CC</string>
<string>6B2AEC750FFB8AB0005BE9CC</string>
<string>6B2AECB50FFB8AB0005BE9CC</string>
<string>6B2AECE10FFB8AB0005BE9CC</string>
<string>6B2AED930FFBA45B005BE9CC</string>
<string>6B2AED940FFBA45B005BE9CC</string>
<string>6B092B1A0FFC98FF0088D3A5</string>
<string>6B092B530FFCA0A20088D3A5</string>
<string>6B092BBC0FFCEC1A0088D3A5</string>
<string>6B092BEB0FFCEC1A0088D3A5</string>
<string>6B092BED0FFCEC1A0088D3A5</string>
<string>6B2AEC970FFB8AB0005BE9CC</string>
<string>6B0248B81001E4FE00CF7107</string>
<string>6B0248D51001E64300CF7107</string>
<string>6B0248E21001E7F200CF7107</string>
<string>6B0248FE1001EABD00CF7107</string>
<string>6B0249051001EABD00CF7107</string>
<string>6B02493E1002118200CF7107</string>
<string>6B0249841003751300CF7107</string>
<string>6B0249861003751300CF7107</string>
<string>6B0249871003751300CF7107</string>
<string>6B0249881003751300CF7107</string>
<string>6B0249891003751300CF7107</string>
<string>6B02498C1003751300CF7107</string>
<string>6B02498D1003751300CF7107</string>
<string>6B02498E1003751300CF7107</string>
<string>6B0249901003751300CF7107</string>
<string>6B024995100375AF00CF7107</string>
<string>6B024996100375AF00CF7107</string>
<string>6B024997100375AF00CF7107</string>
<string>6B02499C1003762100CF7107</string>
<string>6B0249A11003766D00CF7107</string>
<string>6B0249AA1003774A00CF7107</string>
<string>6B0249C11003793900CF7107</string>
<string>6B0249F910037CFB00CF7107</string>
<string>6B024A0410037DB300CF7107</string>
<string>6B024A0510037DB300CF7107</string>
<string>6B024A0610037DB300CF7107</string>
<string>6B024A0710037DB300CF7107</string>
<string>6B024A0810037DB300CF7107</string>
<string>6B024A0D10037DB300CF7107</string>
<string>6B024A2910037F3100CF7107</string>
<string>6B024A4B1004806000CF7107</string>
<string>6B024A721004A2FE00CF7107</string>
<string>6B024AAE1004A83400CF7107</string>
<string>6B024AAF1004A83400CF7107</string>
<string>6B024ABA1004A95900CF7107</string>
<string>6B024ABB1004A95900CF7107</string>
<string>6B024AD01004AC8D00CF7107</string>
<string>6B024AE91004B12B00CF7107</string>
<string>6B024AEC1004B12B00CF7107</string>
<string>6B024B011004C41E00CF7107</string>
<string>6B024B111004C7E200CF7107</string>
<string>6B024B151004C7E200CF7107</string>
<string>6B024B181004C7E200CF7107</string>
<string>6B024B1A1004C7E200CF7107</string>
<string>6B024B1B1004C7E200CF7107</string>
<string>6B024B1D1004C7E200CF7107</string>
<string>6B024B1F1004C7E200CF7107</string>
<string>6B024B281004CC4800CF7107</string>
<string>6B024B2A1004CC4800CF7107</string>
<string>6B024B2C1004CC4800CF7107</string>
<string>6B024B341004CC8700CF7107</string>
<string>6B024B3C1004CCCC00CF7107</string>
<string>6B024B4C1004D22F00CF7107</string>
<string>6B024B4E1004D22F00CF7107</string>
<string>6B024B501004D22F00CF7107</string>
<string>6B024B521004D22F00CF7107</string>
<string>6B024B5B1005D2CB00CF7107</string>
<string>6B024B5D1005D2CB00CF7107</string>
<string>6B024B5F1005D2CB00CF7107</string>
<string>6B024B691005D68E00CF7107</string>
<string>6B024B6B1005D68E00CF7107</string>
<string>6B024B6D1005D68E00CF7107</string>
<string>6B024B6F1005D68E00CF7107</string>
<string>6B024B711005D68E00CF7107</string>
<string>6B024B731005D68E00CF7107</string>
<string>6B024B751005D68E00CF7107</string>
<string>6B024B7C1005D6EC00CF7107</string>
<string>6B024B831005D76000CF7107</string>
<string>6B024B851005D76000CF7107</string>
<string>6B024B931005D98C00CF7107</string>
<string>6B024B951005D98C00CF7107</string>
<string>6B024B971005D98C00CF7107</string>
<string>6B024B9A1005D98C00CF7107</string>
<string>6B024BAB1005DC3A00CF7107</string>
<string>6B024BAC1005DC3A00CF7107</string>
<string>6B024BAD1005DC3A00CF7107</string>
<string>6B024BAE1005DC3A00CF7107</string>
<string>6B024BBB1005DF5700CF7107</string>
<string>6B024BBC1005DF5700CF7107</string>
<string>6B024BBD1005DF5700CF7107</string>
<string>6B024BBE1005DF5700CF7107</string>
<string>6B024BBF1005DF5700CF7107</string>
<string>6B024BC01005DF5700CF7107</string>
<string>6B024BC11005DF5700CF7107</string>
<string>6B024BC21005DF5700CF7107</string>
<string>6B024BC31005DF5700CF7107</string>
<string>6B024BCD1005DFAB00CF7107</string>
<string>6B024BCE1005DFAB00CF7107</string>
<string>6B024BCF1005DFAB00CF7107</string>
<string>6B024BDA1006059C00CF7107</string>
<string>6B024BDB1006059C00CF7107</string>
<string>6B024BDC1006059C00CF7107</string>
<string>6B024BDD1006059C00CF7107</string>
<string>6B024BDE1006059C00CF7107</string>
<string>6B024BDF1006059C00CF7107</string>
<string>6B024BE01006059C00CF7107</string>
<string>6B024BED1006064C00CF7107</string>
<string>6B024BEE1006064C00CF7107</string>
<string>6B024C031006098300CF7107</string>
<string>6B024C041006098300CF7107</string>
<string>6B024C1310060C7600CF7107</string>
<string>6B11862D1006945C0018F96F</string>
<string>6B1186301006945C0018F96F</string>
<string>6B1186311006945C0018F96F</string>
<string>6B1186401006945C0018F96F</string>
<string>6B1186411006945C0018F96F</string>
<string>6B1186581006945C0018F96F</string>
<string>6B1186591006945C0018F96F</string>
<string>6B118672100694C40018F96F</string>
<string>6B555D15100B125300247EA3</string>
<string>6B555D26100B136A00247EA3</string>
<string>6B555D27100B136A00247EA3</string>
<string>6B555D28100B136A00247EA3</string>
<string>6B555D29100B136A00247EA3</string>
<string>6B555D32100B143200247EA3</string>
<string>6B555D47100B175F00247EA3</string>
<string>6B555D48100B175F00247EA3</string>
<string>6B555D49100B175F00247EA3</string>
<string>6B555D4A100B175F00247EA3</string>
<string>6B555D4B100B175F00247EA3</string>
<string>6B555D4C100B175F00247EA3</string>
<string>6B555D4D100B175F00247EA3</string>
<string>6B555D4E100B175F00247EA3</string>
<string>6B555D4F100B175F00247EA3</string>
<string>6B555D50100B175F00247EA3</string>
<string>6B555D53100B175F00247EA3</string>
<string>6B555D54100B175F00247EA3</string>
<string>6B555D55100B175F00247EA3</string>
<string>6B555D5D100B17DB00247EA3</string>
<string>6B555D5E100B17DB00247EA3</string>
<string>6B555D5F100B17DB00247EA3</string>
<string>6B555D60100B17DB00247EA3</string>
<string>6B555D66100B185A00247EA3</string>
<string>6B555D71100B18EA00247EA3</string>
<string>6B555D73100B18EA00247EA3</string>
<string>6B555D74100B18EA00247EA3</string>
<string>6B555D83100B1A5200247EA3</string>
<string>6B555D85100B1A5200247EA3</string>
<string>6B555D86100B1A5200247EA3</string>
<string>6B555D94100B1B6900247EA3</string>
<string>6B555D96100B1B6900247EA3</string>
<string>6B555D97100B1B6900247EA3</string>
<string>6B555D9E100B1C2400247EA3</string>
<string>6B555DA0100B1C2400247EA3</string>
<string>6B555DAB100B1E6500247EA3</string>
<string>6B555DC3100B236A00247EA3</string>
<string>6B555DC4100B236A00247EA3</string>
<string>6B555DC5100B236A00247EA3</string>
<string>6B555DC6100B236A00247EA3</string>
<string>6B555DC7100B236A00247EA3</string>
<string>6B555DC8100B236A00247EA3</string>
<string>6B555DC9100B236A00247EA3</string>
<string>6B555DCB100B236A00247EA3</string>
<string>6B555DCC100B236A00247EA3</string>
<string>6B555DCD100B236A00247EA3</string>
<string>6B555DCF100B236A00247EA3</string>
<string>6B555DD1100B236A00247EA3</string>
<string>6B555DD3100B236A00247EA3</string>
<string>6B555DD4100B236A00247EA3</string>
<string>6B555DD5100B236A00247EA3</string>
<string>6B555DD6100B236A00247EA3</string>
<string>6B555DD7100B236A00247EA3</string>
<string>6B555DD8100B236A00247EA3</string>
<string>6B555DD9100B236A00247EA3</string>
<string>6B555DDA100B236A00247EA3</string>
<string>6B555DDB100B236A00247EA3</string>
<string>6B555DDD100B236A00247EA3</string>
<string>6B555DDF100B236A00247EA3</string>
<string>6B555DE0100B236A00247EA3</string>
<string>6B555DE2100B236A00247EA3</string>
<string>6B555DE4100B236A00247EA3</string>
<string>6B555DE6100B236A00247EA3</string>
<string>6B555DE8100B236A00247EA3</string>
<string>6B555DEA100B236A00247EA3</string>
<string>6B555DEC100B236A00247EA3</string>
<string>6B555DED100B236A00247EA3</string>
<string>6B555DF2100B25B900247EA3</string>
<string>6B555E08100B285300247EA3</string>
<string>6B555E09100B285300247EA3</string>
<string>6B555E0A100B285300247EA3</string>
<string>6B555E0B100B285300247EA3</string>
<string>6B555E0C100B285300247EA3</string>
<string>6B555E0D100B285300247EA3</string>
<string>6B555E0E100B285300247EA3</string>
<string>6B555E0F100B285300247EA3</string>
<string>6B555E10100B285300247EA3</string>
<string>6B555E11100B285300247EA3</string>
<string>6B555E12100B285300247EA3</string>
<string>6B555E13100B285300247EA3</string>
<string>6B555E15100B285300247EA3</string>
<string>6B555E18100B285300247EA3</string>
<string>6B555E1B100B285300247EA3</string>
<string>6B555E20100B2D9800247EA3</string>
<string>6B555E22100B2D9800247EA3</string>
<string>6B555E45100B311B00247EA3</string>
<string>6B555E46100B311B00247EA3</string>
<string>6B555E47100B311B00247EA3</string>
<string>6B555E48100B311B00247EA3</string>
<string>6B555E49100B311B00247EA3</string>
<string>6B555E4A100B311B00247EA3</string>
<string>6B555E4B100B311B00247EA3</string>
<string>6B555E4C100B311B00247EA3</string>
<string>6B555E4D100B311B00247EA3</string>
<string>6B555E4E100B311B00247EA3</string>
<string>6B555E4F100B311B00247EA3</string>
<string>6B555E50100B311B00247EA3</string>
<string>6B555E51100B311B00247EA3</string>
<string>6B555E52100B311B00247EA3</string>
<string>6B555E53100B311B00247EA3</string>
<string>6B555E54100B311B00247EA3</string>
<string>6B555E55100B311B00247EA3</string>
<string>6B555E56100B311B00247EA3</string>
<string>6B555E57100B311B00247EA3</string>
<string>6B555E67100B334900247EA3</string>
<string>6B555E68100B334900247EA3</string>
<string>6B555E69100B334900247EA3</string>
<string>6B555E6A100B334900247EA3</string>
<string>6B555E6B100B334900247EA3</string>
<string>6B555E6C100B334900247EA3</string>
<string>6B555E6D100B334900247EA3</string>
<string>6B555E6E100B334900247EA3</string>
<string>6B555E6F100B334900247EA3</string>
<string>6B555E70100B334900247EA3</string>
<string>6B555E71100B334900247EA3</string>
<string>6B555E72100B334900247EA3</string>
<string>6B555E73100B334900247EA3</string>
<string>6B555E74100B334900247EA3</string>
<string>6B555E75100B334900247EA3</string>
<string>6B555E76100B334900247EA3</string>
<string>6B555E7F100B350E00247EA3</string>
<string>6B555E80100B350E00247EA3</string>
<string>6B555E81100B350E00247EA3</string>
<string>6B555E82100B350E00247EA3</string>
<string>6B555E83100B350E00247EA3</string>
<string>6B555E84100B350E00247EA3</string>
<string>6B555E85100B350E00247EA3</string>
<string>6B555E8C100B35E000247EA3</string>
<string>6B555EA6100B37AB00247EA3</string>
<string>6B555EA7100B37AB00247EA3</string>
<string>6B555EA8100B37AB00247EA3</string>
<string>6B555EA9100B37AB00247EA3</string>
<string>6B555EAA100B37AB00247EA3</string>
<string>6B555EAB100B37AB00247EA3</string>
<string>6B555EAC100B37AB00247EA3</string>
<string>6B555EAF100B37AB00247EA3</string>
<string>6B555EB1100B37AB00247EA3</string>
<string>6B555EB2100B37AB00247EA3</string>
<string>6B555EB3100B37AB00247EA3</string>
<string>6B555EB4100B37AB00247EA3</string>
<string>6B555EE0100B39A600247EA3</string>
<string>6B555EF9100B42E600247EA3</string>
<string>6B555EFA100B42E600247EA3</string>
<string>6B555EFB100B42E600247EA3</string>
</array>
</dict>
<key>SplitCount</key>
@@ -540,18 +603,18 @@
<key>GeometryConfiguration</key>
<dict>
<key>Frame</key>
<string>{{0, 0}, {976, 531}}</string>
<string>{{0, 0}, {976, 443}}</string>
<key>RubberWindowFrame</key>
<string>0 59 1280 719 0 0 1280 778 </string>
<string>0 91 1280 687 0 0 1280 778 </string>
</dict>
<key>Module</key>
<string>PBXNavigatorGroup</string>
<key>Proportion</key>
<string>531pt</string>
<string>443pt</string>
</dict>
<dict>
<key>Proportion</key>
<string>142pt</string>
<string>198pt</string>
<key>Tabs</key>
<array>
<dict>
@@ -565,7 +628,7 @@
<key>GeometryConfiguration</key>
<dict>
<key>Frame</key>
<string>{{10, 27}, {976, 83}}</string>
<string>{{10, 27}, {976, -27}}</string>
</dict>
<key>Module</key>
<string>XCDetailModule</string>
@@ -581,7 +644,7 @@
<key>GeometryConfiguration</key>
<dict>
<key>Frame</key>
<string>{{10, 27}, {976, 99}}</string>
<string>{{10, 27}, {976, 244}}</string>
</dict>
<key>Module</key>
<string>PBXProjectFindModule</string>
@@ -605,8 +668,6 @@
<string>PBXCVSModule</string>
</dict>
<dict>
<key>BecomeActive</key>
<true/>
<key>ContentConfiguration</key>
<dict>
<key>PBXProjectModuleGUID</key>
@@ -621,9 +682,9 @@
<key>GeometryConfiguration</key>
<dict>
<key>Frame</key>
<string>{{10, 27}, {976, 115}}</string>
<string>{{10, 27}, {976, 171}}</string>
<key>RubberWindowFrame</key>
<string>0 59 1280 719 0 0 1280 778 </string>
<string>0 91 1280 687 0 0 1280 778 </string>
</dict>
<key>Module</key>
<string>PBXBuildResultsModule</string>
@@ -651,11 +712,11 @@
</array>
<key>TableOfContents</key>
<array>
<string>6B0248C51001E53600CF7107</string>
<string>6B555D17100B125300247EA3</string>
<string>1CA23ED40692098700951B8B</string>
<string>6B0248C61001E53600CF7107</string>
<string>6B555D18100B125300247EA3</string>
<string>6B8632A30F78115100E2684A</string>
<string>6B0248C71001E53600CF7107</string>
<string>6B555D19100B125300247EA3</string>
<string>1CA23EDF0692099D00951B8B</string>
<string>1CA23EE00692099D00951B8B</string>
<string>1CA23EE10692099D00951B8B</string>
@@ -704,12 +765,12 @@
<key>GeometryConfiguration</key>
<dict>
<key>Frame</key>
<string>{{0, 0}, {1280, 254}}</string>
<string>{{0, 0}, {1280, 242}}</string>
</dict>
<key>Module</key>
<string>PBXDebugCLIModule</string>
<key>Proportion</key>
<string>254pt</string>
<string>242pt</string>
</dict>
<dict>
<key>ContentConfiguration</key>
@@ -728,8 +789,8 @@
<string>yes</string>
<key>sizes</key>
<array>
<string>{{0, 0}, {637, 115}}</string>
<string>{{637, 0}, {643, 115}}</string>
<string>{{0, 0}, {637, 110}}</string>
<string>{{637, 0}, {643, 110}}</string>
</array>
</dict>
<key>VerticalSplitView</key>
@@ -744,8 +805,8 @@
<string>yes</string>
<key>sizes</key>
<array>
<string>{{0, 0}, {1280, 115}}</string>
<string>{{0, 115}, {1280, 304}}</string>
<string>{{0, 0}, {1280, 110}}</string>
<string>{{0, 110}, {1280, 289}}</string>
</array>
</dict>
</dict>
@@ -765,7 +826,7 @@
<key>DebugSTDIOWindowFrame</key>
<string>{{200, 200}, {500, 300}}</string>
<key>Frame</key>
<string>{{0, 259}, {1280, 419}}</string>
<string>{{0, 247}, {1280, 399}}</string>
<key>PBXDebugSessionStackFrameViewKey</key>
<dict>
<key>DebugVariablesTableConfiguration</key>
@@ -778,13 +839,13 @@
<real>413</real>
</array>
<key>Frame</key>
<string>{{637, 0}, {643, 115}}</string>
<string>{{637, 0}, {643, 110}}</string>
</dict>
</dict>
<key>Module</key>
<string>PBXDebugSessionModule</string>
<key>Proportion</key>
<string>419pt</string>
<string>399pt</string>
</dict>
</array>
<key>Name</key>
@@ -802,14 +863,14 @@
</array>
<key>TableOfContents</key>
<array>
<string>6B0248C81001E53600CF7107</string>
<string>6B555D1A100B125300247EA3</string>
<string>1CCC7628064C1048000F2A68</string>
<string>1CCC7629064C1048000F2A68</string>
<string>6B0248C91001E53600CF7107</string>
<string>6B0248CA1001E53600CF7107</string>
<string>6B0248CB1001E53600CF7107</string>
<string>6B0248CC1001E53600CF7107</string>
<string>6B8632A30F78115100E2684A</string>
<string>6B555D1B100B125300247EA3</string>
<string>6B555D1C100B125300247EA3</string>
<string>6B555D1D100B125300247EA3</string>
<string>6B555D1E100B125300247EA3</string>
<string>6B555D1F100B125300247EA3</string>
</array>
<key>ToolbarConfiguration</key>
<string>xcode.toolbar.config.debugV3</string>
@@ -839,13 +900,10 @@
<integer>5</integer>
<key>WindowOrderList</key>
<array>
<string>6B024C061006098300CF7107</string>
<string>6B0248CD1001E53600CF7107</string>
<string>6B0248CE1001E53600CF7107</string>
<string>/Users/memon/Code/recastnavigation/RecastDemo/Build/Xcode/Recast.xcodeproj</string>
</array>
<key>WindowString</key>
<string>0 59 1280 719 0 0 1280 778 </string>
<string>0 91 1280 687 0 0 1280 778 </string>
<key>WindowToolsV3</key>
<array>
<dict>

View File

@@ -9,8 +9,9 @@
/* Begin PBXBuildFile section */
1DDD58160DA1D0A300B32029 /* MainMenu.xib in Resources */ = {isa = PBXBuildFile; fileRef = 1DDD58140DA1D0A300B32029 /* MainMenu.xib */; };
6B024C0D10060AC600CF7107 /* Icon.icns in Resources */ = {isa = PBXBuildFile; fileRef = 6B024C0C10060AC600CF7107 /* Icon.icns */; };
6B092B940FFCC2BD0088D3A5 /* DetourTiledNavMeshBuilder.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 6B092B930FFCC2BD0088D3A5 /* DetourTiledNavMeshBuilder.cpp */; };
6B137C700F7FCBBB00459200 /* glfont.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 6B137C6B0F7FCBBB00459200 /* glfont.cpp */; };
6B092B940FFCC2BD0088D3A5 /* DetourTileNavMeshBuilder.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 6B092B930FFCC2BD0088D3A5 /* DetourTileNavMeshBuilder.cpp */; };
6B1185F51006895B0018F96F /* DetourNode.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 6B1185F41006895B0018F96F /* DetourNode.cpp */; };
6B1185FE10068B150018F96F /* DetourCommon.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 6B1185FD10068B150018F96F /* DetourCommon.cpp */; };
6B137C710F7FCBBB00459200 /* imgui.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 6B137C6C0F7FCBBB00459200 /* imgui.cpp */; };
6B137C720F7FCBBB00459200 /* MeshLoaderObj.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 6B137C6D0F7FCBBB00459200 /* MeshLoaderObj.cpp */; };
6B137C730F7FCBBB00459200 /* SDLMain.m in Sources */ = {isa = PBXBuildFile; fileRef = 6B137C6E0F7FCBBB00459200 /* SDLMain.m */; };
@@ -23,13 +24,14 @@
6B137C910F7FCC1100459200 /* RecastRasterization.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 6B137C880F7FCC1100459200 /* RecastRasterization.cpp */; };
6B137C920F7FCC1100459200 /* RecastRegion.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 6B137C890F7FCC1100459200 /* RecastRegion.cpp */; };
6B137C930F7FCC1100459200 /* RecastTimer.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 6B137C8A0F7FCC1100459200 /* RecastTimer.cpp */; };
6B25B6190FFA62BE004F1BC4 /* Builder.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 6B25B6140FFA62BE004F1BC4 /* Builder.cpp */; };
6B25B61A0FFA62BE004F1BC4 /* BuilderStatMesh.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 6B25B6150FFA62BE004F1BC4 /* BuilderStatMesh.cpp */; };
6B25B61B0FFA62BE004F1BC4 /* BuilderStatMeshSimple.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 6B25B6160FFA62BE004F1BC4 /* BuilderStatMeshSimple.cpp */; };
6B25B6190FFA62BE004F1BC4 /* Sample.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 6B25B6140FFA62BE004F1BC4 /* Sample.cpp */; };
6B25B61A0FFA62BE004F1BC4 /* Sample_StatMesh.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 6B25B6150FFA62BE004F1BC4 /* Sample_StatMesh.cpp */; };
6B25B61B0FFA62BE004F1BC4 /* Sample_StatMeshSimple.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 6B25B6160FFA62BE004F1BC4 /* Sample_StatMeshSimple.cpp */; };
6B25B61D0FFA62BE004F1BC4 /* main.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 6B25B6180FFA62BE004F1BC4 /* main.cpp */; };
6B2AEC530FFB8958005BE9CC /* BuilderTiledMesh.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 6B2AEC520FFB8958005BE9CC /* BuilderTiledMesh.cpp */; };
6B2AEC560FFB89E7005BE9CC /* BuilderStatMeshTiled.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 6B2AEC550FFB89E7005BE9CC /* BuilderStatMeshTiled.cpp */; };
6B2AEC5A0FFB8A7A005BE9CC /* DetourTiledNavMesh.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 6B2AEC590FFB8A7A005BE9CC /* DetourTiledNavMesh.cpp */; };
6B2AEC530FFB8958005BE9CC /* Sample_TileMesh.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 6B2AEC520FFB8958005BE9CC /* Sample_TileMesh.cpp */; };
6B2AEC560FFB89E7005BE9CC /* Sample_StatMeshTiled.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 6B2AEC550FFB89E7005BE9CC /* Sample_StatMeshTiled.cpp */; };
6B2AEC5A0FFB8A7A005BE9CC /* DetourTileNavMesh.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 6B2AEC590FFB8A7A005BE9CC /* DetourTileNavMesh.cpp */; };
6B555DB1100B212E00247EA3 /* imguiRenderGL.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 6B555DB0100B212E00247EA3 /* imguiRenderGL.cpp */; };
6B8632DA0F78122C00E2684A /* SDL.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 6B8632D90F78122C00E2684A /* SDL.framework */; };
6B8632DC0F78123E00E2684A /* OpenGL.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 6B8632DB0F78123E00E2684A /* OpenGL.framework */; };
6BB788170FC0472B003C24DB /* ChunkyTriMesh.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 6BB788160FC0472B003C24DB /* ChunkyTriMesh.cpp */; };
@@ -49,13 +51,15 @@
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>"; };
6B024C0C10060AC600CF7107 /* Icon.icns */ = {isa = PBXFileReference; lastKnownFileType = image.icns; path = Icon.icns; sourceTree = "<group>"; };
6B092B920FFCC2AC0088D3A5 /* DetourTiledNavMeshBuilder.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = DetourTiledNavMeshBuilder.h; path = ../../../Detour/Include/DetourTiledNavMeshBuilder.h; sourceTree = SOURCE_ROOT; };
6B092B930FFCC2BD0088D3A5 /* DetourTiledNavMeshBuilder.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = DetourTiledNavMeshBuilder.cpp; path = ../../../Detour/Source/DetourTiledNavMeshBuilder.cpp; sourceTree = SOURCE_ROOT; };
6B137C6B0F7FCBBB00459200 /* glfont.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = glfont.cpp; path = ../../Source/glfont.cpp; sourceTree = SOURCE_ROOT; };
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; };
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; };
6B1185FD10068B150018F96F /* DetourCommon.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = DetourCommon.cpp; path = ../../../Detour/Source/DetourCommon.cpp; sourceTree = SOURCE_ROOT; };
6B137C6C0F7FCBBB00459200 /* imgui.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = imgui.cpp; path = ../../Source/imgui.cpp; sourceTree = SOURCE_ROOT; };
6B137C6D0F7FCBBB00459200 /* MeshLoaderObj.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = MeshLoaderObj.cpp; path = ../../Source/MeshLoaderObj.cpp; sourceTree = SOURCE_ROOT; };
6B137C6E0F7FCBBB00459200 /* SDLMain.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = SDLMain.m; path = ../../Source/SDLMain.m; sourceTree = SOURCE_ROOT; };
6B137C790F7FCBE400459200 /* glfont.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = glfont.h; path = ../../Include/glfont.h; sourceTree = SOURCE_ROOT; };
6B137C7A0F7FCBE400459200 /* imgui.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = imgui.h; path = ../../Include/imgui.h; sourceTree = SOURCE_ROOT; };
6B137C7B0F7FCBE400459200 /* MeshLoaderObj.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = MeshLoaderObj.h; path = ../../Include/MeshLoaderObj.h; sourceTree = SOURCE_ROOT; };
6B137C7C0F7FCBE400459200 /* SDLMain.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = SDLMain.h; path = ../../Include/SDLMain.h; sourceTree = SOURCE_ROOT; };
@@ -72,19 +76,22 @@
6B137C880F7FCC1100459200 /* RecastRasterization.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = RecastRasterization.cpp; path = ../../../Recast/Source/RecastRasterization.cpp; sourceTree = SOURCE_ROOT; };
6B137C890F7FCC1100459200 /* RecastRegion.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = RecastRegion.cpp; path = ../../../Recast/Source/RecastRegion.cpp; sourceTree = SOURCE_ROOT; };
6B137C8A0F7FCC1100459200 /* RecastTimer.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = RecastTimer.cpp; path = ../../../Recast/Source/RecastTimer.cpp; sourceTree = SOURCE_ROOT; };
6B25B6100FFA62AD004F1BC4 /* Builder.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = Builder.h; path = ../../Include/Builder.h; sourceTree = SOURCE_ROOT; };
6B25B6110FFA62AD004F1BC4 /* BuilderStatMesh.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = BuilderStatMesh.h; path = ../../Include/BuilderStatMesh.h; sourceTree = SOURCE_ROOT; };
6B25B6120FFA62AD004F1BC4 /* BuilderStatMeshSimple.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = BuilderStatMeshSimple.h; path = ../../Include/BuilderStatMeshSimple.h; sourceTree = SOURCE_ROOT; };
6B25B6140FFA62BE004F1BC4 /* Builder.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = Builder.cpp; path = ../../Source/Builder.cpp; sourceTree = SOURCE_ROOT; };
6B25B6150FFA62BE004F1BC4 /* BuilderStatMesh.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = BuilderStatMesh.cpp; path = ../../Source/BuilderStatMesh.cpp; sourceTree = SOURCE_ROOT; };
6B25B6160FFA62BE004F1BC4 /* BuilderStatMeshSimple.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = BuilderStatMeshSimple.cpp; path = ../../Source/BuilderStatMeshSimple.cpp; sourceTree = SOURCE_ROOT; };
6B25B6100FFA62AD004F1BC4 /* Sample.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = Sample.h; path = ../../Include/Sample.h; sourceTree = SOURCE_ROOT; };
6B25B6110FFA62AD004F1BC4 /* Sample_StatMesh.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = Sample_StatMesh.h; path = ../../Include/Sample_StatMesh.h; sourceTree = SOURCE_ROOT; };
6B25B6120FFA62AD004F1BC4 /* Sample_StatMeshSimple.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = Sample_StatMeshSimple.h; path = ../../Include/Sample_StatMeshSimple.h; sourceTree = SOURCE_ROOT; };
6B25B6140FFA62BE004F1BC4 /* Sample.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = Sample.cpp; path = ../../Source/Sample.cpp; sourceTree = SOURCE_ROOT; };
6B25B6150FFA62BE004F1BC4 /* Sample_StatMesh.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = Sample_StatMesh.cpp; path = ../../Source/Sample_StatMesh.cpp; sourceTree = SOURCE_ROOT; };
6B25B6160FFA62BE004F1BC4 /* Sample_StatMeshSimple.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = Sample_StatMeshSimple.cpp; path = ../../Source/Sample_StatMeshSimple.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 /* BuilderTiledMesh.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = BuilderTiledMesh.h; path = ../../Include/BuilderTiledMesh.h; sourceTree = SOURCE_ROOT; };
6B2AEC520FFB8958005BE9CC /* BuilderTiledMesh.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = BuilderTiledMesh.cpp; path = ../../Source/BuilderTiledMesh.cpp; sourceTree = SOURCE_ROOT; };
6B2AEC550FFB89E7005BE9CC /* BuilderStatMeshTiled.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = BuilderStatMeshTiled.cpp; path = ../../Source/BuilderStatMeshTiled.cpp; sourceTree = SOURCE_ROOT; };
6B2AEC570FFB89F4005BE9CC /* BuilderStatMeshTiled.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = BuilderStatMeshTiled.h; path = ../../Include/BuilderStatMeshTiled.h; sourceTree = SOURCE_ROOT; };
6B2AEC580FFB8A68005BE9CC /* DetourTiledNavMesh.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = DetourTiledNavMesh.h; path = ../../../Detour/Include/DetourTiledNavMesh.h; sourceTree = SOURCE_ROOT; };
6B2AEC590FFB8A7A005BE9CC /* DetourTiledNavMesh.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = DetourTiledNavMesh.cpp; path = ../../../Detour/Source/DetourTiledNavMesh.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; };
6B2AEC520FFB8958005BE9CC /* Sample_TileMesh.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = Sample_TileMesh.cpp; path = ../../Source/Sample_TileMesh.cpp; sourceTree = SOURCE_ROOT; };
6B2AEC550FFB89E7005BE9CC /* Sample_StatMeshTiled.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = Sample_StatMeshTiled.cpp; path = ../../Source/Sample_StatMeshTiled.cpp; sourceTree = SOURCE_ROOT; };
6B2AEC570FFB89F4005BE9CC /* Sample_StatMeshTiled.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = Sample_StatMeshTiled.h; path = ../../Include/Sample_StatMeshTiled.h; 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; };
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; };
6B8632D90F78122C00E2684A /* SDL.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = SDL.framework; path = Library/Frameworks/SDL.framework; sourceTree = SDKROOT; };
6B8632DB0F78123E00E2684A /* OpenGL.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = OpenGL.framework; path = System/Library/Frameworks/OpenGL.framework; sourceTree = SDKROOT; };
6BB788160FC0472B003C24DB /* ChunkyTriMesh.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = ChunkyTriMesh.cpp; path = ../../Source/ChunkyTriMesh.cpp; sourceTree = SOURCE_ROOT; };
@@ -116,23 +123,15 @@
080E96DDFE201D6D7F000001 /* Classes */ = {
isa = PBXGroup;
children = (
6B555DF6100B273500247EA3 /* stb_truetype.h */,
6BDD9E030F91110C00904EEF /* Detour */,
6B137C7D0F7FCBE800459200 /* Recast */,
6B25B6100FFA62AD004F1BC4 /* Builder.h */,
6B25B6140FFA62BE004F1BC4 /* Builder.cpp */,
6B2AEC510FFB8946005BE9CC /* BuilderTiledMesh.h */,
6B2AEC520FFB8958005BE9CC /* BuilderTiledMesh.cpp */,
6B2AEC570FFB89F4005BE9CC /* BuilderStatMeshTiled.h */,
6B2AEC550FFB89E7005BE9CC /* BuilderStatMeshTiled.cpp */,
6B25B6110FFA62AD004F1BC4 /* BuilderStatMesh.h */,
6B25B6150FFA62BE004F1BC4 /* BuilderStatMesh.cpp */,
6B25B6120FFA62AD004F1BC4 /* BuilderStatMeshSimple.h */,
6B25B6160FFA62BE004F1BC4 /* BuilderStatMeshSimple.cpp */,
6B555DF5100B25FC00247EA3 /* Samples */,
6B25B6180FFA62BE004F1BC4 /* main.cpp */,
6B137C790F7FCBE400459200 /* glfont.h */,
6B137C6B0F7FCBBB00459200 /* glfont.cpp */,
6B137C7A0F7FCBE400459200 /* imgui.h */,
6B137C6C0F7FCBBB00459200 /* imgui.cpp */,
6B555DAE100B211D00247EA3 /* imguiRenderGL.h */,
6B555DB0100B212E00247EA3 /* imguiRenderGL.cpp */,
6B137C7B0F7FCBE400459200 /* MeshLoaderObj.h */,
6B137C6D0F7FCBBB00459200 /* MeshLoaderObj.cpp */,
6BB788180FC04753003C24DB /* ChunkyTriMesh.h */,
@@ -231,6 +230,23 @@
name = Recast;
sourceTree = "<group>";
};
6B555DF5100B25FC00247EA3 /* Samples */ = {
isa = PBXGroup;
children = (
6B25B6100FFA62AD004F1BC4 /* Sample.h */,
6B25B6140FFA62BE004F1BC4 /* Sample.cpp */,
6B2AEC510FFB8946005BE9CC /* Sample_TileMesh.h */,
6B2AEC520FFB8958005BE9CC /* Sample_TileMesh.cpp */,
6B2AEC570FFB89F4005BE9CC /* Sample_StatMeshTiled.h */,
6B2AEC550FFB89E7005BE9CC /* Sample_StatMeshTiled.cpp */,
6B25B6110FFA62AD004F1BC4 /* Sample_StatMesh.h */,
6B25B6150FFA62BE004F1BC4 /* Sample_StatMesh.cpp */,
6B25B6120FFA62AD004F1BC4 /* Sample_StatMeshSimple.h */,
6B25B6160FFA62BE004F1BC4 /* Sample_StatMeshSimple.cpp */,
);
name = Samples;
sourceTree = "<group>";
};
6BDD9E030F91110C00904EEF /* Detour */ = {
isa = PBXGroup;
children = (
@@ -240,10 +256,14 @@
6BDD9E080F91113800904EEF /* DetourStatNavMesh.cpp */,
6BDD9E060F91112200904EEF /* DetourStatNavMeshBuilder.h */,
6BDD9E090F91113800904EEF /* DetourStatNavMeshBuilder.cpp */,
6B2AEC580FFB8A68005BE9CC /* DetourTiledNavMesh.h */,
6B2AEC590FFB8A7A005BE9CC /* DetourTiledNavMesh.cpp */,
6B092B920FFCC2AC0088D3A5 /* DetourTiledNavMeshBuilder.h */,
6B092B930FFCC2BD0088D3A5 /* DetourTiledNavMeshBuilder.cpp */,
6B2AEC580FFB8A68005BE9CC /* DetourTileNavMesh.h */,
6B2AEC590FFB8A7A005BE9CC /* DetourTileNavMesh.cpp */,
6B092B920FFCC2AC0088D3A5 /* DetourTileNavMeshBuilder.h */,
6B092B930FFCC2BD0088D3A5 /* DetourTileNavMeshBuilder.cpp */,
6B1185F61006896B0018F96F /* DetourNode.h */,
6B1185F41006895B0018F96F /* DetourNode.cpp */,
6B1185FC10068B040018F96F /* DetourCommon.h */,
6B1185FD10068B150018F96F /* DetourCommon.cpp */,
);
name = Detour;
sourceTree = "<group>";
@@ -304,7 +324,6 @@
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
6B137C700F7FCBBB00459200 /* glfont.cpp in Sources */,
6B137C710F7FCBBB00459200 /* imgui.cpp in Sources */,
6B137C720F7FCBBB00459200 /* MeshLoaderObj.cpp in Sources */,
6B137C730F7FCBBB00459200 /* SDLMain.m in Sources */,
@@ -321,14 +340,17 @@
6BDD9E0B0F91113800904EEF /* DetourStatNavMesh.cpp in Sources */,
6BDD9E0C0F91113800904EEF /* DetourStatNavMeshBuilder.cpp in Sources */,
6BB788170FC0472B003C24DB /* ChunkyTriMesh.cpp in Sources */,
6B25B6190FFA62BE004F1BC4 /* Builder.cpp in Sources */,
6B25B61A0FFA62BE004F1BC4 /* BuilderStatMesh.cpp in Sources */,
6B25B61B0FFA62BE004F1BC4 /* BuilderStatMeshSimple.cpp in Sources */,
6B25B6190FFA62BE004F1BC4 /* Sample.cpp in Sources */,
6B25B61A0FFA62BE004F1BC4 /* Sample_StatMesh.cpp in Sources */,
6B25B61B0FFA62BE004F1BC4 /* Sample_StatMeshSimple.cpp in Sources */,
6B25B61D0FFA62BE004F1BC4 /* main.cpp in Sources */,
6B2AEC530FFB8958005BE9CC /* BuilderTiledMesh.cpp in Sources */,
6B2AEC560FFB89E7005BE9CC /* BuilderStatMeshTiled.cpp in Sources */,
6B2AEC5A0FFB8A7A005BE9CC /* DetourTiledNavMesh.cpp in Sources */,
6B092B940FFCC2BD0088D3A5 /* DetourTiledNavMeshBuilder.cpp in Sources */,
6B2AEC530FFB8958005BE9CC /* Sample_TileMesh.cpp in Sources */,
6B2AEC560FFB89E7005BE9CC /* Sample_StatMeshTiled.cpp in Sources */,
6B2AEC5A0FFB8A7A005BE9CC /* DetourTileNavMesh.cpp in Sources */,
6B092B940FFCC2BD0088D3A5 /* DetourTileNavMeshBuilder.cpp in Sources */,
6B1185F51006895B0018F96F /* DetourNode.cpp in Sources */,
6B1185FE10068B150018F96F /* DetourCommon.cpp in Sources */,
6B555DB1100B212E00247EA3 /* imguiRenderGL.cpp in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};

File diff suppressed because it is too large Load Diff

View File

@@ -1,50 +0,0 @@
#ifndef RECASTBUILDER_H
#define RECASTBUILDER_H
class Builder
{
protected:
const float* m_verts;
int m_nverts;
const int* m_tris;
const float* m_trinorms;
int m_ntris;
float m_bmin[3], m_bmax[3];
float m_cellSize;
float m_cellHeight;
float m_agentHeight;
float m_agentRadius;
float m_agentMaxClimb;
float m_agentMaxSlope;
float m_regionMinSize;
float m_regionMergeSize;
float m_edgeMaxLen;
float m_edgeMaxError;
float m_vertsPerPoly;
public:
Builder();
virtual ~Builder();
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(class GLFont* font, 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();
void resetCommonSettings();
void handleCommonSettings();
};
#endif // RECASTBUILDER_H

View File

@@ -1,70 +0,0 @@
#ifndef RECASTBUILDERSTATMESH_H
#define RECASTBUILDERSTATMESH_H
#include "Builder.h"
#include "DetourStatNavMesh.h"
#include "Recast.h"
#include "RecastLog.h"
class BuilderStatMesh : public Builder
{
protected:
dtStatNavMesh* m_navMesh;
enum ToolMode
{
TOOLMODE_PATHFIND,
TOOLMODE_RAYCAST,
TOOLMODE_DISTANCE_TO_WALL,
TOOLMODE_FIND_POLYS_AROUND,
};
ToolMode m_toolMode;
static const int MAX_POLYS = 256;
dtPolyRef m_startRef;
dtPolyRef m_endRef;
dtPolyRef m_polys[MAX_POLYS];
dtPolyRef m_parent[MAX_POLYS];
int m_npolys;
float m_straightPath[MAX_POLYS*3];
int m_nstraightPath;
float m_polyPickExt[3];
float m_spos[3];
float m_epos[3];
float m_hitPos[3];
float m_hitNormal[3];
float m_distanceToWall;
bool m_sposSet;
bool m_eposSet;
enum ToolRenderFlags
{
NAVMESH_POLYS = 0x01,
NAVMESH_BVTREE = 0x02,
NAVMESH_TOOLS = 0x04,
};
void toolCleanup();
void toolReset();
void toolRecalc();
void toolRender(int flags);
void toolRenderOverlay(class GLFont* font, double* proj, double* model, int* view);
void drawAgent(const float* pos, float r, float h, float c, const float* col);
public:
BuilderStatMesh();
virtual ~BuilderStatMesh();
virtual void handleTools();
virtual void setToolStartPos(const float* p);
virtual void setToolEndPos(const float* p);
};
#endif // RECASTBUILDERSTATMESH_H

View File

@@ -1,63 +0,0 @@
#ifndef RECASTBUILDERSTATMESHSIMPLE_H
#define RECASTBUILDERSTATMESHSIMPLE_H
#include "BuilderStatMesh.h"
#include "DetourStatNavMesh.h"
#include "Recast.h"
#include "RecastLog.h"
class BuilderStatMeshSimple : public BuilderStatMesh
{
protected:
bool m_keepInterResults;
rcBuildTimes m_buildTimes;
unsigned char* m_triflags;
rcHeightfield* m_solid;
rcCompactHeightfield* m_chf;
rcContourSet* m_cset;
rcPolyMesh* m_polyMesh;
rcConfig m_cfg;
enum DrawMode
{
DRAWMODE_NAVMESH,
DRAWMODE_NAVMESH_TRANS,
DRAWMODE_NAVMESH_BVTREE,
DRAWMODE_NAVMESH_INVIS,
DRAWMODE_MESH,
DRAWMODE_VOXELS,
DRAWMODE_VOXELS_WALKABLE,
DRAWMODE_COMPACT,
DRAWMODE_COMPACT_DISTANCE,
DRAWMODE_COMPACT_REGIONS,
DRAWMODE_REGION_CONNECTIONS,
DRAWMODE_RAW_CONTOURS,
DRAWMODE_BOTH_CONTOURS,
DRAWMODE_CONTOURS,
DRAWMODE_POLYMESH,
MAX_DRAWMODE
};
DrawMode m_drawMode;
void cleanup();
public:
BuilderStatMeshSimple();
virtual ~BuilderStatMeshSimple();
virtual void handleSettings();
virtual void handleDebugMode();
virtual void handleRender();
virtual void handleRenderOverlay(class GLFont* font, 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 // RECASTBUILDERSTATMESHSIMPLE_H

View File

@@ -1,91 +0,0 @@
#ifndef RECASTBUILDERSTATMESHTILING_H
#define RECASTBUILDERSTATMESHTILING_H
#include "BuilderStatMesh.h"
#include "DetourStatNavMesh.h"
#include "Recast.h"
#include "RecastLog.h"
#include "ChunkyTriMesh.h"
class BuilderStatMeshTiled : public BuilderStatMesh
{
protected:
struct Tile
{
inline Tile() : chf(0), cset(0), solid(0), buildTime(0) {}
inline ~Tile() { delete chf; delete cset; delete solid; }
rcCompactHeightfield* chf;
rcHeightfield* solid;
rcContourSet* cset;
int buildTime;
};
struct TileSet
{
inline TileSet() : width(0), height(0), tiles(0) {}
inline ~TileSet() { delete [] tiles; }
int width, height;
float bmin[3], bmax[3];
float cs, ch;
Tile* tiles;
};
bool m_measurePerTileTimings;
bool m_keepInterResults;
float m_tileSize;
rcBuildTimes m_buildTimes;
rcChunkyTriMesh* m_chunkyMesh;
rcPolyMesh* m_polyMesh;
rcConfig m_cfg;
TileSet* m_tileSet;
static const int MAX_STAT_BUCKETS = 1000;
int m_statPolysPerTile[MAX_STAT_BUCKETS];
int m_statPolysPerTileSamples;
int m_statTimePerTile[MAX_STAT_BUCKETS];
int m_statTimePerTileSamples;
enum DrawMode
{
DRAWMODE_NAVMESH,
DRAWMODE_NAVMESH_TRANS,
DRAWMODE_NAVMESH_BVTREE,
DRAWMODE_NAVMESH_INVIS,
DRAWMODE_MESH,
DRAWMODE_VOXELS,
DRAWMODE_VOXELS_WALKABLE,
DRAWMODE_COMPACT,
DRAWMODE_COMPACT_DISTANCE,
DRAWMODE_COMPACT_REGIONS,
DRAWMODE_REGION_CONNECTIONS,
DRAWMODE_RAW_CONTOURS,
DRAWMODE_BOTH_CONTOURS,
DRAWMODE_CONTOURS,
DRAWMODE_POLYMESH,
MAX_DRAWMODE
};
DrawMode m_drawMode;
void cleanup();
public:
BuilderStatMeshTiled();
virtual ~BuilderStatMeshTiled();
virtual void handleSettings();
virtual void handleDebugMode();
virtual void handleRender();
virtual void handleRenderOverlay(class GLFont* font, 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 // RECASTBUILDERSTATMESHTILING_H

View File

@@ -1,132 +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 RECASTBUILDERTILEDMESH_H
#define RECASTBUILDERTILEDMESH_H
#include "Builder.h"
#include "DetourTiledNavMesh.h"
#include "Recast.h"
#include "RecastLog.h"
#include "ChunkyTriMesh.h"
class BuilderTiledMesh : public Builder
{
protected:
bool m_keepInterResults;
rcBuildTimes m_buildTimes;
dtTiledNavMesh* m_navMesh;
rcChunkyTriMesh* m_chunkyMesh;
unsigned char* m_triflags;
rcHeightfield* m_solid;
rcCompactHeightfield* m_chf;
rcContourSet* m_cset;
rcPolyMesh* m_polyMesh;
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,
};
dtTilePolyRef m_startRef;
dtTilePolyRef m_endRef;
float m_polyPickExt[3];
static const int MAX_POLYS = 256;
dtTilePolyRef m_polys[MAX_POLYS];
dtTilePolyRef 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();
/* static const int MAX_POLYS = 256;
dtPolyRef m_startRef;
dtPolyRef m_endRef;
dtPolyRef m_polys[MAX_POLYS];
dtPolyRef m_parent[MAX_POLYS];
int m_npolys;
float m_straightPath[MAX_POLYS*3];
int m_nstraightPath;
float m_polyPickExt[3];
float m_spos[3];
float m_epos[3];
float m_hitPos[3];
float m_hitNormal[3];
float m_distanceToWall;
bool m_sposSet;
bool m_eposSet;*/
void buildTile(const float* pos);
void removeTile(const float* pos);
unsigned char* buildTileMesh(const float* bmin, const float* bmax, int& dataSize);
void cleanup();
public:
BuilderTiledMesh();
virtual ~BuilderTiledMesh();
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(class GLFont* font, 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 // RECASTBUILDERTILEDMESH_H

View File

@@ -1,106 +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 GLFONT_H
#define GLFONT_H
class GLFont
{
public:
GLFont(int renderVerts = 4096);
~GLFont();
bool create(const char* fileName);
int getFontSize() const;
int getDescender() const;
int getAscender() const;
float getLineHeight() const;
float getTextLength(const char* text, float size = -1, float tracking = 0);
void drawText(float x, float y, const char* text,
unsigned int col, float size = -1, float tracking = 0);
void render();
void debugDraw();
static unsigned int RGBA(unsigned char r, unsigned char g, unsigned char b, unsigned char a = 255);
private:
bool createFontFromFontData(unsigned char* fd);
struct KerningPair
{
inline KerningPair() {}
inline KerningPair(unsigned char c_, float dx_) : dx(dx_), c(c_) {}
inline void Set(unsigned char c_, float dx_) { dx = dx_; c = c_; }
float dx;
unsigned char c, pad[3];
};
struct CachedGlyph
{
inline CachedGlyph() : w(0), h(0), ox(0), oy(0), tx(0), ty(0), adv(0.0f), nkern(0), kern(0) {}
int w, h;
int ox, oy;
int tx, ty;
float adv;
int nkern;
union
{
KerningPair* kern;
int kernOffset;
};
};
struct FontData
{
unsigned int endian;
unsigned int version;
unsigned int dataSize;
unsigned int kernOffset;
unsigned int textureOffset;
int fontSize;
unsigned int texWidth;
unsigned int texHeight;
int numMipmaps;
int ascender;
int descender;
int lineHeight;
int charMin;
int charCount;
CachedGlyph glyphs[1];
};
FontData* m_fd;
unsigned int m_texId;
struct RenderVertex
{
inline void set(float x_, float y_, float u_, float v_, unsigned int c) { x=x_; y=y_; u=u_; v=v_; col=c; }
float x, y, u, v;
unsigned int col;
};
RenderVertex* m_verts;
int m_nverts;
const int m_maxVerts;
};
#endif // GLFONT_H

View File

@@ -19,35 +19,79 @@
#ifndef IMGUI_H
#define IMGUI_H
#define GENID ((__LINE__ ^ (int)__FILE__) << 16)
#define GENID1(x) ((__LINE__ ^ (int)__FILE__) << 16 | (x))
enum imguiMouseButton
{
IMGUI_MBUT_LEFT = 0x01,
IMGUI_MBUT_RIGHT = 0x02,
IMGUI_MBUT_UP = 0x04,
IMGUI_MBUT_DOWN = 0x08,
};
void imguiBeginFrame(int mx, int my, unsigned char mbut);
void imguiEndFrame();
void imguiRender(void (*drawText)(int x, int y, int dir, const char* text, unsigned int col));
enum imguiTextAlign
{
IMGUI_ALIGN_LEFT,
IMGUI_ALIGN_CENTER,
IMGUI_ALIGN_RIGHT,
};
bool imguiBeginScrollArea(unsigned int id, const char* name, int x, int y, int w, int h, int* scroll);
inline unsigned int imguiRGBA(unsigned char r, unsigned char g, unsigned char b, unsigned char a=255)
{
return (r) | (g << 8) | (b << 16) | (a << 24);
}
void imguiBeginFrame(int mx, int my, unsigned char mbut, int scroll);
void imguiEndFrame();
bool imguiBeginScrollArea(const char* name, int x, int y, int w, int h, int* scroll);
void imguiEndScrollArea();
void imguiIndent();
void imguiUnindent();
void imguiSeparator();
bool imguiButton(unsigned int id, const char* text);
bool imguiItem(unsigned int id, const char* text);
bool imguiCheck(unsigned int id, const char* text, bool checked);
bool imguiCollapse(unsigned int id, const char* text, bool checked);
void imguiLabel(unsigned int id, const char* text);
void imguiValue(unsigned int id, const char* text);
bool imguiSlider(unsigned int id, const char* text, float* val, float vmin, float vmax, float vinc);
bool imguiButton(const char* text, bool enabled = true);
bool imguiItem(const char* text, bool enabled = true);
bool imguiCheck(const char* text, bool checked, bool enabled = true);
bool imguiCollapse(const char* text, bool checked, bool enabled = true);
void imguiLabel(const char* text);
void imguiValue(const char* text);
bool imguiSlider(const char* text, float* val, float vmin, float vmax, float vinc, bool enabled = true);
void imguiDrawText(int x, int y, int align, const char* text, unsigned int color);
// Pull render interface.
enum imguiGfxCmdType
{
IMGUI_GFXCMD_RECT,
IMGUI_GFXCMD_TRIANGLE,
IMGUI_GFXCMD_TEXT,
IMGUI_GFXCMD_SCISSOR,
};
struct imguiGfxRect
{
short x,y,w,h,r;
};
struct imguiGfxText
{
short x,y,align;
const char* text;
};
struct imguiGfxCmd
{
char type;
char flags;
char pad[2];
unsigned int col;
union
{
imguiGfxRect rect;
imguiGfxText text;
};
};
const imguiGfxCmd* imguiGetRenderQueue();
int imguiGetRenderQueueSize();
#endif // IMGUI_H

View File

@@ -0,0 +1,8 @@
#ifndef IMGUI_RENDER_GL_H
#define IMGUI_RENDER_GL_H
bool imguiRenderGLInit(const char* fontpath);
void imguiRenderGLDestroy();
void imguiRenderGLDraw();
#endif // IMGUI_RENDER_GL_H

View File

@@ -1,123 +0,0 @@
#define _USE_MATH_DEFINES
#include <math.h>
#include <stdio.h>
#include "Builder.h"
#include "Recast.h"
#include "RecastDebugDraw.h"
#include "imgui.h"
#ifdef WIN32
# define snprintf _snprintf
#endif
Builder::Builder() :
m_verts(0), m_nverts(0), m_tris(0), m_trinorms(0), m_ntris(0)
{
resetCommonSettings();
}
Builder::~Builder()
{
}
void Builder::handleSettings()
{
}
void Builder::handleTools()
{
}
void Builder::handleDebugMode()
{
}
void Builder::handleRender()
{
if (!m_verts || !m_tris || !m_trinorms)
return;
// Draw mesh
rcDebugDrawMesh(m_verts, m_nverts, m_tris, m_trinorms, m_ntris, 0);
// Draw bounds
float col[4] = {1,1,1,0.5f};
rcDebugDrawBoxWire(m_bmin[0],m_bmin[1],m_bmin[2], m_bmax[0],m_bmax[1],m_bmax[2], col);
}
void Builder::handleRenderOverlay(class GLFont* font, double* proj, double* model, int* view)
{
}
void Builder::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);
}
void Builder::resetCommonSettings()
{
m_cellSize = 0.3f;
m_cellHeight = 0.2f;
m_agentHeight = 2.0f;
m_agentRadius = 0.6f;
m_agentMaxClimb = 0.9f;
m_agentMaxSlope = 45.0f;
m_regionMinSize = 50;
m_regionMergeSize = 20;
m_edgeMaxLen = 12.0f;
m_edgeMaxError = 1.3f;
m_vertsPerPoly = 6.0f;
}
void Builder::handleCommonSettings()
{
imguiLabel(GENID, "Rasterization");
imguiSlider(GENID, "Cell Size", &m_cellSize, 0.1f, 1.0f, 0.01f);
imguiSlider(GENID, "Cell Height", &m_cellHeight, 0.1f, 1.0f, 0.01f);
int gw = 0, gh = 0;
rcCalcGridSize(m_bmin, m_bmax, m_cellSize, &gw, &gh);
char text[64];
snprintf(text, 64, "Voxels %d x %d", gw, gh);
imguiValue(GENID, text);
imguiSeparator();
imguiLabel(GENID, "Agent");
imguiSlider(GENID, "Height", &m_agentHeight, 0.1f, 5.0f, 0.1f);
imguiSlider(GENID, "Radius", &m_agentRadius, 0.0f, 5.0f, 0.1f);
imguiSlider(GENID, "Max Climb", &m_agentMaxClimb, 0.1f, 5.0f, 0.1f);
imguiSlider(GENID, "Max Slope", &m_agentMaxSlope, 0.0f, 90.0f, 1.0f);
imguiSeparator();
imguiLabel(GENID, "Region");
imguiSlider(GENID, "Min Region Size", &m_regionMinSize, 0.0f, 150.0f, 1.0f);
imguiSlider(GENID, "Merged Region Size", &m_regionMergeSize, 0.0f, 150.0f, 1.0f);
imguiSeparator();
imguiLabel(GENID, "Polygonization");
imguiSlider(GENID, "Max Edge Length", &m_edgeMaxLen, 0.0f, 50.0f, 1.0f);
imguiSlider(GENID, "Max Edge Error", &m_edgeMaxError, 0.1f, 3.0f, 0.1f);
imguiSlider(GENID, "Verts Per Poly", &m_vertsPerPoly, 3.0f, 12.0f, 1.0f);
imguiSeparator();
}
void Builder::setToolStartPos(const float* p)
{
}
void Builder::setToolEndPos(const float* p)
{
}
bool Builder::handleBuild()
{
return true;
}

View File

@@ -1,338 +0,0 @@
#define _USE_MATH_DEFINES
#include <math.h>
#include <stdio.h>
#include <string.h>
#include "SDL.h"
#include "SDL_Opengl.h"
#include "glfont.h"
#include "imgui.h"
#include "Builder.h"
#include "BuilderStatMesh.h"
#include "Recast.h"
#include "RecastTimer.h"
#include "RecastDebugDraw.h"
#include "DetourStatNavMesh.h"
#include "DetourStatNavMeshBuilder.h"
#include "DetourDebugDraw.h"
#ifdef WIN32
# define snprintf _snprintf
#endif
BuilderStatMesh::BuilderStatMesh() :
m_navMesh(0),
m_toolMode(TOOLMODE_PATHFIND),
m_sposSet(false),
m_eposSet(false)
{
toolReset();
m_polyPickExt[0] = 2;
m_polyPickExt[1] = 4;
m_polyPickExt[2] = 2;
}
BuilderStatMesh::~BuilderStatMesh()
{
toolCleanup();
}
void BuilderStatMesh::handleTools()
{
if (imguiCheck(GENID, "Pathfind", m_toolMode == TOOLMODE_PATHFIND))
{
m_toolMode = TOOLMODE_PATHFIND;
toolRecalc();
}
if (imguiCheck(GENID, "Distance to Wall", m_toolMode == TOOLMODE_DISTANCE_TO_WALL))
{
m_toolMode = TOOLMODE_DISTANCE_TO_WALL;
toolRecalc();
}
if (imguiCheck(GENID, "Raycast", m_toolMode == TOOLMODE_RAYCAST))
{
m_toolMode = TOOLMODE_RAYCAST;
toolRecalc();
}
if (imguiCheck(GENID, "Find Polys Around", m_toolMode == TOOLMODE_FIND_POLYS_AROUND))
{
m_toolMode = TOOLMODE_FIND_POLYS_AROUND;
toolRecalc();
}
}
void BuilderStatMesh::setToolStartPos(const float* p)
{
m_sposSet = true;
vcopy(m_spos, p);
toolRecalc();
}
void BuilderStatMesh::setToolEndPos(const float* p)
{
m_eposSet = true;
vcopy(m_epos, p);
toolRecalc();
}
void BuilderStatMesh::toolCleanup()
{
delete m_navMesh;
m_navMesh = 0;
}
void BuilderStatMesh::toolReset()
{
m_startRef = 0;
m_endRef = 0;
m_npolys = 0;
m_nstraightPath = 0;
memset(m_hitPos, 0, sizeof(m_hitPos));
memset(m_hitNormal, 0, sizeof(m_hitNormal));
m_distanceToWall = 0;
}
void BuilderStatMesh::toolRecalc()
{
if (!m_navMesh)
return;
if (m_sposSet)
m_startRef = m_navMesh->findNearestPoly(m_spos, m_polyPickExt);
else
m_startRef = 0;
if (m_eposSet)
m_endRef = m_navMesh->findNearestPoly(m_epos, m_polyPickExt);
else
m_endRef = 0;
if (m_toolMode == TOOLMODE_PATHFIND)
{
if (m_sposSet && m_eposSet && m_startRef && m_endRef)
{
m_npolys = m_navMesh->findPath(m_startRef, m_endRef, 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];
if (m_navMesh->raycast(m_startRef, m_spos, m_epos, t, m_polys[0]))
{
m_npolys = 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, 0, MAX_POLYS);
}
}
}
static void getPolyCenter(dtStatNavMesh* navMesh, dtPolyRef ref, float* center)
{
const dtPoly* p = navMesh->getPolyByRef(ref);
if (!p) return;
center[0] = 0;
center[1] = 0;
center[2] = 0;
for (int i = 0; i < (int)p->nv; ++i)
{
const float* v = navMesh->getVertex(p->v[i]);
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 BuilderStatMesh::toolRender(int flags)
{
if (!m_navMesh)
return;
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};
glDepthMask(GL_FALSE);
if (flags & NAVMESH_POLYS)
dtDebugDrawStatNavMesh(m_navMesh);
if (flags & NAVMESH_BVTREE)
dtDebugDrawStatNavMeshBVTree(m_navMesh);
if (flags & NAVMESH_TOOLS)
{
if (m_toolMode == TOOLMODE_PATHFIND)
{
dtDebugDrawStatNavMeshPoly(m_navMesh, m_startRef, startCol);
dtDebugDrawStatNavMeshPoly(m_navMesh, m_endRef, endCol);
if (m_npolys)
{
for (int i = 1; i < m_npolys-1; ++i)
dtDebugDrawStatNavMeshPoly(m_navMesh, m_polys[i], pathCol);
}
if (m_nstraightPath)
{
glColor4ub(128,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)
{
dtDebugDrawStatNavMeshPoly(m_navMesh, m_startRef, startCol);
if (m_nstraightPath)
{
dtDebugDrawStatNavMeshPoly(m_navMesh, m_polys[0], pathCol);
glColor4ub(128,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)
{
dtDebugDrawStatNavMeshPoly(m_navMesh, m_startRef, startCol);
const float col[4] = {1,1,1,0.5f};
rcDebugDrawCylinderWire(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)
{
glLineWidth(2.0f);
for (int i = 0; i < m_npolys; ++i)
{
dtDebugDrawStatNavMeshPoly(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(p0, p1);
}
}
glLineWidth(1.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(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 BuilderStatMesh::toolRenderOverlay(class GLFont* font, double* proj, double* model, int* view)
{
GLdouble x, y, z;
// Draw start and end point labels
if (m_sposSet && gluProject((GLdouble)m_spos[0], (GLdouble)m_spos[1], (GLdouble)m_spos[2],
model, proj, view, &x, &y, &z))
{
const float len = font->getTextLength("Start");
font->drawText((float)x - len/2, (float)y-font->getLineHeight(), "Start", GLFont::RGBA(0,0,0,220));
}
if (m_eposSet && gluProject((GLdouble)m_epos[0], (GLdouble)m_epos[1], (GLdouble)m_epos[2],
model, proj, view, &x, &y, &z))
{
const float len = font->getTextLength("End");
font->drawText((float)x-len/2, (float)y-font->getLineHeight(), "End", GLFont::RGBA(0,0,0,220));
}
}
void BuilderStatMesh::drawAgent(const float* pos, float r, float h, float c, const float* col)
{
glDepthMask(GL_FALSE);
// Agent dimensions.
glLineWidth(2.0f);
rcDebugDrawCylinderWire(pos[0]-r, pos[1]+0.02f, pos[2]-r, pos[0]+r, pos[1]+h, pos[2]+r, col);
glLineWidth(1.0f);
glColor4ub(0,0,0,196);
glBegin(GL_LINES);
glVertex3f(pos[0], pos[1]-c, pos[2]);
glVertex3f(pos[0], pos[1]+c, pos[2]);
glVertex3f(pos[0]-r/2, pos[1]+0.02f, pos[2]);
glVertex3f(pos[0]+r/2, pos[1]+0.02f, pos[2]);
glVertex3f(pos[0], pos[1]+0.02f, pos[2]-r/2);
glVertex3f(pos[0], pos[1]+0.02f, pos[2]+r/2);
glEnd();
glDepthMask(GL_TRUE);
}

View File

@@ -1,508 +0,0 @@
#define _USE_MATH_DEFINES
#include <math.h>
#include <stdio.h>
#include <string.h>
#include "SDL.h"
#include "SDL_Opengl.h"
#include "imgui.h"
#include "glfont.h"
#include "Builder.h"
#include "BuilderStatMeshSimple.h"
#include "Recast.h"
#include "RecastTimer.h"
#include "RecastDebugDraw.h"
#include "DetourStatNavMesh.h"
#include "DetourStatNavMeshBuilder.h"
#include "DetourDebugDraw.h"
#ifdef WIN32
# define snprintf _snprintf
#endif
BuilderStatMeshSimple::BuilderStatMeshSimple() :
m_keepInterResults(false),
m_triflags(0),
m_solid(0),
m_chf(0),
m_cset(0),
m_polyMesh(0),
m_drawMode(DRAWMODE_NAVMESH)
{
}
BuilderStatMeshSimple::~BuilderStatMeshSimple()
{
cleanup();
}
void BuilderStatMeshSimple::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_polyMesh;
m_polyMesh = 0;
toolCleanup();
}
void BuilderStatMeshSimple::handleSettings()
{
Builder::handleCommonSettings();
if (imguiCheck(GENID, "Keep Itermediate Results", m_keepInterResults))
m_keepInterResults = !m_keepInterResults;
imguiSeparator();
}
void BuilderStatMeshSimple::handleDebugMode()
{
// Check which modes are valid.
bool valid[MAX_DRAWMODE];
for (int i = 0; i < MAX_DRAWMODE; ++i)
valid[i] = false;
if (m_verts && m_tris)
{
valid[DRAWMODE_NAVMESH] = m_navMesh != 0;
valid[DRAWMODE_NAVMESH_TRANS] = m_navMesh != 0;
valid[DRAWMODE_NAVMESH_BVTREE] = m_navMesh != 0;
valid[DRAWMODE_NAVMESH_INVIS] = m_navMesh != 0;
valid[DRAWMODE_MESH] = true;
valid[DRAWMODE_VOXELS] = m_solid != 0;
valid[DRAWMODE_VOXELS_WALKABLE] = m_solid != 0;
valid[DRAWMODE_COMPACT] = m_chf != 0;
valid[DRAWMODE_COMPACT_DISTANCE] = m_chf != 0;
valid[DRAWMODE_COMPACT_REGIONS] = m_chf != 0;
valid[DRAWMODE_REGION_CONNECTIONS] = m_cset != 0;
valid[DRAWMODE_RAW_CONTOURS] = m_cset != 0;
valid[DRAWMODE_BOTH_CONTOURS] = m_cset != 0;
valid[DRAWMODE_CONTOURS] = m_cset != 0;
valid[DRAWMODE_POLYMESH] = m_polyMesh != 0;
}
if (!valid[m_drawMode])
m_drawMode = DRAWMODE_MESH;
int unavail = 0;
for (int i = 0; i < MAX_DRAWMODE; ++i)
if (!valid[i]) unavail++;
if (unavail == MAX_DRAWMODE)
return;
imguiLabel(GENID, "Draw");
if (valid[DRAWMODE_MESH] && imguiCheck(GENID, "Input Mesh", m_drawMode == DRAWMODE_MESH))
m_drawMode = DRAWMODE_MESH;
if (valid[DRAWMODE_NAVMESH] && imguiCheck(GENID, "Navmesh", m_drawMode == DRAWMODE_NAVMESH))
m_drawMode = DRAWMODE_NAVMESH;
if (valid[DRAWMODE_NAVMESH_INVIS] && imguiCheck(GENID, "Navmesh Invis", m_drawMode == DRAWMODE_NAVMESH_INVIS))
m_drawMode = DRAWMODE_NAVMESH_INVIS;
if (valid[DRAWMODE_NAVMESH_TRANS] && imguiCheck(GENID, "Navmesh Trans", m_drawMode == DRAWMODE_NAVMESH_TRANS))
m_drawMode = DRAWMODE_NAVMESH_TRANS;
if (valid[DRAWMODE_NAVMESH_BVTREE] && imguiCheck(GENID, "Navmesh BVTree", m_drawMode == DRAWMODE_NAVMESH_BVTREE))
m_drawMode = DRAWMODE_NAVMESH_BVTREE;
if (valid[DRAWMODE_VOXELS] && imguiCheck(GENID, "Voxels", m_drawMode == DRAWMODE_VOXELS))
m_drawMode = DRAWMODE_VOXELS;
if (valid[DRAWMODE_VOXELS_WALKABLE] && imguiCheck(GENID, "Walkable Voxels", m_drawMode == DRAWMODE_VOXELS_WALKABLE))
m_drawMode = DRAWMODE_VOXELS_WALKABLE;
if (valid[DRAWMODE_COMPACT] && imguiCheck(GENID, "Compact", m_drawMode == DRAWMODE_COMPACT))
m_drawMode = DRAWMODE_COMPACT;
if (valid[DRAWMODE_COMPACT_DISTANCE] && imguiCheck(GENID, "Compact Distance", m_drawMode == DRAWMODE_COMPACT_DISTANCE))
m_drawMode = DRAWMODE_COMPACT_DISTANCE;
if (valid[DRAWMODE_COMPACT_REGIONS] && imguiCheck(GENID, "Compact Regions", m_drawMode == DRAWMODE_COMPACT_REGIONS))
m_drawMode = DRAWMODE_COMPACT_REGIONS;
if (valid[DRAWMODE_REGION_CONNECTIONS] && imguiCheck(GENID, "Region Connections", m_drawMode == DRAWMODE_REGION_CONNECTIONS))
m_drawMode = DRAWMODE_REGION_CONNECTIONS;
if (valid[DRAWMODE_RAW_CONTOURS] && imguiCheck(GENID, "Raw Contours", m_drawMode == DRAWMODE_RAW_CONTOURS))
m_drawMode = DRAWMODE_RAW_CONTOURS;
if (valid[DRAWMODE_BOTH_CONTOURS] && imguiCheck(GENID, "Both Contours", m_drawMode == DRAWMODE_BOTH_CONTOURS))
m_drawMode = DRAWMODE_BOTH_CONTOURS;
if (valid[DRAWMODE_CONTOURS] && imguiCheck(GENID, "Contours", m_drawMode == DRAWMODE_CONTOURS))
m_drawMode = DRAWMODE_CONTOURS;
if (valid[DRAWMODE_POLYMESH] && imguiCheck(GENID, "Poly Mesh", m_drawMode == DRAWMODE_POLYMESH))
m_drawMode = DRAWMODE_POLYMESH;
if (unavail)
{
imguiValue(GENID, "Tick 'Keep Itermediate Results'");
imguiValue(GENID, "to see more debug mode options.");
}
}
void BuilderStatMeshSimple::handleRender()
{
if (!m_verts || !m_tris || !m_trinorms)
return;
float col[4];
glEnable(GL_FOG);
glDepthMask(GL_TRUE);
if (m_drawMode == DRAWMODE_MESH)
{
// Draw mesh
rcDebugDrawMeshSlope(m_verts, m_nverts, m_tris, m_trinorms, m_ntris, m_agentMaxSlope);
}
else if (m_drawMode != DRAWMODE_NAVMESH_TRANS)
{
// Draw mesh
rcDebugDrawMesh(m_verts, m_nverts, m_tris, m_trinorms, m_ntris, 0);
}
glDisable(GL_FOG);
glDepthMask(GL_FALSE);
// Draw bounds
col[0] = 1; col[1] = 1; col[2] = 1; col[3] = 0.5f;
rcDebugDrawBoxWire(m_bmin[0],m_bmin[1],m_bmin[2], m_bmax[0],m_bmax[1],m_bmax[2], col);
if (m_navMesh &&
(m_drawMode == DRAWMODE_NAVMESH ||
m_drawMode == DRAWMODE_NAVMESH_TRANS ||
m_drawMode == DRAWMODE_NAVMESH_BVTREE ||
m_drawMode == DRAWMODE_NAVMESH_INVIS))
{
int flags = NAVMESH_TOOLS;
if (m_drawMode != DRAWMODE_NAVMESH_INVIS)
flags |= NAVMESH_POLYS;
if (m_drawMode == DRAWMODE_NAVMESH_BVTREE)
flags |= NAVMESH_BVTREE;
toolRender(flags);
}
glDepthMask(GL_TRUE);
if (m_chf && m_drawMode == DRAWMODE_COMPACT)
rcDebugDrawCompactHeightfieldSolid(*m_chf);
if (m_chf && m_drawMode == DRAWMODE_COMPACT_DISTANCE)
rcDebugDrawCompactHeightfieldDistance(*m_chf);
if (m_chf && m_drawMode == DRAWMODE_COMPACT_REGIONS)
rcDebugDrawCompactHeightfieldRegions(*m_chf);
if (m_solid && m_drawMode == DRAWMODE_VOXELS)
{
glEnable(GL_FOG);
rcDebugDrawHeightfieldSolid(*m_solid);
glDisable(GL_FOG);
}
if (m_solid && m_drawMode == DRAWMODE_VOXELS_WALKABLE)
{
glEnable(GL_FOG);
rcDebugDrawHeightfieldWalkable(*m_solid);
glDisable(GL_FOG);
}
if (m_cset && m_drawMode == DRAWMODE_RAW_CONTOURS)
{
glDepthMask(GL_FALSE);
rcDebugDrawRawContours(*m_cset, m_cfg.bmin, m_cfg.cs, m_cfg.ch);
glDepthMask(GL_TRUE);
}
if (m_cset && m_drawMode == DRAWMODE_BOTH_CONTOURS)
{
glDepthMask(GL_FALSE);
rcDebugDrawRawContours(*m_cset, m_cfg.bmin, m_cfg.cs, m_cfg.ch, 0.5f);
rcDebugDrawContours(*m_cset, m_cfg.bmin, m_cfg.cs, m_cfg.ch);
glDepthMask(GL_TRUE);
}
if (m_cset && m_drawMode == DRAWMODE_CONTOURS)
{
glDepthMask(GL_FALSE);
rcDebugDrawContours(*m_cset, m_cfg.bmin, m_cfg.cs, m_cfg.ch);
glDepthMask(GL_TRUE);
}
if (m_chf && m_cset && m_drawMode == DRAWMODE_REGION_CONNECTIONS)
{
rcDebugDrawCompactHeightfieldRegions(*m_chf);
glDepthMask(GL_FALSE);
rcDebugDrawRegionConnections(*m_cset, m_cfg.bmin, m_cfg.cs, m_cfg.ch);
glDepthMask(GL_TRUE);
}
if (m_polyMesh && m_drawMode == DRAWMODE_POLYMESH)
{
glDepthMask(GL_FALSE);
rcDebugDrawPolyMesh(*m_polyMesh);
glDepthMask(GL_TRUE);
}
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 };
if (m_sposSet)
drawAgent(m_spos, m_agentRadius, m_agentHeight, m_agentMaxClimb, startCol);
if (m_eposSet)
drawAgent(m_epos, m_agentRadius, m_agentHeight, m_agentMaxClimb, endCol);
}
void BuilderStatMeshSimple::handleRenderOverlay(class GLFont* font, double* proj, double* model, int* view)
{
toolRenderOverlay(font, proj, model, view);
}
void BuilderStatMeshSimple::handleMeshChanged(const float* verts, int nverts,
const int* tris, const float* trinorms, int ntris,
const float* bmin, const float* bmax)
{
Builder::handleMeshChanged(verts, nverts, tris, trinorms, ntris, bmin, bmax);
toolCleanup();
toolReset();
}
bool BuilderStatMeshSimple::handleBuild()
{
if (!m_verts || ! m_tris)
{
if (rcGetLog())
rcGetLog()->log(RC_LOG_ERROR, "buildNavigation: Input mesh is not specified.");
return false;
}
cleanup();
toolCleanup();
// 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;
if (m_cfg.maxVertsPerPoly == DT_VERTS_PER_POLYGON)
m_drawMode = DRAWMODE_NAVMESH;
else
m_drawMode = DRAWMODE_POLYMESH;
// Set the area where the navigation will be build.
// Here the bounds of the input mesh are used, but the
// area could be specified by an user defined box, etc.
vcopy(m_cfg.bmin, m_bmin);
vcopy(m_cfg.bmax, m_bmax);
rcCalcGridSize(m_cfg.bmin, m_cfg.bmax, m_cfg.cs, &m_cfg.width, &m_cfg.height);
// 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 false;
}
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 false;
}
// 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_ntris];
if (!m_triflags)
{
if (rcGetLog())
rcGetLog()->log(RC_LOG_ERROR, "buildNavigation: Out of memory 'triangleFlags' (%d).", m_ntris);
return false;
}
// Find triangles which are walkable based on their slope and rasterize them.
// If your input data is multiple meshes, you can transform them here, calculate
// the flags for each of the meshes and rasterize them.
memset(m_triflags, 0, m_ntris*sizeof(unsigned char));
rcMarkWalkableTriangles(m_cfg.walkableSlopeAngle, m_verts, m_nverts, m_tris, m_ntris, m_triflags);
rcRasterizeTriangles(m_verts, m_nverts, m_tris, m_triflags, m_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 false;
}
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 false;
}
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 false;
}
// 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.");
}
// Create contours.
m_cset = new rcContourSet;
if (!m_cset)
{
if (rcGetLog())
rcGetLog()->log(RC_LOG_ERROR, "buildNavigation: Out of memory 'cset'.");
return false;
}
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 false;
}
if (!m_keepInterResults)
{
delete m_chf;
m_chf = 0;
}
// Build polygon navmesh from the contours.
m_polyMesh = new rcPolyMesh;
if (!m_polyMesh)
{
if (rcGetLog())
rcGetLog()->log(RC_LOG_ERROR, "buildNavigation: Out of memory 'polyMesh'.");
return false;
}
if (!rcBuildPolyMesh(*m_cset, m_cfg.bmin, m_cfg.bmax, m_cfg.cs, m_cfg.ch, m_cfg.maxVertsPerPoly, *m_polyMesh))
{
if (rcGetLog())
rcGetLog()->log(RC_LOG_ERROR, "buildNavigation: Could not triangulate contours.");
return false;
}
if (!m_keepInterResults)
{
delete m_cset;
m_cset = 0;
}
if (m_cfg.maxVertsPerPoly == DT_VERTS_PER_POLYGON)
{
unsigned char* navData = 0;
int navDataSize = 0;
if (!dtCreateNavMeshData(m_polyMesh->verts, m_polyMesh->nverts,
m_polyMesh->polys, m_polyMesh->npolys, m_polyMesh->nvp,
m_cfg.bmin, m_cfg.bmax, m_cfg.cs, m_cfg.ch, &navData, &navDataSize))
{
if (rcGetLog())
rcGetLog()->log(RC_LOG_ERROR, "Could not build Detour navmesh.");
return false;
}
m_navMesh = new dtStatNavMesh;
if (!m_navMesh)
{
delete [] navData;
if (rcGetLog())
rcGetLog()->log(RC_LOG_ERROR, "Could not create Detour navmesh");
return false;
}
if (!m_navMesh->init(navData, navDataSize, true))
{
delete [] navData;
if (rcGetLog())
rcGetLog()->log(RC_LOG_ERROR, "Could not init Detour navmesh");
return false;
}
}
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, "Fixup contours: %.1fms (%.1f%%)", m_buildTimes.fixupContours/1000.0f, m_buildTimes.fixupContours*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_polyMesh->nverts, m_polyMesh->npolys);
rcGetLog()->log(RC_LOG_PROGRESS, "TOTAL: %.1fms", rcGetDeltaTimeUsec(totStartTime, totEndTime)/1000.0f);
}
toolRecalc();
return true;
}

View File

@@ -1,983 +0,0 @@
#define _USE_MATH_DEFINES
#include <math.h>
#include <stdio.h>
#include <string.h>
#include "SDL.h"
#include "SDL_Opengl.h"
#include "imgui.h"
#include "glfont.h"
#include "Builder.h"
#include "BuilderStatMeshTiled.h"
#include "Recast.h"
#include "RecastTimer.h"
#include "RecastDebugDraw.h"
#include "DetourStatNavMesh.h"
#include "DetourStatNavMeshBuilder.h"
#include "DetourDebugDraw.h"
#ifdef WIN32
# define snprintf _snprintf
#endif
BuilderStatMeshTiled::BuilderStatMeshTiled() :
m_keepInterResults(false),
m_measurePerTileTimings(false),
m_tileSize(64),
m_chunkyMesh(0),
m_tileSet(0),
m_polyMesh(0),
m_drawMode(DRAWMODE_NAVMESH),
m_statTimePerTileSamples(0),
m_statPolysPerTileSamples(0)
{
}
BuilderStatMeshTiled::~BuilderStatMeshTiled()
{
cleanup();
}
void BuilderStatMeshTiled::cleanup()
{
delete m_chunkyMesh;
m_chunkyMesh = 0;
delete m_tileSet;
m_tileSet = 0;
delete m_polyMesh;
m_polyMesh = 0;
toolCleanup();
m_statTimePerTileSamples = 0;
m_statPolysPerTileSamples = 0;
}
void BuilderStatMeshTiled::handleSettings()
{
Builder::handleCommonSettings();
imguiLabel(GENID, "Tiling");
imguiSlider(GENID, "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(GENID, text);
imguiSeparator();
if (imguiCheck(GENID, "Keep Itermediate Results", m_keepInterResults))
m_keepInterResults = !m_keepInterResults;
if (imguiCheck(GENID, "Measure Per Tile Timings", m_measurePerTileTimings))
m_measurePerTileTimings = !m_measurePerTileTimings;
imguiSeparator();
}
void BuilderStatMeshTiled::handleDebugMode()
{
// Check which modes are valid.
bool valid[MAX_DRAWMODE];
for (int i = 0; i < MAX_DRAWMODE; ++i)
valid[i] = false;
bool hasChf = false;
bool hasSolid = false;
bool hasCset = false;
if (m_tileSet)
{
for (int i = 0; i < m_tileSet->width*m_tileSet->height; ++i)
{
if (m_tileSet->tiles[i].solid) hasSolid = true;
if (m_tileSet->tiles[i].chf) hasChf = true;
if (m_tileSet->tiles[i].cset) hasCset = true;
}
}
if (m_verts && m_tris)
{
valid[DRAWMODE_NAVMESH] = m_navMesh != 0;
valid[DRAWMODE_NAVMESH_TRANS] = m_navMesh != 0;
valid[DRAWMODE_NAVMESH_BVTREE] = m_navMesh != 0;
valid[DRAWMODE_NAVMESH_INVIS] = m_navMesh != 0;
valid[DRAWMODE_MESH] = true;
valid[DRAWMODE_VOXELS] = hasSolid;
valid[DRAWMODE_VOXELS_WALKABLE] = hasSolid;
valid[DRAWMODE_COMPACT] = hasChf;
valid[DRAWMODE_COMPACT_DISTANCE] = hasChf;
valid[DRAWMODE_COMPACT_REGIONS] = hasChf;
valid[DRAWMODE_REGION_CONNECTIONS] = hasCset;
valid[DRAWMODE_RAW_CONTOURS] = hasCset;
valid[DRAWMODE_BOTH_CONTOURS] = hasCset;
valid[DRAWMODE_CONTOURS] = hasCset;
valid[DRAWMODE_POLYMESH] = m_polyMesh != 0;
}
if (!valid[m_drawMode])
m_drawMode = DRAWMODE_MESH;
int unavail = 0;
for (int i = 0; i < MAX_DRAWMODE; ++i)
if (!valid[i]) unavail++;
if (unavail == MAX_DRAWMODE)
return;
imguiLabel(GENID, "Draw");
if (valid[DRAWMODE_MESH] && imguiCheck(GENID, "Input Mesh", m_drawMode == DRAWMODE_MESH))
m_drawMode = DRAWMODE_MESH;
if (valid[DRAWMODE_NAVMESH] && imguiCheck(GENID, "Navmesh", m_drawMode == DRAWMODE_NAVMESH))
m_drawMode = DRAWMODE_NAVMESH;
if (valid[DRAWMODE_NAVMESH_INVIS] && imguiCheck(GENID, "Navmesh Invis", m_drawMode == DRAWMODE_NAVMESH_INVIS))
m_drawMode = DRAWMODE_NAVMESH_INVIS;
if (valid[DRAWMODE_NAVMESH_TRANS] && imguiCheck(GENID, "Navmesh Trans", m_drawMode == DRAWMODE_NAVMESH_TRANS))
m_drawMode = DRAWMODE_NAVMESH_TRANS;
if (valid[DRAWMODE_NAVMESH_BVTREE] && imguiCheck(GENID, "Navmesh BVTree", m_drawMode == DRAWMODE_NAVMESH_BVTREE))
m_drawMode = DRAWMODE_NAVMESH_BVTREE;
if (valid[DRAWMODE_VOXELS] && imguiCheck(GENID, "Voxels", m_drawMode == DRAWMODE_VOXELS))
m_drawMode = DRAWMODE_VOXELS;
if (valid[DRAWMODE_VOXELS_WALKABLE] && imguiCheck(GENID, "Walkable Voxels", m_drawMode == DRAWMODE_VOXELS_WALKABLE))
m_drawMode = DRAWMODE_VOXELS_WALKABLE;
if (valid[DRAWMODE_COMPACT] && imguiCheck(GENID, "Compact", m_drawMode == DRAWMODE_COMPACT))
m_drawMode = DRAWMODE_COMPACT;
if (valid[DRAWMODE_COMPACT_DISTANCE] && imguiCheck(GENID, "Compact Distance", m_drawMode == DRAWMODE_COMPACT_DISTANCE))
m_drawMode = DRAWMODE_COMPACT_DISTANCE;
if (valid[DRAWMODE_COMPACT_REGIONS] && imguiCheck(GENID, "Compact Regions", m_drawMode == DRAWMODE_COMPACT_REGIONS))
m_drawMode = DRAWMODE_COMPACT_REGIONS;
if (valid[DRAWMODE_REGION_CONNECTIONS] && imguiCheck(GENID, "Region Connections", m_drawMode == DRAWMODE_REGION_CONNECTIONS))
m_drawMode = DRAWMODE_REGION_CONNECTIONS;
if (valid[DRAWMODE_RAW_CONTOURS] && imguiCheck(GENID, "Raw Contours", m_drawMode == DRAWMODE_RAW_CONTOURS))
m_drawMode = DRAWMODE_RAW_CONTOURS;
if (valid[DRAWMODE_BOTH_CONTOURS] && imguiCheck(GENID, "Both Contours", m_drawMode == DRAWMODE_BOTH_CONTOURS))
m_drawMode = DRAWMODE_BOTH_CONTOURS;
if (valid[DRAWMODE_CONTOURS] && imguiCheck(GENID, "Contours", m_drawMode == DRAWMODE_CONTOURS))
m_drawMode = DRAWMODE_CONTOURS;
if (valid[DRAWMODE_POLYMESH] && imguiCheck(GENID, "Poly Mesh", m_drawMode == DRAWMODE_POLYMESH))
m_drawMode = DRAWMODE_POLYMESH;
if (unavail)
{
imguiValue(GENID, "Tick 'Keep Itermediate Results'");
imguiValue(GENID, "to see more debug mode options.");
}
}
void BuilderStatMeshTiled::handleRender()
{
if (!m_verts || !m_tris || !m_trinorms)
return;
float col[4];
glEnable(GL_FOG);
glDepthMask(GL_TRUE);
if (m_drawMode == DRAWMODE_MESH)
{
// Draw mesh
rcDebugDrawMeshSlope(m_verts, m_nverts, m_tris, m_trinorms, m_ntris, m_agentMaxSlope);
}
else if (m_drawMode != DRAWMODE_NAVMESH_TRANS)
{
// Draw mesh
rcDebugDrawMesh(m_verts, m_nverts, m_tris, m_trinorms, m_ntris, 0);
}
glDisable(GL_FOG);
glDepthMask(GL_FALSE);
// Draw bounds
col[0] = 1; col[1] = 1; col[2] = 1; col[3] = 0.5f;
rcDebugDrawBoxWire(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();
if (m_navMesh &&
(m_drawMode == DRAWMODE_NAVMESH ||
m_drawMode == DRAWMODE_NAVMESH_TRANS ||
m_drawMode == DRAWMODE_NAVMESH_BVTREE ||
m_drawMode == DRAWMODE_NAVMESH_INVIS))
{
int flags = NAVMESH_TOOLS;
if (m_drawMode != DRAWMODE_NAVMESH_INVIS)
flags |= NAVMESH_POLYS;
if (m_drawMode == DRAWMODE_NAVMESH_BVTREE)
flags |= NAVMESH_BVTREE;
toolRender(flags);
}
glDepthMask(GL_TRUE);
if (m_tileSet)
{
if (m_drawMode == DRAWMODE_COMPACT)
{
for (int i = 0; i < m_tileSet->width*m_tileSet->height; ++i)
{
if (m_tileSet->tiles[i].chf)
rcDebugDrawCompactHeightfieldSolid(*m_tileSet->tiles[i].chf);
}
}
if (m_drawMode == DRAWMODE_COMPACT_DISTANCE)
{
for (int i = 0; i < m_tileSet->width*m_tileSet->height; ++i)
{
if (m_tileSet->tiles[i].chf)
rcDebugDrawCompactHeightfieldDistance(*m_tileSet->tiles[i].chf);
}
}
if (m_drawMode == DRAWMODE_COMPACT_REGIONS)
{
for (int i = 0; i < m_tileSet->width*m_tileSet->height; ++i)
{
if (m_tileSet->tiles[i].chf)
rcDebugDrawCompactHeightfieldRegions(*m_tileSet->tiles[i].chf);
}
}
if (m_drawMode == DRAWMODE_VOXELS)
{
glEnable(GL_FOG);
for (int i = 0; i < m_tileSet->width*m_tileSet->height; ++i)
{
if (m_tileSet->tiles[i].solid)
rcDebugDrawHeightfieldSolid(*m_tileSet->tiles[i].solid);
}
glDisable(GL_FOG);
}
if (m_drawMode == DRAWMODE_VOXELS_WALKABLE)
{
glEnable(GL_FOG);
for (int i = 0; i < m_tileSet->width*m_tileSet->height; ++i)
{
if (m_tileSet->tiles[i].solid)
rcDebugDrawHeightfieldWalkable(*m_tileSet->tiles[i].solid);
}
glDisable(GL_FOG);
}
if (m_drawMode == DRAWMODE_RAW_CONTOURS)
{
glDepthMask(GL_FALSE);
for (int i = 0; i < m_tileSet->width*m_tileSet->height; ++i)
{
if (m_tileSet->tiles[i].cset)
rcDebugDrawRawContours(*m_tileSet->tiles[i].cset, m_cfg.bmin, m_cfg.cs, m_cfg.ch);
}
glDepthMask(GL_TRUE);
}
if (m_drawMode == DRAWMODE_BOTH_CONTOURS)
{
glDepthMask(GL_FALSE);
for (int i = 0; i < m_tileSet->width*m_tileSet->height; ++i)
{
if (m_tileSet->tiles[i].cset)
{
rcDebugDrawRawContours(*m_tileSet->tiles[i].cset, m_cfg.bmin, m_cfg.cs, m_cfg.ch, 0.5f);
rcDebugDrawContours(*m_tileSet->tiles[i].cset, m_cfg.bmin, m_cfg.cs, m_cfg.ch);
}
}
glDepthMask(GL_TRUE);
}
if (m_drawMode == DRAWMODE_CONTOURS)
{
glDepthMask(GL_FALSE);
for (int i = 0; i < m_tileSet->width*m_tileSet->height; ++i)
{
if (m_tileSet->tiles[i].cset)
rcDebugDrawContours(*m_tileSet->tiles[i].cset, m_cfg.bmin, m_cfg.cs, m_cfg.ch);
}
glDepthMask(GL_TRUE);
}
if (m_drawMode == DRAWMODE_REGION_CONNECTIONS)
{
for (int i = 0; i < m_tileSet->width*m_tileSet->height; ++i)
{
if (m_tileSet->tiles[i].chf)
rcDebugDrawCompactHeightfieldRegions(*m_tileSet->tiles[i].chf);
}
glDepthMask(GL_FALSE);
for (int i = 0; i < m_tileSet->width*m_tileSet->height; ++i)
{
if (m_tileSet->tiles[i].cset)
rcDebugDrawRegionConnections(*m_tileSet->tiles[i].cset, m_cfg.bmin, m_cfg.cs, m_cfg.ch);
}
glDepthMask(GL_TRUE);
}
if (m_polyMesh && m_drawMode == DRAWMODE_POLYMESH)
{
glDepthMask(GL_FALSE);
rcDebugDrawPolyMesh(*m_polyMesh);
glDepthMask(GL_TRUE);
}
}
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 };
if (m_sposSet)
drawAgent(m_spos, m_agentRadius, m_agentHeight, m_agentMaxClimb, startCol);
if (m_eposSet)
drawAgent(m_epos, m_agentRadius, m_agentHeight, m_agentMaxClimb, endCol);
}
static float nicenum(float x, int round)
{
float expv = floorf(log10f(x));
float f = x / powf(10.0f, expv);
float nf;
if (round)
{
if (f < 1.5f) nf = 1.0f;
else if (f < 3.0f) nf = 2.0f;
else if (f < 7.0f) nf = 5.0f;
else nf = 10.0f;
}
else
{
if (f <= 1.0f) nf = 1.0f;
else if (f <= 2.0f) nf = 2.0f;
else if (f <= 5.0f) nf = 5.0f;
else nf = 10.0f;
}
return nf*powf(10.0f, expv);
}
static void drawLabels(int x, int y, int w, int h,
int nticks, float vmin, float vmax, const char* unit, GLFont* font)
{
char str[8], temp[32];
float range = nicenum(vmax-vmin, 0);
float d = nicenum(range/(float)(nticks-1), 1);
float graphmin = floorf(vmin/d)*d;
float graphmax = ceilf(vmax/d)*d;
int nfrac = (int)-floorf(log10f(d));
if (nfrac < 0) nfrac = 0;
snprintf(str, 6, "%%.%df %%s", nfrac);
for (float v = graphmin; v < graphmax+d/2; v += d)
{
float lx = x + (v-vmin)/(vmax-vmin)*w;
if (lx < 0 || lx > w) continue;
snprintf(temp, 20, str, v, unit);
font->drawText(lx+2, (float)y+2, temp, GLFont::RGBA(255,255,255));
glColor4ub(0,0,0,64);
glBegin(GL_LINES);
glVertex2f(lx,(float)y);
glVertex2f(lx,(float)(y+h));
glEnd();
}
}
static void drawGraph(const char* name, int x, int y, int w, int h, float sd,
const int* samples, int n, int nsamples, const char* unit, GLFont* font)
{
char text[64];
int first, last, maxval;
first = 0;
last = n-1;
while (first < n && samples[first] == 0)
first++;
while (last >= 0 && samples[last] == 0)
last--;
if (first == last)
return;
maxval = 1;
for (int i = first; i <= last; ++i)
{
if (samples[i] > maxval)
maxval = samples[i];
}
const float sx = (float)w / (float)(last-first);
const float sy = (float)h / (float)maxval;
glBegin(GL_QUADS);
glColor4ub(32,32,32,64);
glVertex2i(x,y);
glVertex2i(x+w,y);
glVertex2i(x+w,y+h);
glVertex2i(x,y+h);
glEnd();
glColor4ub(255,255,255,64);
glBegin(GL_LINES);
for (int i = 0; i <= 4; ++i)
{
int yy = y+i*h/4;
glVertex2i(x,yy);
glVertex2i(x+w,yy);
}
glEnd();
glColor4ub(0,196,255,255);
glBegin(GL_LINE_STRIP);
for (int i = first; i <= last; ++i)
{
float fx = x + (i-first)*sx;
float fy = y + samples[i]*sy;
glVertex2f(fx,fy);
}
glEnd();
snprintf(text,64,"%d", maxval);
font->drawText((float)x+w-20+2,(float)y+h-2-font->getLineHeight(),text,GLFont::RGBA(0,0,0));
font->drawText((float)x+2,(float)y+h-2-font->getLineHeight(),name,GLFont::RGBA(255,255,255));
drawLabels(x, y, w, h, 10, first*sd, last*sd, unit, font);
}
void BuilderStatMeshTiled::handleRenderOverlay(class GLFont* font, double* proj, double* model, int* view)
{
toolRenderOverlay(font, proj, model, view);
if (m_measurePerTileTimings)
{
if (m_statTimePerTileSamples)
drawGraph("Build Time/Tile", 10, 10, 500, 100, 1.0f, m_statTimePerTile, MAX_STAT_BUCKETS, m_statTimePerTileSamples, "ms", font);
if (m_statPolysPerTileSamples)
drawGraph("Polygons/Tile", 10, 120, 500, 100, 1.0f, m_statPolysPerTile, MAX_STAT_BUCKETS, m_statPolysPerTileSamples, "", font);
int validTiles = 0;
if (m_tileSet)
{
for (int i = 0; i < m_tileSet->width*m_tileSet->height; ++i)
{
if (m_tileSet->tiles[i].buildTime > 0)
validTiles++;
}
}
char text[64];
snprintf(text,64,"Tiles %d\n", validTiles);
font->drawText(10, 240, text, GLFont::RGBA(255,255,255));
}
}
void BuilderStatMeshTiled::handleMeshChanged(const float* verts, int nverts,
const int* tris, const float* trinorms, int ntris,
const float* bmin, const float* bmax)
{
Builder::handleMeshChanged(verts, nverts, tris, trinorms, ntris, bmin, bmax);
toolCleanup();
toolReset();
m_statTimePerTileSamples = 0;
m_statPolysPerTileSamples = 0;
}
bool BuilderStatMeshTiled::handleBuild()
{
if (!m_verts || ! m_tris)
{
if (rcGetLog())
rcGetLog()->log(RC_LOG_ERROR, "buildNavigation: Input mesh is not specified.");
return false;
}
if (m_measurePerTileTimings)
{
memset(m_statPolysPerTile, 0, sizeof(m_statPolysPerTile));
memset(m_statTimePerTile, 0, sizeof(m_statTimePerTile));
m_statPolysPerTileSamples = 0;
m_statTimePerTileSamples = 0;
}
cleanup();
toolCleanup();
toolReset();
// 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*2 + 2; // Reserve enough padding.
if (m_cfg.maxVertsPerPoly == DT_VERTS_PER_POLYGON)
m_drawMode = DRAWMODE_NAVMESH;
else
m_drawMode = DRAWMODE_POLYMESH;
// Set the area where the navigation will be build.
// Here the bounds of the input mesh are used, but the
// area could be specified by an user defined box, etc.
vcopy(m_cfg.bmin, m_bmin);
vcopy(m_cfg.bmax, m_bmax);
rcCalcGridSize(m_cfg.bmin, m_cfg.bmax, m_cfg.cs, &m_cfg.width, &m_cfg.height);
// Reset build times gathering.
memset(&m_buildTimes, 0, sizeof(m_buildTimes));
rcSetBuildTimes(&m_buildTimes);
// Start the build process.
rcTimeVal totStartTime = rcGetPerformanceTimer();
// Calculate the number of tiles in the output and initialize tiles.
m_tileSet = new TileSet;
if (!m_tileSet)
{
if (rcGetLog())
rcGetLog()->log(RC_LOG_ERROR, "buildTiledNavigation: Out of memory 'tileSet'.");
return false;
}
vcopy(m_tileSet->bmin, m_cfg.bmin);
vcopy(m_tileSet->bmax, m_cfg.bmax);
m_tileSet->cs = m_cfg.cs;
m_tileSet->ch = m_cfg.ch;
m_tileSet->width = (m_cfg.width + m_cfg.tileSize-1) / m_cfg.tileSize;
m_tileSet->height = (m_cfg.height + m_cfg.tileSize-1) / m_cfg.tileSize;
m_tileSet->tiles = new Tile[m_tileSet->height * m_tileSet->width];
if (!m_tileSet->tiles)
{
if (rcGetLog())
rcGetLog()->log(RC_LOG_ERROR, "buildTiledNavigation: Out of memory 'tileSet->tiles' (%d).", m_tileSet->height * m_tileSet->width);
return false;
}
// Build chunky trimesh for local polygon queries.
rcTimeVal chunkyStartTime = rcGetPerformanceTimer();
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;
}
rcTimeVal chunkyEndTime = 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, " - %d x %d tiles", m_tileSet->width, m_tileSet->height);
rcGetLog()->log(RC_LOG_PROGRESS, " - %.1f verts, %.1f tris", m_nverts/1000.0f, m_ntris/1000.0f);
}
// Initialize per tile config.
rcConfig tileCfg;
memcpy(&tileCfg, &m_cfg, sizeof(rcConfig));
tileCfg.width = m_cfg.tileSize + m_cfg.borderSize*2;
tileCfg.height = m_cfg.tileSize + m_cfg.borderSize*2;
// Allocate array that can hold triangle flags for all geom chunks.
unsigned char* triangleFlags = new unsigned char[m_chunkyMesh->maxTrisPerChunk];
if (!triangleFlags)
{
if (rcGetLog())
rcGetLog()->log(RC_LOG_ERROR, "buildTiledNavigation: Out of memory 'triangleFlags' (%d).", m_chunkyMesh->maxTrisPerChunk);
return false;
}
rcHeightfield* solid = 0;
rcCompactHeightfield* chf = 0;
rcContourSet* cset = 0;
for (int y = 0; y < m_tileSet->height; ++y)
{
for (int x = 0; x < m_tileSet->width; ++x)
{
rcTimeVal startTime = rcGetPerformanceTimer();
Tile& tile = m_tileSet->tiles[x + y*m_tileSet->width];
// Calculate the per tile bounding box.
tileCfg.bmin[0] = m_cfg.bmin[0] + (x*m_cfg.tileSize - m_cfg.borderSize)*m_cfg.cs;
tileCfg.bmin[2] = m_cfg.bmin[2] + (y*m_cfg.tileSize - m_cfg.borderSize)*m_cfg.cs;
tileCfg.bmax[0] = m_cfg.bmin[0] + ((x+1)*m_cfg.tileSize + m_cfg.borderSize)*m_cfg.cs;
tileCfg.bmax[2] = m_cfg.bmin[2] + ((y+1)*m_cfg.tileSize + m_cfg.borderSize)*m_cfg.cs;
delete solid;
delete chf;
solid = 0;
chf = 0;
float tbmin[2], tbmax[2];
tbmin[0] = tileCfg.bmin[0];
tbmin[1] = tileCfg.bmin[2];
tbmax[0] = tileCfg.bmax[0];
tbmax[1] = tileCfg.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)
continue;
solid = new rcHeightfield;
if (!solid)
{
if (rcGetLog())
rcGetLog()->log(RC_LOG_ERROR, "buildTiledNavigation: [%d,%d] Out of memory 'solid'.", x, y);
continue;
}
if (!rcCreateHeightfield(*solid, tileCfg.width, tileCfg.height, tileCfg.bmin, tileCfg.bmax, tileCfg.cs, tileCfg.ch))
{
if (rcGetLog())
rcGetLog()->log(RC_LOG_ERROR, "buildTiledNavigation: [%d,%d] Could not create solid heightfield.", x, y);
continue;
}
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;
memset(triangleFlags, 0, ntris*sizeof(unsigned char));
rcMarkWalkableTriangles(tileCfg.walkableSlopeAngle,
m_verts, m_nverts, tris, ntris, triangleFlags);
rcRasterizeTriangles(m_verts, m_nverts, tris, triangleFlags, ntris, *solid);
}
rcFilterLedgeSpans(tileCfg.walkableHeight, tileCfg.walkableClimb, *solid);
rcFilterWalkableLowHeightSpans(tileCfg.walkableHeight, *solid);
chf = new rcCompactHeightfield;
if (!chf)
{
if (rcGetLog())
rcGetLog()->log(RC_LOG_ERROR, "buildTiledNavigation: [%d,%d] Out of memory 'chf'.", x, y);
continue;
}
if (!rcBuildCompactHeightfield(tileCfg.walkableHeight, tileCfg.walkableClimb,
RC_WALKABLE, *solid, *chf))
{
if (rcGetLog())
rcGetLog()->log(RC_LOG_ERROR, "buildTiledNavigation: [%d,%d] Could not build compact data.", x, y);
continue;
}
if (!rcBuildDistanceField(*chf))
{
if (rcGetLog())
rcGetLog()->log(RC_LOG_ERROR, "buildTiledNavigation: [%d,%d] Could not build distance fields.", x, y);
continue;
}
if (!rcBuildRegions(*chf, tileCfg.walkableRadius, tileCfg.borderSize, tileCfg.minRegionSize, tileCfg.mergeRegionSize))
{
if (rcGetLog())
rcGetLog()->log(RC_LOG_ERROR, "buildTiledNavigation: [%d,%d] Could not build regions.", x, y);
continue;
}
cset = new rcContourSet;
if (!cset)
{
if (rcGetLog())
rcGetLog()->log(RC_LOG_ERROR, "buildTiledNavigation: [%d,%d] Out of memory 'cset'.", x, y);
continue;
}
if (!rcBuildContours(*chf, tileCfg.maxSimplificationError, tileCfg.maxEdgeLen, *cset))
{
if (rcGetLog())
rcGetLog()->log(RC_LOG_ERROR, "buildTiledNavigation: [%d,%d] Could not create contours.", x, y);
continue;
}
if (m_keepInterResults)
{
tile.solid = solid;
solid = 0;
tile.chf = chf;
chf = 0;
}
if (!cset->nconts)
{
delete cset;
cset = 0;
continue;
}
tile.cset = cset;
// Offset the vertices in the cset.
rcTranslateContours(tile.cset, x*tileCfg.tileSize - tileCfg.borderSize, 0, y*tileCfg.tileSize - tileCfg.borderSize);
rcTimeVal endTime = rcGetPerformanceTimer();
tile.buildTime += rcGetDeltaTimeUsec(startTime, endTime);
}
}
delete [] triangleFlags;
delete solid;
delete chf;
// Some extra code to measure some per tile statistics,
// such as build time and how many polygons there are per tile.
if (m_measurePerTileTimings)
{
for (int y = 0; y < m_tileSet->height; ++y)
{
for (int x = 0; x < m_tileSet->width; ++x)
{
Tile& tile = m_tileSet->tiles[x + y*m_tileSet->width];
if (!tile.cset)
continue;
rcTimeVal startTime = rcGetPerformanceTimer();
rcPolyMesh* polyMesh = new rcPolyMesh;
if (!polyMesh)
continue;
if (rcBuildPolyMesh(*tile.cset, m_cfg.bmin, m_cfg.bmax,
m_cfg.cs, m_cfg.ch, m_cfg.maxVertsPerPoly, *polyMesh))
{
int bucket = polyMesh->npolys;
if (bucket < 0) bucket = 0;
if (bucket >= MAX_STAT_BUCKETS) bucket = MAX_STAT_BUCKETS-1;
m_statPolysPerTile[bucket]++;
m_statPolysPerTileSamples++;
}
delete polyMesh;
rcTimeVal endTime = rcGetPerformanceTimer();
int time = tile.buildTime += rcGetDeltaTimeUsec(startTime, endTime);
int bucket = (time+500)/1000;
if (bucket < 0) bucket = 0;
if (bucket >= MAX_STAT_BUCKETS) bucket = MAX_STAT_BUCKETS-1;
m_statTimePerTile[bucket]++;
m_statTimePerTileSamples++;
}
}
}
// Make sure that the vertices along the tile edges match,
// so that they can be later properly stitched together.
for (int y = 0; y < m_tileSet->height; ++y)
{
for (int x = 0; x < m_tileSet->width; ++x)
{
rcTimeVal startTime = rcGetPerformanceTimer();
if ((x+1) < m_tileSet->width)
{
if (!rcFixupAdjacentContours(m_tileSet->tiles[x + y*m_tileSet->width].cset,
m_tileSet->tiles[x+1 + y*m_tileSet->width].cset,
m_cfg.walkableClimb, (x+1)*m_cfg.tileSize, -1))
{
if (rcGetLog())
rcGetLog()->log(RC_LOG_ERROR, "buildTiledNavigation: [%d,%d] Could not fixup x+1.", x, y);
return false;
}
}
if ((y+1) < m_tileSet->height)
{
if (!rcFixupAdjacentContours(m_tileSet->tiles[x + y*m_tileSet->width].cset,
m_tileSet->tiles[x + (y+1)*m_tileSet->width].cset,
m_cfg.walkableClimb, -1, (y+1)*m_cfg.tileSize))
{
if (rcGetLog())
rcGetLog()->log(RC_LOG_ERROR, "buildTiledNavigation: [%d,%d] Could not fixup y+1.", x, y);
return false;
}
}
rcTimeVal endTime = rcGetPerformanceTimer();
m_tileSet->tiles[x+y*m_tileSet->width].buildTime += rcGetDeltaTimeUsec(startTime, endTime);
}
}
// Combine contours.
rcContourSet combSet;
combSet.nconts = 0;
for (int y = 0; y < m_tileSet->height; ++y)
{
for (int x = 0; x < m_tileSet->width; ++x)
{
Tile& tile = m_tileSet->tiles[x + y*m_tileSet->width];
if (!tile.cset) continue;
combSet.nconts += tile.cset->nconts;
}
}
combSet.conts = new rcContour[combSet.nconts];
if (!combSet.conts)
{
if (rcGetLog())
rcGetLog()->log(RC_LOG_ERROR, "buildTiledNavigation: Out of memory 'combSet.conts' (%d).", combSet.nconts);
return false;
}
int n = 0;
for (int y = 0; y < m_tileSet->height; ++y)
{
for (int x = 0; x < m_tileSet->width; ++x)
{
Tile& tile = m_tileSet->tiles[x + y*m_tileSet->width];
if (!tile.cset) continue;
for (int i = 0; i < tile.cset->nconts; ++i)
{
combSet.conts[n].verts = tile.cset->conts[i].verts;
combSet.conts[n].nverts = tile.cset->conts[i].nverts;
combSet.conts[n].reg = tile.cset->conts[i].reg;
n++;
}
}
}
m_polyMesh = new rcPolyMesh;
if (!m_polyMesh)
{
if (rcGetLog())
rcGetLog()->log(RC_LOG_ERROR, "buildNavigation: Out of memory 'polyMesh'.");
return false;
}
bool polyRes = rcBuildPolyMesh(combSet, m_cfg.bmin, m_cfg.bmax, m_cfg.cs, m_cfg.ch, m_cfg.maxVertsPerPoly, *m_polyMesh);
// Remove vertex binding to avoid double deletion.
for (int i = 0; i < combSet.nconts; ++i)
{
combSet.conts[i].verts = 0;
combSet.conts[i].nverts = 0;
}
if (!polyRes)
{
if (rcGetLog())
rcGetLog()->log(RC_LOG_ERROR, "buildTiledNavigation: Could not triangulate contours.");
return false;
}
if (!m_keepInterResults)
{
for (int y = 0; y < m_tileSet->height; ++y)
{
for (int x = 0; x < m_tileSet->width; ++x)
{
Tile& tile = m_tileSet->tiles[x + y*m_tileSet->width];
delete tile.cset;
tile.cset = 0;
}
}
}
if (m_cfg.maxVertsPerPoly == DT_VERTS_PER_POLYGON)
{
unsigned char* navData = 0;
int navDataSize = 0;
if (!dtCreateNavMeshData(m_polyMesh->verts, m_polyMesh->nverts,
m_polyMesh->polys, m_polyMesh->npolys, m_polyMesh->nvp,
m_cfg.bmin, m_cfg.bmax, m_cfg.cs, m_cfg.ch, &navData, &navDataSize))
{
if (rcGetLog())
rcGetLog()->log(RC_LOG_ERROR, "Could not build Detour navmesh.");
return false;
}
m_navMesh = new dtStatNavMesh;
if (!m_navMesh)
{
delete [] navData;
if (rcGetLog())
rcGetLog()->log(RC_LOG_ERROR, "Could not create Detour navmesh");
return false;
}
if (!m_navMesh->init(navData, navDataSize, true))
{
if (rcGetLog())
rcGetLog()->log(RC_LOG_ERROR, "Could not init Detour navmesh");
return false;
}
}
rcTimeVal totEndTime = rcGetPerformanceTimer();
if (rcGetLog())
{
const float pc = 100.0f / rcGetDeltaTimeUsec(totStartTime, totEndTime);
rcGetLog()->log(RC_LOG_PROGRESS, "Chunky Mesh: %.1fms (%.1f%%)", rcGetDeltaTimeUsec(chunkyStartTime, chunkyEndTime)/1000.0f, rcGetDeltaTimeUsec(chunkyStartTime, chunkyEndTime)*pc);
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, "Fixup contours: %.1fms (%.1f%%)", m_buildTimes.fixupContours/1000.0f, m_buildTimes.fixupContours*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_polyMesh->nverts, m_polyMesh->npolys);
rcGetLog()->log(RC_LOG_PROGRESS, "TOTAL: %.1fms", rcGetDeltaTimeUsec(totStartTime, totEndTime)/1000.0f);
}
toolRecalc();
return true;
}

View File

@@ -1,899 +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 "glfont.h"
#include "Builder.h"
#include "BuilderTiledMesh.h"
#include "Recast.h"
#include "RecastTimer.h"
#include "RecastDebugDraw.h"
#include "DetourTiledNavMesh.h"
#include "DetourTiledNavMeshBuilder.h"
#include "DetourDebugDraw.h"
#ifdef WIN32
# define snprintf _snprintf
#endif
BuilderTiledMesh::BuilderTiledMesh() :
m_tileSize(32),
m_navMesh(0),
m_chunkyMesh(0),
m_keepInterResults(true),
m_tileBuildTime(0),
m_tileMemUsage(0),
m_triflags(0),
m_solid(0),
m_chf(0),
m_cset(0),
m_polyMesh(0),
m_tileTriCount(0),
m_toolMode(TOOLMODE_CREATE_TILES),
m_startRef(0),
m_endRef(0),
m_npolys(0),
m_nstraightPath(0)
{
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;
}
BuilderTiledMesh::~BuilderTiledMesh()
{
cleanup();
delete m_navMesh;
delete m_chunkyMesh;
}
void BuilderTiledMesh::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_polyMesh;
m_polyMesh = 0;
}
void BuilderTiledMesh::handleSettings()
{
Builder::handleCommonSettings();
imguiLabel(GENID, "Tiling");
imguiSlider(GENID, "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(GENID, text);
}
void BuilderTiledMesh::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_eposSet)
// m_npolys = m_navMesh->queryPolygons(m_epos, m_polyPickExt, m_polys, MAX_POLYS);
/* if (m_startRef && m_endRef)
{
m_npolys = m_navMesh->findPath(m_startRef, m_endRef, 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;
}
*/
if (m_toolMode == TOOLMODE_PATHFIND)
{
if (m_sposSet && m_eposSet && m_startRef && m_endRef)
{
m_npolys = m_navMesh->findPath(m_startRef, m_endRef, 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, 0, MAX_POLYS);
}
}
}
void BuilderTiledMesh::handleTools()
{
if (imguiCheck(GENID, "Create Tiles", m_toolMode == TOOLMODE_CREATE_TILES))
{
m_toolMode = TOOLMODE_CREATE_TILES;
toolRecalc();
}
if (imguiCheck(GENID, "Pathfind", m_toolMode == TOOLMODE_PATHFIND))
{
m_toolMode = TOOLMODE_PATHFIND;
toolRecalc();
}
if (imguiCheck(GENID, "Distance to Wall", m_toolMode == TOOLMODE_DISTANCE_TO_WALL))
{
m_toolMode = TOOLMODE_DISTANCE_TO_WALL;
toolRecalc();
}
if (imguiCheck(GENID, "Raycast", m_toolMode == TOOLMODE_RAYCAST))
{
m_toolMode = TOOLMODE_RAYCAST;
toolRecalc();
}
if (imguiCheck(GENID, "Find Polys Around", m_toolMode == TOOLMODE_FIND_POLYS_AROUND))
{
m_toolMode = TOOLMODE_FIND_POLYS_AROUND;
toolRecalc();
}
}
void BuilderTiledMesh::handleDebugMode()
{
}
static void getPolyCenter(dtTiledNavMesh* navMesh, dtTilePolyRef ref, float* center)
{
const dtTilePoly* 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 BuilderTiledMesh::handleRender()
{
if (!m_verts || !m_tris || !m_trinorms)
return;
// Draw mesh
rcDebugDrawMesh(m_verts, m_nverts, m_tris, m_trinorms, m_ntris, 0);
glDepthMask(GL_FALSE);
// Draw bounds
float col[4] = {1,1,1,0.5f};
rcDebugDrawBoxWire(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(m_tileBmin[0],m_tileBmin[1],m_tileBmin[2], m_tileBmax[0],m_tileBmax[1],m_tileBmax[2], m_tileCol);
/* if (m_eposSet)
{
col[0] = 1; col[1] = 1; col[2] = 1; col[3] = 1;
const float s = 0.2f;
rcDebugDrawBoxWire(m_epos[0]-s,m_epos[1]-s,m_epos[2]-s, m_epos[0]+s,m_epos[1]+s,m_epos[2]+s, col);
}*/
/* if (m_polyMesh)
rcDebugDrawPolyMesh(*m_polyMesh);*/
if (m_navMesh)
dtDebugDrawTiledNavMesh(m_navMesh);
if (m_sposSet)
{
const float s = 0.5f;
glColor4ub(128,0,0,255);
glBegin(GL_LINES);
glVertex3f(m_spos[0]-s,m_spos[1],m_spos[2]);
glVertex3f(m_spos[0]+s,m_spos[1],m_spos[2]);
glVertex3f(m_spos[0],m_spos[1]-s,m_spos[2]);
glVertex3f(m_spos[0],m_spos[1]+s,m_spos[2]);
glVertex3f(m_spos[0],m_spos[1],m_spos[2]-s);
glVertex3f(m_spos[0],m_spos[1],m_spos[2]+s);
glEnd();
}
if (m_eposSet)
{
const float s = 0.5f;
glColor4ub(0,128,0,255);
glBegin(GL_LINES);
glVertex3f(m_epos[0]-s,m_epos[1],m_epos[2]);
glVertex3f(m_epos[0]+s,m_epos[1],m_epos[2]);
glVertex3f(m_epos[0],m_epos[1]-s,m_epos[2]);
glVertex3f(m_epos[0],m_epos[1]+s,m_epos[2]);
glVertex3f(m_epos[0],m_epos[1],m_epos[2]-s);
glVertex3f(m_epos[0],m_epos[1],m_epos[2]+s);
glEnd();
col[0] = 0; col[1] = 1; col[2] = 0; col[3] = 1;
rcDebugDrawBoxWire(m_epos[0]-m_polyPickExt[0],m_epos[1]-m_polyPickExt[1],m_epos[2]-m_polyPickExt[2],
m_epos[0]+m_polyPickExt[0],m_epos[1]+m_polyPickExt[1],m_epos[2]+m_polyPickExt[2], col);
}
/* if (m_startRef && m_navMesh)
{
col[0] = 1; col[1] = 0; col[2] = 0; col[3] = 1;
dtDebugDrawTiledNavMeshPoly(m_navMesh, m_startRef, col);
}
if (m_endRef && m_navMesh)
{
col[0] = 0; col[1] = 1; col[2] = 0; col[3] = 1;
dtDebugDrawTiledNavMeshPoly(m_navMesh, m_endRef, col);
dtTilePolyRef nei[DT_TILE_VERTS_PER_POLYGON*2];
int nn = m_navMesh->getPolyNeighbours(m_endRef, nei, DT_TILE_VERTS_PER_POLYGON*2);
if (nn)
{
col[0] = 0; col[1] = 0; col[2] = 1; col[3] = 1;
for (int i = 0; i < nn; ++i)
dtDebugDrawTiledNavMeshPoly(m_navMesh, nei[i], col);
}
}
if (m_npolys && m_navMesh)
{
col[0] = 0; col[1] = 0; col[2] = 0; col[3] = 1;
for (int i = 0; i < m_npolys; ++i)
dtDebugDrawTiledNavMeshPoly(m_navMesh, m_polys[i], col);
}
if (m_nstraightPath && m_navMesh)
{
glColor4ub(128,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);
}*/
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)
{
dtDebugDrawTiledNavMeshPoly(m_navMesh, m_startRef, startCol);
dtDebugDrawTiledNavMeshPoly(m_navMesh, m_endRef, endCol);
if (m_npolys)
{
for (int i = 1; i < m_npolys-1; ++i)
dtDebugDrawTiledNavMeshPoly(m_navMesh, m_polys[i], pathCol);
}
if (m_nstraightPath)
{
glColor4ub(128,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)
{
dtDebugDrawTiledNavMeshPoly(m_navMesh, m_startRef, startCol);
if (m_nstraightPath)
{
for (int i = 1; i < m_npolys; ++i)
dtDebugDrawTiledNavMeshPoly(m_navMesh, m_polys[i], pathCol);
glColor4ub(128,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)
{
dtDebugDrawTiledNavMeshPoly(m_navMesh, m_startRef, startCol);
const float col[4] = {1,1,1,0.5f};
rcDebugDrawCylinderWire(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)
{
glLineWidth(2.0f);
for (int i = 0; i < m_npolys; ++i)
{
dtDebugDrawTiledNavMeshPoly(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(p0, p1);
}
}
glLineWidth(1.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(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 BuilderTiledMesh::handleRenderOverlay(class GLFont* font, 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);
const float len = font->getTextLength(text);
font->drawText((float)x - len/2, (float)y-font->getLineHeight(), text, GLFont::RGBA(0,0,0,220));
}
}
void BuilderTiledMesh::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 BuilderTiledMesh::setToolStartPos(const float* p)
{
m_sposSet = true;
vcopy(m_spos, p);
if (m_toolMode == TOOLMODE_CREATE_TILES)
removeTile(m_spos);
else
toolRecalc();
}
void BuilderTiledMesh::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 BuilderTiledMesh::handleBuild()
{
if (!m_verts || !m_tris)
{
printf("No verts or tris\n");
return false;
}
delete m_navMesh;
m_navMesh = new dtTiledNavMesh;
if (!m_navMesh)
{
printf("Could not allocate navmehs\n");
return false;
}
if (!m_navMesh->init(m_bmin, m_tileSize*m_cellSize, m_agentMaxClimb*m_cellHeight))
{
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 BuilderTiledMesh::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.2f; m_tileCol[1] = 1; m_tileCol[2] = 0; m_tileCol[3] = 1;
int dataSize = 0;
unsigned char* data = buildTileMesh(m_tileBmin, m_tileBmax, dataSize);
if (data)
m_navMesh->addTile(tx,ty,data,dataSize);
}
void BuilderTiledMesh::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] = 1; m_tileCol[1] = 0; m_tileCol[2] = 0; m_tileCol[3] = 1;
m_navMesh->removeTile(tx,ty);
}
unsigned char* BuilderTiledMesh::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*2 + 2; // Reserve enough padding.
m_cfg.width = m_cfg.tileSize + m_cfg.borderSize*2;
m_cfg.height = m_cfg.tileSize + m_cfg.borderSize*2;
/* if (m_cfg.maxVertsPerPoly == DT_VERTS_PER_POLYGON)
m_drawMode = DRAWMODE_NAVMESH;
else
m_drawMode = DRAWMODE_POLYMESH;*/
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_keepInterResults)
{
delete m_chf;
m_chf = 0;
}
// Build polygon navmesh from the contours.
m_polyMesh = new rcPolyMesh;
if (!m_polyMesh)
{
if (rcGetLog())
rcGetLog()->log(RC_LOG_ERROR, "buildNavigation: Out of memory 'polyMesh'.");
return 0;
}
if (!rcBuildPolyMesh(*m_cset, m_cfg.bmin, m_cfg.bmax, m_cfg.cs, m_cfg.ch, m_cfg.maxVertsPerPoly, *m_polyMesh))
{
if (rcGetLog())
rcGetLog()->log(RC_LOG_ERROR, "buildNavigation: Could not triangulate contours.");
return 0;
}
if (!m_keepInterResults)
{
delete m_cset;
m_cset = 0;
}
unsigned char* navData = 0;
int navDataSize = 0;
if (m_cfg.maxVertsPerPoly == DT_TILE_VERTS_PER_POLYGON)
{
// Remove padding from the polymesh data.
for (int i = 0; i < m_polyMesh->nverts; ++i)
{
unsigned short* v = &m_polyMesh->verts[i*3];
v[0] -= (unsigned short)m_cfg.borderSize;
v[2] -= (unsigned short)m_cfg.borderSize;
}
if (!dtCreateNavMeshTileData(m_polyMesh->verts, m_polyMesh->nverts,
m_polyMesh->polys, m_polyMesh->npolys, m_polyMesh->nvp,
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, "Fixup contours: %.1fms (%.1f%%)", m_buildTimes.fixupContours/1000.0f, m_buildTimes.fixupContours*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_polyMesh->nverts, m_polyMesh->npolys);
rcGetLog()->log(RC_LOG_PROGRESS, "TOTAL: %.1fms", rcGetDeltaTimeUsec(totStartTime, totEndTime)/1000.0f);
}
m_tileBuildTime = rcGetDeltaTimeUsec(totStartTime, totEndTime)/1000.0f;
dataSize = navDataSize;
return navData;
}

View File

@@ -1,285 +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 "GlFont.h"
#include <stdio.h>
#define _USE_MATH_DEFINES
#include <math.h>
#include <SDL_Opengl.h>
#include <stdlib.h>
GLFont::GLFont(int renderVerts) :
m_fd(0),
m_texId(0),
m_verts(0),
m_nverts(0),
m_maxVerts(renderVerts)
{
}
GLFont::~GLFont()
{
if (m_texId)
glDeleteTextures(1, (GLuint*)&m_texId);
unsigned char* data = (unsigned char*)m_fd;
if (data)
free(data);
if (m_verts)
free(m_verts);
}
bool GLFont::create(const char* fileName)
{
unsigned char* data = 0;
FILE* fp = fopen(fileName, "rb");
if (!fp)
return false;
// Read cache file
fseek(fp, 0, SEEK_END);
unsigned n = ftell(fp);
fseek(fp, 0, SEEK_SET);
data = (unsigned char*)malloc(n);
fread(data, n, 1, fp);
fclose(fp);
if (!m_verts)
m_verts = (RenderVertex*)malloc(m_maxVerts*sizeof(RenderVertex));
return createFontFromFontData(data);
}
bool GLFont::createFontFromFontData(unsigned char* data)
{
if (!data)
{
printf("GLFont::createFontFromFontData: No input data!\n");
return false;
}
m_fd = (FontData*)data;
// Patch kern pointers.
for (int i = 0; i < m_fd->charCount; ++i)
m_fd->glyphs[i].kern = (KerningPair*)((int)m_fd->glyphs[i].kernOffset + data);
unsigned char* texData = data + m_fd->textureOffset;
// Create textures
glEnable(GL_TEXTURE_2D);
glGenTextures(1, (GLuint*)&m_texId);
glBindTexture(GL_TEXTURE_2D, m_texId);
glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
glTexImage2D(GL_TEXTURE_2D, 0, GL_ALPHA, m_fd->texWidth, m_fd->texHeight, 0,
GL_ALPHA, GL_UNSIGNED_BYTE, texData);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
return true;
}
int GLFont::getFontSize() const
{
return m_fd ? m_fd->fontSize : 0;
}
int GLFont::getDescender() const
{
return m_fd ? m_fd->descender : 0;
}
int GLFont::getAscender() const
{
return m_fd ? m_fd->ascender : 0;
}
float GLFont::getLineHeight() const
{
return m_fd ? m_fd->lineHeight : 0.0f;
}
float GLFont::getTextLength(const char* text, float size, float tracking)
{
if (!m_texId) return 0.0f;
if (!m_fd) return 0.0f;
float scale = size < 0 ? 1 : size / (float)m_fd->fontSize;
float track = scale * m_fd->ascender * tracking / 1000.0f;
const unsigned char* src = (const unsigned char*)text;
int prevc = -1;
float len = 0.0f;
float tx = 0.0f;
for (; *src; ++src)
{
int c = (int)*src - m_fd->charMin;
if (c < 0 || c >= m_fd->charCount)
{
prevc = c;
continue;
}
CachedGlyph& cg = m_fd->glyphs[c];
if (prevc > 0 && prevc < m_fd->charCount)
{
CachedGlyph& prevcg = m_fd->glyphs[prevc];
if (prevcg.nkern != 0)
{
for (int i = 0; i < prevcg.nkern; ++i)
{
if (prevcg.kern[i].c == c)
{
tx += prevcg.kern[i].dx * scale;
break;
}
}
}
}
len = tx + (cg.ox + cg.w) * scale;
tx += cg.adv * scale + track;
prevc = c;
}
return len;
}
void GLFont::drawText(float tx, float ty, const char* text,
unsigned int col, float size, float tracking)
{
if (!m_fd) return;
if (!m_texId) return;
if (!m_verts) return;
float scale = size < 0 ? 1 : size / (float)m_fd->fontSize;
float track = scale * m_fd->ascender * tracking / 1000.0f;
float su = 1.0f / m_fd->texWidth;
float sv = 1.0f / m_fd->texHeight;
const unsigned char* src = (const unsigned char*)text;
RenderVertex* v = &m_verts[m_nverts];
int prevc = -1;
for (; *src; ++src)
{
int c = (int)*src - m_fd->charMin;
if (c == '\n')
{
ty -= getLineHeight();
prevc = -1;
continue;
}
if (c < 0 || c >= m_fd->charCount)
{
prevc = c;
continue;
}
CachedGlyph& cg = m_fd->glyphs[c];
if (prevc > 0 && prevc < m_fd->charCount)
{
CachedGlyph& prevcg = m_fd->glyphs[prevc];
if (prevcg.nkern != 0)
{
for (int i = 0; i < prevcg.nkern; ++i)
{
if (prevcg.kern[i].c == c)
{
tx += prevcg.kern[i].dx * scale;
break;
}
}
}
}
float x0 = floorf(tx + (cg.ox - 1) * scale + 0.5f);
float y0 = floorf(ty + (cg.oy - 1) * scale + 0.5f);
float x1 = floorf(x0 + (cg.w + 2) * scale + 0.5f);
float y1 = floorf(y0 + (cg.h + 2) * scale + 0.5f);
float u0 = (cg.tx - 1) * su;
float v0 = (cg.ty - 1) * sv;
float u1 = (cg.tx + cg.w + 1) * su;
float v1 = (cg.ty + cg.h + 1) * sv;
if (m_nverts+6 > m_maxVerts) break;
v->set(x0, y0, u0, v0, col); v++;
v->set(x1, y0, u1, v0, col); v++;
v->set(x1, y1, u1, v1, col); v++;
v->set(x0, y0, u0, v0, col); v++;
v->set(x1, y1, u1, v1, col); v++;
v->set(x0, y1, u0, v1, col); v++;
m_nverts += 6;
tx += cg.adv * scale + track;
prevc = c;
}
render();
}
void GLFont::render()
{
if (!m_fd) return;
if (!m_texId) return;
if (!m_verts) return;
// Render
glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, m_texId);
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
glDisableClientState(GL_NORMAL_ARRAY);
glEnableClientState(GL_COLOR_ARRAY);
glEnableClientState(GL_VERTEX_ARRAY);
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
glVertexPointer(2, GL_FLOAT, sizeof(RenderVertex), &m_verts[0].x);
glTexCoordPointer(2, GL_FLOAT, sizeof(RenderVertex), &m_verts[0].u);
glColorPointer(4, GL_UNSIGNED_BYTE, sizeof(RenderVertex), &m_verts[0].col);
glDrawArrays(GL_TRIANGLES, 0, m_nverts);
m_nverts = 0;
glDisableClientState(GL_COLOR_ARRAY);
glDisableClientState(GL_VERTEX_ARRAY);
glDisableClientState(GL_TEXTURE_COORD_ARRAY);
glDisable(GL_TEXTURE_2D);
}
unsigned int GLFont::RGBA(unsigned char r, unsigned char g, unsigned char b, unsigned char a)
{
return (a<<24) | (b<<16) | (g<<8) | r;
/*#ifdef WIN32
return (a<<24) | (b<<16) | (g<<8) | r;
#else
return (r<<24) | (g<<16) | (b<<8) | a;
#endif*/
}

View File

@@ -16,58 +16,22 @@
// 3. This notice may not be removed or altered from any source distribution.
//
#include <stdio.h>
#include <string.h>
#define _USE_MATH_DEFINES
#include <math.h>
#include "imgui.h"
#include "SDL.h"
#include "SDL_opengl.h"
#ifdef WIN32
# define snprintf _snprintf
#endif
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
enum GfxCmdType
{
GFXCMD_RECT,
GFXCMD_TRIANGLE,
GFXCMD_TEXT,
GFXCMD_SCISSOR,
};
struct GfxRect
{
short x,y,w,h,r;
};
struct GfxText
{
short x,y,dir;
const char* text;
};
struct GfxCmd
{
char type;
char flags;
char pad[2];
unsigned int col;
union
{
GfxRect rect;
GfxText text;
};
};
unsigned int RGBA(unsigned char r, unsigned char g, unsigned char b, unsigned char a)
{
return (r) | (g << 8) | (b << 16) | (a << 24);
}
static const unsigned TEXT_POOL_SIZE = 4096;
static const unsigned TEXT_POOL_SIZE = 8000;
static char g_textPool[TEXT_POOL_SIZE];
static unsigned g_textPoolSize = 0;
const char* allocText(const char* text)
static const char* allocText(const char* text)
{
unsigned len = strlen(text)+1;
if (g_textPoolSize + len >= TEXT_POOL_SIZE)
@@ -79,282 +43,21 @@ const char* allocText(const char* text)
}
static const unsigned GFXCMD_QUEUE_SIZE = 1024;
static GfxCmd g_gfxCmdQueue[GFXCMD_QUEUE_SIZE];
static imguiGfxCmd g_gfxCmdQueue[GFXCMD_QUEUE_SIZE];
static unsigned g_gfxCmdQueueSize = 0;
void resetGfxCmdQueue()
static void resetGfxCmdQueue()
{
g_gfxCmdQueueSize = 0;
g_textPoolSize = 0;
}
static const unsigned TEMP_COORD_COUNT = 100;
static float g_tempCoords[TEMP_COORD_COUNT*2];
static float g_tempNormals[TEMP_COORD_COUNT*2];
static void drawPolygon(const float* coords, unsigned numCoords, float r, unsigned int col)
{
if (numCoords > TEMP_COORD_COUNT) numCoords = TEMP_COORD_COUNT;
for (unsigned i = 0, j = numCoords-1; i < numCoords; j=i++)
{
const float* v0 = &coords[j*2];
const float* v1 = &coords[i*2];
float dx = v1[0] - v0[0];
float dy = v1[1] - v0[1];
float d = sqrtf(dx*dx+dy*dy);
if (d > 0)
{
d = 1.0f/d;
dx *= d;
dy *= d;
}
g_tempNormals[j*2+0] = dy;
g_tempNormals[j*2+1] = -dx;
}
for (unsigned i = 0, j = numCoords-1; i < numCoords; j=i++)
{
float dlx0 = g_tempNormals[j*2+0];
float dly0 = g_tempNormals[j*2+1];
float dlx1 = g_tempNormals[i*2+0];
float dly1 = g_tempNormals[i*2+1];
float dmx = (dlx0 + dlx1) * 0.5f;
float dmy = (dly0 + dly1) * 0.5f;
float dmr2 = dmx*dmx + dmy*dmy;
if (dmr2 > 0.000001f)
{
float scale = 1.0f / dmr2;
if (scale > 10.0f) scale = 10.0f;
dmx *= scale;
dmy *= scale;
}
g_tempCoords[i*2+0] = coords[i*2+0]+dmx*r;
g_tempCoords[i*2+1] = coords[i*2+1]+dmy*r;
}
unsigned int colTrans = RGBA(col&0xff, (col>>8)&0xff, (col>>16)&0xff, 0);
glBegin(GL_TRIANGLES);
glColor4ubv((GLubyte*)&col);
for (unsigned i = 0, j = numCoords-1; i < numCoords; j=i++)
{
glVertex2fv(&coords[i*2]);
glVertex2fv(&coords[j*2]);
glColor4ubv((GLubyte*)&colTrans);
glVertex2fv(&g_tempCoords[j*2]);
glVertex2fv(&g_tempCoords[j*2]);
glVertex2fv(&g_tempCoords[i*2]);
glColor4ubv((GLubyte*)&col);
glVertex2fv(&coords[i*2]);
}
glColor4ubv((GLubyte*)&col);
for (unsigned i = 2; i < numCoords; ++i)
{
glVertex2fv(&coords[0]);
glVertex2fv(&coords[(i-1)*2]);
glVertex2fv(&coords[i*2]);
}
glEnd();
}
static const int CIRCLE_VERTS = 8*4;
static float g_circleVerts[CIRCLE_VERTS*2];
static bool g_circleVertsInitialized = false;
const float* getCircleVerts()
{
if (!g_circleVertsInitialized)
{
g_circleVertsInitialized = true;
for (unsigned i = 0; i < CIRCLE_VERTS; ++i)
{
float a = (float)i/(float)CIRCLE_VERTS * (float)M_PI*2;
g_circleVerts[i*2+0] = cosf(a);
g_circleVerts[i*2+1] = sinf(a);
}
}
return g_circleVerts;
}
static void drawRect(float x, float y, float w, float h, float fth, unsigned int col)
{
float verts[4*2] =
{
x, y,
x+w, y,
x+w, y+h,
x, y+h,
};
drawPolygon(verts, 4, fth, col);
}
static void drawEllipse(float x, float y, float w, float h, float fth, unsigned int col)
{
float verts[CIRCLE_VERTS*2];
const float* cverts = getCircleVerts();
float* v = verts;
for (unsigned i = 0; i < CIRCLE_VERTS; ++i)
{
*v++ = x + cverts[i*2]*w;
*v++ = y + cverts[i*2+1]*h;
}
drawPolygon(verts, CIRCLE_VERTS, fth, col);
}
static void drawRoundedRect(float x, float y, float w, float h, float r, float fth, unsigned int col)
{
const unsigned n = CIRCLE_VERTS/4;
float verts[(n+1)*4*2];
const float* cverts = getCircleVerts();
float* v = verts;
for (unsigned i = 0; i <= n; ++i)
{
*v++ = x+w-r + cverts[i*2]*r;
*v++ = y+h-r + cverts[i*2+1]*r;
}
for (unsigned i = n; i <= n*2; ++i)
{
*v++ = x+r + cverts[i*2]*r;
*v++ = y+h-r + cverts[i*2+1]*r;
}
for (unsigned i = n*2; i <= n*3; ++i)
{
*v++ = x+r + cverts[i*2]*r;
*v++ = y+r + cverts[i*2+1]*r;
}
for (unsigned i = n*3; i < n*4; ++i)
{
*v++ = x+w-r + cverts[i*2]*r;
*v++ = y+r + cverts[i*2+1]*r;
}
*v++ = x+w-r + cverts[0]*r;
*v++ = y+r + cverts[1]*r;
drawPolygon(verts, (n+1)*4, fth, col);
}
static void drawLine(float x0, float y0, float x1, float y1, float r, float fth, unsigned int col)
{
float dx = x1-x0;
float dy = y1-y0;
float d = sqrtf(dx*dx+dy*dy);
if (d > 0.0001f)
{
d = 1.0f/d;
dx *= d;
dy *= d;
}
float t = dx;
dx = dy;
dy = -t;
float verts[4*2];
r -= fth;
r *= 0.5f;
if (r < 0.01f) r = 0.01f;
dx *= r;
dy *= r;
verts[0] = x0-dx;
verts[1] = y0-dy;
verts[2] = x0+dx;
verts[3] = y0+dy;
verts[4] = x1+dx;
verts[5] = y1+dy;
verts[6] = x1-dx;
verts[7] = y1-dy;
drawPolygon(verts, 4, fth, col);
}
void renderGfxCmdQueue(void (*drawText)(int x, int y, int dir, const char* text, unsigned int col))
{
glDisable(GL_SCISSOR_TEST);
for (unsigned i = 0; i < g_gfxCmdQueueSize; ++i)
{
const GfxCmd& cmd = g_gfxCmdQueue[i];
if (cmd.type == GFXCMD_RECT)
{
if (cmd.rect.r == 0)
{
drawRect((float)cmd.rect.x+0.5f, (float)cmd.rect.y+0.5f,
(float)cmd.rect.w-1, (float)cmd.rect.h-1,
1.0f, cmd.col);
}
else
{
drawRoundedRect((float)cmd.rect.x+0.5f, (float)cmd.rect.y+0.5f,
(float)cmd.rect.w-1, (float)cmd.rect.h-1,
(float)cmd.rect.r, 1.0f, cmd.col);
}
}
else if (cmd.type == GFXCMD_TRIANGLE)
{
glColor4ub(cmd.col&0xff, (cmd.col>>8)&0xff, (cmd.col>>16)&0xff, (cmd.col>>24)&0xff);
if (cmd.flags == 1)
{
const float verts[3*2] =
{
(float)cmd.rect.x+0.5f, (float)cmd.rect.y+0.5f,
(float)cmd.rect.x+0.5f+(float)cmd.rect.w-1, (float)cmd.rect.y+0.5f+(float)cmd.rect.h/2-0.5f,
(float)cmd.rect.x+0.5f, (float)cmd.rect.y+0.5f+(float)cmd.rect.h-1,
};
drawPolygon(verts, 3, 1.0f, cmd.col);
}
if (cmd.flags == 2)
{
const float verts[3*2] =
{
(float)cmd.rect.x+0.5f, (float)cmd.rect.y+(float)cmd.rect.h-1,
(float)cmd.rect.x+0.5f+(float)cmd.rect.w/2-0.5f, (float)cmd.rect.y+0.5f,
(float)cmd.rect.x+0.5f+(float)cmd.rect.w-1, (float)cmd.rect.y+0.5f+(float)cmd.rect.h-1,
};
drawPolygon(verts, 3, 1.0f, cmd.col);
}
}
else if (cmd.type == GFXCMD_TEXT)
{
drawText(cmd.text.x, cmd.text.y, cmd.text.dir, cmd.text.text, cmd.col);
}
else if (cmd.type == GFXCMD_SCISSOR)
{
if (cmd.flags)
{
glEnable(GL_SCISSOR_TEST);
glScissor(cmd.rect.x, cmd.rect.y, cmd.rect.w, cmd.rect.h);
}
else
{
glDisable(GL_SCISSOR_TEST);
}
}
}
glDisable(GL_SCISSOR_TEST);
}
void addGfxCmdScissor(int x, int y, int w, int h)
static void addGfxCmdScissor(int x, int y, int w, int h)
{
if (g_gfxCmdQueueSize >= GFXCMD_QUEUE_SIZE)
return;
GfxCmd& cmd = g_gfxCmdQueue[g_gfxCmdQueueSize++];
cmd.type = GFXCMD_SCISSOR;
imguiGfxCmd& cmd = g_gfxCmdQueue[g_gfxCmdQueueSize++];
cmd.type = IMGUI_GFXCMD_SCISSOR;
cmd.flags = x < 0 ? 0 : 1; // on/off flag.
cmd.col = 0;
cmd.rect.x = (short)x;
@@ -363,12 +66,12 @@ void addGfxCmdScissor(int x, int y, int w, int h)
cmd.rect.h = (short)h;
}
void addGfxCmdRect(int x, int y, int w, int h, unsigned int color)
static void addGfxCmdRect(int x, int y, int w, int h, unsigned int color)
{
if (g_gfxCmdQueueSize >= GFXCMD_QUEUE_SIZE)
return;
GfxCmd& cmd = g_gfxCmdQueue[g_gfxCmdQueueSize++];
cmd.type = GFXCMD_RECT;
imguiGfxCmd& cmd = g_gfxCmdQueue[g_gfxCmdQueueSize++];
cmd.type = IMGUI_GFXCMD_RECT;
cmd.flags = 0;
cmd.col = color;
cmd.rect.x = (short)x;
@@ -378,12 +81,12 @@ void addGfxCmdRect(int x, int y, int w, int h, unsigned int color)
cmd.rect.r = 0;
}
void addGfxCmdRoundedRect(int x, int y, int w, int h, int r, unsigned int color)
static void addGfxCmdRoundedRect(int x, int y, int w, int h, int r, unsigned int color)
{
if (g_gfxCmdQueueSize >= GFXCMD_QUEUE_SIZE)
return;
GfxCmd& cmd = g_gfxCmdQueue[g_gfxCmdQueueSize++];
cmd.type = GFXCMD_RECT;
imguiGfxCmd& cmd = g_gfxCmdQueue[g_gfxCmdQueueSize++];
cmd.type = IMGUI_GFXCMD_RECT;
cmd.flags = 0;
cmd.col = color;
cmd.rect.x = (short)x;
@@ -393,12 +96,12 @@ void addGfxCmdRoundedRect(int x, int y, int w, int h, int r, unsigned int color)
cmd.rect.r = (short)r;
}
void addGfxCmdTriangle(int x, int y, int w, int h, int flags, unsigned int color)
static void addGfxCmdTriangle(int x, int y, int w, int h, int flags, unsigned int color)
{
if (g_gfxCmdQueueSize >= GFXCMD_QUEUE_SIZE)
return;
GfxCmd& cmd = g_gfxCmdQueue[g_gfxCmdQueueSize++];
cmd.type = GFXCMD_TRIANGLE;
imguiGfxCmd& cmd = g_gfxCmdQueue[g_gfxCmdQueueSize++];
cmd.type = IMGUI_GFXCMD_TRIANGLE;
cmd.flags = (char)flags;
cmd.col = color;
cmd.rect.x = (short)x;
@@ -407,17 +110,17 @@ void addGfxCmdTriangle(int x, int y, int w, int h, int flags, unsigned int color
cmd.rect.h = (short)h;
}
void addGfxCmdText(int x, int y, int dir, const char* text, unsigned int color)
static void addGfxCmdText(int x, int y, int align, const char* text, unsigned int color)
{
if (g_gfxCmdQueueSize >= GFXCMD_QUEUE_SIZE)
return;
GfxCmd& cmd = g_gfxCmdQueue[g_gfxCmdQueueSize++];
cmd.type = GFXCMD_TEXT;
imguiGfxCmd& cmd = g_gfxCmdQueue[g_gfxCmdQueueSize++];
cmd.type = IMGUI_GFXCMD_TEXT;
cmd.flags = 0;
cmd.col = color;
cmd.text.x = (short)x;
cmd.text.y = (short)y;
cmd.text.dir = (short)dir;
cmd.text.align = (short)align;
cmd.text.text = allocText(text);
}
@@ -425,19 +128,19 @@ void addGfxCmdText(int x, int y, int dir, const char* text, unsigned int color)
struct GuiState
{
GuiState() :
leftPressed(false), leftReleased(false), left(false), mx(-1), my(-1),
upPressed(false), downPressed(false), up(false), down(false),
leftPressed(false), leftReleased(false), left(false), mx(-1), my(-1), scroll(0),
isHot(false), isActive(false), wentActive(false),
dragX(0), dragY(0), dragOrig(0),
widgetX(0), widgetY(0), widgetW(100),
active(0), hot(0), hotToBe(0)
active(0), hot(0), hotToBe(0),
areaId(0), widgetId(0)
{
}
bool left, up, down;
bool upPressed, downPressed;
bool left;
bool leftPressed, leftReleased;
int mx,my;
int scroll;
unsigned int active;
unsigned int hot;
unsigned int hotToBe;
@@ -447,6 +150,9 @@ struct GuiState
int dragX, dragY;
float dragOrig;
int widgetX, widgetY, widgetW;
unsigned int areaId;
unsigned int widgetId;
};
static GuiState g_state;
@@ -471,34 +177,33 @@ inline bool inRect(int x, int y, int w, int h)
return g_state.mx >= x && g_state.mx <= x+w && g_state.my >= y && g_state.my <= y+h;
}
void clearInput()
inline void clearInput()
{
g_state.leftPressed = false;
g_state.leftReleased = false;
g_state.upPressed = false;
g_state.downPressed = false;
g_state.scroll = 0;
}
void clearActive(void)
inline void clearActive()
{
g_state.active = 0;
// mark all UI for this frame as processed
clearInput();
}
void setActive(unsigned int id)
inline void setActive(unsigned int id)
{
g_state.active = id;
g_state.wentActive = true;
}
void setHot(unsigned int id)
inline void setHot(unsigned int id)
{
g_state.hotToBe = id;
}
bool buttonLogic(unsigned int id, bool over)
static bool buttonLogic(unsigned int id, bool over)
{
bool res = false;
// process down
@@ -530,11 +235,9 @@ bool buttonLogic(unsigned int id, bool over)
return res;
}
static void updateInput(int mx, int my, unsigned char mbut)
static void updateInput(int mx, int my, unsigned char mbut, int scroll)
{
bool left = (mbut & IMGUI_MBUT_LEFT) != 0;
bool up = (mbut & IMGUI_MBUT_UP) != 0;
bool down = (mbut & IMGUI_MBUT_DOWN) != 0;
g_state.mx = mx;
g_state.my = my;
@@ -542,15 +245,12 @@ static void updateInput(int mx, int my, unsigned char mbut)
g_state.leftReleased = g_state.left && !left;
g_state.left = left;
g_state.upPressed = !g_state.up && up;
g_state.downPressed = !g_state.down && down;
g_state.up = up;
g_state.down = down;
g_state.scroll = scroll;
}
void imguiBeginFrame(int mx, int my, unsigned char mbut)
void imguiBeginFrame(int mx, int my, unsigned char mbut, int scroll)
{
updateInput(mx,my,mbut);
updateInput(mx,my,mbut,scroll);
g_state.hot = g_state.hotToBe;
g_state.hotToBe = 0;
@@ -563,6 +263,9 @@ void imguiBeginFrame(int mx, int my, unsigned char mbut)
g_state.widgetY = 0;
g_state.widgetW = 0;
g_state.areaId = 1;
g_state.widgetId = 1;
resetGfxCmdQueue();
}
@@ -571,9 +274,14 @@ void imguiEndFrame()
clearInput();
}
void imguiRender(void (*drawText)(int x, int y, int dir, const char* text, unsigned int col))
const imguiGfxCmd* imguiGetRenderQueue()
{
renderGfxCmdQueue(drawText);
return g_gfxCmdQueue;
}
int imguiGetRenderQueueSize()
{
return g_gfxCmdQueueSize;
}
@@ -598,9 +306,11 @@ static int g_focusBottom = 0;
static unsigned int g_scrollId = 0;
static bool g_insideScrollArea = false;
bool imguiBeginScrollArea(unsigned int id, const char* name, int x, int y, int w, int h, int* scroll)
bool imguiBeginScrollArea(const char* name, int x, int y, int w, int h, int* scroll)
{
g_scrollId = id;
g_state.areaId++;
g_state.widgetId = 0;
g_scrollId = (g_state.areaId<<16) | g_state.widgetId;
g_state.widgetX = x + SCROLL_AREA_PADDING;
g_state.widgetY = y+h-AREA_HEADER + (*scroll);
@@ -615,9 +325,9 @@ bool imguiBeginScrollArea(unsigned int id, const char* name, int x, int y, int w
g_focusTop = y-AREA_HEADER;
g_focusBottom = y-AREA_HEADER+h;
addGfxCmdRoundedRect(x, y, w, h, 6, RGBA(0,0,0,192));
addGfxCmdRoundedRect(x, y, w, h, 6, imguiRGBA(0,0,0,192));
addGfxCmdText(x+AREA_HEADER/2, y+h-AREA_HEADER/2-TEXT_HEIGHT/2, 1, name, RGBA(255,255,255,128));
addGfxCmdText(x+AREA_HEADER/2, y+h-AREA_HEADER/2-TEXT_HEIGHT/2, IMGUI_ALIGN_LEFT, name, imguiRGBA(255,255,255,128));
addGfxCmdScissor(x+SCROLL_AREA_PADDING, y+SCROLL_AREA_PADDING, w-SCROLL_AREA_PADDING*4, h-AREA_HEADER-SCROLL_AREA_PADDING);
@@ -677,24 +387,20 @@ void imguiEndScrollArea()
}
// BG
addGfxCmdRoundedRect(x, y, w, h, w/2-1, RGBA(0,0,0,196));
addGfxCmdRoundedRect(x, y, w, h, w/2-1, imguiRGBA(0,0,0,196));
// Bar
if (isActive(hid))
addGfxCmdRoundedRect(hx, hy, hw, hh, w/2-1, RGBA(255,196,0,196));
addGfxCmdRoundedRect(hx, hy, hw, hh, w/2-1, imguiRGBA(255,196,0,196));
else
addGfxCmdRoundedRect(hx, hy, hw, hh, w/2-1, isHot(hid) ? RGBA(255,196,0,96) : RGBA(255,255,255,64));
addGfxCmdRoundedRect(hx, hy, hw, hh, w/2-1, isHot(hid) ? imguiRGBA(255,196,0,96) : imguiRGBA(255,255,255,64));
// Handle mouse scrolling.
if (g_insideScrollArea) // && !anyActive())
{
if (g_state.upPressed)
if (g_state.scroll)
{
*g_scrollVal -= 20;
*g_scrollVal += 20*g_state.scroll;
if (*g_scrollVal < 0) *g_scrollVal = 0;
}
else if (g_state.downPressed)
{
*g_scrollVal += 20;
if (*g_scrollVal > (sh - h)) *g_scrollVal = (sh - h);
}
}
@@ -702,65 +408,92 @@ void imguiEndScrollArea()
}
}
bool imguiButton(unsigned int id, const char* text)
bool imguiButton(const char* text, bool enabled)
{
g_state.widgetId++;
unsigned int id = (g_state.areaId<<16) | g_state.widgetId;
int x = g_state.widgetX;
int y = g_state.widgetY - BUTTON_HEIGHT;
int w = g_state.widgetW;
int h = BUTTON_HEIGHT;
g_state.widgetY -= BUTTON_HEIGHT + DEFAULT_SPACING;
bool over = inRect(x, y, w, h);
bool over = enabled && inRect(x, y, w, h);
bool res = buttonLogic(id, over);
addGfxCmdRoundedRect(x, y, w, h, BUTTON_HEIGHT/2-1, RGBA(128,128,128, isActive(id)?196:96));
addGfxCmdText(x+BUTTON_HEIGHT/2, y+BUTTON_HEIGHT/2-TEXT_HEIGHT/2, 1, text, isHot(id) ? RGBA(255,196,0,255) : RGBA(255,255,255,200));
addGfxCmdRoundedRect(x, y, w, h, BUTTON_HEIGHT/2-1, imguiRGBA(128,128,128, isActive(id)?196:96));
if (enabled)
addGfxCmdText(x+BUTTON_HEIGHT/2, y+BUTTON_HEIGHT/2-TEXT_HEIGHT/2, IMGUI_ALIGN_LEFT, text, isHot(id) ? imguiRGBA(255,196,0,255) : imguiRGBA(255,255,255,200));
else
addGfxCmdText(x+BUTTON_HEIGHT/2, y+BUTTON_HEIGHT/2-TEXT_HEIGHT/2, IMGUI_ALIGN_LEFT, text, imguiRGBA(128,128,128,200));
return res;
}
bool imguiItem(unsigned int id, const char* text)
bool imguiItem(const char* text, bool enabled)
{
g_state.widgetId++;
unsigned int id = (g_state.areaId<<16) | g_state.widgetId;
int x = g_state.widgetX;
int y = g_state.widgetY - BUTTON_HEIGHT;
int w = g_state.widgetW;
int h = BUTTON_HEIGHT;
g_state.widgetY -= BUTTON_HEIGHT + DEFAULT_SPACING;
bool over = inRect(x, y, w, h);
bool over = enabled && inRect(x, y, w, h);
bool res = buttonLogic(id, over);
if (isHot(id))
addGfxCmdRoundedRect(x, y, w, h, 2, RGBA(255,196,0,isActive(id)?196:96));
addGfxCmdText(x+BUTTON_HEIGHT/2, y+BUTTON_HEIGHT/2-TEXT_HEIGHT/2, 1, text, RGBA(255,255,255,200));
addGfxCmdRoundedRect(x, y, w, h, 2, imguiRGBA(255,196,0,isActive(id)?196:96));
if (enabled)
addGfxCmdText(x+BUTTON_HEIGHT/2, y+BUTTON_HEIGHT/2-TEXT_HEIGHT/2, IMGUI_ALIGN_LEFT, text, imguiRGBA(255,255,255,200));
else
addGfxCmdText(x+BUTTON_HEIGHT/2, y+BUTTON_HEIGHT/2-TEXT_HEIGHT/2, IMGUI_ALIGN_LEFT, text, imguiRGBA(128,128,128,200));
return res;
}
bool imguiCheck(unsigned int id, const char* text, bool checked)
bool imguiCheck(const char* text, bool checked, bool enabled)
{
g_state.widgetId++;
unsigned int id = (g_state.areaId<<16) | g_state.widgetId;
int x = g_state.widgetX;
int y = g_state.widgetY - BUTTON_HEIGHT;
int w = g_state.widgetW;
int h = BUTTON_HEIGHT;
g_state.widgetY -= BUTTON_HEIGHT + DEFAULT_SPACING;
bool over = inRect(x, y, w, h);
bool over = enabled && inRect(x, y, w, h);
bool res = buttonLogic(id, over);
const int cx = x+BUTTON_HEIGHT/2-CHECK_SIZE/2;
const int cy = y+BUTTON_HEIGHT/2-CHECK_SIZE/2;
addGfxCmdRoundedRect(cx-3, cy-3, CHECK_SIZE+6, CHECK_SIZE+6, 4, RGBA(128,128,128, isActive(id)?196:96));
addGfxCmdRoundedRect(cx-3, cy-3, CHECK_SIZE+6, CHECK_SIZE+6, 4, imguiRGBA(128,128,128, isActive(id)?196:96));
if (checked)
addGfxCmdRoundedRect(cx, cy, CHECK_SIZE, CHECK_SIZE, CHECK_SIZE/2-1, RGBA(255,255,255,isActive(id)?255:200));
{
if (enabled)
addGfxCmdRoundedRect(cx, cy, CHECK_SIZE, CHECK_SIZE, CHECK_SIZE/2-1, imguiRGBA(255,255,255,isActive(id)?255:200));
else
addGfxCmdRoundedRect(cx, cy, CHECK_SIZE, CHECK_SIZE, CHECK_SIZE/2-1, imguiRGBA(128,128,128,200));
}
addGfxCmdText(x+BUTTON_HEIGHT, y+BUTTON_HEIGHT/2-TEXT_HEIGHT/2, 1, text, isHot(id) ? RGBA(255,196,0,255) : RGBA(255,255,255,200));
if (enabled)
addGfxCmdText(x+BUTTON_HEIGHT, y+BUTTON_HEIGHT/2-TEXT_HEIGHT/2, IMGUI_ALIGN_LEFT, text, isHot(id) ? imguiRGBA(255,196,0,255) : imguiRGBA(255,255,255,200));
else
addGfxCmdText(x+BUTTON_HEIGHT, y+BUTTON_HEIGHT/2-TEXT_HEIGHT/2, IMGUI_ALIGN_LEFT, text, imguiRGBA(128,128,128,200));
return res;
}
bool imguiCollapse(unsigned int id, const char* text, bool checked)
bool imguiCollapse(const char* text, bool checked, bool enabled)
{
g_state.widgetId++;
unsigned int id = (g_state.areaId<<16) | g_state.widgetId;
int x = g_state.widgetX;
int y = g_state.widgetY - BUTTON_HEIGHT;
int w = g_state.widgetW;
@@ -774,42 +507,45 @@ bool imguiCollapse(unsigned int id, const char* text, bool checked)
bool res = buttonLogic(id, over);
if (checked)
addGfxCmdTriangle(cx, cy, CHECK_SIZE, CHECK_SIZE, 1, RGBA(255,255,255,isActive(id)?255:200));
addGfxCmdTriangle(cx, cy, CHECK_SIZE, CHECK_SIZE, 1, imguiRGBA(255,255,255,isActive(id)?255:200));
else
addGfxCmdTriangle(cx, cy, CHECK_SIZE, CHECK_SIZE, 2, RGBA(255,255,255,isActive(id)?255:200));
addGfxCmdTriangle(cx, cy, CHECK_SIZE, CHECK_SIZE, 2, imguiRGBA(255,255,255,isActive(id)?255:200));
addGfxCmdText(x+BUTTON_HEIGHT, y+BUTTON_HEIGHT/2-TEXT_HEIGHT/2, 1, text, isHot(id) ? RGBA(255,196,0,255) : RGBA(255,255,255,200));
addGfxCmdText(x+BUTTON_HEIGHT, y+BUTTON_HEIGHT/2-TEXT_HEIGHT/2, IMGUI_ALIGN_LEFT, text, isHot(id) ? imguiRGBA(255,196,0,255) : imguiRGBA(255,255,255,200));
return res;
}
void imguiLabel(unsigned int /*id*/, const char* text)
void imguiLabel(const char* text)
{
int x = g_state.widgetX;
int y = g_state.widgetY - BUTTON_HEIGHT;
g_state.widgetY -= BUTTON_HEIGHT;
addGfxCmdText(x, y+BUTTON_HEIGHT/2-TEXT_HEIGHT/2, 1, text, RGBA(255,255,255,255));
addGfxCmdText(x, y+BUTTON_HEIGHT/2-TEXT_HEIGHT/2, IMGUI_ALIGN_LEFT, text, imguiRGBA(255,255,255,255));
}
void imguiValue(unsigned int /*id*/, const char* text)
void imguiValue(const char* text)
{
const int x = g_state.widgetX;
const int y = g_state.widgetY - BUTTON_HEIGHT;
const int w = g_state.widgetW;
g_state.widgetY -= BUTTON_HEIGHT;
addGfxCmdText(x+w-BUTTON_HEIGHT/2, y+BUTTON_HEIGHT/2-TEXT_HEIGHT/2, -1, text, RGBA(255,255,255,200));
addGfxCmdText(x+w-BUTTON_HEIGHT/2, y+BUTTON_HEIGHT/2-TEXT_HEIGHT/2, IMGUI_ALIGN_RIGHT, text, imguiRGBA(255,255,255,200));
}
bool imguiSlider(unsigned int id, const char* text, float* val, float vmin, float vmax, float vinc)
bool imguiSlider(const char* text, float* val, float vmin, float vmax, float vinc, bool enabled)
{
g_state.widgetId++;
unsigned int id = (g_state.areaId<<16) | g_state.widgetId;
int x = g_state.widgetX;
int y = g_state.widgetY - BUTTON_HEIGHT;
int w = g_state.widgetW;
int h = SLIDER_HEIGHT;
g_state.widgetY -= SLIDER_HEIGHT + DEFAULT_SPACING;
addGfxCmdRoundedRect(x, y, w, h, 4, RGBA(0,0,0,128));
addGfxCmdRoundedRect(x, y, w, h, 4, imguiRGBA(0,0,0,128));
const int range = w - SLIDER_MARKER_WIDTH;
@@ -842,18 +578,19 @@ bool imguiSlider(unsigned int id, const char* text, float* val, float vmin, floa
}
if (isActive(id))
addGfxCmdRoundedRect(x+m, y, SLIDER_MARKER_WIDTH, SLIDER_HEIGHT, 4, RGBA(255,255,255,255));
addGfxCmdRoundedRect(x+m, y, SLIDER_MARKER_WIDTH, SLIDER_HEIGHT, 4, imguiRGBA(255,255,255,255));
else
addGfxCmdRoundedRect(x+m, y, SLIDER_MARKER_WIDTH, SLIDER_HEIGHT, 4, isHot(id) ? RGBA(255,196,0,128) : RGBA(255,255,255,64));
addGfxCmdRoundedRect(x+m, y, SLIDER_MARKER_WIDTH, SLIDER_HEIGHT, 4, isHot(id) ? imguiRGBA(255,196,0,128) : imguiRGBA(255,255,255,64));
// TODO: fix this, take a look at 'nicenum'.
int digits = (int)(ceilf(log10f(vinc)));
char fmt[16];
snprintf(fmt, 16, "%%.%df", digits >= 0 ? 0 : -digits);
char msg[128];
snprintf(msg, 128, fmt, *val);
addGfxCmdText(x+SLIDER_HEIGHT/2, y+SLIDER_HEIGHT/2-TEXT_HEIGHT/2, 1, text, isHot(id) ? RGBA(255,196,0,255) : RGBA(255,255,255,200));
addGfxCmdText(x+w-SLIDER_HEIGHT/2, y+SLIDER_HEIGHT/2-TEXT_HEIGHT/2, -1, msg, isHot(id) ? RGBA(255,196,0,255) : RGBA(255,255,255,200));
addGfxCmdText(x+SLIDER_HEIGHT/2, y+SLIDER_HEIGHT/2-TEXT_HEIGHT/2, IMGUI_ALIGN_LEFT, text, isHot(id) ? imguiRGBA(255,196,0,255) : imguiRGBA(255,255,255,200));
addGfxCmdText(x+w-SLIDER_HEIGHT/2, y+SLIDER_HEIGHT/2-TEXT_HEIGHT/2, IMGUI_ALIGN_RIGHT, msg, isHot(id) ? imguiRGBA(255,196,0,255) : imguiRGBA(255,255,255,200));
return res || valChanged;
}
@@ -874,4 +611,9 @@ void imguiUnindent()
void imguiSeparator()
{
g_state.widgetY -= DEFAULT_SPACING*3;
}
}
void imguiDrawText(int x, int y, int align, const char* text, unsigned int color)
{
addGfxCmdText(x, y, align, text, color);
}

View File

@@ -0,0 +1,410 @@
#include <math.h>
#include "imgui.h"
#include "SDL.h"
#include "SDL_opengl.h"
#define STBTT_malloc(x) malloc(x)
#define STBTT_free(x) free(x)
#define STB_TRUETYPE_IMPLEMENTATION
#include "stb_truetype.h"
static const unsigned TEMP_COORD_COUNT = 100;
static float g_tempCoords[TEMP_COORD_COUNT*2];
static float g_tempNormals[TEMP_COORD_COUNT*2];
static const int CIRCLE_VERTS = 8*4;
static float g_circleVerts[CIRCLE_VERTS*2];
static stbtt_bakedchar g_cdata[96]; // ASCII 32..126 is 95 glyphs
static GLuint g_ftex = 0;
inline unsigned int RGBA(unsigned char r, unsigned char g, unsigned char b, unsigned char a)
{
return (r) | (g << 8) | (b << 16) | (a << 24);
}
static void drawPolygon(const float* coords, unsigned numCoords, float r, unsigned int col)
{
if (numCoords > TEMP_COORD_COUNT) numCoords = TEMP_COORD_COUNT;
for (unsigned i = 0, j = numCoords-1; i < numCoords; j=i++)
{
const float* v0 = &coords[j*2];
const float* v1 = &coords[i*2];
float dx = v1[0] - v0[0];
float dy = v1[1] - v0[1];
float d = sqrtf(dx*dx+dy*dy);
if (d > 0)
{
d = 1.0f/d;
dx *= d;
dy *= d;
}
g_tempNormals[j*2+0] = dy;
g_tempNormals[j*2+1] = -dx;
}
for (unsigned i = 0, j = numCoords-1; i < numCoords; j=i++)
{
float dlx0 = g_tempNormals[j*2+0];
float dly0 = g_tempNormals[j*2+1];
float dlx1 = g_tempNormals[i*2+0];
float dly1 = g_tempNormals[i*2+1];
float dmx = (dlx0 + dlx1) * 0.5f;
float dmy = (dly0 + dly1) * 0.5f;
float dmr2 = dmx*dmx + dmy*dmy;
if (dmr2 > 0.000001f)
{
float scale = 1.0f / dmr2;
if (scale > 10.0f) scale = 10.0f;
dmx *= scale;
dmy *= scale;
}
g_tempCoords[i*2+0] = coords[i*2+0]+dmx*r;
g_tempCoords[i*2+1] = coords[i*2+1]+dmy*r;
}
unsigned int colTrans = RGBA(col&0xff, (col>>8)&0xff, (col>>16)&0xff, 0);
glBegin(GL_TRIANGLES);
glColor4ubv((GLubyte*)&col);
for (unsigned i = 0, j = numCoords-1; i < numCoords; j=i++)
{
glVertex2fv(&coords[i*2]);
glVertex2fv(&coords[j*2]);
glColor4ubv((GLubyte*)&colTrans);
glVertex2fv(&g_tempCoords[j*2]);
glVertex2fv(&g_tempCoords[j*2]);
glVertex2fv(&g_tempCoords[i*2]);
glColor4ubv((GLubyte*)&col);
glVertex2fv(&coords[i*2]);
}
glColor4ubv((GLubyte*)&col);
for (unsigned i = 2; i < numCoords; ++i)
{
glVertex2fv(&coords[0]);
glVertex2fv(&coords[(i-1)*2]);
glVertex2fv(&coords[i*2]);
}
glEnd();
}
static void drawRect(float x, float y, float w, float h, float fth, unsigned int col)
{
float verts[4*2] =
{
x, y,
x+w, y,
x+w, y+h,
x, y+h,
};
drawPolygon(verts, 4, fth, col);
}
static void drawEllipse(float x, float y, float w, float h, float fth, unsigned int col)
{
float verts[CIRCLE_VERTS*2];
const float* cverts = g_circleVerts;
float* v = verts;
for (unsigned i = 0; i < CIRCLE_VERTS; ++i)
{
*v++ = x + cverts[i*2]*w;
*v++ = y + cverts[i*2+1]*h;
}
drawPolygon(verts, CIRCLE_VERTS, fth, col);
}
static void drawRoundedRect(float x, float y, float w, float h, float r, float fth, unsigned int col)
{
const unsigned n = CIRCLE_VERTS/4;
float verts[(n+1)*4*2];
const float* cverts = g_circleVerts;
float* v = verts;
for (unsigned i = 0; i <= n; ++i)
{
*v++ = x+w-r + cverts[i*2]*r;
*v++ = y+h-r + cverts[i*2+1]*r;
}
for (unsigned i = n; i <= n*2; ++i)
{
*v++ = x+r + cverts[i*2]*r;
*v++ = y+h-r + cverts[i*2+1]*r;
}
for (unsigned i = n*2; i <= n*3; ++i)
{
*v++ = x+r + cverts[i*2]*r;
*v++ = y+r + cverts[i*2+1]*r;
}
for (unsigned i = n*3; i < n*4; ++i)
{
*v++ = x+w-r + cverts[i*2]*r;
*v++ = y+r + cverts[i*2+1]*r;
}
*v++ = x+w-r + cverts[0]*r;
*v++ = y+r + cverts[1]*r;
drawPolygon(verts, (n+1)*4, fth, col);
}
static void drawLine(float x0, float y0, float x1, float y1, float r, float fth, unsigned int col)
{
float dx = x1-x0;
float dy = y1-y0;
float d = sqrtf(dx*dx+dy*dy);
if (d > 0.0001f)
{
d = 1.0f/d;
dx *= d;
dy *= d;
}
float t = dx;
dx = dy;
dy = -t;
float verts[4*2];
r -= fth;
r *= 0.5f;
if (r < 0.01f) r = 0.01f;
dx *= r;
dy *= r;
verts[0] = x0-dx;
verts[1] = y0-dy;
verts[2] = x0+dx;
verts[3] = y0+dy;
verts[4] = x1+dx;
verts[5] = y1+dy;
verts[6] = x1-dx;
verts[7] = y1-dy;
drawPolygon(verts, 4, fth, col);
}
bool imguiRenderGLInit(const char* fontpath)
{
for (unsigned i = 0; i < CIRCLE_VERTS; ++i)
{
float a = (float)i/(float)CIRCLE_VERTS * (float)M_PI*2;
g_circleVerts[i*2+0] = cosf(a);
g_circleVerts[i*2+1] = sinf(a);
}
// Load font.
FILE* fp = 0;
unsigned char* ttfBuffer = 0;
unsigned char* bmap = 0;
bool res = false;
fp = fopen(fontpath, "rb");
if (!fp) goto error;
fseek(fp, 0, SEEK_END);
int size = ftell(fp);
fseek(fp, 0, SEEK_SET);
ttfBuffer = (unsigned char*)malloc(size);
if (!ttfBuffer) goto error;
fread(ttfBuffer, 1, size, fp);
fclose(fp);
fp = 0;
bmap = (unsigned char*)malloc(512*512);
if (!bmap) goto error;
stbtt_BakeFontBitmap(ttfBuffer,0, 15.0f, bmap,512,512, 32,96, g_cdata);
// can free ttf_buffer at this point
glGenTextures(1, &g_ftex);
glBindTexture(GL_TEXTURE_2D, g_ftex);
glTexImage2D(GL_TEXTURE_2D, 0, GL_ALPHA, 512,512, 0, GL_ALPHA, GL_UNSIGNED_BYTE, bmap);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
res = true;
error:
if (ttfBuffer)
free(ttfBuffer);
if (bmap)
free(bmap);
if (fp)
fclose(fp);
return res;
}
void imguiRenderGLDestroy()
{
if (g_ftex)
{
glDeleteTextures(1, &g_ftex);
g_ftex = 0;
}
}
static void getBakedQuad(stbtt_bakedchar *chardata, int pw, int ph, int char_index,
float *xpos, float *ypos, stbtt_aligned_quad *q)
{
stbtt_bakedchar *b = chardata + char_index;
int round_x = STBTT_ifloor(*xpos + b->xoff);
int round_y = STBTT_ifloor(*ypos - b->yoff);
q->x0 = round_x;
q->y0 = round_y;
q->x1 = round_x + b->x1 - b->x0;
q->y1 = round_y - b->y1 + b->y0;
q->s0 = b->x0 / (float)pw;
q->t0 = b->y0 / (float)pw;
q->s1 = b->x1 / (float)ph;
q->t1 = b->y1 / (float)ph;
*xpos += b->xadvance;
}
static float getTextLength(stbtt_bakedchar *chardata, const char* text)
{
float xpos = 0;
float len = 0;
while (*text)
{
int c = (unsigned char)*text;
if (c >= 32 && c < 128)
{
stbtt_bakedchar *b = chardata + c-32;
int round_x = STBTT_ifloor((xpos + b->xoff) + 0.5);
len = round_x + b->x1 - b->x0 + 0.5f;
xpos += b->xadvance;
}
++text;
}
return len;
}
static void drawText(float x, float y, const char *text, int align, unsigned int col)
{
if (!g_ftex) return;
if (align == IMGUI_ALIGN_CENTER)
x -= getTextLength(g_cdata, text)/2;
else if (align == IMGUI_ALIGN_RIGHT)
x -= getTextLength(g_cdata, text);
glColor4ub(col&0xff, (col>>8)&0xff, (col>>16)&0xff, (col>>24)&0xff);
glEnable(GL_TEXTURE_2D);
// assume orthographic projection with units = screen pixels, origin at top left
glBindTexture(GL_TEXTURE_2D, g_ftex);
glBegin(GL_TRIANGLES);
while (*text)
{
int c = (unsigned char)*text;
if (c >= 32 && c < 128)
{
stbtt_aligned_quad q;
getBakedQuad(g_cdata, 512,512, c-32, &x,&y,&q);
glTexCoord2f(q.s0, q.t0);
glVertex2f(q.x0, q.y0);
glTexCoord2f(q.s1, q.t1);
glVertex2f(q.x1, q.y1);
glTexCoord2f(q.s1, q.t0);
glVertex2f(q.x1, q.y0);
glTexCoord2f(q.s0, q.t0);
glVertex2f(q.x0, q.y0);
glTexCoord2f(q.s0, q.t1);
glVertex2f(q.x0, q.y1);
glTexCoord2f(q.s1, q.t1);
glVertex2f(q.x1, q.y1);
}
++text;
}
glEnd();
glDisable(GL_TEXTURE_2D);
}
void imguiRenderGLDraw()
{
const imguiGfxCmd* q = imguiGetRenderQueue();
int nq = imguiGetRenderQueueSize();
glDisable(GL_SCISSOR_TEST);
for (unsigned i = 0; i < nq; ++i)
{
const imguiGfxCmd& cmd = q[i];
if (cmd.type == IMGUI_GFXCMD_RECT)
{
if (cmd.rect.r == 0)
{
drawRect((float)cmd.rect.x+0.5f, (float)cmd.rect.y+0.5f,
(float)cmd.rect.w-1, (float)cmd.rect.h-1,
1.0f, cmd.col);
}
else
{
drawRoundedRect((float)cmd.rect.x+0.5f, (float)cmd.rect.y+0.5f,
(float)cmd.rect.w-1, (float)cmd.rect.h-1,
(float)cmd.rect.r, 1.0f, cmd.col);
}
}
else if (cmd.type == IMGUI_GFXCMD_TRIANGLE)
{
if (cmd.flags == 1)
{
const float verts[3*2] =
{
(float)cmd.rect.x+0.5f, (float)cmd.rect.y+0.5f,
(float)cmd.rect.x+0.5f+(float)cmd.rect.w-1, (float)cmd.rect.y+0.5f+(float)cmd.rect.h/2-0.5f,
(float)cmd.rect.x+0.5f, (float)cmd.rect.y+0.5f+(float)cmd.rect.h-1,
};
drawPolygon(verts, 3, 1.0f, cmd.col);
}
if (cmd.flags == 2)
{
const float verts[3*2] =
{
(float)cmd.rect.x+0.5f, (float)cmd.rect.y+(float)cmd.rect.h-1,
(float)cmd.rect.x+0.5f+(float)cmd.rect.w/2-0.5f, (float)cmd.rect.y+0.5f,
(float)cmd.rect.x+0.5f+(float)cmd.rect.w-1, (float)cmd.rect.y+0.5f+(float)cmd.rect.h-1,
};
drawPolygon(verts, 3, 1.0f, cmd.col);
}
}
else if (cmd.type == IMGUI_GFXCMD_TEXT)
{
drawText(cmd.text.x, cmd.text.y, cmd.text.text, cmd.text.align, cmd.col);
}
else if (cmd.type == IMGUI_GFXCMD_SCISSOR)
{
if (cmd.flags)
{
glEnable(GL_SCISSOR_TEST);
glScissor(cmd.rect.x, cmd.rect.y, cmd.rect.w, cmd.rect.h);
}
else
{
glDisable(GL_SCISSOR_TEST);
}
}
}
glDisable(GL_SCISSOR_TEST);
}

View File

@@ -9,30 +9,27 @@
#include "SDL.h"
#include "SDL_Opengl.h"
#include "GLFont.h"
#include "imgui.h"
#include "imguiRenderGL.h"
#include "Recast.h"
#include "RecastDebugDraw.h"
#include "MeshLoaderObj.h"
#include "BuilderStatMeshSimple.h"
#include "BuilderStatMeshTiled.h"
#include "BuilderTiledMesh.h"
#include "Sample_StatMeshSimple.h"
#include "Sample_StatMeshTiled.h"
#include "Sample_TileMesh.h"
#ifdef WIN32
# define snprintf _snprintf
#endif
GLFont g_font;
/*GLFont g_font;
void drawText(int x, int y, int dir, const char* text, unsigned int col)
{
if (dir < 0)
g_font.drawText((float)x - g_font.getTextLength(text), (float)y, text, col);
else
g_font.drawText((float)x, (float)y, text, col);
}
}*/
struct FileList
{
@@ -187,6 +184,26 @@ static bool raycast(rcMeshLoaderObj& mesh, float* src, float* dst, float& tmin)
return hit;
}
struct SampleItem
{
Sample* (*create)();
const char* name;
};
Sample* createStatSimple() { return new Sample_StatMeshSimple(); }
Sample* createStatTiled() { return new Sample_StatMeshTiled(); }
Sample* createTile() { return new Sample_TileMesh(); }
static SampleItem g_samples[] =
{
{ createStatSimple, "Static Mesh (Simple)" },
{ createStatTiled, "Static Mesh (Tiled)" },
{ createTile, "Tile Mesh" },
};
static const int g_nsamples = sizeof(g_samples)/sizeof(SampleItem);
int main(int argc, char *argv[])
{
// Init SDL
@@ -204,8 +221,10 @@ int main(int argc, char *argv[])
SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, 8);
SDL_GL_SetAttribute(SDL_GL_ALPHA_SIZE, 8);
int width = 1200;
int height = 700;
const SDL_VideoInfo* vi = SDL_GetVideoInfo();
int width = vi->current_w - 20;
int height = vi->current_h - 50;
SDL_Surface* screen = SDL_SetVideoMode(width, height, 0, SDL_OPENGL);
if (!screen)
{
@@ -215,12 +234,19 @@ int main(int argc, char *argv[])
SDL_WM_SetCaption("Recast Demo", 0);
if(!g_font.create("font.cfnt"))
if (!imguiRenderGLInit("DroidSans.ttf"))
{
printf("Could not init GUI renderer.\n");
SDL_Quit();
return -1;
}
/* if(!g_font.create("font.cfnt"))
{
printf("Could not load font.\n");
SDL_Quit();
return -1;
}
}*/
float t = 0.0f;
Uint32 lastTime = SDL_GetTicks();
@@ -234,18 +260,19 @@ int main(int argc, char *argv[])
bool rotate = false;
float rays[3], raye[3];
bool mouseOverMenu = false;
bool showMenu = true;
bool showLog = false;
bool showDebugMode = true;
bool showTools = true;
bool showLevels = false;
bool showBuilder = false;
bool showSample = false;
int propScroll = 0;
int logScroll = 0;
int toolsScroll = 0;
int debugScroll = 0;
char builderName[64] = "Choose Builder...";
char sampleName[64] = "Choose Builder...";
FileList meshFiles;
char meshName[128] = "Choose Mesh...";
@@ -253,7 +280,11 @@ int main(int argc, char *argv[])
rcMeshLoaderObj* mesh = 0;
float meshBMin[3], meshBMax[3];
Builder* builder = 0;
float mpos[3];
bool mposSet = false;
Sample* sample = 0;
rcLog log;
log.clear();
@@ -275,7 +306,7 @@ int main(int argc, char *argv[])
while(!done)
{
// Handle input events.
unsigned char mbut = 0;
int mscroll = 0;
SDL_Event event;
while(SDL_PollEvent(&event))
{
@@ -305,28 +336,46 @@ int main(int argc, char *argv[])
else if (event.button.button == SDL_BUTTON_LEFT)
{
// Hit test mesh.
if (mesh && builder)
if (mesh && sample)
{
// Hit test mesh.
float t;
if (raycast(*mesh, rays, raye, t))
{
float pos[3];
pos[0] = rays[0] + (raye[0] - rays[0])*t;
pos[1] = rays[1] + (raye[1] - rays[1])*t;
pos[2] = rays[2] + (raye[2] - rays[2])*t;
if (SDL_GetModState() & KMOD_SHIFT)
builder->setToolStartPos(pos);
if (SDL_GetModState() & KMOD_CTRL)
{
mposSet = true;
mpos[0] = rays[0] + (raye[0] - rays[0])*t;
mpos[1] = rays[1] + (raye[1] - rays[1])*t;
mpos[2] = rays[2] + (raye[2] - rays[2])*t;
}
else
builder->setToolEndPos(pos);
{
float pos[3];
pos[0] = rays[0] + (raye[0] - rays[0])*t;
pos[1] = rays[1] + (raye[1] - rays[1])*t;
pos[2] = rays[2] + (raye[2] - rays[2])*t;
if (SDL_GetModState() & KMOD_SHIFT)
sample->setToolStartPos(pos);
else
sample->setToolEndPos(pos);
}
}
else
{
if (SDL_GetModState() & KMOD_CTRL)
{
mposSet = false;
}
}
}
}
}
if (event.button.button == SDL_BUTTON_WHEELUP)
mbut |= IMGUI_MBUT_UP;
mscroll--;
if (event.button.button == SDL_BUTTON_WHEELDOWN)
mbut |= IMGUI_MBUT_DOWN;
mscroll++;
break;
case SDL_MOUSEBUTTONUP:
@@ -358,6 +407,7 @@ int main(int argc, char *argv[])
}
}
unsigned char mbut = 0;
if (SDL_GetMouseState(0,0) & SDL_BUTTON_LMASK)
mbut |= IMGUI_MBUT_LEFT;
if (SDL_GetMouseState(0,0) & SDL_BUTTON_RMASK)
@@ -368,6 +418,7 @@ int main(int argc, char *argv[])
lastTime = time;
t += dt;
// Update and render
glViewport(0, 0, width, height);
@@ -425,8 +476,8 @@ int main(int argc, char *argv[])
glEnable(GL_FOG);
if (builder)
builder->handleRender();
if (sample)
sample->handleRender();
glDisable(GL_FOG);
@@ -438,138 +489,139 @@ int main(int argc, char *argv[])
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
if (builder)
{
builder->handleRenderOverlay(&g_font, (double*)proj, (double*)model, (int*)view);
glDisable(GL_TEXTURE_2D);
}
imguiBeginFrame(mx,my,mbut,mscroll);
imguiBeginFrame(mx,my,mbut);
if (sample)
{
sample->handleRenderOverlay((double*)proj, (double*)model, (int*)view);
}
// Help text.
if (showMenu)
{
const char msg[] = "W/S/A/D: Move RMB: Rotate LMB: Place Start LMB+SHIFT: Place End";
imguiDrawText(width/2, height-20, IMGUI_ALIGN_CENTER, msg, imguiRGBA(255,255,255,128));
}
mouseOverMenu = false;
int propDiv = showDebugMode ? (int)(height*0.6f) : height;
if (imguiBeginScrollArea(GENID, "Properties",
width-250-10, 10+height-propDiv, 250, propDiv-20, &propScroll))
mouseOverMenu = true;
if (imguiCheck(GENID, "Show Log", showLog))
showLog = !showLog;
if (imguiCheck(GENID, "Show Tools", showTools))
showTools = !showTools;
if (imguiCheck(GENID, "Show Debug Mode", showDebugMode))
showDebugMode = !showDebugMode;
if (showMenu)
{
int propDiv = showDebugMode ? (int)(height*0.6f) : height;
if (imguiBeginScrollArea("Properties",
width-250-10, 10+height-propDiv, 250, propDiv-20, &propScroll))
mouseOverMenu = true;
if (imguiCheck("Show Log", showLog))
showLog = !showLog;
if (imguiCheck("Show Tools", showTools))
showTools = !showTools;
if (imguiCheck("Show Debug Mode", showDebugMode))
showDebugMode = !showDebugMode;
imguiSeparator();
imguiLabel(GENID, "Builder");
if (imguiButton(GENID, builderName))
{
if (showBuilder)
{
showBuilder = false;
}
else
{
showBuilder = true;
showLevels = false;
}
}
if (builder)
{
imguiSeparator();
imguiLabel(GENID, "Input Mesh");
if (imguiButton(GENID, meshName))
imguiLabel("Sample");
if (imguiButton(sampleName))
{
if (showLevels)
if (showSample)
{
showLevels = false;
showSample = false;
}
else
{
showBuilder = false;
showLevels = true;
scanDirectory("meshes", ".obj", meshFiles);
showSample = true;
showLevels = false;
}
}
if (mesh)
if (sample)
{
char text[64];
snprintf(text, 64, "Verts: %.1fk Tris: %.1fk", mesh->getVertCount()/1000.0f, mesh->getTriCount()/1000.0f);
imguiValue(GENID, text);
}
imguiSeparator();
}
if (mesh && builder)
{
builder->handleSettings();
if (imguiButton(GENID, "Build"))
{
log.clear();
if (!builder->handleBuild())
imguiSeparator();
imguiLabel("Input Mesh");
if (imguiButton(meshName))
{
showLog = true;
logScroll = 0;
if (showLevels)
{
showLevels = false;
}
else
{
showSample = false;
showLevels = true;
scanDirectory("meshes", ".obj", meshFiles);
}
}
if (mesh)
{
char text[64];
snprintf(text, 64, "Verts: %.1fk Tris: %.1fk", mesh->getVertCount()/1000.0f, mesh->getTriCount()/1000.0f);
imguiValue(text);
}
imguiSeparator();
}
if (mesh && sample)
{
sample->handleSettings();
if (imguiButton("Build"))
{
log.clear();
if (!sample->handleBuild())
{
showLog = true;
logScroll = 0;
}
}
imguiSeparator();
}
imguiSeparator();
}
imguiEndScrollArea();
if (showDebugMode)
{
if (imguiBeginScrollArea(GENID, "Debug Mode",
width-250-10, 10,
250, height-propDiv-10, &debugScroll))
mouseOverMenu = true;
if (builder)
builder->handleDebugMode();
imguiEndScrollArea();
if (showDebugMode)
{
if (imguiBeginScrollArea("Debug Mode",
width-250-10, 10,
250, height-propDiv-10, &debugScroll))
mouseOverMenu = true;
if (sample)
sample->handleDebugMode();
imguiEndScrollArea();
}
}
// Builder selection dialog.
if (showBuilder)
if (showSample)
{
static int levelScroll = 0;
if (imguiBeginScrollArea(GENID, "Choose Level", width-10-250-10-200, height-10-250, 200, 250, &levelScroll))
if (imguiBeginScrollArea("Choose Level", width-10-250-10-200, height-10-250, 200, 250, &levelScroll))
mouseOverMenu = true;
Builder* newBuilder = 0;
if (imguiItem(GENID, "Simple Static Mesh"))
Sample* newSample = 0;
for (int i = 0; i < g_nsamples; ++i)
{
newBuilder = new BuilderStatMeshSimple();
if (newBuilder) strcpy(builderName, "Simple Static Mesh");
}
if (imguiItem(GENID, "Tiled Static Mesh"))
{
newBuilder = new BuilderStatMeshTiled();
if (newBuilder) strcpy(builderName, "Tiled Static Mesh");
}
if (imguiItem(GENID, "Tiled Mesh"))
{
newBuilder = new BuilderTiledMesh();
if (newBuilder) strcpy(builderName, "Tiled Mesh");
}
if (newBuilder)
{
delete builder;
builder = newBuilder;
if (mesh && builder)
if (imguiItem(g_samples[i].name))
{
builder->handleMeshChanged(mesh->getVerts(), mesh->getVertCount(),
mesh->getTris(), mesh->getNormals(), mesh->getTriCount(),
meshBMin, meshBMax);
newSample = g_samples[i].create();
if (newSample) strcpy(sampleName, g_samples[i].name);
}
showBuilder = false;
}
if (newSample)
{
delete sample;
sample = newSample;
if (mesh && sample)
{
sample->handleMeshChanged(mesh->getVerts(), mesh->getVertCount(),
mesh->getTris(), mesh->getNormals(), mesh->getTriCount(),
meshBMin, meshBMax);
}
showSample = false;
}
imguiEndScrollArea();
@@ -579,13 +631,13 @@ int main(int argc, char *argv[])
if (showLevels)
{
static int levelScroll = 0;
if (imguiBeginScrollArea(GENID, "Choose Level", width-10-250-10-200, height-10-250, 200, 250, &levelScroll))
if (imguiBeginScrollArea("Choose Level", width-10-250-10-200, height-10-250, 200, 250, &levelScroll))
mouseOverMenu = true;
int levelToLoad = -1;
for (int i = 0; i < meshFiles.size; ++i)
{
if (imguiItem(GENID1(i), meshFiles.files[i]))
if (imguiItem(meshFiles.files[i]))
levelToLoad = i;
}
@@ -612,11 +664,11 @@ int main(int argc, char *argv[])
if (mesh)
rcCalcBounds(mesh->getVerts(), mesh->getVertCount(), meshBMin, meshBMax);
if (builder)
if (sample)
{
builder->handleMeshChanged(mesh->getVerts(), mesh->getVertCount(),
mesh->getTris(), mesh->getNormals(), mesh->getTriCount(),
meshBMin, meshBMax);
sample->handleMeshChanged(mesh->getVerts(), mesh->getVertCount(),
mesh->getTris(), mesh->getNormals(), mesh->getTriCount(),
meshBMin, meshBMax);
}
// Reset camera and fog to match the mesh bounds.
@@ -638,43 +690,58 @@ int main(int argc, char *argv[])
}
// Log
if (showLog)
if (showLog && showMenu)
{
if (imguiBeginScrollArea(GENID, "Log", 10, 10, width - 300, 200, &logScroll))
if (imguiBeginScrollArea("Log", 10, 10, width - 300, 200, &logScroll))
mouseOverMenu = true;
for (int i = 0; i < log.getMessageCount(); ++i)
imguiLabel(GENID1(i), log.getMessageText(i));
imguiLabel(log.getMessageText(i));
imguiEndScrollArea();
}
// Tools
if (showTools && mesh && builder)
if (showTools && showMenu && mesh && sample)
{
if (imguiBeginScrollArea(GENID, "Tools", 10, height - 10 - 200, 150, 200, &toolsScroll))
if (imguiBeginScrollArea("Tools", 10, height - 10 - 200, 150, 200, &toolsScroll))
mouseOverMenu = true;
builder->handleTools();
sample->handleTools();
imguiEndScrollArea();
}
// Help text.
const char msg[] = "W/S/A/D: Move RMB: Rotate LMB: Place Start LMB+SHIFT: Place End";
const float len = g_font.getTextLength(msg);
g_font.drawText(width/2-len/2, (float)height-20.0f, msg, GLFont::RGBA(255,255,255,128));
glDisable(GL_TEXTURE_2D);
// Marker
if (mposSet && gluProject((GLdouble)mpos[0], (GLdouble)mpos[1], (GLdouble)mpos[2],
model, proj, view, &x, &y, &z))
{
// Draw marker circle
glLineWidth(5.0f);
glColor4ub(240,220,0,196);
glBegin(GL_LINE_LOOP);
const float r = 25.0f;
for (int i = 0; i < 20; ++i)
{
const float a = (float)i / 20.0f * M_PI*2;
const float fx = (float)x + cosf(a)*r;
const float fy = (float)y + sinf(a)*r;
glVertex2f(fx,fy);
}
glEnd();
glLineWidth(1.0f);
}
imguiEndFrame();
imguiRender(&drawText);
imguiRenderGLDraw();
glEnable(GL_DEPTH_TEST);
SDL_GL_SwapBuffers();
}
imguiRenderGLDestroy();
SDL_Quit();
delete builder;
delete sample;
delete mesh;
return 0;