- fixed bugs with unique vertices of detailed mesh in generation and conversion of navigation mesh

- set default physic type and name for navigation mesh object
This commit is contained in:
Nick Samarin
2010-07-14 13:20:13 +00:00
parent 81021db4f9
commit b17f90b22c
4 changed files with 52 additions and 10 deletions

View File

@@ -44,7 +44,7 @@
Name="VCCLCompilerTool"
Optimization="2"
InlineFunctionExpansion="1"
AdditionalIncludeDirectories="..\..\..\..\lib\windows\QTDevWin\CIncludes;..\..\..\..\lib\windows\sdl\include;..\..\..\..\lib\windows\python\include\python2.6;..\..\..\..\build\msvc_9\intern\bsp\include;..\..\..\..\build\msvc_9\intern\ghost\include;..\..\..\..\build\msvc_9\intern\elbeem\include;..\..\..\..\build\msvc_9\intern\opennl\include;..\..\..\..\build\msvc_9\intern\bmfont\include;..\..\..\..\build\msvc_9\intern\blenkey\include;..\..\..\..\build\msvc_9\intern\decimation\include;..\..\..\..\build\msvc_9\intern\memutil\include;..\..\..\..\build\msvc_9\intern\guardedalloc\include;..\..\..\..\build\msvc_9\intern\smoke\include;..\..\..\..\build\msvc_9\intern\soundsystem\include;..\..\..\source\blender;..\..\..\source\blender\img;..\..\..\source\blender\verify;..\..\..\source\blender\ftfont;..\..\..\source\blender\misc;..\..\..\source\blender\imbuf;..\..\..\source\blender\blenlib;..\..\..\source\blender\python;..\..\..\source\blender\editors\include;..\..\..\source\blender\editors\interface;..\..\..\source\blender\renderui;..\..\..\source\blender\blenloader;..\..\..\source\blender\quicktime;..\..\..\source\blender\blenkernel;..\..\..\source\blender\blenfont;..\..\..\source\blender\makesdna;..\..\..\source\blender\makesrna;..\..\..\source\blender\nodes;..\..\..\source\blender\windowmanager;..\..\..\source\blender\blenpluginapi;..\..\..\source\blender\renderconverter;..\..\..\source\blender\readstreamglue;..\..\..\source\blender\render\extern\include;..\..\..\source\blender\radiosity\extern\include;..\..\..\source\kernel\gen_system;..\..\..\source\gameengine\network;..\..\..\source\gameengine\soundsystem\snd_openal;..\..\..\..\build\msvc_9\extern\verse\include;..\..\..\..\lib\windows\pthreads\include;..\..\..\..\lib\windows\ffmpeg\include;..\..\..\..\build\msvc_9\extern\glew\include;..\..\..\source\blender\gpu;..\..\..\intern\audaspace\intern;..\..\..\source\blender\ikplugin;..\..\..\..\lib\windows\openal\include;..\..\..\..\lib\windows\jack\include"
AdditionalIncludeDirectories="..\..\..\..\lib\windows\QTDevWin\CIncludes;..\..\..\..\lib\windows\sdl\include;..\..\..\..\lib\windows\python\include\python2.6;..\..\..\..\build\msvc_9\intern\bsp\include;..\..\..\..\build\msvc_9\intern\ghost\include;..\..\..\..\build\msvc_9\intern\elbeem\include;..\..\..\..\build\msvc_9\intern\opennl\include;..\..\..\..\build\msvc_9\intern\bmfont\include;..\..\..\..\build\msvc_9\intern\blenkey\include;..\..\..\..\build\msvc_9\intern\decimation\include;..\..\..\..\build\msvc_9\intern\memutil\include;..\..\..\..\build\msvc_9\intern\guardedalloc\include;..\..\..\..\build\msvc_9\intern\smoke\include;..\..\..\..\build\msvc_9\intern\soundsystem\include;..\..\..\source\blender;..\..\..\source\blender\img;..\..\..\source\blender\verify;..\..\..\source\blender\ftfont;..\..\..\source\blender\misc;..\..\..\source\blender\imbuf;..\..\..\source\blender\blenlib;..\..\..\source\blender\python;..\..\..\source\blender\editors\include;..\..\..\source\blender\editors\interface;..\..\..\source\blender\renderui;..\..\..\source\blender\blenloader;..\..\..\source\blender\quicktime;..\..\..\source\blender\blenkernel;..\..\..\source\blender\blenfont;..\..\..\source\blender\makesdna;..\..\..\source\blender\makesrna;..\..\..\source\blender\nodes;..\..\..\source\blender\windowmanager;..\..\..\source\blender\blenpluginapi;..\..\..\source\blender\renderconverter;..\..\..\source\blender\readstreamglue;..\..\..\source\blender\render\extern\include;..\..\..\source\blender\radiosity\extern\include;..\..\..\source\kernel\gen_system;..\..\..\source\gameengine\network;..\..\..\source\gameengine\soundsystem\snd_openal;..\..\..\..\build\msvc_9\extern\verse\include;..\..\..\..\lib\windows\pthreads\include;..\..\..\..\lib\windows\ffmpeg\include;..\..\..\..\build\msvc_9\extern\glew\include;..\..\..\source\blender\gpu;..\..\..\intern\audaspace\intern;..\..\..\source\blender\ikplugin;..\..\..\..\lib\windows\openal\include;..\..\..\..\lib\windows\jack\include;..\..\..\..\build\msvc_9\extern\recastnavigation\Recast\Include"
PreprocessorDefinitions="NDEBUG;WIN32;_LIB;_CONSOLE;GAMEBLENDER=1;WITH_QUICKTIME;INTERNATIONAL;WITH_FREETYPE2;WITH_INTERNATIONAL;WITH_OPENEXR;WITH_DDS;WITH_BULLET=1;WITH_FFMPEG;WITH_SDL;WITH_OPENAL;WITH_JACK"
StringPooling="true"
RuntimeLibrary="0"

View File

@@ -253,7 +253,7 @@
<Tool
Name="VCCLCompilerTool"
Optimization="2"
AdditionalIncludeDirectories="..\..\..\..\lib\windows\zlib\include;..\..\..\..\build\msvc_9\intern\bsp\include;..\..\..\..\build\msvc_9\intern\guardedalloc\include;..\..\..\..\build\msvc_9\intern\decimation\include;..\..\..\..\build\msvc_9\intern\elbeem\include;..\..\..\..\build\msvc_9\intern\iksolver\include;..\..\..\source\blender\blenlib;..\..\..\source\blender\blenkernel;..\..\..\source\blender\blenkernel\intern;..\..\..\source\blender\makesdna;..\..\..\source\blender\modifiers;..\..\..\source\blender\render\extern\include"
AdditionalIncludeDirectories="..\..\..\..\lib\windows\zlib\include;..\..\..\..\build\msvc_9\intern\bsp\include;..\..\..\..\build\msvc_9\intern\guardedalloc\include;..\..\..\..\build\msvc_9\intern\decimation\include;..\..\..\..\build\msvc_9\intern\elbeem\include;..\..\..\..\build\msvc_9\intern\iksolver\include;..\..\..\source\blender\blenlib;..\..\..\source\blender\blenkernel;..\..\..\source\blender\blenkernel\intern;..\..\..\source\blender\makesdna;..\..\..\source\blender\modifiers;..\..\..\source\blender\render\extern\include;..\..\..\..\build\msvc_9\extern\recastnavigation\Recast\Include;..\..\..\source\blender\editors\include;..\..\..\source\blender\gpu"
PreprocessorDefinitions="NDEBUG;WIN32;_LIB;WITH_LZO;WITH_LZMA"
BasicRuntimeChecks="0"
RuntimeLibrary="0"

View File

@@ -38,6 +38,7 @@ extern "C"
#include "DNA_meshdata_types.h"
#include "DNA_ID.h"
#include "BKE_library.h"
#include "BKE_depsgraph.h"
#include "BKE_context.h"
#include "BKE_mesh.h"
@@ -345,7 +346,7 @@ static Object* createRepresentation(bContext *C, rcPolyMesh*& pmesh, rcPolyMeshD
//create unique verts
for (j=nv; j<ndv; j++)
{
copy_v3_v3(co, &dmesh->verts[vbase + j]);
copy_v3_v3(co, &dmesh->verts[3*(vbase + j)]);
SWAP(float, co[1], co[2]);
addvertlist(em, co, NULL);
}
@@ -386,6 +387,11 @@ static Object* createRepresentation(bContext *C, rcPolyMesh*& pmesh, rcPolyMeshD
ED_object_exit_editmode(C, EM_FREEDATA);
WM_event_add_notifier(C, NC_OBJECT|ND_DRAW, obedit);
obedit->gameflag &= ~OB_COLLISION;
obedit->gameflag |= OB_NAVMESH;
obedit->body_type = OB_BODY_TYPE_NAVMESH;
rename_id((ID *)obedit, "Navmesh");
return obedit;
}

View File

@@ -70,6 +70,24 @@ inline void flipAxes(float* vec)
std::swap(vec[1],vec[2]);
}
static float distPointToSegmentSq(const float* point, const float* a, const float* b)
{
float abx[3], dx[3];
vsub(abx, b,a);
vsub(dx, point,a);
float d = abx[0]*abx[0]+abx[1]*abx[1];
float t = abx[0]*dx[0]+abx[1]*dx[1];
if (d > 0)
t /= d;
if (t < 0)
t = 0;
else if (t > 1)
t = 1;
dx[0] = a[0] + t*abx[0] - point[0];
dx[1] = a[1] + t*abx[1] - point[1];
return dx[0]*dx[0] + dx[1]*dx[1];
}
KX_NavMeshObject::KX_NavMeshObject(void* sgReplicationInfo, SG_Callbacks callbacks)
: KX_GameObject(sgReplicationInfo, callbacks)
, m_navMesh(NULL)
@@ -177,7 +195,7 @@ bool KX_NavMeshObject::BuildVertIndArrays(RAS_MeshObject* meshobj, float *&verti
for (int polyidx=0; polyidx<npolys; polyidx++)
{
vector<int> poly;
vector<unsigned short> poly, tempPoly;
//search border
int btri = -1;
int bedge = -1;
@@ -239,8 +257,20 @@ bool KX_NavMeshObject::BuildVertIndArrays(RAS_MeshObject* meshobj, float *&verti
}
}
//.todo: process poly to remove degenerate vertices
if (poly.size()>=vertsPerPoly)
size_t nv = poly.size();
for (size_t i=0; i<nv; i++)
{
unsigned short prev = poly[(poly.size()+i-1)%nv];
unsigned short cur = poly[i];
unsigned short next = poly[(i+1)%nv];
float distSq = distPointToSegmentSq(mvert[cur].co, mvert[prev].co, mvert[next].co);
static const float tolerance = 0.001f;
if (distSq>tolerance)
tempPoly.push_back(cur);
}
poly = tempPoly;
if (poly.size()>vertsPerPoly)
{
printf("Error! Polygon size exceeds max verts count");
return false;
@@ -254,7 +284,6 @@ bool KX_NavMeshObject::BuildVertIndArrays(RAS_MeshObject* meshobj, float *&verti
//assumption: vertices in mesh are stored in following order:
//navigation mesh vertices - unique detailed mesh vertex
unsigned short maxidx = 0;
for (int polyidx=0; polyidx<npolys; polyidx++)
{
@@ -295,7 +324,7 @@ bool KX_NavMeshObject::BuildVertIndArrays(RAS_MeshObject* meshobj, float *&verti
unsigned short minvert = 0xffff, maxvert = 0;
for (int j=0; j<dmesh[3]; j++)
{
unsigned short* dtri = &dtris[dmesh[2]*3*2+j];
unsigned short* dtri = &dtris[(dmesh[2]+j)*3*2];
for (int k=0; k<3; k++)
{
if (dtri[k]<nverts)
@@ -308,7 +337,7 @@ bool KX_NavMeshObject::BuildVertIndArrays(RAS_MeshObject* meshobj, float *&verti
dmesh[1] = minvert != 0xffff ? maxvert - minvert + 1 : 0; //vnum
}
//recalculate detailed mesh indices (it must be local)
//recalculate detailed mesh indices (they must be local)
for (int polyIdx=0; polyIdx<npolys; polyIdx++)
{
unsigned short * poly = &polys[polyIdx*vertsPerPoly*2];
@@ -350,6 +379,8 @@ bool KX_NavMeshObject::BuildVertIndArrays(RAS_MeshObject* meshobj, float *&verti
}
}
}
if (dmesh[1]>0)
dmesh[0] -= nverts;
}
}
else
@@ -434,6 +465,11 @@ bool KX_NavMeshObject::BuildNavMesh()
{
flipAxes(&vertices[i*3]);
}
for (int i=0; i<ndvertsuniq; i++)
{
flipAxes(&dvertices[i*3]);
}
/*
//reorder tris
for (int i=0; i<npolys; i++)
@@ -599,7 +635,7 @@ void KX_NavMeshObject::DrawNavMesh()
MT_Vector3 color(0.f, 0.f, 0.f);
enum RenderMode {POLYS ,DETAILED_TRIS, WALLS};
static const RenderMode renderMode = DETAILED_TRIS;//POLYS;
static const RenderMode renderMode = DETAILED_TRIS;// DETAILED_TRIS POLYS
switch (renderMode)
{
case POLYS :