Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCampbell Barton <ideasman42@gmail.com>2011-10-14 02:50:01 +0400
committerCampbell Barton <ideasman42@gmail.com>2011-10-14 02:50:01 +0400
commit7eadd540d48ceaae0078d48a05ede663df3ea01a (patch)
tree4c7743146970928e7d73ad768249d5d5d9b5ab54 /source/blender
parent02b409ee1320e5f2bb473ef1410bef165efbb51c (diff)
parentf6cd962df7c5f70570647e5b0cadcb632717ad3d (diff)
svn merge ^/trunk/blender -r40872:40890
Diffstat (limited to 'source/blender')
-rw-r--r--source/blender/blenkernel/BKE_mesh.h2
-rw-r--r--source/blender/blenkernel/CMakeLists.txt4
-rw-r--r--source/blender/blenkernel/intern/DerivedMesh.c184
-rw-r--r--source/blender/blenkernel/intern/cdderivedmesh.c5
-rw-r--r--source/blender/blenkernel/intern/editderivedbmesh.c8
-rw-r--r--source/blender/blenkernel/intern/mesh.c16
-rw-r--r--source/blender/blenloader/intern/readfile.c4
-rw-r--r--source/blender/editors/interface/interface_handlers.c53
-rw-r--r--source/blender/editors/mesh/mesh_navmesh.c9
-rw-r--r--source/blender/editors/space_view3d/drawmesh.c12
-rw-r--r--source/blender/editors/space_view3d/view3d_select.c9
-rw-r--r--source/blender/makesdna/DNA_modifier_types.h5
-rw-r--r--source/blender/makesrna/intern/rna_modifier.c15
-rw-r--r--source/blender/makesrna/intern/rna_object.c15
-rw-r--r--source/blender/modifiers/CMakeLists.txt1
-rw-r--r--source/blender/modifiers/intern/MOD_navmesh.c313
-rw-r--r--source/blender/modifiers/intern/MOD_util.c1
17 files changed, 285 insertions, 371 deletions
diff --git a/source/blender/blenkernel/BKE_mesh.h b/source/blender/blenkernel/BKE_mesh.h
index df22fdcc78a..b414bcef474 100644
--- a/source/blender/blenkernel/BKE_mesh.h
+++ b/source/blender/blenkernel/BKE_mesh.h
@@ -196,6 +196,8 @@ int BKE_mesh_validate_dm(struct DerivedMesh *dm);
void BKE_mesh_calc_edges(struct Mesh *mesh, int update);
+void BKE_mesh_ensure_navmesh(struct Mesh *me);
+
/*convert a triangle of loop facedata to mface facedata*/
void mesh_loops_to_tri_corners(struct CustomData *fdata, struct CustomData *ldata,
struct CustomData *pdata, int lindex[3], int findex,
diff --git a/source/blender/blenkernel/CMakeLists.txt b/source/blender/blenkernel/CMakeLists.txt
index 2a8d0fb0fb9..35116a7e2f4 100644
--- a/source/blender/blenkernel/CMakeLists.txt
+++ b/source/blender/blenkernel/CMakeLists.txt
@@ -357,12 +357,14 @@ endif()
if(WITH_GAMEENGINE)
list(APPEND INC_SYS
- ../../../extern/recastnavigation
+ ../../../extern/recastnavigation
)
list(APPEND SRC
intern/navmesh_conversion.c
BKE_navmesh_conversion.h
)
+
+ add_definitions(-DWITH_GAMEENGINE)
endif()
## Warnings as errors, this is too strict!
diff --git a/source/blender/blenkernel/intern/DerivedMesh.c b/source/blender/blenkernel/intern/DerivedMesh.c
index 5e0ccac360f..1578eebb4fe 100644
--- a/source/blender/blenkernel/intern/DerivedMesh.c
+++ b/source/blender/blenkernel/intern/DerivedMesh.c
@@ -66,6 +66,10 @@
#include "BKE_tessmesh.h"
#include "BKE_bvhutils.h"
+#ifdef WITH_GAMEENGINE
+#include "BKE_navmesh_conversion.h"
+#endif
+
#include "BLO_sys_types.h" // for intptr_t support
#include "GL/glew.h"
@@ -80,7 +84,9 @@ extern GLubyte stipple_quarttone[128]; /* glutil.c, bad level data */
static void add_shapekey_layers(DerivedMesh *dm, Mesh *me, Object *ob);
static void shapekey_layers_to_keyblocks(DerivedMesh *dm, Mesh *me, int actshape_uid);
- ///////////////////////////////////
+static DerivedMesh *navmesh_dm_createNavMeshForVisualization(DerivedMesh *dm);
+
+///////////////////////////////////
///////////////////////////////////
static MVert *dm_getVertArray(DerivedMesh *dm)
@@ -1432,6 +1438,18 @@ static void mesh_calc_modifiers(Scene *scene, Object *ob, float (*inputVertexCos
add_orco_dm(ob, NULL, *deform_r, NULL, CD_ORCO);
}
+#ifdef WITH_GAMEENGINE
+ /* NavMesh - this is a hack but saves having a NavMesh modifier */
+ if ((ob->gameflag & OB_NAVMESH) && (finaldm->type == DM_TYPE_CDDM)) {
+ DerivedMesh *tdm;
+ tdm= navmesh_dm_createNavMeshForVisualization(finaldm);
+ if (finaldm != tdm) {
+ finaldm->release(finaldm);
+ finaldm= tdm;
+ }
+ }
+#endif /* WITH_GAMEENGINE */
+
*final_r = finaldm;
if(orcodm)
@@ -2282,3 +2300,167 @@ void DM_set_object_boundbox(Object *ob, DerivedMesh *dm)
boundbox_set_from_min_max(ob->bb, min, max);
}
+
+/* --- NAVMESH (begin) --- */
+#ifdef WITH_GAMEENGINE
+
+BM_INLINE int navmesh_bit(int a, int b)
+{
+ return (a & (1 << b)) >> b;
+}
+
+static void navmesh_intToCol(int i, float* col)
+{
+ int r = navmesh_bit(i, 0) + navmesh_bit(i, 3) * 2 + 1;
+ int g = navmesh_bit(i, 1) + navmesh_bit(i, 4) * 2 + 1;
+ int b = navmesh_bit(i, 2) + navmesh_bit(i, 5) * 2 + 1;
+ col[0] = 1 - r*63.0f/255.0f;
+ col[1] = 1 - g*63.0f/255.0f;
+ col[2] = 1 - b*63.0f/255.0f;
+}
+
+static void navmesh_drawColored(DerivedMesh *dm)
+{
+ int a, glmode;
+ MVert *mvert = (MVert *)CustomData_get_layer(&dm->vertData, CD_MVERT);
+ MFace *mface = (MFace *)CustomData_get_layer(&dm->faceData, CD_MFACE);
+ int* polygonIdx = (int*)CustomData_get_layer(&dm->faceData, CD_RECAST);
+ const float BLACK_COLOR[3] = {0.f, 0.f, 0.f};
+ float col[3];
+
+ if (!polygonIdx)
+ return;
+
+ /*
+ //UI_ThemeColor(TH_WIRE);
+ glDisable(GL_LIGHTING);
+ glLineWidth(2.0);
+ dm->drawEdges(dm, 0, 1);
+ glLineWidth(1.0);
+ glEnable(GL_LIGHTING);*/
+
+ glDisable(GL_LIGHTING);
+ if(GPU_buffer_legacy(dm) ) {
+ DEBUG_VBO( "Using legacy code. drawNavMeshColored\n" );
+ //glShadeModel(GL_SMOOTH);
+ glBegin(glmode = GL_QUADS);
+ for(a = 0; a < dm->numFaceData; a++, mface++) {
+ int new_glmode = mface->v4?GL_QUADS:GL_TRIANGLES;
+ int polygonIdx = *(int*)CustomData_get(&dm->faceData, a, CD_RECAST);
+ if (polygonIdx<=0)
+ memcpy(col, BLACK_COLOR, 3*sizeof(float));
+ else
+ navmesh_intToCol(polygonIdx, col);
+
+ if(new_glmode != glmode) {
+ glEnd();
+ glBegin(glmode = new_glmode);
+ }
+ glColor3fv(col);
+ glVertex3fv(mvert[mface->v1].co);
+ glVertex3fv(mvert[mface->v2].co);
+ glVertex3fv(mvert[mface->v3].co);
+ if(mface->v4) {
+ glVertex3fv(mvert[mface->v4].co);
+ }
+ }
+ glEnd();
+ }
+ glEnable(GL_LIGHTING);
+}
+
+static void navmesh_DM_drawFacesTex(DerivedMesh *dm, int (*setDrawOptions)(MTFace *tface, int has_mcol, int matnr))
+{
+ (void) setDrawOptions;
+
+ navmesh_drawColored(dm);
+}
+
+static void navmesh_DM_drawFacesSolid(DerivedMesh *dm,
+ float (*partial_redraw_planes)[4],
+ int UNUSED(fast), int (*setMaterial)(int, void *attribs))
+{
+ (void) partial_redraw_planes;
+ (void) setMaterial;
+
+ //drawFacesSolid_original(dm, partial_redraw_planes, fast, setMaterial);
+ navmesh_drawColored(dm);
+}
+
+static DerivedMesh *navmesh_dm_createNavMeshForVisualization(DerivedMesh *dm)
+{
+ DerivedMesh *result;
+ int maxFaces = dm->getNumFaces(dm);
+ int *recastData;
+ int vertsPerPoly=0, nverts=0, ndtris=0, npolys=0;
+ float* verts=NULL;
+ unsigned short *dtris=NULL, *dmeshes=NULL, *polys=NULL;
+ int *dtrisToPolysMap=NULL, *dtrisToTrisMap=NULL, *trisToFacesMap=NULL;
+ int res;
+
+ result = CDDM_copy(dm);
+ if (!CustomData_has_layer(&result->faceData, CD_RECAST)) {
+ int *sourceRecastData = (int*)CustomData_get_layer(&dm->faceData, CD_RECAST);
+ CustomData_add_layer_named(&result->faceData, CD_RECAST, CD_DUPLICATE,
+ sourceRecastData, maxFaces, "recastData");
+ }
+ recastData = (int*)CustomData_get_layer(&result->faceData, CD_RECAST);
+
+ /* note: This is not good design! - really should not be doing this */
+ result->drawFacesTex = navmesh_DM_drawFacesTex;
+ result->drawFacesSolid = navmesh_DM_drawFacesSolid;
+
+
+ /* process mesh */
+ res = buildNavMeshDataByDerivedMesh(dm, &vertsPerPoly, &nverts, &verts, &ndtris, &dtris,
+ &npolys, &dmeshes, &polys, &dtrisToPolysMap, &dtrisToTrisMap,
+ &trisToFacesMap);
+ if (res) {
+ size_t polyIdx;
+
+ /* invalidate concave polygon */
+ for (polyIdx=0; polyIdx<(size_t)npolys; polyIdx++) {
+ unsigned short* poly = &polys[polyIdx*2*vertsPerPoly];
+ if (!polyIsConvex(poly, vertsPerPoly, verts)) {
+ /* set negative polygon idx to all faces */
+ unsigned short *dmesh = &dmeshes[4*polyIdx];
+ unsigned short tbase = dmesh[2];
+ unsigned short tnum = dmesh[3];
+ unsigned short ti;
+
+ for (ti=0; ti<tnum; ti++) {
+ unsigned short triidx = dtrisToTrisMap[tbase+ti];
+ unsigned short faceidx = trisToFacesMap[triidx];
+ if (recastData[faceidx] > 0) {
+ recastData[faceidx] = -recastData[faceidx];
+ }
+ }
+ }
+ }
+ }
+ else {
+ printf("Error during creation polygon infos\n");
+ }
+
+ /* clean up */
+ if (verts!=NULL)
+ MEM_freeN(verts);
+ if (dtris!=NULL)
+ MEM_freeN(dtris);
+ if (dmeshes!=NULL)
+ MEM_freeN(dmeshes);
+ if (polys!=NULL)
+ MEM_freeN(polys);
+ if (dtrisToPolysMap!=NULL)
+ MEM_freeN(dtrisToPolysMap);
+ if (dtrisToTrisMap!=NULL)
+ MEM_freeN(dtrisToTrisMap);
+ if (trisToFacesMap!=NULL)
+ MEM_freeN(trisToFacesMap);
+
+ return result;
+}
+
+#endif /* WITH_GAMEENGINE */
+
+/* --- NAVMESH (end) --- */
diff --git a/source/blender/blenkernel/intern/cdderivedmesh.c b/source/blender/blenkernel/intern/cdderivedmesh.c
index f8dfbd4b7b6..5fbb87e618c 100644
--- a/source/blender/blenkernel/intern/cdderivedmesh.c
+++ b/source/blender/blenkernel/intern/cdderivedmesh.c
@@ -787,9 +787,10 @@ static void cdDM_drawFacesTex_common(DerivedMesh *dm,
unsigned char *colors = MEM_mallocN(dm->getNumTessFaces(dm)*4*3*sizeof(unsigned char), "cdDM_drawFacesTex_common");
for( i=0; i < dm->getNumTessFaces(dm); i++ ) {
for( j=0; j < 4; j++ ) {
- colors[i*12+j*3] = col[i*4+j].r;
+ /* bgr -> rgb is intentional (and stupid), but how its stored internally */
+ colors[i*12+j*3] = col[i*4+j].b;
colors[i*12+j*3+1] = col[i*4+j].g;
- colors[i*12+j*3+2] = col[i*4+j].b;
+ colors[i*12+j*3+2] = col[i*4+j].r;
}
}
GPU_color3_upload(dm,colors);
diff --git a/source/blender/blenkernel/intern/editderivedbmesh.c b/source/blender/blenkernel/intern/editderivedbmesh.c
index 1b9116a7533..acc58b1899e 100644
--- a/source/blender/blenkernel/intern/editderivedbmesh.c
+++ b/source/blender/blenkernel/intern/editderivedbmesh.c
@@ -660,7 +660,9 @@ static void bmDM_drawMappedFaces(DerivedMesh *dm,
else {
const GLenum shade_type= drawSmooth ? GL_SMOOTH : GL_FLAT;
if (shade_type != shade_prev) {
- glShadeModel((shade_prev= shade_type));
+ if(poly_prev != GL_ZERO) glEnd();
+ glShadeModel((shade_prev= shade_type)); /* same as below but switch shading */
+ glBegin((poly_prev= poly_type)); /* BMesh: will always be GL_TRIANGLES */
}
if(poly_type != poly_prev) {
if(poly_prev != GL_ZERO) glEnd();
@@ -726,7 +728,9 @@ static void bmDM_drawMappedFaces(DerivedMesh *dm,
else {
const GLenum shade_type= drawSmooth ? GL_SMOOTH : GL_FLAT;
if (shade_type != shade_prev) {
- glShadeModel((shade_prev= shade_type));
+ if(poly_prev != GL_ZERO) glEnd();
+ glShadeModel((shade_prev= shade_type)); /* same as below but switch shading */
+ glBegin((poly_prev= poly_type)); /* BMesh: will always be GL_TRIANGLES */
}
if(poly_type != poly_prev) {
if(poly_prev != GL_ZERO) glEnd();
diff --git a/source/blender/blenkernel/intern/mesh.c b/source/blender/blenkernel/intern/mesh.c
index ce2193fe09a..01f521e3a02 100644
--- a/source/blender/blenkernel/intern/mesh.c
+++ b/source/blender/blenkernel/intern/mesh.c
@@ -2558,3 +2558,19 @@ void mesh_translate(Mesh *me, float offset[3], int do_keys)
}
}
}
+
+
+void BKE_mesh_ensure_navmesh(Mesh *me)
+{
+ if (!CustomData_has_layer(&me->fdata, CD_RECAST)) {
+ int i;
+ int numFaces = me->totface;
+ int* recastData;
+ CustomData_add_layer_named(&me->fdata, CD_RECAST, CD_CALLOC, NULL, numFaces, "recastData");
+ recastData = (int*)CustomData_get_layer(&me->fdata, CD_RECAST);
+ for (i=0; i<numFaces; i++) {
+ recastData[i] = i+1;
+ }
+ CustomData_add_layer_named(&me->fdata, CD_RECAST, CD_REFERENCE, recastData, numFaces, "recastData");
+ }
+}
diff --git a/source/blender/blenloader/intern/readfile.c b/source/blender/blenloader/intern/readfile.c
index 6530f25f349..91b17d783ab 100644
--- a/source/blender/blenloader/intern/readfile.c
+++ b/source/blender/blenloader/intern/readfile.c
@@ -4560,7 +4560,9 @@ static void lib_link_scene(FileData *fd, Main *main)
seq->scene_sound = NULL;
if(seq->scene) {
seq->scene= newlibadr(fd, sce->id.lib, seq->scene);
- seq->scene_sound = sound_scene_add_scene_sound(sce, seq, seq->startdisp, seq->enddisp, seq->startofs + seq->anim_startofs);
+ if(seq->scene) {
+ seq->scene_sound = sound_scene_add_scene_sound(sce, seq, seq->startdisp, seq->enddisp, seq->startofs + seq->anim_startofs);
+ }
}
if(seq->scene_camera) seq->scene_camera= newlibadr(fd, sce->id.lib, seq->scene_camera);
if(seq->sound) {
diff --git a/source/blender/editors/interface/interface_handlers.c b/source/blender/editors/interface/interface_handlers.c
index 9ad828f91c1..6417a6b58dd 100644
--- a/source/blender/editors/interface/interface_handlers.c
+++ b/source/blender/editors/interface/interface_handlers.c
@@ -1481,13 +1481,12 @@ static void ui_textedit_move(uiBut *but, uiHandleButtonData *data, int direction
}
}
-static int ui_textedit_delete(uiBut *but, uiHandleButtonData *data, int direction, int all)
+static int ui_textedit_delete(uiBut *but, uiHandleButtonData *data, int direction, const int all, const int jump)
{
- char *str;
- int len, x, changed= 0;
+ char *str= data->str;
+ const int len= strlen(str);
- str= data->str;
- len= strlen(str);
+ int x, changed= 0;
if(all) {
if(len) changed=1;
@@ -1499,9 +1498,24 @@ static int ui_textedit_delete(uiBut *but, uiHandleButtonData *data, int directio
changed= ui_textedit_delete_selection(but, data);
}
else if(but->pos>=0 && but->pos<len) {
+ int step;
+
+ if (jump) {
+ x = but->pos;
+ step= 0;
+ while(x < len) {
+ x++;
+ step++;
+ if(test_special_char(str[x])) break;
+ }
+ }
+ else {
+ step= 1;
+ }
+
for(x=but->pos; x<len; x++)
- str[x]= str[x+1];
- str[len-1]='\0';
+ str[x]= str[x+step];
+ str[len-step]='\0';
changed= 1;
}
}
@@ -1511,11 +1525,26 @@ static int ui_textedit_delete(uiBut *but, uiHandleButtonData *data, int directio
changed= ui_textedit_delete_selection(but, data);
}
else if(but->pos>0) {
+ int step;
+
+ if (jump) {
+ x = but->pos;
+ step= 0;
+ while(x > 0) {
+ x--;
+ step++;
+ if((step > 1) && test_special_char(str[x])) break;
+ }
+ }
+ else {
+ step= 1;
+ }
+
for(x=but->pos; x<len; x++)
- str[x-1]= str[x];
- str[len-1]='\0';
+ str[x-step]= str[x];
+ str[len-step]='\0';
- but->pos--;
+ but->pos -= step;
changed= 1;
}
}
@@ -1846,12 +1875,12 @@ static void ui_do_but_textedit(bContext *C, uiBlock *block, uiBut *but, uiHandle
retval= WM_UI_HANDLER_BREAK;
break;
case DELKEY:
- changed= ui_textedit_delete(but, data, 1, 0);
+ changed= ui_textedit_delete(but, data, 1, 0, event->ctrl);
retval= WM_UI_HANDLER_BREAK;
break;
case BACKSPACEKEY:
- changed= ui_textedit_delete(but, data, 0, event->shift);
+ changed= ui_textedit_delete(but, data, 0, event->shift, event->ctrl);
retval= WM_UI_HANDLER_BREAK;
break;
diff --git a/source/blender/editors/mesh/mesh_navmesh.c b/source/blender/editors/mesh/mesh_navmesh.c
index e4b884744e1..f427b51570b 100644
--- a/source/blender/editors/mesh/mesh_navmesh.c
+++ b/source/blender/editors/mesh/mesh_navmesh.c
@@ -296,7 +296,6 @@ static Object* createRepresentation(bContext *C, struct recast_polyMesh *pmesh,
int i,j, k;
unsigned short* v;
int face[3];
- Main *bmain= CTX_data_main(C);
Scene *scene= CTX_data_scene(C);
Object* obedit;
int createob= base==NULL;
@@ -305,7 +304,6 @@ static Object* createRepresentation(bContext *C, struct recast_polyMesh *pmesh,
unsigned int *meshes;
float bmin[3], cs, ch, *dverts;
unsigned char *tris;
- ModifierData *md;
zero_v3(co);
zero_v3(rot);
@@ -419,11 +417,8 @@ static Object* createRepresentation(bContext *C, struct recast_polyMesh *pmesh,
obedit->body_type= OB_BODY_TYPE_NAVMESH;
rename_id((ID *)obedit, "Navmesh");
}
-
- md= modifiers_findByType(obedit, eModifierType_NavMesh);
- if(!md) {
- ED_object_modifier_add(NULL, bmain, scene, obedit, NULL, eModifierType_NavMesh);
- }
+
+ BKE_mesh_ensure_navmesh(obedit->data);
return obedit;
}
diff --git a/source/blender/editors/space_view3d/drawmesh.c b/source/blender/editors/space_view3d/drawmesh.c
index 7e8448917b1..ae9ef2c4dfd 100644
--- a/source/blender/editors/space_view3d/drawmesh.c
+++ b/source/blender/editors/space_view3d/drawmesh.c
@@ -453,9 +453,9 @@ static void add_tface_color_layer(DerivedMesh *dm)
}
} else if (tface && tface->mode&TF_OBCOL) {
for(j=0;j<4;j++) {
- finalCol[i*4+j].r = FTOCHAR(Gtexdraw.obcol[0]);
+ finalCol[i*4+j].b = FTOCHAR(Gtexdraw.obcol[0]);
finalCol[i*4+j].g = FTOCHAR(Gtexdraw.obcol[1]);
- finalCol[i*4+j].b = FTOCHAR(Gtexdraw.obcol[2]);
+ finalCol[i*4+j].r = FTOCHAR(Gtexdraw.obcol[2]);
}
} else if (!mcol) {
if (tface) {
@@ -474,9 +474,9 @@ static void add_tface_color_layer(DerivedMesh *dm)
else copy_v3_v3(col, &ma->r);
for(j=0;j<4;j++) {
- finalCol[i*4+j].b = FTOCHAR(col[2]);
+ finalCol[i*4+j].b = FTOCHAR(col[0]);
finalCol[i*4+j].g = FTOCHAR(col[1]);
- finalCol[i*4+j].r = FTOCHAR(col[0]);
+ finalCol[i*4+j].r = FTOCHAR(col[2]);
}
}
else
@@ -488,9 +488,9 @@ static void add_tface_color_layer(DerivedMesh *dm)
}
} else {
for(j=0;j<4;j++) {
- finalCol[i*4+j].b = mcol[i*4+j].r;
+ finalCol[i*4+j].r = mcol[i*4+j].r;
finalCol[i*4+j].g = mcol[i*4+j].g;
- finalCol[i*4+j].r = mcol[i*4+j].b;
+ finalCol[i*4+j].b = mcol[i*4+j].b;
}
}
}
diff --git a/source/blender/editors/space_view3d/view3d_select.c b/source/blender/editors/space_view3d/view3d_select.c
index 28f220cd6d0..f30b20ba7d6 100644
--- a/source/blender/editors/space_view3d/view3d_select.c
+++ b/source/blender/editors/space_view3d/view3d_select.c
@@ -1953,7 +1953,7 @@ void VIEW3D_OT_select_border(wmOperatorType *ot)
/* much like facesel_face_pick()*/
/* returns 0 if not found, otherwise 1 */
-static int vertsel_vert_pick(struct bContext *C, Mesh *me, const int mval[2], unsigned int *index, short rect)
+static int vertsel_vert_pick(struct bContext *C, Mesh *me, const int mval[2], unsigned int *index, int size)
{
ViewContext vc;
view3d_set_viewcontext(C, &vc);
@@ -1961,12 +1961,12 @@ static int vertsel_vert_pick(struct bContext *C, Mesh *me, const int mval[2], un
if (!me || me->totvert==0)
return 0;
- if (rect) {
+ if (size > 0) {
/* sample rect to increase changes of selecting, so that when clicking
on an face in the backbuf, we can still select a vert */
int dist;
- *index = view3d_sample_backbuf_rect(&vc, mval, 3, 1, me->totvert+1, &dist,0,NULL, NULL);
+ *index = view3d_sample_backbuf_rect(&vc, mval, size, 1, me->totvert+1, &dist,0,NULL, NULL);
}
else {
/* sample only on the exact position */
@@ -1988,7 +1988,8 @@ static int mouse_weight_paint_vertex_select(bContext *C, const int mval[2], shor
Mesh* me= obact->data; /* already checked for NULL */
unsigned int index = 0;
MVert *mv;
- if(vertsel_vert_pick(C, me, mval, &index, 1)) {
+
+ if(vertsel_vert_pick(C, me, mval, &index, 50)) {
mv = me->mvert+index;
if(extend) {
mv->flag ^= SELECT;
diff --git a/source/blender/makesdna/DNA_modifier_types.h b/source/blender/makesdna/DNA_modifier_types.h
index 84c09e8ade9..7bc81e7fe05 100644
--- a/source/blender/makesdna/DNA_modifier_types.h
+++ b/source/blender/makesdna/DNA_modifier_types.h
@@ -74,7 +74,6 @@ typedef enum ModifierType {
eModifierType_WeightVGEdit,
eModifierType_WeightVGMix,
eModifierType_WeightVGProximity,
- eModifierType_NavMesh,
eModifierType_DynamicPaint, /* reserve slot */
/* BMESH ONLY - keeps getting bumped by new modifiers in trunk */
@@ -760,10 +759,6 @@ typedef struct NgonInterpModifierData {
int resolution, pad0;
} NgonInterpModifierData;
-typedef struct NavMeshModifierData {
- ModifierData modifier;
-} NavMeshModifierData;
-
typedef struct WarpModifierData {
ModifierData modifier;
/* keep in sync with MappingInfoModifierData */
diff --git a/source/blender/makesrna/intern/rna_modifier.c b/source/blender/makesrna/intern/rna_modifier.c
index 614e5ab243d..896f1eed127 100644
--- a/source/blender/makesrna/intern/rna_modifier.c
+++ b/source/blender/makesrna/intern/rna_modifier.c
@@ -91,7 +91,6 @@ EnumPropertyItem modifier_type_items[] ={
{eModifierType_Collision, "COLLISION", ICON_MOD_PHYSICS, "Collision", ""},
{eModifierType_Explode, "EXPLODE", ICON_MOD_EXPLODE, "Explode", ""},
{eModifierType_Fluidsim, "FLUID_SIMULATION", ICON_MOD_FLUIDSIM, "Fluid Simulation", ""},
- {eModifierType_NavMesh, "NAVMESH", ICON_MOD_PHYSICS, "Navigation mesh", ""},
{eModifierType_ParticleInstance, "PARTICLE_INSTANCE", ICON_MOD_PARTICLES, "Particle Instance", ""},
{eModifierType_ParticleSystem, "PARTICLE_SYSTEM", ICON_MOD_PARTICLES, "Particle System", ""},
{eModifierType_Smoke, "SMOKE", ICON_MOD_SMOKE, "Smoke", ""},
@@ -192,8 +191,6 @@ static StructRNA* rna_Modifier_refine(struct PointerRNA *ptr)
return &RNA_ScrewModifier;
case eModifierType_Warp:
return &RNA_WarpModifier;
- case eModifierType_NavMesh:
- return &RNA_NavMeshModifier;
case eModifierType_WeightVGEdit:
return &RNA_VertexWeightEditModifier;
case eModifierType_WeightVGMix:
@@ -2493,17 +2490,6 @@ static void rna_def_modifier_screw(BlenderRNA *brna)
RNA_def_property_update(prop, 0, "rna_Modifier_update");*/
}
-static void rna_def_modifier_navmesh(BlenderRNA *brna)
-{
- StructRNA *srna;
- /* PropertyRNA *prop; */ /* UNUSED */
-
- srna= RNA_def_struct(brna, "NavMeshModifier", "Modifier");
- RNA_def_struct_ui_text(srna, "NavMesh Modifier", "NavMesh modifier");
- RNA_def_struct_sdna(srna, "NavMeshModifierData");
- RNA_def_struct_ui_icon(srna, ICON_MOD_DECIM);
-}
-
static void rna_def_modifier_weightvg_mask(BlenderRNA *brna, StructRNA *srna)
{
static EnumPropertyItem weightvg_mask_tex_map_items[] = {
@@ -2915,7 +2901,6 @@ void RNA_def_modifier(BlenderRNA *brna)
rna_def_modifier_smoke(brna);
rna_def_modifier_solidify(brna);
rna_def_modifier_screw(brna);
- rna_def_modifier_navmesh(brna);
rna_def_modifier_weightvgedit(brna);
rna_def_modifier_weightvgmix(brna);
rna_def_modifier_weightvgproximity(brna);
diff --git a/source/blender/makesrna/intern/rna_object.c b/source/blender/makesrna/intern/rna_object.c
index 0786a7d801b..58272fa7c5e 100644
--- a/source/blender/makesrna/intern/rna_object.c
+++ b/source/blender/makesrna/intern/rna_object.c
@@ -891,6 +891,7 @@ static int rna_GameObjectSettings_physics_type_get(PointerRNA *ptr)
static void rna_GameObjectSettings_physics_type_set(PointerRNA *ptr, int value)
{
Object *ob= (Object*)ptr->id.data;
+ const int was_navmesh= (ob->gameflag & OB_NAVMESH);
ob->body_type= value;
switch (ob->body_type) {
@@ -906,6 +907,12 @@ static void rna_GameObjectSettings_physics_type_set(PointerRNA *ptr, int value)
case OB_BODY_TYPE_NAVMESH:
ob->gameflag |= OB_NAVMESH;
ob->gameflag &= ~(OB_SENSOR|OB_COLLISION|OB_DYNAMIC|OB_OCCLUDER);
+
+ if (ob->type == OB_MESH) {
+ /* could be moved into mesh UI but for now ensure mesh data layer */
+ BKE_mesh_ensure_navmesh(ob->data);
+ }
+
break;
case OB_BODY_TYPE_NO_COLLISION:
ob->gameflag &= ~(OB_SENSOR|OB_COLLISION|OB_OCCLUDER|OB_DYNAMIC|OB_NAVMESH);
@@ -937,6 +944,14 @@ static void rna_GameObjectSettings_physics_type_set(PointerRNA *ptr, int value)
ob->bsoft = bsbNew();
break;
}
+
+ if (was_navmesh != (ob->gameflag & OB_NAVMESH)) {
+ if (ob->type == OB_MESH) {
+ DAG_id_tag_update(ptr->id.data, OB_RECALC_DATA);
+ WM_main_add_notifier(NC_OBJECT|ND_DRAW, ptr->id.data);
+ }
+ }
+
}
static PointerRNA rna_Object_active_particle_system_get(PointerRNA *ptr)
diff --git a/source/blender/modifiers/CMakeLists.txt b/source/blender/modifiers/CMakeLists.txt
index a50b769ee11..f31565dd48e 100644
--- a/source/blender/modifiers/CMakeLists.txt
+++ b/source/blender/modifiers/CMakeLists.txt
@@ -67,7 +67,6 @@ set(SRC
intern/MOD_mirror.c
intern/MOD_multires.c
intern/MOD_ngoninterp.c
- intern/MOD_navmesh.c
intern/MOD_none.c
intern/MOD_particleinstance.c
intern/MOD_particlesystem.c
diff --git a/source/blender/modifiers/intern/MOD_navmesh.c b/source/blender/modifiers/intern/MOD_navmesh.c
deleted file mode 100644
index c259239a003..00000000000
--- a/source/blender/modifiers/intern/MOD_navmesh.c
+++ /dev/null
@@ -1,313 +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) 2005 by the Blender Foundation.
-* All rights reserved.
-*
-* Contributor(s):
-*
-* ***** END GPL LICENSE BLOCK *****
-*
-*/
-
-/** \file blender/modifiers/intern/MOD_navmesh.c
- * \ingroup modifiers
- */
-
-
-#include <math.h>
-
-#include "DNA_mesh_types.h"
-#include "DNA_meshdata_types.h"
-
-#ifdef WITH_GAMEENGINE
-# include "recast-capi.h"
-# include "BKE_navmesh_conversion.h"
-# include "GL/glew.h"
-# include "GPU_buffers.h"
-# include "GPU_draw.h"
-#endif
-
-#include "BLI_math.h"
-#include "BLI_utildefines.h"
-
-#include "BKE_cdderivedmesh.h"
-#include "BKE_mesh.h"
-#include "BKE_modifier.h"
-#include "BKE_particle.h"
-#include "BKE_customdata.h"
-#include "MEM_guardedalloc.h"
-
-BM_INLINE int bit(int a, int b)
-{
- return (a & (1 << b)) >> b;
-}
-
-BM_INLINE void intToCol(int i, float* col)
-{
- int r = bit(i, 0) + bit(i, 3) * 2 + 1;
- int g = bit(i, 1) + bit(i, 4) * 2 + 1;
- int b = bit(i, 2) + bit(i, 5) * 2 + 1;
- col[0] = 1 - r*63.0f/255.0f;
- col[1] = 1 - g*63.0f/255.0f;
- col[2] = 1 - b*63.0f/255.0f;
-}
-
-
-static void initData(ModifierData *UNUSED(md))
-{
- /* NavMeshModifierData *nmmd = (NavMeshModifierData*) md; */ /* UNUSED */
-}
-
-static void copyData(ModifierData *UNUSED(md), ModifierData *UNUSED(target))
-{
- /* NavMeshModifierData *nmmd = (NavMeshModifierData*) md; */
- /* NavMeshModifierData *tnmmd = (NavMeshModifierData*) target; */
-
- //.todo - deep copy
-}
-
-/*
-static void (*drawFacesSolid_original)(DerivedMesh *dm, float (*partial_redraw_planes)[4],
- int fast, int (*setMaterial)(int, void *attribs)) = NULL;*/
-
-#ifdef WITH_GAMEENGINE
-
-static void drawNavMeshColored(DerivedMesh *dm)
-{
- int a, glmode;
- MVert *mvert = (MVert *)CustomData_get_layer(&dm->vertData, CD_MVERT);
- MFace *mface = (MFace *)CustomData_get_layer(&dm->faceData, CD_MFACE);
- int* polygonIdx = (int*)CustomData_get_layer(&dm->faceData, CD_RECAST);
- const float BLACK_COLOR[3] = {0.f, 0.f, 0.f};
- float col[3];
-
- if (!polygonIdx)
- return;
-
- /*
- //UI_ThemeColor(TH_WIRE);
- glDisable(GL_LIGHTING);
- glLineWidth(2.0);
- dm->drawEdges(dm, 0, 1);
- glLineWidth(1.0);
- glEnable(GL_LIGHTING);*/
-
- glDisable(GL_LIGHTING);
- if(GPU_buffer_legacy(dm) ) {
- DEBUG_VBO( "Using legacy code. drawNavMeshColored\n" );
- //glShadeModel(GL_SMOOTH);
- glBegin(glmode = GL_QUADS);
- for(a = 0; a < dm->numFaceData; a++, mface++) {
- int new_glmode = mface->v4?GL_QUADS:GL_TRIANGLES;
- int polygonIdx = *(int*)CustomData_get(&dm->faceData, a, CD_RECAST);
- if (polygonIdx<=0)
- memcpy(col, BLACK_COLOR, 3*sizeof(float));
- else
- intToCol(polygonIdx, col);
-
- if(new_glmode != glmode) {
- glEnd();
- glBegin(glmode = new_glmode);
- }
- glColor3fv(col);
- glVertex3fv(mvert[mface->v1].co);
- glVertex3fv(mvert[mface->v2].co);
- glVertex3fv(mvert[mface->v3].co);
- if(mface->v4) {
- glVertex3fv(mvert[mface->v4].co);
- }
- }
- glEnd();
- }
- glEnable(GL_LIGHTING);
-}
-
-static void navDM_drawFacesTex(DerivedMesh *dm, int (*setDrawOptions)(MTFace *tface, int has_mcol, int matnr))
-{
- (void) setDrawOptions;
-
- drawNavMeshColored(dm);
-}
-
-static void navDM_drawFacesSolid(DerivedMesh *dm,
- float (*partial_redraw_planes)[4],
- int UNUSED(fast), int (*setMaterial)(int, void *attribs))
-{
- (void) partial_redraw_planes;
- (void) setMaterial;
-
- //drawFacesSolid_original(dm, partial_redraw_planes, fast, setMaterial);
- drawNavMeshColored(dm);
-}
-#endif /* WITH_GAMEENGINE */
-
-static DerivedMesh *createNavMeshForVisualization(NavMeshModifierData *UNUSED(mmd), DerivedMesh *dm)
-{
-#ifdef WITH_GAMEENGINE
- DerivedMesh *result;
- int maxFaces = dm->getNumFaces(dm);
- int *recastData;
- int vertsPerPoly=0, nverts=0, ndtris=0, npolys=0;
- float* verts=NULL;
- unsigned short *dtris=NULL, *dmeshes=NULL, *polys=NULL;
- int *dtrisToPolysMap=NULL, *dtrisToTrisMap=NULL, *trisToFacesMap=NULL;
- int res;
-
- result = CDDM_copy(dm);
- if (!CustomData_has_layer(&result->faceData, CD_RECAST))
- {
- int *sourceRecastData = (int*)CustomData_get_layer(&dm->faceData, CD_RECAST);
- CustomData_add_layer_named(&result->faceData, CD_RECAST, CD_DUPLICATE,
- sourceRecastData, maxFaces, "recastData");
- }
- recastData = (int*)CustomData_get_layer(&result->faceData, CD_RECAST);
- result->drawFacesTex = navDM_drawFacesTex;
- result->drawFacesSolid = navDM_drawFacesSolid;
-
-
- //process mesh
- res = buildNavMeshDataByDerivedMesh(dm, &vertsPerPoly, &nverts, &verts, &ndtris, &dtris,
- &npolys, &dmeshes, &polys, &dtrisToPolysMap, &dtrisToTrisMap,
- &trisToFacesMap);
- if (res)
- {
- size_t polyIdx;
-
- //invalidate concave polygon
- for (polyIdx=0; polyIdx<(size_t)npolys; polyIdx++)
- {
- unsigned short* poly = &polys[polyIdx*2*vertsPerPoly];
- if (!polyIsConvex(poly, vertsPerPoly, verts))
- {
- //set negative polygon idx to all faces
- unsigned short *dmesh = &dmeshes[4*polyIdx];
- unsigned short tbase = dmesh[2];
- unsigned short tnum = dmesh[3];
- unsigned short ti;
-
- for (ti=0; ti<tnum; ti++)
- {
- unsigned short triidx = dtrisToTrisMap[tbase+ti];
- unsigned short faceidx = trisToFacesMap[triidx];
- if (recastData[faceidx]>0)
- recastData[faceidx] = -recastData[faceidx];
- }
- }
- }
-
- }
- else
- {
- printf("Error during creation polygon infos\n");
- }
-
- //clean up
- if (verts!=NULL)
- MEM_freeN(verts);
- if (dtris!=NULL)
- MEM_freeN(dtris);
- if (dmeshes!=NULL)
- MEM_freeN(dmeshes);
- if (polys!=NULL)
- MEM_freeN(polys);
- if (dtrisToPolysMap!=NULL)
- MEM_freeN(dtrisToPolysMap);
- if (dtrisToTrisMap!=NULL)
- MEM_freeN(dtrisToTrisMap);
- if (trisToFacesMap!=NULL)
- MEM_freeN(trisToFacesMap);
-
- return result;
-#else // WITH_GAMEENGINE
- return dm;
-#endif // WITH_GAMEENGINE
-}
-
-/*
-static int isDisabled(ModifierData *md, int useRenderParams)
-{
- NavMeshModifierData *amd = (NavMeshModifierData*) md;
- return false;
-}*/
-
-
-
-static DerivedMesh *applyModifier(ModifierData *md, Object *ob, DerivedMesh *derivedData,
- int UNUSED(useRenderParams), int UNUSED(isFinalCalc))
-{
- DerivedMesh *result = NULL;
- NavMeshModifierData *nmmd = (NavMeshModifierData*) md;
- int hasRecastData = CustomData_has_layer(&derivedData->faceData, CD_RECAST)>0;
- if (ob->body_type!=OB_BODY_TYPE_NAVMESH || !hasRecastData )
- {
- //convert to nav mesh object:
- //1)set physics type
- ob->gameflag &= ~OB_COLLISION;
- ob->gameflag |= OB_NAVMESH;
- ob->body_type = OB_BODY_TYPE_NAVMESH;
- //2)add and init recast data layer
- if (!hasRecastData)
- {
- Mesh* obmesh = (Mesh *)ob->data;
- if (obmesh)
- {
- int i;
- int numFaces = obmesh->totface;
- int* recastData;
- CustomData_add_layer_named(&obmesh->fdata, CD_RECAST, CD_CALLOC, NULL, numFaces, "recastData");
- recastData = (int*)CustomData_get_layer(&obmesh->fdata, CD_RECAST);
- for (i=0; i<numFaces; i++)
- {
- recastData[i] = i+1;
- }
- CustomData_add_layer_named(&derivedData->faceData, CD_RECAST, CD_REFERENCE, recastData, numFaces, "recastData");
- }
- }
- }
-
- result = createNavMeshForVisualization(nmmd, derivedData);
-
- return result;
-}
-
-
-ModifierTypeInfo modifierType_NavMesh = {
- /* name */ "NavMesh",
- /* structName */ "NavMeshModifierData",
- /* structSize */ sizeof(NavMeshModifierData),
- /* type */ eModifierTypeType_Constructive,
- /* flags */ (ModifierTypeFlag) (eModifierTypeFlag_AcceptsMesh
- | eModifierTypeFlag_Single),
- /* copyData */ copyData,
- /* deformVerts */ 0,
- /* deformMatrices */ 0,
- /* deformVertsEM */ 0,
- /* deformMatricesEM */ 0,
- /* applyModifier */ applyModifier,
- /* applyModifierEM */ 0,
- /* initData */ initData,
- /* requiredDataMask */ 0,
- /* freeData */ 0,
- /* isDisabled */ 0,
- /* updateDepgraph */ 0,
- /* dependsOnTime */ 0,
- /* foreachObjectLink */ 0,
- /* foreachIDLink */ 0,
-};
diff --git a/source/blender/modifiers/intern/MOD_util.c b/source/blender/modifiers/intern/MOD_util.c
index 85ad559cb0a..13abaa7058f 100644
--- a/source/blender/modifiers/intern/MOD_util.c
+++ b/source/blender/modifiers/intern/MOD_util.c
@@ -295,7 +295,6 @@ void modifier_type_init(ModifierTypeInfo *types[])
INIT_TYPE(Solidify);
INIT_TYPE(Screw);
INIT_TYPE(Warp);
- INIT_TYPE(NavMesh);
INIT_TYPE(WeightVGEdit);
INIT_TYPE(WeightVGMix);
INIT_TYPE(WeightVGProximity);