import navmesh generation code by Fuma (from daemonmap), fix #8

This commit is contained in:
Thomas Debesse
2015-07-19 05:40:56 +02:00
parent 20683fc51a
commit 004cd059ec
6 changed files with 1562 additions and 22 deletions
+25 -1
View File
@@ -484,7 +484,7 @@ endif
$(INSTALLDIR)/q3map2.$(EXE): LIBS_EXTRA := $(LIBS_XML) $(LIBS_GLIB) $(LIBS_PNG) $(LIBS_JPEG) $(LIBS_ZLIB)
$(INSTALLDIR)/q3map2.$(EXE): CPPFLAGS_EXTRA := $(CPPFLAGS_XML) $(CPPFLAGS_GLIB) $(CPPFLAGS_PNG) $(CPPFLAGS_JPEG) -Itools/quake3/common -Ilibs -Iinclude
$(INSTALLDIR)/q3map2.$(EXE): CPPFLAGS_EXTRA := $(CPPFLAGS_XML) $(CPPFLAGS_GLIB) $(CPPFLAGS_PNG) $(CPPFLAGS_JPEG) -lm -Itools/quake3/common -Ilibs -Iinclude
$(INSTALLDIR)/q3map2.$(EXE): \
tools/quake3/common/cmdlib.o \
tools/quake3/common/imagelib.o \
@@ -497,6 +497,29 @@ $(INSTALLDIR)/q3map2.$(EXE): \
tools/quake3/common/threads.o \
tools/quake3/common/unzip.o \
tools/quake3/common/vfs.o \
tools/quake3/libs/detour/DetourAlloc.o \
tools/quake3/libs/detour/DetourNavMeshQuery.o \
tools/quake3/libs/detour/DetourDebugDraw.o \
tools/quake3/libs/detour/DetourNode.o \
tools/quake3/libs/detour/DetourPathCorridor.o \
tools/quake3/libs/detour/DetourNavMeshBuilder.o \
tools/quake3/libs/detour/DebugDraw.o \
tools/quake3/libs/detour/DetourCommon.o \
tools/quake3/libs/detour/DetourNavMesh.o \
tools/quake3/libs/detour/DetourTileCacheBuilder.o \
tools/quake3/libs/detour/DetourTileCache.o \
tools/quake3/libs/recast/ChunkyTriMesh.o \
tools/quake3/libs/fastlz/fastlz.o \
tools/quake3/libs/recast/RecastMesh.o \
tools/quake3/libs/recast/RecastRegion.o \
tools/quake3/libs/recast/RecastRasterization.o \
tools/quake3/libs/recast/RecastMeshDetail.o \
tools/quake3/libs/recast/RecastLayers.o \
tools/quake3/libs/recast/RecastContour.o \
tools/quake3/libs/recast/RecastAlloc.o \
tools/quake3/libs/recast/RecastFilter.o \
tools/quake3/libs/recast/RecastArea.o \
tools/quake3/libs/recast/Recast.o \
tools/quake3/q3map2/brush.o \
tools/quake3/q3map2/brush_primit.o \
tools/quake3/q3map2/bspfile_abstract.o \
@@ -520,6 +543,7 @@ $(INSTALLDIR)/q3map2.$(EXE): \
tools/quake3/q3map2/map.o \
tools/quake3/q3map2/mesh.o \
tools/quake3/q3map2/model.o \
tools/quake3/q3map2/nav.o \
tools/quake3/q3map2/patch.o \
tools/quake3/q3map2/path_init.o \
tools/quake3/q3map2/portals.o \
+9
View File
@@ -47,10 +47,19 @@ void Broadcast_Shutdown();
#define SYS_ERR 3 // error
#define SYS_NOXML 4 // don't send that down the XML stream
#ifdef __cplusplus
extern "C"
{
#endif
extern qboolean verbose;
void Sys_Printf( const char *text, ... );
void Sys_FPrintf( int flag, const char *text, ... );
#ifdef __cplusplus
}
#endif
#ifdef _DEBUG
#define DBG_XML 1
#endif
+19 -1
View File
@@ -36,7 +36,20 @@
/* dependencies */
#include "q3map2.h"
char *surfaceTypes[ NUM_SURFACE_TYPES ] =
{
"SURFACE_BAD",
"SURFACE_FACE",
"SURFACE_PATCH",
"SURFACE_TRIANGLES",
"SURFACE_FLARE",
"SURFACE_FOLIAGE",
"SURFACE_FORCED_META",
"SURFACE_META",
"SURFACE_FOGHULL",
"SURFACE_DECAL",
"SURFACE_SHADER"
};
/*
Random()
@@ -1869,6 +1882,11 @@ int main( int argc, char **argv ){
r = MiniMapBSPMain( argc - 1, argv + 1 );
}
/* Navigation Mesh generation */
else if(!strcmp(argv[1], "-nav")) {
r = NavMain(argc - 1, argv + 1);
}
/* ydnar: otherwise create a bsp */
else{
r = BSPMain( argc, argv );
File diff suppressed because it is too large Load Diff
+106
View File
@@ -0,0 +1,106 @@
/*
===========================================================================
Copyright (C) 2012 Unvanquished Developers
This file is part of Daemon source code.
Daemon source code is free software; you can redistribute it
and/or modify it under the terms of the GNU General Public License as
published by the Free Software Foundation; either version 2 of the License,
or (at your option) any later version.
Daemon source code is distributed in the hope that it will be
useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Daemon source code; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
===========================================================================
*/
#include "../libs/recast/Recast.h"
#include "../libs/recast/RecastAlloc.h"
#include "../libs/recast/RecastAssert.h"
#include "../libs/recast/ChunkyTriMesh.h"
#include "../libs/detour/DetourCommon.h"
#include "../libs/detour/DetourNavMesh.h"
#include "../libs/detour/DetourNavMeshBuilder.h"
#include "../libs/detour/DetourTileCache.h"
#include "../libs/detour/DetourTileCacheBuilder.h"
#include "../libs/botlib/nav.h"
static const int MAX_LAYERS = 32;
static const int EXPECTED_LAYERS_PER_TILE = 4;
struct TileCacheData
{
unsigned char* data;
int dataSize;
};
struct RasterizationContext
{
rcHeightfield* solid;
unsigned char* triareas;
rcHeightfieldLayerSet* lset;
rcCompactHeightfield* chf;
TileCacheData tiles[MAX_LAYERS];
int ntiles;
RasterizationContext() :
solid(0),
triareas(0),
lset(0),
chf(0),
ntiles(0)
{
memset( tiles, 0, sizeof(TileCacheData)*MAX_LAYERS );
}
~RasterizationContext()
{
rcFreeHeightField(solid);
delete[] triareas;
rcFreeHeightfieldLayerSet( lset );
rcFreeCompactHeightfield( chf );
for ( int i = 0; i < MAX_LAYERS; ++i )
{
dtFree(tiles[i].data);
tiles[i].data = 0;
}
}
};
class Geometry
{
private:
float mins[ 3 ];
float maxs[ 3 ];
float *verts;
int nverts;
rcChunkyTriMesh mesh;
public:
Geometry() : verts(0), nverts(0) {}
~Geometry() { delete[] verts; }
void init( const float *v, int nv, const int *tris, int ntris )
{
verts = new float[ nv * 3 ];
memcpy( verts, v, sizeof( float ) * nv * 3 );
nverts = nv;
rcCreateChunkyTriMesh( verts, tris, ntris, 1024, &mesh );
rcCalcBounds( verts, nverts, mins, maxs );
}
const float *getMins(){ return mins; }
const float *getMaxs() { return maxs; }
const float *getVerts() { return verts; }
const int getNumVerts() { return nverts; }
const rcChunkyTriMesh *getChunkyMesh() { return &mesh; }
};
+22 -20
View File
@@ -33,6 +33,10 @@
#define Q3MAP2_H
#ifdef __cplusplus
extern "C"
{
#endif
/* version */
#ifndef Q3MAP_VERSION
@@ -79,7 +83,18 @@
#include "polylib.h"
#include "imagelib.h"
#include "qthreads.h"
#ifdef __cplusplus
}
#endif
#include "inout.h"
#ifdef __cplusplus
extern "C"
{
#endif
#include "vfs.h"
#include "png.h"
#include "md4.h"
@@ -1001,26 +1016,7 @@ typedef enum
}
surfaceType_t;
char *surfaceTypes[ NUM_SURFACE_TYPES ]
#ifndef MAIN_C
;
#else
=
{
"SURFACE_BAD",
"SURFACE_FACE",
"SURFACE_PATCH",
"SURFACE_TRIANGLES",
"SURFACE_FLARE",
"SURFACE_FOLIAGE",
"SURFACE_FORCED_META",
"SURFACE_META",
"SURFACE_FOGHULL",
"SURFACE_DECAL",
"SURFACE_SHADER"
};
#endif
extern char *surfaceTypes[ NUM_SURFACE_TYPES ];
/* ydnar: this struct needs an overhaul (again, heh) */
typedef struct mapDrawSurface_s
@@ -1540,6 +1536,8 @@ int ConvertBSPToASE( char *bspName );
/* convert_obj.c */
int ConvertBSPToOBJ( char *bspName );
/* nav.cpp */
int NavMain(int argc, char **argv);
/* brush.c */
sideRef_t *AllocSideRef( side_t *side, sideRef_t *next );
@@ -2555,5 +2553,9 @@ Q_EXTERN bspAdvertisement_t bspAds[ MAX_MAP_ADVERTISEMENTS ];
#define Image_LinearFloatFromsRGBFloat( c ) ( ( ( c ) <= 0.04045f ) ? ( c ) * ( 1.0f / 12.92f ) : (float)pow( ( ( c ) + 0.055f ) * ( 1.0f / 1.055f ), 2.4f ) )
#define Image_sRGBFloatFromLinearFloat( c ) ( ( ( c ) < 0.0031308f ) ? ( c ) * 12.92f : 1.055f * (float)pow( ( c ), 1.0f / 2.4f ) - 0.055f )
#ifdef __cplusplus
}
#endif
/* end marker */
#endif