use faster method of getting vert/edge/face indices which uses BLI_mempool_findelem to skip over chunks rather than going over every element
This commit is contained in:
@@ -334,6 +334,10 @@ void BM_ElemIndex_Ensure(BMesh *bm, const char hflag);
|
||||
|
||||
void BM_ElemIndex_Validate(BMesh *bm, const char *location, const char *func, const char *msg_a, const char *msg_b);
|
||||
|
||||
BMVert *BM_Vert_AtIndex(BMesh *bm, const int index);
|
||||
BMEdge *BM_Edge_AtIndex(BMesh *bm, const int index);
|
||||
BMFace *BM_Face_AtIndex(BMesh *bm, const int index);
|
||||
|
||||
/*start/stop edit*/
|
||||
void bmesh_begin_edit(struct BMesh *bm, int flag);
|
||||
void bmesh_end_edit(struct BMesh *bm, int flag);
|
||||
|
||||
@@ -3,7 +3,9 @@
|
||||
#include "bmesh.h"
|
||||
#include "bmesh_private.h"
|
||||
|
||||
|
||||
/*
|
||||
* note, we have BM_Vert_AtIndex/BM_Edge_AtIndex/BM_Face_AtIndex for arrays
|
||||
*/
|
||||
void *BMIter_AtIndex(struct BMesh *bm, const char htype, void *data, int index)
|
||||
{
|
||||
BMIter iter;
|
||||
|
||||
@@ -587,3 +587,18 @@ void BM_ElemIndex_Validate(BMesh *bm, const char *location, const char *func, co
|
||||
#endif
|
||||
#endif
|
||||
}
|
||||
|
||||
BMVert *BM_Vert_AtIndex(BMesh *bm, const int index)
|
||||
{
|
||||
return BLI_mempool_findelem(bm->vpool, index);
|
||||
}
|
||||
|
||||
BMEdge *BM_Edge_AtIndex(BMesh *bm, const int index)
|
||||
{
|
||||
return BLI_mempool_findelem(bm->epool, index);
|
||||
}
|
||||
|
||||
BMFace *BM_Face_AtIndex(BMesh *bm, const int index)
|
||||
{
|
||||
return BLI_mempool_findelem(bm->fpool, index);
|
||||
}
|
||||
|
||||
@@ -366,7 +366,7 @@ static void findnearestvert__doClosest(void *userData, BMVert *eve, int x, int y
|
||||
static unsigned int findnearestvert__backbufIndextest(void *handle, unsigned int index)
|
||||
{
|
||||
BMEditMesh *em= (BMEditMesh *)handle;
|
||||
BMVert *eve = BMIter_AtIndex(em->bm, BM_VERTS_OF_MESH, NULL, index-1);
|
||||
BMVert *eve = BM_Vert_AtIndex(em->bm, index-1);
|
||||
|
||||
if(eve && BM_TestHFlag(eve, BM_SELECT)) return 0;
|
||||
return 1;
|
||||
@@ -390,7 +390,7 @@ BMVert *EDBM_findnearestvert(ViewContext *vc, int *dist, short sel, short strict
|
||||
if(strict) index = view3d_sample_backbuf_rect(vc, vc->mval, 50, bm_wireoffs, 0xFFFFFF, &distance, strict, vc->em, findnearestvert__backbufIndextest);
|
||||
else index = view3d_sample_backbuf_rect(vc, vc->mval, 50, bm_wireoffs, 0xFFFFFF, &distance, 0, NULL, NULL);
|
||||
|
||||
eve = BMIter_AtIndex(vc->em->bm, BM_VERTS_OF_MESH, NULL, index-1);
|
||||
eve = BM_Vert_AtIndex(vc->em->bm, index-1);
|
||||
|
||||
if(eve && distance < *dist) {
|
||||
*dist = distance;
|
||||
@@ -405,7 +405,7 @@ BMVert *EDBM_findnearestvert(ViewContext *vc, int *dist, short sel, short strict
|
||||
static int lastSelectedIndex=0;
|
||||
static BMVert *lastSelected=NULL;
|
||||
|
||||
if (lastSelected && BMIter_AtIndex(vc->em->bm, BM_VERTS_OF_MESH, NULL, lastSelectedIndex)!=lastSelected) {
|
||||
if (lastSelected && BM_Vert_AtIndex(vc->em->bm, lastSelectedIndex) != lastSelected) {
|
||||
lastSelectedIndex = 0;
|
||||
lastSelected = NULL;
|
||||
}
|
||||
@@ -499,7 +499,7 @@ BMEdge *EDBM_findnearestedge(ViewContext *vc, int *dist)
|
||||
view3d_validate_backbuf(vc);
|
||||
|
||||
index = view3d_sample_backbuf_rect(vc, vc->mval, 50, bm_solidoffs, bm_wireoffs, &distance,0, NULL, NULL);
|
||||
eed = BMIter_AtIndex(vc->em->bm, BM_EDGES_OF_MESH, NULL, index-1);
|
||||
eed = BM_Edge_AtIndex(vc->em->bm, index-1);
|
||||
|
||||
if (eed && distance<*dist) {
|
||||
*dist = distance;
|
||||
@@ -569,7 +569,7 @@ BMFace *EDBM_findnearestface(ViewContext *vc, int *dist)
|
||||
view3d_validate_backbuf(vc);
|
||||
|
||||
index = view3d_sample_backbuf(vc, vc->mval[0], vc->mval[1]);
|
||||
efa = BMIter_AtIndex(vc->em->bm, BM_FACES_OF_MESH, NULL, index-1);
|
||||
efa = BM_Face_AtIndex(vc->em->bm, index-1);
|
||||
|
||||
if (efa) {
|
||||
struct { short mval[2]; int dist; BMFace *toFace; } data;
|
||||
@@ -594,7 +594,7 @@ BMFace *EDBM_findnearestface(ViewContext *vc, int *dist)
|
||||
static int lastSelectedIndex=0;
|
||||
static BMFace *lastSelected=NULL;
|
||||
|
||||
if (lastSelected && BMIter_AtIndex(vc->em->bm, BM_FACES_OF_MESH, NULL, lastSelectedIndex)!=lastSelected) {
|
||||
if (lastSelected && BM_Face_AtIndex(vc->em->bm, lastSelectedIndex) != lastSelected) {
|
||||
lastSelectedIndex = 0;
|
||||
lastSelected = NULL;
|
||||
}
|
||||
|
||||
@@ -556,7 +556,7 @@ static float get_vert_def_nr(Object *ob, int def_nr, int vertnum)
|
||||
me= ob->data;
|
||||
|
||||
if(me->edit_btmesh) {
|
||||
eve= BMIter_AtIndex(me->edit_btmesh->bm, BM_VERTS_OF_MESH, NULL, vertnum);
|
||||
eve= BM_Vert_AtIndex(me->edit_btmesh->bm, vertnum);
|
||||
if(!eve) {
|
||||
return 0.0f;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user