realized some parts of the code might use screen/vert projection on instance objects which dont use the object matrix normally.

moved functions outside *_foreachScreen' funcs into their callers (mainly selection tools)
This commit is contained in:
Campbell Barton 2009-10-11 20:32:25 +00:00
parent 84172b31b5
commit 6b652ca543
6 changed files with 27 additions and 7 deletions

@ -2242,6 +2242,7 @@ static short findnearestNurbvert(ViewContext *vc, short sel, int mval[2], Nurb *
data.mval[0] = mval[0];
data.mval[1] = mval[1];
ED_view3d_init_mats_rv3d(vc->obedit, vc->rv3d);
nurbs_foreachScreenVert(vc, findnearestNurbvert__doClosest, &data);
*nurb = data.nurb;

@ -422,6 +422,9 @@ EditVert *findnearestvert(ViewContext *vc, int *dist, short sel, short strict)
data.closestIndex = 0;
data.pass = 0;
ED_view3d_init_mats_rv3d(vc->obedit, vc->rv3d);
mesh_foreachScreenVert(vc, findnearestvert__doClosest, &data, 1);
if (data.dist>3) {
@ -511,6 +514,7 @@ EditEdge *findnearestedge(ViewContext *vc, int *dist)
data.dist = *dist;
data.closest = NULL;
ED_view3d_init_mats_rv3d(vc->obedit, vc->rv3d);
mesh_foreachScreenEdge(vc, findnearestedge__doClosest, &data, 2);
*dist = data.dist;
@ -566,6 +570,7 @@ static EditFace *findnearestface(ViewContext *vc, int *dist)
data.dist = 0x7FFF; /* largest short */
data.toFace = efa;
ED_view3d_init_mats_rv3d(vc->obedit, vc->rv3d);
mesh_foreachScreenFace(vc, findnearestface__getDistance, &data);
if(vc->em->selectmode == SCE_SELECT_FACE || data.dist<*dist) { /* only faces, no dist check */
@ -594,6 +599,8 @@ static EditFace *findnearestface(ViewContext *vc, int *dist)
data.closestIndex = 0;
data.pass = 0;
ED_view3d_init_mats_rv3d(vc->obedit, vc->rv3d);
mesh_foreachScreenFace(vc, findnearestface__doClosest, &data);
if (data.dist>3) {

@ -543,7 +543,9 @@ void xsortvert_flag(bContext *C, int flag)
if(eve->f & flag)
sortblock[i].v1 = eve;
ED_view3d_init_mats_rv3d(vc.obedit, vc.rv3d);
mesh_foreachScreenVert(&vc, xsortvert_flag__doSetX, sortblock, 0);
qsort(sortblock, amount, sizeof(xvertsort), vergxco);
/* make temporal listbase */

@ -292,6 +292,7 @@ static BPoint *findnearestLattvert(ViewContext *vc, short mval[2], int sel)
data.mval[0]= mval[0];
data.mval[1]= mval[1];
ED_view3d_init_mats_rv3d(vc->obedit, vc->rv3d);
lattice_foreachScreenVert(vc, findnearestLattvert__doClosest, &data);
return data.bp;

@ -1207,8 +1207,6 @@ void lattice_foreachScreenVert(ViewContext *vc, void (*func)(void *userData, BPo
int i, N = lt->editlatt->pntsu*lt->editlatt->pntsv*lt->editlatt->pntsw;
short s[2] = {IS_CLIPPED, 0};
ED_view3d_init_mats_rv3d(vc->obedit, vc->rv3d); /* so view3d_project_short works */
for (i=0; i<N; i++, bp++, co+=3) {
if (bp->hide==0) {
view3d_project_short_clip(vc->ar, dl?co:bp->vec, s);
@ -1303,6 +1301,10 @@ static void drawlattice(Scene *scene, View3D *v3d, Object *ob)
/* ***************** ******************** */
/* Note! - foreach funcs should be called while drawing or directly after
* if not, ED_view3d_init_mats_rv3d() can be used for selection tools
* but would not give correct results with dupli's for eg. which dont
* use the object matrix in the useual way */
static void mesh_foreachScreenVert__mapFunc(void *userData, int index, float *co, float *no_f, short *no_s)
{
struct { void (*func)(void *userData, EditVert *eve, int x, int y, int index); void *userData; ViewContext vc; int clipVerts; } *data = userData;
@ -1332,7 +1334,6 @@ void mesh_foreachScreenVert(ViewContext *vc, void (*func)(void *userData, EditVe
data.userData = userData;
data.clipVerts = clipVerts;
ED_view3d_init_mats_rv3d(vc->obedit, vc->rv3d); /* so view3d_project_short works */
EM_init_index_arrays(vc->em, 1, 0, 0);
dm->foreachMappedVert(dm, mesh_foreachScreenVert__mapFunc, &data);
EM_free_index_arrays();
@ -1375,7 +1376,6 @@ void mesh_foreachScreenEdge(ViewContext *vc, void (*func)(void *userData, EditEd
data.userData = userData;
data.clipVerts = clipVerts;
ED_view3d_init_mats_rv3d(vc->obedit, vc->rv3d); /* so view3d_project_short works */
EM_init_index_arrays(vc->em, 0, 1, 0);
dm->foreachMappedEdge(dm, mesh_foreachScreenEdge__mapFunc, &data);
EM_free_index_arrays();
@ -1405,7 +1405,6 @@ void mesh_foreachScreenFace(ViewContext *vc, void (*func)(void *userData, EditFa
data.func = func;
data.userData = userData;
ED_view3d_init_mats_rv3d(vc->obedit, vc->rv3d); /* so view3d_project_short works */
EM_init_index_arrays(vc->em, 0, 0, 1);
dm->foreachMappedFaceCenter(dm, mesh_foreachScreenFace__mapFunc, &data);
EM_free_index_arrays();
@ -1420,8 +1419,6 @@ void nurbs_foreachScreenVert(ViewContext *vc, void (*func)(void *userData, Nurb
Nurb *nu;
int i;
ED_view3d_init_mats_rv3d(vc->obedit, vc->rv3d); /* so view3d_project_short works */
for (nu= cu->editnurb->first; nu; nu=nu->next) {
if(nu->type == CU_BEZIER) {
for (i=0; i<nu->pntsu; i++) {

@ -459,6 +459,9 @@ static void do_lasso_select_mesh(ViewContext *vc, short mcords[][2], short moves
data.pass = 0;
bbsel= EM_mask_init_backbuf_border(vc, mcords, moves, rect.xmin, rect.ymin, rect.xmax, rect.ymax);
ED_view3d_init_mats_rv3d(vc->obedit, vc->rv3d); /* for foreach's screen/vert projection */
ED_view3d_init_mats_rv3d(vc->obedit, vc->rv3d); /* for foreach's screen/vert projection */
if(ts->selectmode & SCE_SELECT_VERTEX) {
if (bbsel) {
@ -584,6 +587,7 @@ static void do_lasso_select_curve(ViewContext *vc, short mcords[][2], short move
data.moves = moves;
data.select = select;
ED_view3d_init_mats_rv3d(vc->obedit, vc->rv3d); /* for foreach's screen/vert projection */
nurbs_foreachScreenVert(vc, do_lasso_select_curve__doSelect, &data);
}
@ -604,6 +608,7 @@ static void do_lasso_select_lattice(ViewContext *vc, short mcords[][2], short mo
data.moves = moves;
data.select = select;
ED_view3d_init_mats_rv3d(vc->obedit, vc->rv3d); /* for foreach's screen/vert projection */
lattice_foreachScreenVert(vc, do_lasso_select_lattice__doSelect, &data);
}
@ -1256,6 +1261,7 @@ static void do_nurbs_box_select(ViewContext *vc, rcti *rect, int select)
data.rect = rect;
data.select = select;
ED_view3d_init_mats_rv3d(vc->obedit, vc->rv3d); /* for foreach's screen/vert projection */
nurbs_foreachScreenVert(vc, do_nurbs_box_select__doSelect, &data);
}
@ -1275,6 +1281,7 @@ static void do_lattice_box_select(ViewContext *vc, rcti *rect, int select)
data.rect = rect;
data.select = select;
ED_view3d_init_mats_rv3d(vc->obedit, vc->rv3d); /* for foreach's screen/vert projection */
lattice_foreachScreenVert(vc, do_lattice_box_select__doSelect, &data);
}
@ -1324,6 +1331,7 @@ static void do_mesh_box_select(ViewContext *vc, rcti *rect, int select)
data.done = 0;
bbsel= EM_init_backbuf_border(vc, rect->xmin, rect->ymin, rect->xmax, rect->ymax);
ED_view3d_init_mats_rv3d(vc->obedit, vc->rv3d); /* for foreach's screen/vert projection */
if(ts->selectmode & SCE_SELECT_VERTEX) {
if (bbsel) {
@ -1705,6 +1713,8 @@ static void mesh_circle_select(ViewContext *vc, int selecting, short *mval, floa
struct {ViewContext *vc; short select, mval[2]; float radius; } data;
bbsel= EM_init_backbuf_circle(vc, mval[0], mval[1], (short)(rad+1.0));
ED_view3d_init_mats_rv3d(vc->obedit, vc->rv3d); /* for foreach's screen/vert projection */
vc->em= ((Mesh *)vc->obedit->data)->edit_mesh;
data.select = selecting;
@ -1773,6 +1783,7 @@ static void nurbscurve_circle_select(ViewContext *vc, int selecting, short *mval
data.mval[1] = mval[1];
data.radius = rad;
ED_view3d_init_mats_rv3d(vc->obedit, vc->rv3d); /* for foreach's screen/vert projection */
nurbs_foreachScreenVert(vc, nurbscurve_circle_doSelect, &data);
}
@ -1798,6 +1809,7 @@ static void lattice_circle_select(ViewContext *vc, int selecting, short *mval, f
data.mval[1] = mval[1];
data.radius = rad;
ED_view3d_init_mats_rv3d(vc->obedit, vc->rv3d); /* for foreach's screen/vert projection */
lattice_foreachScreenVert(vc, latticecurve_circle_doSelect, &data);
}