EditMesh: further cleanup, made derivedmesh itterator functions
work by gathering all related data in local ViewContext struct.
(scene, editmesh, region, view3d, obedit).
Also removed bad inclusion of view3d_intern.h in mesh module.
This commit is contained in:
Ton Roosendaal 2008-12-30 16:03:29 +00:00
parent 3fd28ca440
commit 1402534ebc
12 changed files with 322 additions and 269 deletions

@ -29,6 +29,8 @@
#define ED_MESH_H
struct View3D;
struct ARegion;
struct EditMesh;
// edge and face flag both
#define EM_FGON 2
@ -51,25 +53,36 @@ struct View3D;
#define B_JOINTRIA_MAT 0X1000
/* especially for derivedmesh drawing callbacks */
typedef struct ViewContext {
Scene *scene;
Object *obact;
Object *obedit;
struct ARegion *ar;
struct View3D *v3d;
struct EditMesh *em;
} ViewContext;
/* editmesh.c */
void EM_init_index_arrays(EditMesh *em, int forVert, int forEdge, int forFace);
void EM_init_index_arrays(struct EditMesh *em, int forVert, int forEdge, int forFace);
void EM_free_index_arrays(void);
EditVert *EM_get_vert_for_index(int index);
EditEdge *EM_get_edge_for_index(int index);
EditFace *EM_get_face_for_index(int index);
int EM_texFaceCheck(EditMesh *em);
int EM_vertColorCheck(EditMesh *em);
int EM_texFaceCheck(struct EditMesh *em);
int EM_vertColorCheck(struct EditMesh *em);
/* editmesh_lib.c */
EditFace *EM_get_actFace(EditMesh *em, int sloppy);
EditFace *EM_get_actFace(struct EditMesh *em, int sloppy);
void EM_select_edge(EditEdge *eed, int sel);
void EM_select_face_fgon(EditMesh *em, EditFace *efa, int val);
void EM_selectmode_flush(EditMesh *em);
void EM_deselect_flush(EditMesh *em);
void EM_select_face_fgon(struct EditMesh *em, EditFace *efa, int val);
void EM_selectmode_flush(struct EditMesh *em);
void EM_deselect_flush(struct EditMesh *em);

@ -31,7 +31,13 @@
/* ********* exports for space_view3d/ module ********** */
struct ARegion;
struct View3D;
struct ViewContext;
struct BPoint;
struct Nurb;
struct BezTriple;
struct EditVert;
struct EditEdge;
struct EditFace;
float *give_cursor(Scene *scene, View3D *v3d);
@ -52,5 +58,17 @@ void project_float_noclip(struct ARegion *ar, struct View3D *v3d, float *vec, fl
void viewline(struct ARegion *ar, struct View3D *v3d, short mval[2], float ray_start[3], float ray_end[3]);
void viewray(struct ARegion *ar, struct View3D *v3d, short mval[2], float ray_start[3], float ray_normal[3]);
/* drawobject.c itterators */
void mesh_foreachScreenVert(struct ViewContext *vc, void (*func)(void *userData, struct EditVert *eve, int x, int y, int index), void *userData, int clipVerts);
void mesh_foreachScreenEdge(struct ViewContext *vc, void (*func)(void *userData, struct EditEdge *eed, int x0, int y0, int x1, int y1, int index), void *userData, int clipVerts);
void mesh_foreachScreenFace(struct ViewContext *vc, void (*func)(void *userData, struct EditFace *efa, int x, int y, int index), void *userData);
void nurbs_foreachScreenVert(struct ViewContext *vc, void (*func)(void *userData, struct Nurb *nu, struct BPoint *bp, struct BezTriple *bezt, int beztindex, int x, int y), void *userData);
void lattice_foreachScreenVert(struct ViewContext *vc, void (*func)(void *userData, struct BPoint *bp, int x, int y), void *userData);
int view3d_test_clipping(struct View3D *v3d, float *vec);
void view3d_align_axis_to_vector(struct View3D *v3d, int axisidx, float vec[3]);
#endif /* ED_VIEW3D_H */

@ -54,11 +54,11 @@
#include "BLI_dynstr.h"
#include "BLI_rand.h"
#include "BKE_DerivedMesh.h"
#include "BKE_cloth.h"
#include "BKE_customdata.h"
#include "BKE_context.h"
#include "BKE_customdata.h"
#include "BKE_depsgraph.h"
#include "BKE_DerivedMesh.h"
#include "BKE_global.h"
#include "BKE_key.h"
#include "BKE_library.h"
@ -2188,3 +2188,15 @@ int EM_vertColorCheck(EditMesh *em)
return 0;
}
void em_setup_viewcontext(bContext *C, ViewContext *vc)
{
memset(vc, 0, sizeof(ViewContext));
vc->ar= CTX_wm_region(C);
vc->scene= CTX_data_scene(C);
vc->v3d= (View3D *)CTX_wm_space_data(C);
vc->obact= vc->scene->basact?vc->scene->basact->object:NULL;
vc->obedit= G.obedit; // XXX
vc->em= NULL; // XXX
}

@ -32,7 +32,7 @@
#ifndef EDITMESH_H
#define EDITMESH_H
struct View3D;
struct bContext;
#define TEST_EDITMESH if(G.obedit==0) return; /* layer test XXX */
@ -98,6 +98,8 @@ int editedge_containsVert(struct EditEdge *eed, struct EditVert *eve);
int editface_containsVert(struct EditFace *efa, struct EditVert *eve);
int editface_containsEdge(struct EditFace *efa, struct EditEdge *eed);
void em_setup_viewcontext(struct bContext *C, ViewContext *vc);
/* ******************* editmesh_add.c */
@ -167,7 +169,7 @@ extern struct EditFace *EM_face_from_faces(EditMesh *em, struct EditFace *efa1,
/* ******************* editmesh_mods.c */
extern EditEdge *findnearestedge(struct View3D *v3d, EditMesh *em, int *dist);
extern EditEdge *findnearestedge(ViewContext *vc, int *dist);
extern void EM_automerge(int update);
void editmesh_select_by_material(EditMesh *em, int index);
void righthandfaces(EditMesh *em, int select); /* makes faces righthand turning */
@ -182,7 +184,7 @@ void EM_select_more(EditMesh *em);
* if 0, unselected vertice are given the bias
* strict: if 1, the vertice corresponding to the sel parameter are ignored and not just biased
*/
extern EditVert *findnearestvert(struct View3D *v3d, EditMesh *em, int *dist, short sel, short strict);
extern EditVert *findnearestvert(ViewContext *vc, int *dist, short sel, short strict);
/* ******************* editmesh_tools.c */

@ -195,7 +195,7 @@ static void edgering_sel(EditMesh *em, EditEdge *startedge, int select, int prev
}
void CutEdgeloop(EditMesh *em, int numcuts)
{
View3D *v3d= NULL; // XXX
ViewContext vc; // XXX
EditEdge *nearest=NULL, *eed;
float fac;
int keys = 0, holdnum=0, selectmode, dist;
@ -219,7 +219,7 @@ void CutEdgeloop(EditMesh *em, int numcuts)
mvalo[0] = mval[0];
mvalo[1] = mval[1];
dist= 50;
nearest = findnearestedge(v3d, em, &dist); // returns actual distance in dist
nearest = findnearestedge(&vc, &dist); // returns actual distance in dist
// scrarea_do_windraw(curarea); // after findnearestedge, backbuf!
sprintf(msg,"Number of Cuts: %d",numcuts);

@ -57,6 +57,7 @@ editmesh_mods.c, UI level access, no geometry changes
#include "BLI_editVert.h"
#include "BLI_rand.h"
#include "BKE_context.h"
#include "BKE_displist.h"
#include "BKE_depsgraph.h"
#include "BKE_DerivedMesh.h"
@ -74,6 +75,7 @@ editmesh_mods.c, UI level access, no geometry changes
#include "ED_multires.h"
#include "ED_mesh.h"
#include "ED_view3d.h"
#include "BIF_gl.h"
#include "BIF_glutil.h"
@ -82,12 +84,6 @@ editmesh_mods.c, UI level access, no geometry changes
#include "BLO_sys_types.h" // for intptr_t support
/* XXX ONLY TO GET COMPILED! XXX
the backbuffer select code will move to view3d later */
#include "../space_view3d/view3d_intern.h"
/* XXX ********************** XXX */
static void *read_backbuf() {return NULL;}
static int sample_backbuf_rect() {return 0;}
static int sample_backbuf() {return 0;}
@ -383,13 +379,12 @@ static unsigned int findnearestvert__backbufIndextest(unsigned int index)
* if 0, unselected vertice are given the bias
* strict: if 1, the vertice corresponding to the sel parameter are ignored and not just biased
*/
EditVert *findnearestvert(View3D *v3d, EditMesh *em, int *dist, short sel, short strict)
EditVert *findnearestvert(ViewContext *vc, int *dist, short sel, short strict)
{
ARegion *ar= NULL; // XXX
short mval[2];
// XXX getmouseco_areawin(mval);
if(v3d->drawtype>OB_WIRE && (v3d->flag & V3D_ZBUF_SELECT)){
if(vc->v3d->drawtype>OB_WIRE && (vc->v3d->flag & V3D_ZBUF_SELECT)){
int distance;
unsigned int index;
EditVert *eve;
@ -397,7 +392,7 @@ EditVert *findnearestvert(View3D *v3d, EditMesh *em, int *dist, short sel, short
if(strict) index = sample_backbuf_rect(mval, 50, em_wireoffs, 0xFFFFFF, &distance, strict, findnearestvert__backbufIndextest);
else index = sample_backbuf_rect(mval, 50, em_wireoffs, 0xFFFFFF, &distance, 0, NULL);
eve = BLI_findlink(&em->verts, index-1);
eve = BLI_findlink(&vc->em->verts, index-1);
if(eve && distance < *dist) {
*dist = distance;
@ -412,7 +407,7 @@ EditVert *findnearestvert(View3D *v3d, EditMesh *em, int *dist, short sel, short
static int lastSelectedIndex=0;
static EditVert *lastSelected=NULL;
if (lastSelected && BLI_findlink(&em->verts, lastSelectedIndex)!=lastSelected) {
if (lastSelected && BLI_findlink(&vc->em->verts, lastSelectedIndex)!=lastSelected) {
lastSelectedIndex = 0;
lastSelected = NULL;
}
@ -427,11 +422,11 @@ EditVert *findnearestvert(View3D *v3d, EditMesh *em, int *dist, short sel, short
data.closestIndex = 0;
data.pass = 0;
mesh_foreachScreenVert(ar, v3d, findnearestvert__doClosest, &data, 1);
mesh_foreachScreenVert(vc, findnearestvert__doClosest, &data, 1);
if (data.dist>3) {
data.pass = 1;
mesh_foreachScreenVert(ar, v3d, findnearestvert__doClosest, &data, 1);
mesh_foreachScreenVert(vc, findnearestvert__doClosest, &data, 1);
}
*dist = data.dist;
@ -459,8 +454,7 @@ static float labda_PdistVL2Dfl( float *v1, float *v2, float *v3)
/* note; uses v3d, so needs active 3d window */
static void findnearestedge__doClosest(void *userData, EditEdge *eed, int x0, int y0, int x1, int y1, int index)
{
View3D *v3d; /* XXX */
struct { float mval[2]; int dist; EditEdge *closest; } *data = userData;
struct { ViewContext vc; float mval[2]; int dist; EditEdge *closest; } *data = userData;
float v1[2], v2[2];
int distance;
@ -473,7 +467,7 @@ static void findnearestedge__doClosest(void *userData, EditEdge *eed, int x0, in
if(eed->f & SELECT) distance+=5;
if(distance < data->dist) {
if(v3d->flag & V3D_CLIPPING) {
if(data->vc.v3d->flag & V3D_CLIPPING) {
float labda= labda_PdistVL2Dfl(data->mval, v1, v2);
float vec[3];
@ -482,7 +476,7 @@ static void findnearestedge__doClosest(void *userData, EditEdge *eed, int x0, in
vec[2]= eed->v1->co[2] + labda*(eed->v2->co[2] - eed->v1->co[2]);
Mat4MulVecfl(G.obedit->obmat, vec);
if(view3d_test_clipping(v3d, vec)==0) {
if(view3d_test_clipping(data->vc.v3d, vec)==0) {
data->dist = distance;
data->closest = eed;
}
@ -493,17 +487,16 @@ static void findnearestedge__doClosest(void *userData, EditEdge *eed, int x0, in
}
}
}
EditEdge *findnearestedge(View3D *v3d, EditMesh *em, int *dist)
EditEdge *findnearestedge(ViewContext *vc, int *dist)
{
ARegion *ar= NULL; // XXX
short mval[2];
// XXX getmouseco_areawin(mval);
if(v3d->drawtype>OB_WIRE && (v3d->flag & V3D_ZBUF_SELECT)) {
if(vc->v3d->drawtype>OB_WIRE && (vc->v3d->flag & V3D_ZBUF_SELECT)) {
int distance;
unsigned int index = sample_backbuf_rect(mval, 50, em_solidoffs, em_wireoffs, &distance,0, NULL);
EditEdge *eed = BLI_findlink(&em->edges, index-1);
EditEdge *eed = BLI_findlink(&vc->em->edges, index-1);
if (eed && distance<*dist) {
*dist = distance;
@ -513,14 +506,15 @@ EditEdge *findnearestedge(View3D *v3d, EditMesh *em, int *dist)
}
}
else {
struct { float mval[2]; int dist; EditEdge *closest; } data;
struct { ViewContext vc; float mval[2]; int dist; EditEdge *closest; } data;
data.vc= *vc;
data.mval[0] = mval[0];
data.mval[1] = mval[1];
data.dist = *dist;
data.closest = NULL;
mesh_foreachScreenEdge(ar, v3d, findnearestedge__doClosest, &data, 2);
mesh_foreachScreenEdge(vc, findnearestedge__doClosest, &data, 2);
*dist = data.dist;
return data.closest;
@ -560,16 +554,15 @@ static void findnearestface__doClosest(void *userData, EditFace *efa, int x, int
}
}
}
static EditFace *findnearestface(View3D *v3d, EditMesh *em, int *dist)
static EditFace *findnearestface(ViewContext *vc, int *dist)
{
ARegion *ar= NULL; // XXX
short mval[2];
// XXX getmouseco_areawin(mval);
if(v3d->drawtype>OB_WIRE && (v3d->flag & V3D_ZBUF_SELECT)) {
if(vc->v3d->drawtype>OB_WIRE && (vc->v3d->flag & V3D_ZBUF_SELECT)) {
unsigned int index = sample_backbuf(mval[0], mval[1]);
EditFace *efa = BLI_findlink(&em->faces, index-1);
EditFace *efa = BLI_findlink(&vc->em->faces, index-1);
if (efa) {
struct { short mval[2]; int dist; EditFace *toFace; } data;
@ -579,9 +572,9 @@ static EditFace *findnearestface(View3D *v3d, EditMesh *em, int *dist)
data.dist = 0x7FFF; /* largest short */
data.toFace = efa;
mesh_foreachScreenFace(ar, v3d, findnearestface__getDistance, &data);
mesh_foreachScreenFace(vc, findnearestface__getDistance, &data);
if(em->selectmode == SCE_SELECT_FACE || data.dist<*dist) { /* only faces, no dist check */
if(vc->em->selectmode == SCE_SELECT_FACE || data.dist<*dist) { /* only faces, no dist check */
*dist= data.dist;
return efa;
}
@ -594,7 +587,7 @@ static EditFace *findnearestface(View3D *v3d, EditMesh *em, int *dist)
static int lastSelectedIndex=0;
static EditFace *lastSelected=NULL;
if (lastSelected && BLI_findlink(&em->faces, lastSelectedIndex)!=lastSelected) {
if (lastSelected && BLI_findlink(&vc->em->faces, lastSelectedIndex)!=lastSelected) {
lastSelectedIndex = 0;
lastSelected = NULL;
}
@ -607,11 +600,11 @@ static EditFace *findnearestface(View3D *v3d, EditMesh *em, int *dist)
data.closestIndex = 0;
data.pass = 0;
mesh_foreachScreenFace(ar, v3d, findnearestface__doClosest, &data);
mesh_foreachScreenFace(vc, findnearestface__doClosest, &data);
if (data.dist>3) {
data.pass = 1;
mesh_foreachScreenFace(ar, v3d, findnearestface__doClosest, &data);
mesh_foreachScreenFace(vc, findnearestface__doClosest, &data);
}
*dist = data.dist;
@ -768,8 +761,9 @@ static void unified_select_draw(EditMesh *em, EditVert *eve, EditEdge *eed, Edit
selected vertices and edges get disadvantage
return 1 if found one
*/
static int unified_findnearest(View3D *v3d, EditMesh *em, EditVert **eve, EditEdge **eed, EditFace **efa)
static int unified_findnearest(ViewContext *vc, EditVert **eve, EditEdge **eed, EditFace **efa)
{
EditMesh *em= vc->em;
int dist= 75;
*eve= NULL;
@ -777,13 +771,13 @@ static int unified_findnearest(View3D *v3d, EditMesh *em, EditVert **eve, EditEd
*efa= NULL;
if(em->selectmode & SCE_SELECT_VERTEX)
*eve= findnearestvert(v3d, em, &dist, SELECT, 0);
*eve= findnearestvert(vc, &dist, SELECT, 0);
if(em->selectmode & SCE_SELECT_FACE)
*efa= findnearestface(v3d, em, &dist);
*efa= findnearestface(vc, &dist);
dist-= 20; /* since edges select lines, we give dots advantage of 20 pix */
if(em->selectmode & SCE_SELECT_EDGE)
*eed= findnearestedge(v3d, em, &dist);
*eed= findnearestedge(vc, &dist);
/* return only one of 3 pointers, for frontbuffer redraws */
if(*eed) {
@ -2081,14 +2075,15 @@ void loop_multiselect(EditMesh *em, int looptype)
/* just to have the functions nice together */
static void mouse_mesh_loop(Scene *scene, View3D *v3d, EditMesh *em)
static void mouse_mesh_loop(ViewContext *vc)
{
EditMesh *em= vc->em;
EditEdge *eed;
int select= 1;
int dist= 50;
int shift= 0, alt= 0, ctrl= 0; // XXX
eed= findnearestedge(v3d, em, &dist);
eed= findnearestedge(vc, &dist);
if(eed) {
if (0) { // XXX G.scene->toolsettings->edge_mode == EDGE_MODE_SELECT) {
if(shift==0) EM_clear_flag_all(em, SELECT);
@ -2118,7 +2113,7 @@ static void mouse_mesh_loop(Scene *scene, View3D *v3d, EditMesh *em)
EM_selectmode_flush(em);
// if (EM_texFaceCheck())
} else { /*(G.scene->toolsettings->edge_mode == EDGE_MODE_TAG_*)*/
int act = (edgetag_context_check(scene, eed)==0);
int act = (edgetag_context_check(vc->scene, eed)==0);
int path = 0;
if (alt && ctrl && em->selected.last) {
@ -2129,7 +2124,7 @@ static void mouse_mesh_loop(Scene *scene, View3D *v3d, EditMesh *em)
eed_act = (EditEdge*)ese->data;
if (eed_act != eed) {
/* If shift is pressed we need to use the last active edge, (if it exists) */
if (edgetag_shortest_path(scene, em, eed_act, eed)) {
if (edgetag_shortest_path(vc->scene, em, eed_act, eed)) {
EM_remove_selection(em, eed_act, EDITEDGE);
EM_select_edge(eed_act, 0);
path = 1;
@ -2138,7 +2133,7 @@ static void mouse_mesh_loop(Scene *scene, View3D *v3d, EditMesh *em)
}
}
if (path==0) {
edgetag_context_set(scene, eed, act); /* switch the edge option */
edgetag_context_set(vc->scene, eed, act); /* switch the edge option */
}
if (act) {
@ -2183,15 +2178,20 @@ static void mouse_mesh_loop(Scene *scene, View3D *v3d, EditMesh *em)
/* here actual select happens */
void mouse_mesh(Scene *scene, View3D *v3d, EditMesh *em)
void mouse_mesh(bContext *C)
{
ViewContext vc;
EditMesh *em= NULL; // XXX
EditVert *eve;
EditEdge *eed;
EditFace *efa;
int shift= 0, alt= 0; // XXX
if(alt) mouse_mesh_loop(scene, v3d, em);
else if(unified_findnearest(v3d, em, &eve, &eed, &efa)) {
/* setup view context for argument to callbacks */
em_setup_viewcontext(C, &vc);
if(alt) mouse_mesh_loop(&vc);
else if(unified_findnearest(&vc, &eve, &eed, &efa)) {
if((shift)==0) EM_clear_flag_all(em, SELECT);
@ -2290,17 +2290,21 @@ void selectconnected_mesh_all(EditMesh *em)
BIF_undo_push("Select Connected (All)");
}
void selectconnected_mesh(View3D *v3d, EditMesh *em)
void selectconnected_mesh(bContext *C)
{
ViewContext vc;
EditVert *eve, *v1, *v2;
EditEdge *eed;
EditFace *efa;
short done=1, sel, toggle=0;
int shift= 0; // XXX
if(em->edges.first==0) return;
/* setup view context for argument to callbacks */
em_setup_viewcontext(C, &vc);
if( unified_findnearest(v3d, em, &eve, &eed, &efa)==0 ) {
if(vc.em->edges.first==0) return;
if( unified_findnearest(&vc, &eve, &eed, &efa)==0 ) {
/* error("Nothing indicated "); */ /* this is mostly annoying, eps with occluded geometry */
return;
}
@ -2309,7 +2313,7 @@ void selectconnected_mesh(View3D *v3d, EditMesh *em)
if(shift) sel=0;
/* clear test flags */
for(v1= em->verts.first; v1; v1= v1->next) v1->f1= 0;
for(v1= vc.em->verts.first; v1; v1= v1->next) v1->f1= 0;
/* start vertex/face/edge */
if(eve) eve->f1= 1;
@ -2321,8 +2325,8 @@ void selectconnected_mesh(View3D *v3d, EditMesh *em)
done= 0;
toggle++;
if(toggle & 1) eed= em->edges.first;
else eed= em->edges.last;
if(toggle & 1) eed= vc.em->edges.first;
else eed= vc.em->edges.last;
while(eed) {
v1= eed->v1;
@ -2345,11 +2349,11 @@ void selectconnected_mesh(View3D *v3d, EditMesh *em)
}
/* now use vertex f1 flag to select/deselect */
for(eed= em->edges.first; eed; eed= eed->next) {
for(eed= vc.em->edges.first; eed; eed= eed->next) {
if(eed->v1->f1 && eed->v2->f1)
EM_select_edge(eed, sel);
}
for(efa= em->faces.first; efa; efa= efa->next) {
for(efa= vc.em->faces.first; efa; efa= efa->next) {
if(efa->v1->f1 && efa->v2->f1 && efa->v3->f1 && (efa->v4==NULL || efa->v4->f1))
EM_select_face(efa, sel);
}
@ -2372,13 +2376,14 @@ void selectconnected_mesh(View3D *v3d, EditMesh *em)
/* all - 1) use all faces for extending the selection 2) only use the mouse face
* sel - 1) select 0) deselect
* */
static void selectconnected_delimit_mesh__internal(EditMesh *em, short all, short sel)
static void selectconnected_delimit_mesh__internal(ViewContext *vc, short all, short sel)
{
View3D *v3d= NULL; // XXX
EditMesh *em= vc->em;
EditFace *efa;
EditEdge *eed;
short done=1, change=0;
int dist = 75;
EditEdge *eed;
if(em->faces.first==0) return;
/* flag all edges as off*/
@ -2394,7 +2399,7 @@ static void selectconnected_delimit_mesh__internal(EditMesh *em, short all, shor
}
}
} else {
EditFace *efa_mouse = findnearestface(v3d, em, &dist);
EditFace *efa_mouse = findnearestface(vc, &dist);
if( !efa_mouse ) {
/* error("Nothing indicated "); */ /* this is mostly annoying, eps with occluded geometry */
@ -2461,9 +2466,9 @@ void selectconnected_delimit_mesh(EditMesh *em)
// XXX selectconnected_delimit_mesh__internal(em, 0, ((G.qual & LR_SHIFTKEY)==0));
}
void selectconnected_delimit_mesh_all(EditMesh *em)
void selectconnected_delimit_mesh_all(ViewContext *vc)
{
selectconnected_delimit_mesh__internal(em, 1, 1);
selectconnected_delimit_mesh__internal(vc, 1, 1);
}

@ -61,8 +61,9 @@ editmesh_tool.c: UI called tools for editmesh, geometry changes here, otherwise
#include "BLI_linklist.h"
#include "BLI_heap.h"
#include "BKE_depsgraph.h"
#include "BKE_context.h"
#include "BKE_customdata.h"
#include "BKE_depsgraph.h"
#include "BKE_global.h"
#include "BKE_library.h"
#include "BKE_mesh.h"
@ -83,8 +84,6 @@ editmesh_tool.c: UI called tools for editmesh, geometry changes here, otherwise
#include "editmesh.h"
#include "../space_view3d/view3d_intern.h" // <--- mesh_foreachScreenVert XXX
/* XXX */
static void BIF_undo_push() {}
static int extern_qread() {return 0;}
@ -491,22 +490,26 @@ static void xsortvert_flag__doSetX(void *userData, EditVert *eve, int x, int y,
sortblock[index].x = x;
}
void xsortvert_flag(ARegion *ar, View3D *v3d, EditMesh *em, int flag)
/* all verts with (flag & 'flag') are sorted */
void xsortvert_flag(bContext *C, int flag)
{
/* all verts with (flag & 'flag') are sorted */
ViewContext vc;
EditVert *eve;
xvertsort *sortblock;
ListBase tbase;
int i, amount = BLI_countlist(&em->verts);
int i, amount;
if(multires_test()) return;
em_setup_viewcontext(C, &vc);
amount = BLI_countlist(&vc.em->verts);
sortblock = MEM_callocN(sizeof(xvertsort)*amount,"xsort");
for (i=0,eve=em->verts.first; eve; i++,eve=eve->next)
for (i=0,eve= vc.em->verts.first; eve; i++,eve=eve->next)
if(eve->f & flag)
sortblock[i].v1 = eve;
mesh_foreachScreenVert(ar, v3d, xsortvert_flag__doSetX, sortblock, 0);
mesh_foreachScreenVert(&vc, xsortvert_flag__doSetX, sortblock, 0);
qsort(sortblock, amount, sizeof(xvertsort), vergxco);
/* make temporal listbase */
@ -515,12 +518,12 @@ void xsortvert_flag(ARegion *ar, View3D *v3d, EditMesh *em, int flag)
eve = sortblock[i].v1;
if (eve) {
BLI_remlink(&em->verts, eve);
BLI_remlink(&vc.em->verts, eve);
BLI_addtail(&tbase, eve);
}
}
addlisttolist(&em->verts, &tbase);
addlisttolist(&vc.em->verts, &tbase);
MEM_freeN(sortblock);

@ -1029,9 +1029,7 @@ static EnumPropertyItem prop_clear_track_types[] = {
/* note, poll should check for editable scene */
static int object_clear_track_exec(bContext *C, wmOperator *op)
{
Object *ob= CTX_data_active_object(C);
if(G.obedit) return;
if(G.obedit) return OPERATOR_CANCELLED;
CTX_DATA_BEGIN(C, Object*, ob, selected_objects) {
/*if(TESTBASELIB(v3d, base)) {*/
@ -1891,12 +1889,10 @@ static int make_track_exec(bContext *C, wmOperator *op)
{
Scene *scene= CTX_data_scene(C);
ScrArea *sa= CTX_wm_area(C);
ARegion *ar= CTX_wm_region(C);
View3D *v3d= sa->spacedata.first;
Base *base;
if(scene->id.lib) return;
if(scene->id.lib) return OPERATOR_CANCELLED;
if(RNA_enum_is_equal(op->ptr, "type", "TRACKTO")){
bConstraint *con;

@ -1081,10 +1081,8 @@ static void lattice_draw_verts(Lattice *lt, DispList *dl, short sel)
bglEnd();
}
void lattice_foreachScreenVert(void (*func)(void *userData, BPoint *bp, int x, int y), void *userData)
void lattice_foreachScreenVert(ViewContext *vc, void (*func)(void *userData, BPoint *bp, int x, int y), void *userData)
{
ARegion *ar= NULL; // XXX
View3D *v3d= NULL; // XXX
BPoint *bp = editLatt->def;
DispList *dl = find_displist(&G.obedit->disp, DL_VERTS);
float *co = dl?dl->verts:NULL;
@ -1092,11 +1090,11 @@ void lattice_foreachScreenVert(void (*func)(void *userData, BPoint *bp, int x, i
int i, N = editLatt->pntsu*editLatt->pntsv*editLatt->pntsw;
short s[2];
view3d_get_object_project_mat(v3d, G.obedit, pmat, vmat);
view3d_get_object_project_mat(vc->v3d, vc->obedit, pmat, vmat);
for (i=0; i<N; i++, bp++, co+=3) {
if (bp->hide==0) {
view3d_project_short_clip(ar, v3d, dl?co:bp->vec, s, pmat, vmat);
view3d_project_short_clip(vc->ar, vc->v3d, dl?co:bp->vec, s, pmat, vmat);
func(userData, bp, s[0], s[1]);
}
}
@ -1191,36 +1189,34 @@ static void drawlattice(View3D *v3d, Object *ob)
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; ARegion *ar; View3D *v3d; int clipVerts; float pmat[4][4], vmat[4][4]; } *data = userData;
struct { void (*func)(void *userData, EditVert *eve, int x, int y, int index); void *userData; ViewContext vc; int clipVerts; float pmat[4][4], vmat[4][4]; } *data = userData;
EditVert *eve = EM_get_vert_for_index(index);
short s[2];
if (eve->h==0) {
if (data->clipVerts) {
view3d_project_short_clip(data->ar, data->v3d, co, s, data->pmat, data->vmat);
view3d_project_short_clip(data->vc.ar, data->vc.v3d, co, s, data->pmat, data->vmat);
} else {
view3d_project_short_noclip(data->ar, co, s, data->pmat);
view3d_project_short_noclip(data->vc.ar, co, s, data->pmat);
}
data->func(data->userData, eve, s[0], s[1], index);
}
}
void mesh_foreachScreenVert(ARegion *ar, View3D *v3d, void (*func)(void *userData, EditVert *eve, int x, int y, int index), void *userData, int clipVerts)
void mesh_foreachScreenVert(ViewContext *vc, void (*func)(void *userData, EditVert *eve, int x, int y, int index), void *userData, int clipVerts)
{
struct { void (*func)(void *userData, EditVert *eve, int x, int y, int index); void *userData; ARegion *ar; View3D *v3d; int clipVerts; float pmat[4][4], vmat[4][4]; } data;
struct { void (*func)(void *userData, EditVert *eve, int x, int y, int index); void *userData; ViewContext vc; int clipVerts; float pmat[4][4], vmat[4][4]; } data;
DerivedMesh *dm = editmesh_get_derived_cage(CD_MASK_BAREMESH);
EditMesh *em= NULL; // XXX
data.vc= *vc;
data.func = func;
data.userData = userData;
data.ar= ar;
data.v3d= v3d;
data.clipVerts = clipVerts;
view3d_get_object_project_mat(v3d, G.obedit, data.pmat, data.vmat);
view3d_get_object_project_mat(vc->v3d, vc->obedit, data.pmat, data.vmat);
EM_init_index_arrays(em, 1, 0, 0);
EM_init_index_arrays(vc->em, 1, 0, 0);
dm->foreachMappedVert(dm, mesh_foreachScreenVert__mapFunc, &data);
EM_free_index_arrays();
@ -1229,21 +1225,21 @@ void mesh_foreachScreenVert(ARegion *ar, View3D *v3d, void (*func)(void *userDat
static void mesh_foreachScreenEdge__mapFunc(void *userData, int index, float *v0co, float *v1co)
{
struct { void (*func)(void *userData, EditEdge *eed, int x0, int y0, int x1, int y1, int index); void *userData; ARegion *ar; View3D *v3d; int clipVerts; float pmat[4][4], vmat[4][4]; } *data = userData;
struct { void (*func)(void *userData, EditEdge *eed, int x0, int y0, int x1, int y1, int index); void *userData; ViewContext vc; int clipVerts; float pmat[4][4], vmat[4][4]; } *data = userData;
EditEdge *eed = EM_get_edge_for_index(index);
short s[2][2];
if (eed->h==0) {
if (data->clipVerts==1) {
view3d_project_short_clip(data->ar, data->v3d, v0co, s[0], data->pmat, data->vmat);
view3d_project_short_clip(data->ar, data->v3d, v1co, s[1], data->pmat, data->vmat);
view3d_project_short_clip(data->vc.ar, data->vc.v3d, v0co, s[0], data->pmat, data->vmat);
view3d_project_short_clip(data->vc.ar, data->vc.v3d, v1co, s[1], data->pmat, data->vmat);
} else {
view3d_project_short_noclip(data->ar, v0co, s[0], data->pmat);
view3d_project_short_noclip(data->ar, v1co, s[1], data->pmat);
view3d_project_short_noclip(data->vc.ar, v0co, s[0], data->pmat);
view3d_project_short_noclip(data->vc.ar, v1co, s[1], data->pmat);
if (data->clipVerts==2) {
if (!(s[0][0]>=0 && s[0][1]>= 0 && s[0][0]<data->ar->winx && s[0][1]<data->ar->winy))
if (!(s[1][0]>=0 && s[1][1]>= 0 && s[1][0]<data->ar->winx && s[1][1]<data->ar->winy))
if (!(s[0][0]>=0 && s[0][1]>= 0 && s[0][0]<data->vc.ar->winx && s[0][1]<data->vc.ar->winy))
if (!(s[1][0]>=0 && s[1][1]>= 0 && s[1][0]<data->vc.ar->winx && s[1][1]<data->vc.ar->winy))
return;
}
}
@ -1252,21 +1248,19 @@ static void mesh_foreachScreenEdge__mapFunc(void *userData, int index, float *v0
}
}
void mesh_foreachScreenEdge(ARegion *ar, View3D *v3d, void (*func)(void *userData, EditEdge *eed, int x0, int y0, int x1, int y1, int index), void *userData, int clipVerts)
void mesh_foreachScreenEdge(ViewContext *vc, void (*func)(void *userData, EditEdge *eed, int x0, int y0, int x1, int y1, int index), void *userData, int clipVerts)
{
struct { void (*func)(void *userData, EditEdge *eed, int x0, int y0, int x1, int y1, int index); void *userData; ARegion *ar; View3D *v3d; int clipVerts; float pmat[4][4], vmat[4][4]; } data;
struct { void (*func)(void *userData, EditEdge *eed, int x0, int y0, int x1, int y1, int index); void *userData; ViewContext vc; int clipVerts; float pmat[4][4], vmat[4][4]; } data;
DerivedMesh *dm = editmesh_get_derived_cage(CD_MASK_BAREMESH);
EditMesh *em= NULL; // XXX
data.vc= *vc;
data.func = func;
data.ar= ar;
data.v3d= v3d;
data.userData = userData;
data.clipVerts = clipVerts;
view3d_get_object_project_mat(v3d, G.obedit, data.pmat, data.vmat);
view3d_get_object_project_mat(vc->v3d, vc->obedit, data.pmat, data.vmat);
EM_init_index_arrays(em, 0, 1, 0);
EM_init_index_arrays(vc->em, 0, 1, 0);
dm->foreachMappedEdge(dm, mesh_foreachScreenEdge__mapFunc, &data);
EM_free_index_arrays();
@ -1275,45 +1269,43 @@ void mesh_foreachScreenEdge(ARegion *ar, View3D *v3d, void (*func)(void *userDat
static void mesh_foreachScreenFace__mapFunc(void *userData, int index, float *cent, float *no)
{
struct { void (*func)(void *userData, EditFace *efa, int x, int y, int index); void *userData; ARegion *ar; View3D *v3d; float pmat[4][4], vmat[4][4]; } *data = userData;
struct { void (*func)(void *userData, EditFace *efa, int x, int y, int index); void *userData; ViewContext vc; float pmat[4][4], vmat[4][4]; } *data = userData;
EditFace *efa = EM_get_face_for_index(index);
short s[2];
if (efa && efa->h==0 && efa->fgonf!=EM_FGON) {
view3d_project_short_clip(data->ar, data->v3d, cent, s, data->pmat, data->vmat);
view3d_project_short_clip(data->vc.ar, data->vc.v3d, cent, s, data->pmat, data->vmat);
data->func(data->userData, efa, s[0], s[1], index);
}
}
void mesh_foreachScreenFace(ARegion *ar, View3D *v3d, void (*func)(void *userData, EditFace *efa, int x, int y, int index), void *userData)
void mesh_foreachScreenFace(ViewContext *vc, void (*func)(void *userData, EditFace *efa, int x, int y, int index), void *userData)
{
struct { void (*func)(void *userData, EditFace *efa, int x, int y, int index); void *userData; ARegion *ar; View3D *v3d; float pmat[4][4], vmat[4][4]; } data;
struct { void (*func)(void *userData, EditFace *efa, int x, int y, int index); void *userData; ViewContext vc; float pmat[4][4], vmat[4][4]; } data;
DerivedMesh *dm = editmesh_get_derived_cage(CD_MASK_BAREMESH);
EditMesh *em= NULL; // XXX
data.vc= *vc;
data.func = func;
data.ar= ar;
data.v3d= v3d;
data.userData = userData;
view3d_get_object_project_mat(v3d, G.obedit, data.pmat, data.vmat);
view3d_get_object_project_mat(vc->v3d, vc->obedit, data.pmat, data.vmat);
EM_init_index_arrays(em, 0, 0, 1);
EM_init_index_arrays(vc->em, 0, 0, 1);
dm->foreachMappedFaceCenter(dm, mesh_foreachScreenFace__mapFunc, &data);
EM_free_index_arrays();
dm->release(dm);
}
void nurbs_foreachScreenVert(ARegion *ar, View3D *v3d, void (*func)(void *userData, Nurb *nu, BPoint *bp, BezTriple *bezt, int beztindex, int x, int y), void *userData)
void nurbs_foreachScreenVert(ViewContext *vc, void (*func)(void *userData, Nurb *nu, BPoint *bp, BezTriple *bezt, int beztindex, int x, int y), void *userData)
{
float pmat[4][4], vmat[4][4];
short s[2];
Nurb *nu;
int i;
view3d_get_object_project_mat(v3d, G.obedit, pmat, vmat);
view3d_get_object_project_mat(vc->v3d, vc->obedit, pmat, vmat);
for (nu= editNurb.first; nu; nu=nu->next) {
if((nu->type & 7)==CU_BEZIER) {
@ -1322,17 +1314,17 @@ void nurbs_foreachScreenVert(ARegion *ar, View3D *v3d, void (*func)(void *userDa
if(bezt->hide==0) {
if (G.f & G_HIDDENHANDLES) {
view3d_project_short_clip(ar, v3d, bezt->vec[1], s, pmat, vmat);
view3d_project_short_clip(vc->ar, vc->v3d, bezt->vec[1], s, pmat, vmat);
if (s[0] != IS_CLIPPED)
func(userData, nu, NULL, bezt, 1, s[0], s[1]);
} else {
view3d_project_short_clip(ar, v3d, bezt->vec[0], s, pmat, vmat);
view3d_project_short_clip(vc->ar, vc->v3d, bezt->vec[0], s, pmat, vmat);
if (s[0] != IS_CLIPPED)
func(userData, nu, NULL, bezt, 0, s[0], s[1]);
view3d_project_short_clip(ar, v3d, bezt->vec[1], s, pmat, vmat);
view3d_project_short_clip(vc->ar, vc->v3d, bezt->vec[1], s, pmat, vmat);
if (s[0] != IS_CLIPPED)
func(userData, nu, NULL, bezt, 1, s[0], s[1]);
view3d_project_short_clip(ar, v3d, bezt->vec[2], s, pmat, vmat);
view3d_project_short_clip(vc->ar, vc->v3d, bezt->vec[2], s, pmat, vmat);
if (s[0] != IS_CLIPPED)
func(userData, nu, NULL, bezt, 2, s[0], s[1]);
}
@ -1344,7 +1336,7 @@ void nurbs_foreachScreenVert(ARegion *ar, View3D *v3d, void (*func)(void *userDa
BPoint *bp = &nu->bp[i];
if(bp->hide==0) {
view3d_project_short_clip(ar, v3d, bp->vec, s, pmat, vmat);
view3d_project_short_clip(vc->ar, vc->v3d, bp->vec, s, pmat, vmat);
func(userData, nu, bp, NULL, -1, s[0], s[1]);
}
}
@ -1963,8 +1955,8 @@ static void draw_em_fancy(Scene *scene, View3D *v3d, Object *ob, EditMesh *em, D
EditEdge *eed_act = NULL;
EditVert *eve_act = NULL;
if (G.editMesh->selected.last) {
EditSelection *ese = G.editMesh->selected.last;
if (em->selected.last) {
EditSelection *ese = em->selected.last;
/* face is handeled above */
/*if (ese->type == EDITFACE ) {
efa_act = (EditFace *)ese->data;
@ -2361,6 +2353,7 @@ static void draw_mesh_fancy(Scene *scene, View3D *v3d, Base *base, int dt, int f
/* returns 1 if nothing was drawn, for detecting to draw an object center */
static int draw_mesh_object(Scene *scene, View3D *v3d, Base *base, int dt, int flag)
{
EditMesh *em= NULL; // XXX
Object *ob= base->object;
Mesh *me= ob->data;
int do_alpha_pass= 0, drawlinked= 0, retval= 0, glsl, check_alpha;
@ -2385,7 +2378,7 @@ static int draw_mesh_object(Scene *scene, View3D *v3d, Base *base, int dt, int f
GPU_set_object_materials(v3d, scene, ob, glsl, NULL);
}
draw_em_fancy(scene, v3d, ob, G.editMesh, cageDM, finalDM, dt);
draw_em_fancy(scene, v3d, ob, em, cageDM, finalDM, dt);
if (G.obedit!=ob && finalDM)
finalDM->release(finalDM);
@ -5370,7 +5363,7 @@ static void bbs_mesh_solid(Object *ob)
dm->release(dm);
}
void draw_object_backbufsel(Scene *scene, View3D *v3d, Object *ob)
void draw_object_backbufsel(Scene *scene, View3D *v3d, EditMesh *em, Object *ob)
{
wmMultMatrix(ob->obmat);
@ -5381,7 +5374,6 @@ void draw_object_backbufsel(Scene *scene, View3D *v3d, Object *ob)
switch( ob->type) {
case OB_MESH:
if(ob==G.obedit) {
EditMesh *em= NULL; // XXX
DerivedMesh *dm = editmesh_get_derived_cage(CD_MASK_BAREMESH);
EM_init_index_arrays(em, 1, 1, 1);

@ -36,14 +36,10 @@ struct BoundBox;
struct Object;
struct DerivedMesh;
struct wmOperatorType;
struct EditVert;
struct EditEdge;
struct EditFace;
struct Nurb;
struct BezTriple;
struct BPoint;
struct bContext;
struct wmWindowManager;
struct EditMesh;
struct ViewContext;
typedef struct ViewDepths {
unsigned short w, h;
@ -90,11 +86,6 @@ int draw_glsl_material(Scene *scene, Object *ob, View3D *v3d, int dt);
void drawcircball(int mode, float *cent, float rad, float tmat[][4]);
void draw_object_instance(Scene *scene, View3D *v3d, Object *ob, int dt, int outline);
void drawaxes(float size, int flag, char drawtype);
void mesh_foreachScreenVert(ARegion *ar, View3D *v3d, void (*func)(void *userData, struct EditVert *eve, int x, int y, int index), void *userData, int clipVerts);
void mesh_foreachScreenEdge(ARegion *ar, View3D *v3d, void (*func)(void *userData, struct EditEdge *eed, int x0, int y0, int x1, int y1, int index), void *userData, int clipVerts);
void mesh_foreachScreenFace(ARegion *ar, View3D *v3d, void (*func)(void *userData, struct EditFace *efa, int x, int y, int index), void *userData);
void nurbs_foreachScreenVert(ARegion *ar, View3D *v3d, void (*func)(void *userData, struct Nurb *nu, struct BPoint *bp, struct BezTriple *bezt, int beztindex, int x, int y), void *userData);
void lattice_foreachScreenVert(void (*func)(void *userData, struct BPoint *bp, int x, int y), void *userData);
/* drawarmature.c */
int draw_armature(Scene *scene, View3D *v3d, Base *base, int dt, int flag);
@ -105,7 +96,6 @@ void draw_mesh_textured(Scene *scene, View3D *v3d, Object *ob, struct DerivedMes
/* view3d_draw.c */
void drawview3dspace(Scene *scene, ARegion *ar, View3D *v3d);
void draw_depth(Scene *scene, ARegion *ar, View3D *v3d, int (* func)(void *));
int view3d_test_clipping(View3D *v3d, float *vec);
void view3d_clr_clipping(void);
void view3d_set_clipping(View3D *v3d);
void add_view3d_after(View3D *v3d, Base *base, int type, int flag);
@ -139,15 +129,13 @@ int get_view3d_viewplane(View3D *v3d, int winxi, int winyi, rctf *viewplane, flo
void view_settings_from_ob(Object *ob, float *ofs, float *quat, float *dist, float *lens);
void obmat_to_viewmat(View3D *v3d, Object *ob, short smooth);
short view3d_opengl_select(Scene *scene, ARegion *ar, View3D *v3d, unsigned int *buffer, unsigned int bufsize, rcti *input);
short view3d_opengl_select(struct ViewContext *vc, unsigned int *buffer, unsigned int bufsize, rcti *input);
void initlocalview(Scene *scene, ARegion *ar, View3D *v3d);
void restore_localviewdata(View3D *vd);
void endlocalview(Scene *scene, ScrArea *sa);
void centerview(ARegion *ar, View3D *v3d);
void view3d_align_axis_to_vector(View3D *v3d, int axisidx, float vec[3]);
void smooth_view(struct bContext *C, Object *, Object *, float *ofs, float *quat, float *dist, float *lens);
void setwinmatrixview3d(View3D *v3d, int winx, int winy, rctf *rect); /* rect: for picking */

@ -286,8 +286,9 @@ int lasso_inside_edge(short mcords[][2], short moves, int x0, int y0, int x1, in
/* warning; lasso select with backbuffer-check draws in backbuf with persp(PERSP_WIN)
and returns with persp(PERSP_VIEW). After lasso select backbuf is not OK
*/
static void do_lasso_select_pose(ARegion *ar, View3D *v3d, Object *ob, short mcords[][2], short moves, short select)
static void do_lasso_select_pose(ViewContext *vc, short mcords[][2], short moves, short select)
{
Object *ob= vc->obact;
bPoseChannel *pchan;
float vec[3];
short sco1[2], sco2[2];
@ -297,10 +298,10 @@ static void do_lasso_select_pose(ARegion *ar, View3D *v3d, Object *ob, short mco
for(pchan= ob->pose->chanbase.first; pchan; pchan= pchan->next) {
VECCOPY(vec, pchan->pose_head);
Mat4MulVecfl(ob->obmat, vec);
project_short(ar, v3d, vec, sco1);
project_short(vc->ar, vc->v3d, vec, sco1);
VECCOPY(vec, pchan->pose_tail);
Mat4MulVecfl(ob->obmat, vec);
project_short(ar, v3d, vec, sco2);
project_short(vc->ar, vc->v3d, vec, sco2);
if(lasso_inside_edge(mcords, moves, sco1[0], sco1[1], sco2[0], sco2[1])) {
if(select) pchan->bone->flag |= BONE_SELECTED;
@ -310,13 +311,13 @@ static void do_lasso_select_pose(ARegion *ar, View3D *v3d, Object *ob, short mco
}
static void do_lasso_select_objects(Scene *scene, ARegion *ar, View3D *v3d, short mcords[][2], short moves, short select)
static void do_lasso_select_objects(ViewContext *vc, short mcords[][2], short moves, short select)
{
Base *base;
for(base= scene->base.first; base; base= base->next) {
if(base->lay & v3d->lay) {
project_short(ar, v3d, base->object->obmat[3], &base->sx);
for(base= vc->scene->base.first; base; base= base->next) {
if(base->lay & vc->v3d->lay) {
project_short(vc->ar, vc->v3d, base->object->obmat[3], &base->sx);
if(lasso_inside(mcords, moves, base->sx, base->sy)) {
if(select) ED_base_object_select(base, BA_SELECT);
@ -324,7 +325,7 @@ static void do_lasso_select_objects(Scene *scene, ARegion *ar, View3D *v3d, shor
base->object->flag= base->flag;
}
if(base->object->flag & OB_POSEMODE) {
do_lasso_select_pose(ar, v3d, base->object, mcords, moves, select);
do_lasso_select_pose(vc, mcords, moves, select);
}
}
}
@ -347,7 +348,7 @@ void lasso_select_boundbox(rcti *rect, short mcords[][2], short moves)
static void do_lasso_select_mesh__doSelectVert(void *userData, EditVert *eve, int x, int y, int index)
{
struct { rcti *rect; short (*mcords)[2], moves, select, pass, done; } *data = userData;
struct { ViewContext vc; rcti *rect; short (*mcords)[2], moves, select, pass, done; } *data = userData;
if (BLI_in_rcti(data->rect, x, y) && lasso_inside(data->mcords, data->moves, x, y)) {
eve->f = data->select?(eve->f|1):(eve->f&~1);
@ -355,7 +356,7 @@ static void do_lasso_select_mesh__doSelectVert(void *userData, EditVert *eve, in
}
static void do_lasso_select_mesh__doSelectEdge(void *userData, EditEdge *eed, int x0, int y0, int x1, int y1, int index)
{
struct { rcti *rect; short (*mcords)[2], moves, select, pass, done; } *data = userData;
struct { ViewContext vc; rcti *rect; short (*mcords)[2], moves, select, pass, done; } *data = userData;
if (EM_check_backbuf(em_solidoffs+index)) {
if (data->pass==0) {
@ -374,23 +375,22 @@ static void do_lasso_select_mesh__doSelectEdge(void *userData, EditEdge *eed, in
}
static void do_lasso_select_mesh__doSelectFace(void *userData, EditFace *efa, int x, int y, int index)
{
struct { rcti *rect; short (*mcords)[2], moves, select, pass, done; } *data = userData;
EditMesh *em= NULL; // XXX
struct { ViewContext vc; rcti *rect; short (*mcords)[2], moves, select, pass, done; } *data = userData;
if (BLI_in_rcti(data->rect, x, y) && lasso_inside(data->mcords, data->moves, x, y)) {
EM_select_face_fgon(em, efa, data->select);
EM_select_face_fgon(data->vc.em, efa, data->select);
}
}
static void do_lasso_select_mesh(Scene *scene, ARegion *ar, View3D *v3d, short mcords[][2], short moves, short select)
static void do_lasso_select_mesh(ViewContext *vc, short mcords[][2], short moves, short select)
{
struct { rcti *rect; short (*mcords)[2], moves, select, pass, done; } data;
EditMesh *em = G.editMesh; // XXX
struct { ViewContext vc; rcti *rect; short (*mcords)[2], moves, select, pass, done; } data;
rcti rect;
int bbsel;
lasso_select_boundbox(&rect, mcords, moves);
data.vc= *vc;
data.rect = &rect;
data.mcords = mcords;
data.moves = moves;
@ -398,44 +398,43 @@ static void do_lasso_select_mesh(Scene *scene, ARegion *ar, View3D *v3d, short m
data.done = 0;
data.pass = 0;
bbsel= EM_mask_init_backbuf_border(v3d, mcords, moves, rect.xmin, rect.ymin, rect.xmax, rect.ymax);
bbsel= EM_mask_init_backbuf_border(vc->v3d, mcords, moves, rect.xmin, rect.ymin, rect.xmax, rect.ymax);
if(scene->selectmode & SCE_SELECT_VERTEX) {
if(vc->scene->selectmode & SCE_SELECT_VERTEX) {
if (bbsel) {
EM_backbuf_checkAndSelectVerts(em, select);
EM_backbuf_checkAndSelectVerts(vc->em, select);
} else {
mesh_foreachScreenVert(ar, v3d, do_lasso_select_mesh__doSelectVert, &data, 1);
mesh_foreachScreenVert(vc, do_lasso_select_mesh__doSelectVert, &data, 1);
}
}
if(scene->selectmode & SCE_SELECT_EDGE) {
if(vc->scene->selectmode & SCE_SELECT_EDGE) {
/* Does both bbsel and non-bbsel versions (need screen cos for both) */
data.pass = 0;
mesh_foreachScreenEdge(ar, v3d, do_lasso_select_mesh__doSelectEdge, &data, 0);
mesh_foreachScreenEdge(vc, do_lasso_select_mesh__doSelectEdge, &data, 0);
if (data.done==0) {
data.pass = 1;
mesh_foreachScreenEdge(ar, v3d, do_lasso_select_mesh__doSelectEdge, &data, 0);
mesh_foreachScreenEdge(vc, do_lasso_select_mesh__doSelectEdge, &data, 0);
}
}
if(scene->selectmode & SCE_SELECT_FACE) {
if(vc->scene->selectmode & SCE_SELECT_FACE) {
if (bbsel) {
EM_backbuf_checkAndSelectFaces(em, select);
EM_backbuf_checkAndSelectFaces(vc->em, select);
} else {
mesh_foreachScreenFace(ar, v3d, do_lasso_select_mesh__doSelectFace, &data);
mesh_foreachScreenFace(vc, do_lasso_select_mesh__doSelectFace, &data);
}
}
EM_free_backbuf();
EM_selectmode_flush(em);
EM_selectmode_flush(vc->em);
}
#if 0
/* this is an exception in that its the only lasso that dosnt use the 3d view (uses space image view) */
static void do_lasso_select_mesh_uv(short mcords[][2], short moves, short select)
{
EditMesh *em = G.editMesh;
EditFace *efa;
MTFace *tf;
int screenUV[2], nverts, i, ok = 1;
@ -483,8 +482,8 @@ static void do_lasso_select_mesh_uv(short mcords[][2], short moves, short select
}
}
if (ok && G.sima->flag & SI_SYNC_UVSEL) {
if (select) EM_select_flush();
else EM_deselect_flush(em);
if (select) EM_select_flush(vc->em);
else EM_deselect_flush(vc->em);
}
}
#endif
@ -513,7 +512,7 @@ static void do_lasso_select_curve__doSelect(void *userData, Nurb *nu, BPoint *bp
}
}
static void do_lasso_select_curve(ARegion *ar, View3D *v3d, short mcords[][2], short moves, short select)
static void do_lasso_select_curve(ViewContext *vc, short mcords[][2], short moves, short select)
{
struct { short (*mcords)[2]; short moves; short select; } data;
@ -521,7 +520,7 @@ static void do_lasso_select_curve(ARegion *ar, View3D *v3d, short mcords[][2], s
data.moves = moves;
data.select = select;
nurbs_foreachScreenVert(ar, v3d, do_lasso_select_curve__doSelect, &data);
nurbs_foreachScreenVert(vc, do_lasso_select_curve__doSelect, &data);
}
static void do_lasso_select_lattice__doSelect(void *userData, BPoint *bp, int x, int y)
@ -532,7 +531,7 @@ static void do_lasso_select_lattice__doSelect(void *userData, BPoint *bp, int x,
bp->f1 = data->select?(bp->f1|SELECT):(bp->f1&~SELECT);
}
}
static void do_lasso_select_lattice(short mcords[][2], short moves, short select)
static void do_lasso_select_lattice(ViewContext *vc, short mcords[][2], short moves, short select)
{
struct { short (*mcords)[2]; short moves; short select; } data;
@ -540,10 +539,10 @@ static void do_lasso_select_lattice(short mcords[][2], short moves, short select
data.moves = moves;
data.select = select;
lattice_foreachScreenVert(do_lasso_select_lattice__doSelect, &data);
lattice_foreachScreenVert(vc, do_lasso_select_lattice__doSelect, &data);
}
static void do_lasso_select_armature(ARegion *ar, View3D *v3d, short mcords[][2], short moves, short select)
static void do_lasso_select_armature(ViewContext *vc, short mcords[][2], short moves, short select)
{
EditBone *ebone;
float vec[3];
@ -553,10 +552,10 @@ static void do_lasso_select_armature(ARegion *ar, View3D *v3d, short mcords[][2]
VECCOPY(vec, ebone->head);
Mat4MulVecfl(G.obedit->obmat, vec);
project_short(ar, v3d, vec, sco1);
project_short(vc->ar, vc->v3d, vec, sco1);
VECCOPY(vec, ebone->tail);
Mat4MulVecfl(G.obedit->obmat, vec);
project_short(ar, v3d, vec, sco2);
project_short(vc->ar, vc->v3d, vec, sco2);
didpoint= 0;
if(lasso_inside(mcords, moves, sco1[0], sco1[1])) {
@ -578,9 +577,9 @@ static void do_lasso_select_armature(ARegion *ar, View3D *v3d, short mcords[][2]
// XXX countall(); /* abused for flushing selection!!!! */
}
static void do_lasso_select_facemode(Scene *scene, View3D *v3d, short mcords[][2], short moves, short select)
static void do_lasso_select_facemode(ViewContext *vc, short mcords[][2], short moves, short select)
{
Object *ob= OBACT;
Object *ob= vc->obact;
Mesh *me= ob?ob->data:NULL;
rcti rect;
@ -590,7 +589,7 @@ static void do_lasso_select_facemode(Scene *scene, View3D *v3d, short mcords[][2
em_vertoffs= me->totface+1; /* max index array */
lasso_select_boundbox(&rect, mcords, moves);
EM_mask_init_backbuf_border(v3d, mcords, moves, rect.xmin, rect.ymin, rect.xmax, rect.ymax);
EM_mask_init_backbuf_border(vc->v3d, mcords, moves, rect.xmin, rect.ymin, rect.xmax, rect.ymax);
EM_backbuf_checkAndSelectTFaces(me, select);
@ -630,26 +629,26 @@ static void do_lasso_select_node(short mcords[][2], short moves, short select)
}
#endif
void view3d_lasso_select(Scene *scene, ARegion *ar, View3D *v3d, short mcords[][2], short moves, short select)
void view3d_lasso_select(ViewContext *vc, short mcords[][2], short moves, short select)
{
if(G.obedit==NULL) {
if(FACESEL_PAINT_TEST)
do_lasso_select_facemode(scene, v3d, mcords, moves, select);
do_lasso_select_facemode(vc, mcords, moves, select);
else if(G.f & (G_VERTEXPAINT|G_TEXTUREPAINT|G_WEIGHTPAINT))
;
// XX else if(G.f & G_PARTICLEEDIT)
// PE_do_lasso_select(mcords, moves, select);
else
do_lasso_select_objects(scene, ar, v3d, mcords, moves, select);
do_lasso_select_objects(vc, mcords, moves, select);
}
else if(G.obedit->type==OB_MESH) {
do_lasso_select_mesh(scene, ar, v3d, mcords, moves, select);
do_lasso_select_mesh(vc, mcords, moves, select);
} else if(G.obedit->type==OB_CURVE || G.obedit->type==OB_SURF)
do_lasso_select_curve(ar, v3d, mcords, moves, select);
do_lasso_select_curve(vc, mcords, moves, select);
else if(G.obedit->type==OB_LATTICE)
do_lasso_select_lattice(mcords, moves, select);
do_lasso_select_lattice(vc, mcords, moves, select);
else if(G.obedit->type==OB_ARMATURE)
do_lasso_select_armature(ar, v3d, mcords, moves, select);
do_lasso_select_armature(vc, mcords, moves, select);
BIF_undo_push("Lasso select");
@ -725,8 +724,10 @@ static void deselectall_except(Scene *scene, Base *b) /* deselect all except b
}
}
static Base *mouse_select_menu(Scene *scene, ARegion *ar, View3D *v3d, unsigned int *buffer, int hits, short *mval)
static Base *mouse_select_menu(ViewContext *vc, unsigned int *buffer, int hits, short *mval)
{
Scene *scene= vc->scene;
View3D *v3d= vc->v3d;
Base *baseList[SEL_MENU_SIZE]={NULL}; /*baseList is used to store all possible bases to bring up a menu */
Base *base;
short baseCount = 0;
@ -748,7 +749,7 @@ static Base *mouse_select_menu(Scene *scene, ARegion *ar, View3D *v3d, unsigned
else {
int temp, dist=15;
project_short(ar, v3d, base->object->obmat[3], &base->sx);
project_short(vc->ar, vc->v3d, base->object->obmat[3], &base->sx);
temp= abs(base->sx -mval[0]) + abs(base->sy -mval[1]);
if(temp<dist ) baseList[baseCount] = base;
@ -778,7 +779,7 @@ static Base *mouse_select_menu(Scene *scene, ARegion *ar, View3D *v3d, unsigned
/* we want a select buffer with bones, if there are... */
/* so check three selection levels and compare */
static short mixed_bones_object_selectbuffer(Scene *scene, ARegion *ar, View3D *v3d, unsigned int *buffer, short *mval)
static short mixed_bones_object_selectbuffer(ViewContext *vc, unsigned int *buffer, short *mval)
{
rcti rect;
int offs;
@ -786,19 +787,19 @@ static short mixed_bones_object_selectbuffer(Scene *scene, ARegion *ar, View3D *
short has_bones15=0, has_bones9=0, has_bones5=0;
BLI_init_rcti(&rect, mval[0]-14, mval[0]+14, mval[1]-14, mval[1]+14);
hits15= view3d_opengl_select(scene, ar, v3d, buffer, MAXPICKBUF, &rect);
hits15= view3d_opengl_select(vc, buffer, MAXPICKBUF, &rect);
if(hits15>0) {
for(a=0; a<hits15; a++) if(buffer[4*a+3] & 0xFFFF0000) has_bones15= 1;
offs= 4*hits15;
BLI_init_rcti(&rect, mval[0]-9, mval[0]+9, mval[1]-9, mval[1]+9);
hits9= view3d_opengl_select(scene, ar, v3d, buffer+offs, MAXPICKBUF-offs, &rect);
hits9= view3d_opengl_select(vc, buffer+offs, MAXPICKBUF-offs, &rect);
if(hits9>0) {
for(a=0; a<hits9; a++) if(buffer[offs+4*a+3] & 0xFFFF0000) has_bones9= 1;
offs+= 4*hits9;
BLI_init_rcti(&rect, mval[0]-5, mval[0]+5, mval[1]-5, mval[1]+5);
hits5= view3d_opengl_select(scene, ar, v3d, buffer+offs, MAXPICKBUF-offs, &rect);
hits5= view3d_opengl_select(vc, buffer+offs, MAXPICKBUF-offs, &rect);
if(hits5>0) {
for(a=0; a<hits5; a++) if(buffer[offs+4*a+3] & 0xFFFF0000) has_bones5= 1;
}
@ -837,6 +838,7 @@ static short mixed_bones_object_selectbuffer(Scene *scene, ARegion *ar, View3D *
/* mval is region coords */
static void mouse_select(bContext *C, short *mval, short modifier)
{
ViewContext vc;
ARegion *ar= CTX_wm_region(C);
View3D *v3d= (View3D *)CTX_wm_space_data(C);
Scene *scene= CTX_data_scene(C);
@ -845,6 +847,13 @@ static void mouse_select(bContext *C, short *mval, short modifier)
int temp, a, dist=100;
short hits;
/* setup view context for argument to callbacks */
memset(&vc, 0, sizeof(ViewContext));
vc.ar= ar;
vc.scene= scene;
vc.v3d= v3d;
vc.obact= OBACT;
/* always start list from basact in wire mode */
startbase= FIRSTBASE;
if(BASACT && BASACT->next) startbase= BASACT->next;
@ -854,7 +863,7 @@ static void mouse_select(bContext *C, short *mval, short modifier)
/* note; shift+alt goes to group-flush-selecting */
if(modifier == KM_ALT && modifier == KM_CTRL)
basact= mouse_select_menu(scene, ar, v3d, NULL, 0, mval);
basact= mouse_select_menu(&vc, NULL, 0, mval);
else {
base= startbase;
while(base) {
@ -879,7 +888,7 @@ static void mouse_select(bContext *C, short *mval, short modifier)
else {
/* if objects have posemode set, the bones are in the same selection buffer */
hits= mixed_bones_object_selectbuffer(scene, ar, v3d, buffer, mval);
hits= mixed_bones_object_selectbuffer(&vc, buffer, mval);
if(hits>0) {
int has_bones= 0;
@ -888,7 +897,7 @@ static void mouse_select(bContext *C, short *mval, short modifier)
/* note; shift+alt goes to group-flush-selecting */
if(has_bones==0 && (modifier == KM_ALT))
basact= mouse_select_menu(scene, ar, v3d, buffer, hits, mval);
basact= mouse_select_menu(&vc, buffer, hits, mval);
else {
static short lastmval[2]={-100, -100};
int donearest= 0;
@ -1067,7 +1076,7 @@ int edge_inside_circle(short centx, short centy, short rad, short x1, short y1,
static void do_nurbs_box_select__doSelect(void *userData, Nurb *nu, BPoint *bp, BezTriple *bezt, int beztindex, int x, int y)
{
struct { rcti *rect; int select; } *data = userData;
struct { ViewContext vc; rcti *rect; int select; } *data = userData;
if (BLI_in_rcti(data->rect, x, y)) {
if (bp) {
@ -1088,37 +1097,39 @@ static void do_nurbs_box_select__doSelect(void *userData, Nurb *nu, BPoint *bp,
}
}
}
static void do_nurbs_box_select(ARegion *ar, View3D *v3d, rcti *rect, int select)
static void do_nurbs_box_select(ViewContext *vc, rcti *rect, int select)
{
struct { rcti *rect; int select; } data;
struct { ViewContext vc; rcti *rect; int select; } data;
data.vc= *vc;
data.rect = rect;
data.select = select;
nurbs_foreachScreenVert(ar, v3d, do_nurbs_box_select__doSelect, &data);
nurbs_foreachScreenVert(vc, do_nurbs_box_select__doSelect, &data);
}
static void do_lattice_box_select__doSelect(void *userData, BPoint *bp, int x, int y)
{
struct { rcti *rect; int select; } *data = userData;
struct { ViewContext vc; rcti *rect; int select; } *data = userData;
if (BLI_in_rcti(data->rect, x, y)) {
bp->f1 = data->select?(bp->f1|SELECT):(bp->f1&~SELECT);
}
}
static void do_lattice_box_select(rcti *rect, int select)
static void do_lattice_box_select(ViewContext *vc, rcti *rect, int select)
{
struct { rcti *rect; int select, pass, done; } data;
struct { ViewContext vc; rcti *rect; int select, pass, done; } data;
data.vc= *vc;
data.rect = rect;
data.select = select;
lattice_foreachScreenVert(do_lattice_box_select__doSelect, &data);
lattice_foreachScreenVert(vc, do_lattice_box_select__doSelect, &data);
}
static void do_mesh_box_select__doSelectVert(void *userData, EditVert *eve, int x, int y, int index)
{
struct { rcti *rect; short select, pass, done; } *data = userData;
struct { ViewContext vc; rcti *rect; short select, pass, done; } *data = userData;
if (BLI_in_rcti(data->rect, x, y)) {
eve->f = data->select?(eve->f|1):(eve->f&~1);
@ -1126,7 +1137,7 @@ static void do_mesh_box_select__doSelectVert(void *userData, EditVert *eve, int
}
static void do_mesh_box_select__doSelectEdge(void *userData, EditEdge *eed, int x0, int y0, int x1, int y1, int index)
{
struct { rcti *rect; short select, pass, done; } *data = userData;
struct { ViewContext vc; rcti *rect; short select, pass, done; } *data = userData;
if(EM_check_backbuf(em_solidoffs+index)) {
if (data->pass==0) {
@ -1143,60 +1154,60 @@ static void do_mesh_box_select__doSelectEdge(void *userData, EditEdge *eed, int
}
static void do_mesh_box_select__doSelectFace(void *userData, EditFace *efa, int x, int y, int index)
{
struct { rcti *rect; short select, pass, done; } *data = userData;
EditMesh *em= NULL; // XXX
struct { ViewContext vc; rcti *rect; short select, pass, done; } *data = userData;
if (BLI_in_rcti(data->rect, x, y)) {
EM_select_face_fgon(em, efa, data->select);
EM_select_face_fgon(data->vc.em, efa, data->select);
}
}
static void do_mesh_box_select(Scene *scene, ARegion *ar, View3D *v3d, rcti *rect, int select)
static void do_mesh_box_select(ViewContext *vc, rcti *rect, int select)
{
struct { rcti *rect; short select, pass, done; } data;
EditMesh *em = G.editMesh;
struct { ViewContext vc; rcti *rect; short select, pass, done; } data;
int bbsel;
data.vc= *vc;
data.rect = rect;
data.select = select;
data.pass = 0;
data.done = 0;
bbsel= EM_init_backbuf_border(v3d, rect->xmin, rect->ymin, rect->xmax, rect->ymax);
bbsel= EM_init_backbuf_border(vc->v3d, rect->xmin, rect->ymin, rect->xmax, rect->ymax);
if(scene->selectmode & SCE_SELECT_VERTEX) {
if(vc->scene->selectmode & SCE_SELECT_VERTEX) {
if (bbsel) {
EM_backbuf_checkAndSelectVerts(em, select);
EM_backbuf_checkAndSelectVerts(vc->em, select);
} else {
mesh_foreachScreenVert(ar, v3d, do_mesh_box_select__doSelectVert, &data, 1);
mesh_foreachScreenVert(vc, do_mesh_box_select__doSelectVert, &data, 1);
}
}
if(scene->selectmode & SCE_SELECT_EDGE) {
if(vc->scene->selectmode & SCE_SELECT_EDGE) {
/* Does both bbsel and non-bbsel versions (need screen cos for both) */
data.pass = 0;
mesh_foreachScreenEdge(ar, v3d, do_mesh_box_select__doSelectEdge, &data, 0);
mesh_foreachScreenEdge(vc, do_mesh_box_select__doSelectEdge, &data, 0);
if (data.done==0) {
data.pass = 1;
mesh_foreachScreenEdge(ar, v3d, do_mesh_box_select__doSelectEdge, &data, 0);
mesh_foreachScreenEdge(vc, do_mesh_box_select__doSelectEdge, &data, 0);
}
}
if(scene->selectmode & SCE_SELECT_FACE) {
if(vc->scene->selectmode & SCE_SELECT_FACE) {
if(bbsel) {
EM_backbuf_checkAndSelectFaces(em, select);
EM_backbuf_checkAndSelectFaces(vc->em, select);
} else {
mesh_foreachScreenFace(ar, v3d, do_mesh_box_select__doSelectFace, &data);
mesh_foreachScreenFace(vc, do_mesh_box_select__doSelectFace, &data);
}
}
EM_free_backbuf();
EM_selectmode_flush(em);
EM_selectmode_flush(vc->em);
}
static int view3d_borderselect_exec(bContext *C, wmOperator *op)
{
ViewContext vc;
Scene *scene= CTX_data_scene(C);
ScrArea *sa= CTX_wm_area(C);
ARegion *ar= CTX_wm_region(C);
@ -1208,6 +1219,14 @@ static int view3d_borderselect_exec(bContext *C, wmOperator *op)
int a, index;
short hits, val;
/* setup view context for argument to callbacks */
memset(&vc, 0, sizeof(ViewContext));
vc.ar= ar;
vc.scene= scene;
vc.v3d= v3d;
vc.obact= OBACT;
val= RNA_int_get(op->ptr, "event_type");
rect.xmin= RNA_int_get(op->ptr, "xmin");
rect.ymin= RNA_int_get(op->ptr, "ymin");
@ -1225,18 +1244,18 @@ static int view3d_borderselect_exec(bContext *C, wmOperator *op)
if(G.obedit) {
if(G.obedit->type==OB_MESH) {
do_mesh_box_select(scene, ar, v3d, &rect, (val==LEFTMOUSE));
do_mesh_box_select(&vc, &rect, (val==LEFTMOUSE));
// allqueue(REDRAWVIEW3D, 0);
// if (EM_texFaceCheck())
// allqueue(REDRAWIMAGE, 0);
}
else if(ELEM(G.obedit->type, OB_CURVE, OB_SURF)) {
do_nurbs_box_select(ar, v3d, &rect, val==LEFTMOUSE);
do_nurbs_box_select(&vc, &rect, val==LEFTMOUSE);
// allqueue(REDRAWVIEW3D, 0);
}
else if(G.obedit->type==OB_MBALL) {
hits= view3d_opengl_select(scene, ar, v3d, buffer, MAXPICKBUF, &rect);
hits= view3d_opengl_select(&vc, buffer, MAXPICKBUF, &rect);
ml= NULL; // XXX editelems.first;
@ -1265,7 +1284,7 @@ static int view3d_borderselect_exec(bContext *C, wmOperator *op)
for(ebone= G.edbo.first; ebone; ebone= ebone->next)
ebone->flag &= ~BONE_DONE;
hits= view3d_opengl_select(scene, ar, v3d, buffer, MAXPICKBUF, &rect);
hits= view3d_opengl_select(&vc, buffer, MAXPICKBUF, &rect);
/* first we only check points inside the border */
for (a=0; a<hits; a++){
@ -1312,7 +1331,7 @@ static int view3d_borderselect_exec(bContext *C, wmOperator *op)
}
else if(G.obedit->type==OB_LATTICE) {
do_lattice_box_select(&rect, val==LEFTMOUSE);
do_lattice_box_select(&vc, &rect, val==LEFTMOUSE);
}
}
else { /* no editmode, unified for bones and objects */
@ -1333,7 +1352,7 @@ static int view3d_borderselect_exec(bContext *C, wmOperator *op)
/* selection buffer now has bones potentially too, so we add MAXPICKBUF */
vbuffer = MEM_mallocN(4 * (G.totobj+MAXPICKBUF) * sizeof(unsigned int), "selection buffer");
hits= view3d_opengl_select(scene, ar, v3d, vbuffer, 4*(G.totobj+MAXPICKBUF), &rect);
hits= view3d_opengl_select(&vc, vbuffer, 4*(G.totobj+MAXPICKBUF), &rect);
/*
LOGIC NOTES (theeth):
The buffer and ListBase have the same relative order, which makes the selection
@ -1533,20 +1552,19 @@ static void mesh_selectionCB__doSelectFace(void *userData, EditFace *efa, int x,
}
}
static void mesh_selectionCB(Scene *scene, ARegion *ar, View3D *v3d, int selecting, Object *editobj, short *mval, float rad)
static void mesh_selectionCB(ViewContext *vc, int selecting, Object *editobj, short *mval, float rad)
{
struct { short select, mval[2]; float radius; } data;
EditMesh *em = G.editMesh;
int bbsel;
if(!G.obedit && (FACESEL_PAINT_TEST)) {
Object *ob= OBACT;
Object *ob= vc->obact;
Mesh *me = ob?ob->data:NULL;
if (me) {
em_vertoffs= me->totface+1; /* max index array */
bbsel= EM_init_backbuf_circle(v3d, mval[0], mval[1], (short)(rad+1.0));
bbsel= EM_init_backbuf_circle(vc->v3d, mval[0], mval[1], (short)(rad+1.0));
EM_backbuf_checkAndSelectTFaces(me, selecting==LEFTMOUSE);
EM_free_backbuf();
@ -1556,39 +1574,39 @@ static void mesh_selectionCB(Scene *scene, ARegion *ar, View3D *v3d, int selecti
return;
}
bbsel= EM_init_backbuf_circle(v3d, mval[0], mval[1], (short)(rad+1.0));
bbsel= EM_init_backbuf_circle(vc->v3d, mval[0], mval[1], (short)(rad+1.0));
data.select = (selecting==LEFTMOUSE);
data.mval[0] = mval[0];
data.mval[1] = mval[1];
data.radius = rad;
if(scene->selectmode & SCE_SELECT_VERTEX) {
if(vc->scene->selectmode & SCE_SELECT_VERTEX) {
if(bbsel) {
EM_backbuf_checkAndSelectVerts(em, selecting==LEFTMOUSE);
EM_backbuf_checkAndSelectVerts(vc->em, selecting==LEFTMOUSE);
} else {
mesh_foreachScreenVert(ar, v3d, mesh_selectionCB__doSelectVert, &data, 1);
mesh_foreachScreenVert(vc, mesh_selectionCB__doSelectVert, &data, 1);
}
}
if(scene->selectmode & SCE_SELECT_EDGE) {
if(vc->scene->selectmode & SCE_SELECT_EDGE) {
if (bbsel) {
EM_backbuf_checkAndSelectEdges(em, selecting==LEFTMOUSE);
EM_backbuf_checkAndSelectEdges(vc->em, selecting==LEFTMOUSE);
} else {
mesh_foreachScreenEdge(ar, v3d, mesh_selectionCB__doSelectEdge, &data, 0);
mesh_foreachScreenEdge(vc, mesh_selectionCB__doSelectEdge, &data, 0);
}
}
if(scene->selectmode & SCE_SELECT_FACE) {
if(vc->scene->selectmode & SCE_SELECT_FACE) {
if(bbsel) {
EM_backbuf_checkAndSelectFaces(em, selecting==LEFTMOUSE);
EM_backbuf_checkAndSelectFaces(vc->em, selecting==LEFTMOUSE);
} else {
mesh_foreachScreenFace(ar, v3d, mesh_selectionCB__doSelectFace, &data);
mesh_foreachScreenFace(vc, mesh_selectionCB__doSelectFace, &data);
}
}
EM_free_backbuf();
EM_selectmode_flush(em);
EM_selectmode_flush(vc->em);
}
@ -1612,7 +1630,7 @@ static void nurbscurve_selectionCB__doSelect(void *userData, Nurb *nu, BPoint *b
}
}
}
static void nurbscurve_selectionCB(ARegion *ar, View3D *v3d, int selecting, Object *editobj, short *mval, float rad)
static void nurbscurve_selectionCB(ViewContext *vc, int selecting, Object *editobj, short *mval, float rad)
{
struct { short select, mval[2]; float radius; } data;
@ -1621,7 +1639,7 @@ static void nurbscurve_selectionCB(ARegion *ar, View3D *v3d, int selecting, Obje
data.mval[1] = mval[1];
data.radius = rad;
nurbs_foreachScreenVert(ar, v3d, nurbscurve_selectionCB__doSelect, &data);
nurbs_foreachScreenVert(vc, nurbscurve_selectionCB__doSelect, &data);
}
@ -1635,7 +1653,7 @@ static void latticecurve_selectionCB__doSelect(void *userData, BPoint *bp, int x
bp->f1 = data->select?(bp->f1|SELECT):(bp->f1&~SELECT);
}
}
static void lattice_selectionCB(int selecting, Object *editobj, short *mval, float rad)
static void lattice_selectionCB(ViewContext *vc, int selecting, Object *editobj, short *mval, float rad)
{
struct { short select, mval[2]; float radius; } data;
@ -1644,23 +1662,23 @@ static void lattice_selectionCB(int selecting, Object *editobj, short *mval, flo
data.mval[1] = mval[1];
data.radius = rad;
lattice_foreachScreenVert(latticecurve_selectionCB__doSelect, &data);
lattice_foreachScreenVert(vc, latticecurve_selectionCB__doSelect, &data);
}
/** Callbacks for selection in Editmode */
void obedit_selectionCB(Scene *scene, ARegion *ar, View3D *v3d, short selecting, Object *editobj, short *mval, float rad)
void obedit_selectionCB(ViewContext *vc, short selecting, Object *editobj, short *mval, float rad)
{
switch(editobj->type) {
case OB_MESH:
mesh_selectionCB(scene, ar, v3d, selecting, editobj, mval, rad);
mesh_selectionCB(vc, selecting, editobj, mval, rad);
break;
case OB_CURVE:
case OB_SURF:
nurbscurve_selectionCB(ar, v3d, selecting, editobj, mval, rad);
nurbscurve_selectionCB(vc, selecting, editobj, mval, rad);
break;
case OB_LATTICE:
lattice_selectionCB(selecting, editobj, mval, rad);
lattice_selectionCB(vc, selecting, editobj, mval, rad);
break;
default:
return;

@ -45,8 +45,9 @@
#include "MEM_guardedalloc.h"
#include "BLI_blenlib.h"
#include "BLI_arithb.h"
#include "BLI_blenlib.h"
#include "BLI_editVert.h"
#include "BLI_rand.h"
#include "BKE_anim.h"
@ -66,7 +67,9 @@
#include "WM_api.h"
#include "WM_types.h"
#include "ED_mesh.h"
#include "ED_screen.h"
#include "ED_view3d.h"
#include "UI_interface.h"
#include "UI_resources.h"
@ -974,8 +977,11 @@ void setcameratoview3d(View3D *v3d)
* This is an error, "Too many objects in select buffer"
* and no action should be taken (can crash blender) if this happens
*/
short view3d_opengl_select(Scene *scene, ARegion *ar, View3D *v3d, unsigned int *buffer, unsigned int bufsize, rcti *input)
short view3d_opengl_select(ViewContext *vc, unsigned int *buffer, unsigned int bufsize, rcti *input)
{
Scene *scene= vc->scene;
View3D *v3d= vc->v3d;
ARegion *ar= vc->ar;
rctf rect;
short code, hits;