From dbc8d4274fa47f429084f653008a14980432a65d Mon Sep 17 00:00:00 2001 From: Nick Samarin Date: Fri, 30 Jul 2010 13:02:32 +0000 Subject: - moved navmesh conversion code to ED_Editors project (ED_navmesh_conversion.h and navmesh_conversion.cpp files) - added new custom data layer CD_Recast --- source/blender/editors/util/navmesh_conversion.cpp | 420 +++++++++++++++++++++ 1 file changed, 420 insertions(+) create mode 100644 source/blender/editors/util/navmesh_conversion.cpp (limited to 'source/blender/editors/util') diff --git a/source/blender/editors/util/navmesh_conversion.cpp b/source/blender/editors/util/navmesh_conversion.cpp new file mode 100644 index 00000000000..a5f91198fef --- /dev/null +++ b/source/blender/editors/util/navmesh_conversion.cpp @@ -0,0 +1,420 @@ +/** +* $Id$ +* +* ***** BEGIN GPL LICENSE BLOCK ***** +* +* This program 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. +* +* This program 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 this program; if not, write to the Free Software Foundation, +* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +* +* The Original Code is Copyright (C) 2001-2002 by NaN Holding BV. +* All rights reserved. +* +* The Original Code is: all of this file. +* +* Contributor(s): none yet. +* +* ***** END GPL LICENSE BLOCK ***** +*/ +#include +#include "Recast.h" + + +extern "C"{ +#include "ED_navmesh_conversion.h" + +#include "DNA_meshdata_types.h" +#include "BKE_cdderivedmesh.h" +#include "BLI_math.h" +} + +int polyNumVerts(const unsigned short* p, const int vertsPerPoly) +{ + int nv = 0; + for (int i=0; i 0) + t /= d; + if (t < 0) + t = 0; + else if (t > 1) + t = 1; + dx[0] = a[0] + t*abx[0] - point[0]; + dx[2] = a[2] + t*abx[2] - point[2]; + return dx[0]*dx[0] + dx[2]*dx[2]; +} + +bool buildRawVertIndicesData(DerivedMesh* dm, int &nverts, float *&verts, + int &ntris, unsigned short *&tris, int *&trisToFacesMap, + int *&recastData) +{ + nverts = dm->getNumVerts(dm); + if (nverts>=0xffff) + { + printf("Converting navmesh: Error! Too many vertices. Max number of vertices %d\n", 0xffff); + return false; + } + verts = new float[3*nverts]; + dm->getVertCos(dm, (float(*)[3])verts); + + //flip coordinates + for (int vi=0; vigetNumFaces(dm); + MFace *faces = dm->getFaceArray(dm); + ntris = nfaces; + for (int fi=0; fiv4) + ntris++; + } + + //copy and transform to triangles (reorder on the run) + trisToFacesMap = new int[ntris]; + tris = new unsigned short[3*ntris]; + unsigned short* tri = tris; + int triIdx = 0; + for (int fi=0; fiv1; + tri[3*triIdx+1] = (unsigned short) face->v3; + tri[3*triIdx+2] = (unsigned short) face->v2; + trisToFacesMap[triIdx++]=fi; + if (face->v4) + { + tri[3*triIdx+0] = (unsigned short) face->v1; + tri[3*triIdx+1] = (unsigned short) face->v4; + tri[3*triIdx+2] = (unsigned short) face->v3; + trisToFacesMap[triIdx++]=fi; + } + } + + //carefully, recast data is just reference to data in derived mesh + recastData = (int*)CustomData_get_layer(&dm->faceData, CD_RECAST); + return true; +} + +bool buildPolygonsByDetailedMeshes(const int vertsPerPoly, const int npolys, + unsigned short* polys, const unsigned short* dmeshes, + const float* verts, const unsigned short* dtris, + const int* dtrisToPolysMap) +{ + bool res = false; + int capacity = vertsPerPoly; + unsigned short* newPoly = new unsigned short[capacity]; + memset(newPoly, 0xff, sizeof(unsigned short)*capacity); + for (int polyidx=0; polyidxtolerance) + adjustedPoly[adjustedNv++] = cur; + } + memcpy(newPoly, adjustedPoly, adjustedNv*sizeof(unsigned short)); + delete adjustedPoly; + nv = adjustedNv; + + if (nv<=vertsPerPoly) + { + for (int i=0; irecastData[context->trisToFacesMap[*(int*)a]] - + context->recastData[context->trisToFacesMap[*(int*)b]] ); +} + +bool buildNavMeshData(const int nverts, const float* verts, + const int ntris, const unsigned short *tris, + const int* recastData, const int* trisToFacesMap, + int &ndtris, unsigned short *&dtris, + int &npolys, unsigned short *&dmeshes, unsigned short *&polys, + int &vertsPerPoly, int *&dtrisToPolysMap, int *&dtrisToTrisMap) + +{ + if (!recastData) + { + printf("Converting navmesh: Error! Can't find recast custom data\n"); + return false; + } + + //sort the triangles by polygon idx + int* trisMapping = new int[ntris]; + for (int i=0; i0) + { + validTriStart = i; + break; + } + } + + if (validTriStart<0) + { + printf("Converting navmesh: Error! No valid polygons in mesh\n"); + delete trisMapping; + return false; + } + + ndtris = ntris-validTriStart; + //fill dtris to faces mapping + dtrisToTrisMap = new int[ndtris]; + memcpy(dtrisToTrisMap, &trisMapping[validTriStart], ndtris*sizeof(int)); + delete trisMapping; trisMapping=NULL; + + //create detailed mesh triangles - copy only valid triangles + //and reserve memory for adjacency info + dtris = new unsigned short[3*2*ndtris]; + memset(dtris, 0xffff, sizeof(unsigned short)*3*2*ndtris); + for (int i=0; i Date: Thu, 5 Aug 2010 07:27:28 +0000 Subject: added test for correctness of navigation polygon: check if all triangles are involved in polygon formation --- source/blender/editors/util/navmesh_conversion.cpp | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) (limited to 'source/blender/editors/util') diff --git a/source/blender/editors/util/navmesh_conversion.cpp b/source/blender/editors/util/navmesh_conversion.cpp index a5f91198fef..1fd3d83c69d 100644 --- a/source/blender/editors/util/navmesh_conversion.cpp +++ b/source/blender/editors/util/navmesh_conversion.cpp @@ -156,9 +156,13 @@ bool buildPolygonsByDetailedMeshes(const int vertsPerPoly, const int npolys, //search border int btri = -1; int bedge = -1; - for (int j=0; j Date: Fri, 6 Aug 2010 16:11:17 +0000 Subject: fixed error in forming of navigation polygons: non-traversed polygons are allowed if and only if they haven't border edges --- source/blender/editors/util/navmesh_conversion.cpp | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) (limited to 'source/blender/editors/util') diff --git a/source/blender/editors/util/navmesh_conversion.cpp b/source/blender/editors/util/navmesh_conversion.cpp index 1fd3d83c69d..6a8ee709c99 100644 --- a/source/blender/editors/util/navmesh_conversion.cpp +++ b/source/blender/editors/util/navmesh_conversion.cpp @@ -241,14 +241,26 @@ bool buildPolygonsByDetailedMeshes(const int vertsPerPoly, const int npolys, delete adjustedPoly; nv = adjustedNv; - bool allTraversed = true; + bool allBorderTraversed = true; for (size_t i=0; i<(size_t)dtrisNum; i++) { if (traversedTris[i]==0) - allTraversed = false; + { + //check whether it has border edges + int curpolytri = dtrisBase+i; + for (int k=0; k<3; k++) + { + unsigned short neighbortri = dtris[curpolytri*3*2+3+k]; + if ( neighbortri==0xffff || dtrisToPolysMap[neighbortri]!=polyidx+1) + { + allBorderTraversed = false; + break; + } + } + } } - if (nv<=vertsPerPoly && allTraversed) + if (nv<=vertsPerPoly && allBorderTraversed) { for (int i=0; i Date: Mon, 9 Aug 2010 10:20:53 +0000 Subject: fixed bugs (wrong number of triangle in buildMeshAdjacence, wrong face indexes in applyModifier) --- source/blender/editors/util/navmesh_conversion.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source/blender/editors/util') diff --git a/source/blender/editors/util/navmesh_conversion.cpp b/source/blender/editors/util/navmesh_conversion.cpp index 6a8ee709c99..62e26e2cd55 100644 --- a/source/blender/editors/util/navmesh_conversion.cpp +++ b/source/blender/editors/util/navmesh_conversion.cpp @@ -357,7 +357,7 @@ bool buildNavMeshData(const int nverts, const float* verts, //build adjacency info for detailed mesh triangles - buildMeshAdjacency(dtris, ntris, nverts, 3); + buildMeshAdjacency(dtris, ndtris, nverts, 3); //create detailed mesh description for each navigation polygon npolys = dtrisToPolysMap[ndtris-1]; -- cgit v1.2.3 From 3a8f3dd3f5e843ef8abad41996ebe5f7041e3807 Mon Sep 17 00:00:00 2001 From: Nick Samarin Date: Tue, 10 Aug 2010 20:48:28 +0000 Subject: reworked obstacle simulation in order to have two realizations: with "cell" and "ray" sampling --- source/blender/editors/util/navmesh_conversion.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source/blender/editors/util') diff --git a/source/blender/editors/util/navmesh_conversion.cpp b/source/blender/editors/util/navmesh_conversion.cpp index 62e26e2cd55..873660baa13 100644 --- a/source/blender/editors/util/navmesh_conversion.cpp +++ b/source/blender/editors/util/navmesh_conversion.cpp @@ -341,7 +341,7 @@ bool buildNavMeshData(const int nverts, const float* verts, { memcpy(dtris+3*2*i, tris+3*dtrisToTrisMap[i], sizeof(unsigned short)*3); } - //create new recast data corresponded to dtris and renumber for continious indices + //create new recast data corresponded to dtris and renumber for continuous indices int prevPolyIdx=-1, curPolyIdx, newPolyIdx=0; dtrisToPolysMap = new int[ndtris]; for (int i=0; i Date: Tue, 31 Aug 2010 22:08:01 +0000 Subject: Add CMake build system on Recast&Navigation branch --- source/blender/editors/util/CMakeLists.txt | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'source/blender/editors/util') diff --git a/source/blender/editors/util/CMakeLists.txt b/source/blender/editors/util/CMakeLists.txt index b4b2fd12cef..2c55b0773be 100644 --- a/source/blender/editors/util/CMakeLists.txt +++ b/source/blender/editors/util/CMakeLists.txt @@ -19,13 +19,14 @@ # # ***** END GPL LICENSE BLOCK ***** -FILE(GLOB SRC *.c) +FILE(GLOB SRC *.c *.cpp) SET(INC ../../blenkernel ../../blenlib ../include ../../../../intern/guardedalloc + ../../../../extern/recastnavigation/Recast/Include ../../makesdna ../../makesrna ../../windowmanager -- cgit v1.2.3 From a52f51df2768165e9868bc77c6307c1508b161e2 Mon Sep 17 00:00:00 2001 From: Benoit Bolsee Date: Wed, 1 Sep 2010 21:43:22 +0000 Subject: Recast: add SCons build system. --- source/blender/editors/util/SConscript | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'source/blender/editors/util') diff --git a/source/blender/editors/util/SConscript b/source/blender/editors/util/SConscript index 74ca2c89ba2..810874da865 100644 --- a/source/blender/editors/util/SConscript +++ b/source/blender/editors/util/SConscript @@ -1,10 +1,11 @@ #!/usr/bin/python Import ('env') -sources = env.Glob('*.c') +sources = env.Glob('*.c') + env.Glob('*.cpp') incs = '../include ../../blenlib ../../blenkernel ../../makesdna ../../imbuf' incs += ' ../../windowmanager #/intern/guardedalloc #/extern/glew/include' incs += ' ../../makesrna' +incs += ' #extern/recastnavigation/Recast/Include' env.BlenderLib ( 'bf_editors_util', sources, Split(incs), [], libtype=['core'], priority=[130] ) -- cgit v1.2.3 From c94fe5e2995873536cbdb180652b1aa027e4ef8d Mon Sep 17 00:00:00 2001 From: Sergey Sharybin Date: Tue, 6 Sep 2011 07:59:18 +0000 Subject: Grease pencil: non-blocking sketch sessions - Implement own undo stack for grease pencil, so now there'll be no keymaps conflicts. - Supported redo's during sketch session. - Get rid of flag stored in Globals -- use undo stack to check if grease pencil session is active. --- source/blender/editors/util/undo.c | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'source/blender/editors/util') diff --git a/source/blender/editors/util/undo.c b/source/blender/editors/util/undo.c index a2381a208ef..c1aca61f795 100644 --- a/source/blender/editors/util/undo.c +++ b/source/blender/editors/util/undo.c @@ -54,6 +54,7 @@ #include "ED_armature.h" #include "ED_particle.h" #include "ED_curve.h" +#include "ED_gpencil.h" #include "ED_mball.h" #include "ED_mesh.h" #include "ED_object.h" @@ -126,6 +127,11 @@ static int ed_undo_step(bContext *C, int step, const char *undoname) Object *obact= CTX_data_active_object(C); ScrArea *sa= CTX_wm_area(C); + /* grease pencil can be can be used in plenty of spaces, so check it first */ + if(ED_gpencil_session_active()) { + return ED_undo_gpencil_step(C, step, undoname); + } + if(sa && sa->spacetype==SPACE_IMAGE) { SpaceImage *sima= (SpaceImage *)sa->spacedata.first; -- cgit v1.2.3 From a7f3e347b7799b73d19adeee0057fce783ca2f32 Mon Sep 17 00:00:00 2001 From: "Guillermo S. Romero" Date: Fri, 9 Sep 2011 22:02:12 +0000 Subject: SVN maintenance. --- source/blender/editors/util/navmesh_conversion.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source/blender/editors/util') diff --git a/source/blender/editors/util/navmesh_conversion.cpp b/source/blender/editors/util/navmesh_conversion.cpp index 873660baa13..2068d17435c 100644 --- a/source/blender/editors/util/navmesh_conversion.cpp +++ b/source/blender/editors/util/navmesh_conversion.cpp @@ -441,4 +441,4 @@ int polyFindVertex(const unsigned short* p, const int vertsPerPoly, unsigned sho } } return res; -} \ No newline at end of file +} -- cgit v1.2.3 From 0128218254df07f804b15088036a1e7ef4938664 Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Sat, 10 Sep 2011 03:07:26 +0000 Subject: recast and detour patch now builds again with GCC - rearrange structs to work for 64bit - define all vars before goto's - ifdefs for qsort_r/qsort_s - dont cast pointers to int only for NULL checks - dont printf STR_String directly, get the char pointer from it also minor change to gpu py module, no need to pass empty tuple to PyObject_CallObject, can just be NULL --- source/blender/editors/util/navmesh_conversion.cpp | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) (limited to 'source/blender/editors/util') diff --git a/source/blender/editors/util/navmesh_conversion.cpp b/source/blender/editors/util/navmesh_conversion.cpp index 2068d17435c..255e3387ab2 100644 --- a/source/blender/editors/util/navmesh_conversion.cpp +++ b/source/blender/editors/util/navmesh_conversion.cpp @@ -146,7 +146,6 @@ bool buildPolygonsByDetailedMeshes(const int vertsPerPoly, const int npolys, const float* verts, const unsigned short* dtris, const int* dtrisToPolysMap) { - bool res = false; int capacity = vertsPerPoly; unsigned short* newPoly = new unsigned short[capacity]; memset(newPoly, 0xff, sizeof(unsigned short)*capacity); @@ -268,7 +267,6 @@ bool buildPolygonsByDetailedMeshes(const int vertsPerPoly, const int npolys, } } } - res = true; returnLabel: delete newPoly; @@ -280,8 +278,13 @@ struct SortContext const int* recastData; const int* trisToFacesMap; }; -static int compareByData(void* data, const void * a, const void * b){ - SortContext* context = (SortContext*)data; +#if defined(_MSC_VER) +static int compareByData(const void* data, void * a, void * b) +#else +static int compareByData(const void * a, const void * b, void* data) +#endif +{ + const SortContext* context = (const SortContext*)data; return ( context->recastData[context->trisToFacesMap[*(int*)a]] - context->recastData[context->trisToFacesMap[*(int*)b]] ); } @@ -307,8 +310,11 @@ bool buildNavMeshData(const int nverts, const float* verts, SortContext context; context.recastData = recastData; context.trisToFacesMap = trisToFacesMap; +#if defined(_MSC_VER) qsort_s(trisMapping, ntris, sizeof(int), compareByData, &context); - +#else + qsort_r(trisMapping, ntris, sizeof(int), compareByData, &context); +#endif //search first valid triangle - triangle of convex polygon int validTriStart = -1; for (int i=0; i< ntris; i++) -- cgit v1.2.3 From 01dca44a840cb6066adb4845a5e93e0d118f239c Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Sat, 10 Sep 2011 04:21:58 +0000 Subject: disable navmesh feature when building without the game engine. --- source/blender/editors/util/CMakeLists.txt | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'source/blender/editors/util') diff --git a/source/blender/editors/util/CMakeLists.txt b/source/blender/editors/util/CMakeLists.txt index da6e1990622..5e05342f3dc 100644 --- a/source/blender/editors/util/CMakeLists.txt +++ b/source/blender/editors/util/CMakeLists.txt @@ -40,7 +40,6 @@ set(SRC editmode_undo.c numinput.c undo.c - navmesh_conversion.cpp crazyspace.c util_intern.h @@ -90,4 +89,10 @@ set(SRC ../include/UI_view2d.h ) +if(WITH_GAMEENGINE) + list(APPEND SRC + navmesh_conversion.cpp + ) +endif() + blender_add_lib(bf_editor_util "${SRC}" "${INC}" "${INC_SYS}") -- cgit v1.2.3 From e86bda9a5b5a3730c04a8dbde37b71aa1668fb97 Mon Sep 17 00:00:00 2001 From: Thomas Dinges Date: Sat, 10 Sep 2011 08:25:03 +0000 Subject: Compile fix for scons: * Don't compile with navmesh_conversion.cpp if Game engine is disabled. --- source/blender/editors/util/SConscript | 3 +++ 1 file changed, 3 insertions(+) (limited to 'source/blender/editors/util') diff --git a/source/blender/editors/util/SConscript b/source/blender/editors/util/SConscript index 0ee64fbf9f2..5cb46480e1f 100644 --- a/source/blender/editors/util/SConscript +++ b/source/blender/editors/util/SConscript @@ -9,4 +9,7 @@ incs += ' ../../makesrna' incs += ' #extern/recastnavigation/Recast/Include' incs += ' ../../blenloader' +if not env['WITH_BF_GAMEENGINE']: + sources.remove('navmesh_conversion.cpp') + env.BlenderLib ( 'bf_editors_util', sources, Split(incs), [], libtype=['core','player'], priority=[130,210] ) -- cgit v1.2.3 From 571f7db529c3e0f351b90e7e76b1e7aba878b3a7 Mon Sep 17 00:00:00 2001 From: Thomas Dinges Date: Sat, 10 Sep 2011 09:06:42 +0000 Subject: MSVC build fix by MiikaH for NAVMESH. Thanks! :) --- source/blender/editors/util/navmesh_conversion.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source/blender/editors/util') diff --git a/source/blender/editors/util/navmesh_conversion.cpp b/source/blender/editors/util/navmesh_conversion.cpp index 255e3387ab2..aebd9624bc7 100644 --- a/source/blender/editors/util/navmesh_conversion.cpp +++ b/source/blender/editors/util/navmesh_conversion.cpp @@ -279,7 +279,7 @@ struct SortContext const int* trisToFacesMap; }; #if defined(_MSC_VER) -static int compareByData(const void* data, void * a, void * b) +static int compareByData(void* data, const void * a, const void * b) #else static int compareByData(const void * a, const void * b, void* data) #endif -- cgit v1.2.3 From bdd4aa27b0747bf7bc4af7e23a79b3fbdd3ee5b0 Mon Sep 17 00:00:00 2001 From: Sergey Sharybin Date: Sat, 10 Sep 2011 14:12:15 +0000 Subject: Another set of fixes for recats: osx uses different order of arguments for sort_r and it's callback. Also do not use char constants like 'NAVM' which is casting to int. And added defautl section to switch in KX_NavMeshObject::DrawNavMesh. --- source/blender/editors/util/navmesh_conversion.cpp | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'source/blender/editors/util') diff --git a/source/blender/editors/util/navmesh_conversion.cpp b/source/blender/editors/util/navmesh_conversion.cpp index aebd9624bc7..4d89f78bdf5 100644 --- a/source/blender/editors/util/navmesh_conversion.cpp +++ b/source/blender/editors/util/navmesh_conversion.cpp @@ -280,6 +280,8 @@ struct SortContext }; #if defined(_MSC_VER) static int compareByData(void* data, const void * a, const void * b) +#elif defined(__APPLE__) +static int compareByData(void* data, const void * a, const void * b) #else static int compareByData(const void * a, const void * b, void* data) #endif @@ -312,6 +314,8 @@ bool buildNavMeshData(const int nverts, const float* verts, context.trisToFacesMap = trisToFacesMap; #if defined(_MSC_VER) qsort_s(trisMapping, ntris, sizeof(int), compareByData, &context); +#elif defined(__APPLE__) + qsort_r(trisMapping, ntris, sizeof(int), &context, compareByData); #else qsort_r(trisMapping, ntris, sizeof(int), compareByData, &context); #endif -- cgit v1.2.3 From 782a7a36776897b7b7a05e0c412985d0ce4077a7 Mon Sep 17 00:00:00 2001 From: Sergey Sharybin Date: Sat, 10 Sep 2011 14:28:34 +0000 Subject: Change priority for editor util library. Gave linking errors here. --- source/blender/editors/util/SConscript | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source/blender/editors/util') diff --git a/source/blender/editors/util/SConscript b/source/blender/editors/util/SConscript index 5cb46480e1f..80c05dc5db4 100644 --- a/source/blender/editors/util/SConscript +++ b/source/blender/editors/util/SConscript @@ -12,4 +12,4 @@ incs += ' ../../blenloader' if not env['WITH_BF_GAMEENGINE']: sources.remove('navmesh_conversion.cpp') -env.BlenderLib ( 'bf_editors_util', sources, Split(incs), [], libtype=['core','player'], priority=[130,210] ) +env.BlenderLib ( 'bf_editors_util', sources, Split(incs), [], libtype=['core','player'], priority=[330,210] ) -- cgit v1.2.3 From 4e9381bc359b8734b7df48753957266af622cd56 Mon Sep 17 00:00:00 2001 From: Sergey Sharybin Date: Sat, 10 Sep 2011 14:55:14 +0000 Subject: Fixed for navmesh on FreeBSD. Oatch by sambler, thanks! --- source/blender/editors/util/navmesh_conversion.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'source/blender/editors/util') diff --git a/source/blender/editors/util/navmesh_conversion.cpp b/source/blender/editors/util/navmesh_conversion.cpp index 4d89f78bdf5..8b3fee59e1a 100644 --- a/source/blender/editors/util/navmesh_conversion.cpp +++ b/source/blender/editors/util/navmesh_conversion.cpp @@ -280,7 +280,7 @@ struct SortContext }; #if defined(_MSC_VER) static int compareByData(void* data, const void * a, const void * b) -#elif defined(__APPLE__) +#elif defined(__APPLE__) || defined(__FreeBSD__) static int compareByData(void* data, const void * a, const void * b) #else static int compareByData(const void * a, const void * b, void* data) @@ -314,7 +314,7 @@ bool buildNavMeshData(const int nverts, const float* verts, context.trisToFacesMap = trisToFacesMap; #if defined(_MSC_VER) qsort_s(trisMapping, ntris, sizeof(int), compareByData, &context); -#elif defined(__APPLE__) +#elif defined(__APPLE__) || defined(__FreeBSD__) qsort_r(trisMapping, ntris, sizeof(int), &context, compareByData); #else qsort_r(trisMapping, ntris, sizeof(int), compareByData, &context); -- cgit v1.2.3 From 3a5f2272adc4ec821db16de95781b9ce653dda73 Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Sun, 11 Sep 2011 00:08:07 +0000 Subject: cmake edits to navmesh so includes are not added unless the game engines enabled. --- source/blender/editors/util/CMakeLists.txt | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'source/blender/editors/util') diff --git a/source/blender/editors/util/CMakeLists.txt b/source/blender/editors/util/CMakeLists.txt index 5e05342f3dc..c64b16c2d08 100644 --- a/source/blender/editors/util/CMakeLists.txt +++ b/source/blender/editors/util/CMakeLists.txt @@ -24,7 +24,6 @@ set(INC ../../blenkernel ../../blenlib ../../blenloader - ../../../../extern/recastnavigation/Recast/Include ../../makesdna ../../makesrna ../../windowmanager @@ -63,7 +62,6 @@ set(SRC ../include/ED_markers.h ../include/ED_mball.h ../include/ED_mesh.h - ../include/ED_navmesh_conversion.h ../include/ED_node.h ../include/ED_numinput.h ../include/ED_object.h @@ -90,8 +88,14 @@ set(SRC ) if(WITH_GAMEENGINE) + list(APPEND INC + ../../../../extern/recastnavigation/Recast/Include + ) + list(APPEND SRC navmesh_conversion.cpp + + ../include/ED_navmesh_conversion.h ) endif() -- cgit v1.2.3 From b988a2abf815d74aba7bd9bf910b712735ea8f53 Mon Sep 17 00:00:00 2001 From: Benoit Bolsee Date: Sun, 11 Sep 2011 14:13:04 +0000 Subject: Recast: fix bad level calls, Recast compiled out if BGE not enabled. SCons updated but not tested. --- source/blender/editors/util/CMakeLists.txt | 12 - source/blender/editors/util/SConscript | 6 +- source/blender/editors/util/navmesh_conversion.cpp | 454 --------------------- 3 files changed, 1 insertion(+), 471 deletions(-) delete mode 100644 source/blender/editors/util/navmesh_conversion.cpp (limited to 'source/blender/editors/util') diff --git a/source/blender/editors/util/CMakeLists.txt b/source/blender/editors/util/CMakeLists.txt index c64b16c2d08..72f13c14f5d 100644 --- a/source/blender/editors/util/CMakeLists.txt +++ b/source/blender/editors/util/CMakeLists.txt @@ -87,16 +87,4 @@ set(SRC ../include/UI_view2d.h ) -if(WITH_GAMEENGINE) - list(APPEND INC - ../../../../extern/recastnavigation/Recast/Include - ) - - list(APPEND SRC - navmesh_conversion.cpp - - ../include/ED_navmesh_conversion.h - ) -endif() - blender_add_lib(bf_editor_util "${SRC}" "${INC}" "${INC_SYS}") diff --git a/source/blender/editors/util/SConscript b/source/blender/editors/util/SConscript index 80c05dc5db4..cfbc735eb5c 100644 --- a/source/blender/editors/util/SConscript +++ b/source/blender/editors/util/SConscript @@ -1,15 +1,11 @@ #!/usr/bin/python Import ('env') -sources = env.Glob('*.c') + env.Glob('*.cpp') +sources = env.Glob('*.c') incs = '../include ../../blenlib ../../blenkernel ../../makesdna ../../imbuf' incs += ' ../../windowmanager #/intern/guardedalloc #/extern/glew/include' incs += ' ../../makesrna' -incs += ' #extern/recastnavigation/Recast/Include' incs += ' ../../blenloader' -if not env['WITH_BF_GAMEENGINE']: - sources.remove('navmesh_conversion.cpp') - env.BlenderLib ( 'bf_editors_util', sources, Split(incs), [], libtype=['core','player'], priority=[330,210] ) diff --git a/source/blender/editors/util/navmesh_conversion.cpp b/source/blender/editors/util/navmesh_conversion.cpp deleted file mode 100644 index 8b3fee59e1a..00000000000 --- a/source/blender/editors/util/navmesh_conversion.cpp +++ /dev/null @@ -1,454 +0,0 @@ -/** -* $Id$ -* -* ***** BEGIN GPL LICENSE BLOCK ***** -* -* This program 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. -* -* This program 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 this program; if not, write to the Free Software Foundation, -* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -* -* The Original Code is Copyright (C) 2001-2002 by NaN Holding BV. -* All rights reserved. -* -* The Original Code is: all of this file. -* -* Contributor(s): none yet. -* -* ***** END GPL LICENSE BLOCK ***** -*/ -#include -#include "Recast.h" - - -extern "C"{ -#include "ED_navmesh_conversion.h" - -#include "DNA_meshdata_types.h" -#include "BKE_cdderivedmesh.h" -#include "BLI_math.h" -} - -int polyNumVerts(const unsigned short* p, const int vertsPerPoly) -{ - int nv = 0; - for (int i=0; i 0) - t /= d; - if (t < 0) - t = 0; - else if (t > 1) - t = 1; - dx[0] = a[0] + t*abx[0] - point[0]; - dx[2] = a[2] + t*abx[2] - point[2]; - return dx[0]*dx[0] + dx[2]*dx[2]; -} - -bool buildRawVertIndicesData(DerivedMesh* dm, int &nverts, float *&verts, - int &ntris, unsigned short *&tris, int *&trisToFacesMap, - int *&recastData) -{ - nverts = dm->getNumVerts(dm); - if (nverts>=0xffff) - { - printf("Converting navmesh: Error! Too many vertices. Max number of vertices %d\n", 0xffff); - return false; - } - verts = new float[3*nverts]; - dm->getVertCos(dm, (float(*)[3])verts); - - //flip coordinates - for (int vi=0; vigetNumFaces(dm); - MFace *faces = dm->getFaceArray(dm); - ntris = nfaces; - for (int fi=0; fiv4) - ntris++; - } - - //copy and transform to triangles (reorder on the run) - trisToFacesMap = new int[ntris]; - tris = new unsigned short[3*ntris]; - unsigned short* tri = tris; - int triIdx = 0; - for (int fi=0; fiv1; - tri[3*triIdx+1] = (unsigned short) face->v3; - tri[3*triIdx+2] = (unsigned short) face->v2; - trisToFacesMap[triIdx++]=fi; - if (face->v4) - { - tri[3*triIdx+0] = (unsigned short) face->v1; - tri[3*triIdx+1] = (unsigned short) face->v4; - tri[3*triIdx+2] = (unsigned short) face->v3; - trisToFacesMap[triIdx++]=fi; - } - } - - //carefully, recast data is just reference to data in derived mesh - recastData = (int*)CustomData_get_layer(&dm->faceData, CD_RECAST); - return true; -} - -bool buildPolygonsByDetailedMeshes(const int vertsPerPoly, const int npolys, - unsigned short* polys, const unsigned short* dmeshes, - const float* verts, const unsigned short* dtris, - const int* dtrisToPolysMap) -{ - int capacity = vertsPerPoly; - unsigned short* newPoly = new unsigned short[capacity]; - memset(newPoly, 0xff, sizeof(unsigned short)*capacity); - for (int polyidx=0; polyidxtolerance) - adjustedPoly[adjustedNv++] = cur; - } - memcpy(newPoly, adjustedPoly, adjustedNv*sizeof(unsigned short)); - delete adjustedPoly; - nv = adjustedNv; - - bool allBorderTraversed = true; - for (size_t i=0; i<(size_t)dtrisNum; i++) - { - if (traversedTris[i]==0) - { - //check whether it has border edges - int curpolytri = dtrisBase+i; - for (int k=0; k<3; k++) - { - unsigned short neighbortri = dtris[curpolytri*3*2+3+k]; - if ( neighbortri==0xffff || dtrisToPolysMap[neighbortri]!=polyidx+1) - { - allBorderTraversed = false; - break; - } - } - } - } - - if (nv<=vertsPerPoly && allBorderTraversed) - { - for (int i=0; irecastData[context->trisToFacesMap[*(int*)a]] - - context->recastData[context->trisToFacesMap[*(int*)b]] ); -} - -bool buildNavMeshData(const int nverts, const float* verts, - const int ntris, const unsigned short *tris, - const int* recastData, const int* trisToFacesMap, - int &ndtris, unsigned short *&dtris, - int &npolys, unsigned short *&dmeshes, unsigned short *&polys, - int &vertsPerPoly, int *&dtrisToPolysMap, int *&dtrisToTrisMap) - -{ - if (!recastData) - { - printf("Converting navmesh: Error! Can't find recast custom data\n"); - return false; - } - - //sort the triangles by polygon idx - int* trisMapping = new int[ntris]; - for (int i=0; i0) - { - validTriStart = i; - break; - } - } - - if (validTriStart<0) - { - printf("Converting navmesh: Error! No valid polygons in mesh\n"); - delete trisMapping; - return false; - } - - ndtris = ntris-validTriStart; - //fill dtris to faces mapping - dtrisToTrisMap = new int[ndtris]; - memcpy(dtrisToTrisMap, &trisMapping[validTriStart], ndtris*sizeof(int)); - delete trisMapping; trisMapping=NULL; - - //create detailed mesh triangles - copy only valid triangles - //and reserve memory for adjacency info - dtris = new unsigned short[3*2*ndtris]; - memset(dtris, 0xffff, sizeof(unsigned short)*3*2*ndtris); - for (int i=0; i