UV Editmode

made UV face selecting into a generic function that respects UV sticky modes.
moved this out of lasso so border select uses too.
This commit is contained in:
Campbell Barton 2007-10-08 15:13:07 +00:00
parent 2062aa6838
commit 0b9f1be464
5 changed files with 236 additions and 202 deletions

@ -96,6 +96,7 @@ void reveal_tface_uv(void);
void stitch_limit_uv_tface(void);
void stitch_vert_uv_tface(void);
void unlink_selection(void);
void uvface_setsel__internal(short select);
void select_linked_tface_uv(int mode);
void pin_tface_uv(int mode);
void weld_align_menu_tface_uv(void);

@ -2494,6 +2494,7 @@ void reveal_mesh(void)
BIF_undo_push("Reveal");
}
/* TODO - improve this with sync sel and selection flushing */
void hide_tface_uv(int swap)
{
EditMesh *em = G.editMesh;

@ -830,12 +830,13 @@ void borderselect_sima(short whichuvs)
MTFace *tface;
rcti rect;
rctf rectf;
int val;
short mval[2];
int val, ok = 1;
short mval[2], select;
if( is_uv_tface_editing_allowed()==0) return;
val= get_border(&rect, 3);
select = (val==LEFTMOUSE) ? 1 : 0;
if(val) {
mval[0]= rect.xmin;
@ -845,66 +846,86 @@ void borderselect_sima(short whichuvs)
mval[1]= rect.ymax;
areamouseco_to_ipoco(G.v2d, mval, &rectf.xmax, &rectf.ymax);
if (draw_uvs_face_check() && whichuvs != UV_SELECT_PINNED) {
float cent[2];
ok = 0;
for (efa= em->faces.first; efa; efa= efa->next) {
/* assume not touched */
efa->tmp.l = 0;
tface= CustomData_em_get(&em->fdata, efa->data, CD_MTFACE);
if (SIMA_FACEDRAW_CHECK(efa, tface)) {
tface_center(tface, cent, (void *)efa->v4);
if(BLI_in_rctf(&rectf, cent[0], cent[1])) {
efa->tmp.l = ok = 1;
}
}
}
/* (de)selects all tagged faces and deals with sticky modes */
if (ok)
uvface_setsel__internal(select);
} else {
for (efa= em->faces.first; efa; efa= efa->next) {
tface= CustomData_em_get(&em->fdata, efa->data, CD_MTFACE);
if (SIMA_FACEDRAW_CHECK(efa, tface)) {
if (whichuvs == UV_SELECT_ALL || (G.sima->flag & SI_SYNC_UVSEL) ) {
/* SI_SYNC_UVSEL - cant do pinned selection */
if(BLI_in_rctf(&rectf, (float)tface->uv[0][0], (float)tface->uv[0][1])) {
if(val==LEFTMOUSE) SIMA_UVSEL_SET(efa, tface, 0);
if(BLI_in_rctf(&rectf, tface->uv[0][0], tface->uv[0][1])) {
if(select) SIMA_UVSEL_SET(efa, tface, 0);
else SIMA_UVSEL_UNSET(efa, tface, 0);
}
if(BLI_in_rctf(&rectf, (float)tface->uv[1][0], (float)tface->uv[1][1])) {
if(val==LEFTMOUSE) SIMA_UVSEL_SET(efa, tface, 1);
if(BLI_in_rctf(&rectf, tface->uv[1][0], tface->uv[1][1])) {
if(select) SIMA_UVSEL_SET(efa, tface, 1);
else SIMA_UVSEL_UNSET(efa, tface, 1);
}
if(BLI_in_rctf(&rectf, (float)tface->uv[2][0], (float)tface->uv[2][1])) {
if(val==LEFTMOUSE) SIMA_UVSEL_SET(efa, tface, 2);
if(BLI_in_rctf(&rectf, tface->uv[2][0], tface->uv[2][1])) {
if(select) SIMA_UVSEL_SET(efa, tface, 2);
else SIMA_UVSEL_UNSET(efa, tface, 2);
}
if(efa->v4 && BLI_in_rctf(&rectf, (float)tface->uv[3][0], (float)tface->uv[3][1])) {
if(val==LEFTMOUSE) SIMA_UVSEL_SET(efa, tface, 3);
if(efa->v4 && BLI_in_rctf(&rectf, tface->uv[3][0], tface->uv[3][1])) {
if(select) SIMA_UVSEL_SET(efa, tface, 3);
else SIMA_UVSEL_UNSET(efa, tface, 3);
}
} else if (whichuvs == UV_SELECT_PINNED) {
if ((tface->unwrap & TF_PIN1) &&
BLI_in_rctf(&rectf, (float)tface->uv[0][0], (float)tface->uv[0][1])) {
BLI_in_rctf(&rectf, tface->uv[0][0], tface->uv[0][1])) {
if(val==LEFTMOUSE) SIMA_UVSEL_SET(efa, tface, 0);
if(select) SIMA_UVSEL_SET(efa, tface, 0);
else SIMA_UVSEL_UNSET(efa, tface, 0);
}
if ((tface->unwrap & TF_PIN2) &&
BLI_in_rctf(&rectf, (float)tface->uv[1][0], (float)tface->uv[1][1])) {
BLI_in_rctf(&rectf, tface->uv[1][0], tface->uv[1][1])) {
if(val==LEFTMOUSE) SIMA_UVSEL_SET(efa, tface, 1);
if(select) SIMA_UVSEL_SET(efa, tface, 1);
else SIMA_UVSEL_UNSET(efa, tface, 1);
}
if ((tface->unwrap & TF_PIN3) &&
BLI_in_rctf(&rectf, (float)tface->uv[2][0], (float)tface->uv[2][1])) {
BLI_in_rctf(&rectf, tface->uv[2][0], tface->uv[2][1])) {
if(val==LEFTMOUSE) SIMA_UVSEL_SET(efa, tface, 2);
if(select) SIMA_UVSEL_SET(efa, tface, 2);
else SIMA_UVSEL_UNSET(efa, tface, 2);
}
if ((efa->v4) && (tface->unwrap & TF_PIN4) && BLI_in_rctf(&rectf, (float)tface->uv[3][0], (float)tface->uv[3][1])) {
if(val==LEFTMOUSE) SIMA_UVSEL_SET(efa, tface, 3);
if ((efa->v4) && (tface->unwrap & TF_PIN4) && BLI_in_rctf(&rectf, tface->uv[3][0], tface->uv[3][1])) {
if(select) SIMA_UVSEL_SET(efa, tface, 3);
else SIMA_UVSEL_UNSET(efa, tface, 3);
}
}
}
}
}
if (ok) {
/* make sure newly selected vert selection is updated*/
if (G.sima->flag & SI_SYNC_UVSEL) {
if (G.scene->selectmode != SCE_SELECT_FACE) {
if (val==LEFTMOUSE) EM_select_flush();
if (select) EM_select_flush();
else EM_deselect_flush();
}
allqueue(REDRAWVIEW3D, 0); /* mesh selection has changed */
}
allqueue(REDRAWVIEW3D, 0); /* mesh selection has changed */
BIF_undo_push("Border select UV");
scrarea_queue_winredraw(curarea);
}
}
}
int snap_uv_sel_to_curs(void)
@ -1550,29 +1571,148 @@ void unlink_selection(void)
scrarea_queue_winredraw(curarea);
}
/*
void toggle_uv_select(int mode)
/* this function sets the selection on tagged faces
* This is needed because setting the selection on a face is done in
* a number of places but it also needs to respect the sticky modes
* for the UV verts - dealing with the sticky modes is best done in a seperate function
*
* de-selects faces that have been tagged on efa->tmp.l
*/
void uvface_setsel__internal(short select)
{
switch(mode){
case 'f':
G.sima->flag ^= SI_SELACTFACE;
break;
case 's':
G.sima->flag &= ~SI_LOCALSTICKY;
G.sima->flag |= SI_STICKYUVS;
break;
case 'l':
G.sima->flag &= ~SI_STICKYUVS;
G.sima->flag &= ~SI_LOCALSTICKY;
break;
case 'o':
G.sima->flag &= ~SI_STICKYUVS;
G.sima->flag |= SI_LOCALSTICKY;
/* All functions calling this should call
* draw_uvs_face_check()
*/
/* selecting UV Faces with some modes requires us to change
* the selection in other faces (depending on the stickt mode)
*
* This only needs to be done when the Mesh is not used for selection
* (So for sticky modes - vertex or location based)
* */
EditMesh *em = G.editMesh;
EditFace *efa;
MTFace *tf;
int nverts, i;
if ((G.sima->flag & SI_SYNC_UVSEL)==0 && G.sima->sticky == SI_STICKY_VERTEX) {
/* tag all verts as untouched,
* then touch the ones that have a face center in the loop
* and select all MTFace UV's that use a touched vert */
EditVert *eve;
for (eve= em->verts.first; eve; eve= eve->next)
eve->tmp.l = 0;
for (efa= em->faces.first; efa; efa= efa->next) {
if (efa->tmp.l) {
if (efa->v4) {
efa->v1->tmp.l= efa->v2->tmp.l= efa->v3->tmp.l= efa->v4->tmp.l=1;
} else {
efa->v1->tmp.l= efa->v2->tmp.l= efa->v3->tmp.l= 1;
}
}
}
/* now select tagged verts */
for (efa= em->faces.first; efa; efa= efa->next) {
tf = CustomData_em_get(&em->fdata, efa->data, CD_MTFACE);
nverts= efa->v4? 4: 3;
for(i=0; i<nverts; i++) {
if ((*(&efa->v1 + i))->tmp.l) {
if (select) {
SIMA_UVSEL_SET(efa, tf, i);
} else {
SIMA_UVSEL_UNSET(efa, tf, i);
}
}
}
}
} else if ((G.sima->flag & SI_SYNC_UVSEL)==0 && G.sima->sticky == SI_STICKY_LOC) {
EditFace *efa_vlist;
MTFace *tf_vlist;
UvMapVert *vlist, *start_vlist, *vlist_iter;
struct UvVertMap *vmap;
float limit[2];
int efa_index;
//EditVert *eve; /* removed vert counting for now */
//int a;
get_connected_limit_tface_uv(limit);
EM_init_index_arrays(0, 0, 1);
vmap= make_uv_vert_map_EM(0, 0, limit);
/* verts are numbered above in make_uv_vert_map_EM, make sure this stays true! */
/*for (a=0, eve= em->verts.first; eve; a++, eve= eve->next)
eve->tmp.l = a; */
if(vmap == NULL)
return;
for (efa_index=0, efa= em->faces.first; efa; efa_index++, efa= efa->next) {
if (efa->tmp.l) {
tf = CustomData_em_get(&em->fdata, efa->data, CD_MTFACE);
nverts= efa->v4? 4: 3;
for(i=0; i<nverts; i++) {
if (select) {
SIMA_UVSEL_SET(efa, tf, i);
} else {
SIMA_UVSEL_UNSET(efa, tf, i);
}
vlist= vlist_iter= get_uv_map_vert_EM(vmap, (*(&efa->v1 + i))->tmp.l);
while (vlist_iter) {
if (vlist_iter->separate)
start_vlist = vlist_iter;
if (efa_index == vlist_iter->f) {
break;
}
allqueue(REDRAWIMAGE, 0);
vlist_iter = vlist_iter->next;
}
vlist_iter = start_vlist;
while (vlist_iter) {
if (vlist_iter != start_vlist && vlist_iter->separate)
break;
if (efa_index != vlist_iter->f) {
efa_vlist = EM_get_face_for_index(vlist_iter->f);
tf_vlist = CustomData_em_get(&em->fdata, efa_vlist->data, CD_MTFACE);
if (select) {
SIMA_UVSEL_SET(efa_vlist, tf_vlist, vlist_iter->tfindex);
} else {
SIMA_UVSEL_UNSET(efa_vlist, tf_vlist, vlist_iter->tfindex);
}
}
vlist_iter = vlist_iter->next;
}
}
}
}
EM_free_index_arrays();
free_uv_vert_map_EM(vmap);
} else { /* SI_STICKY_DISABLE or G.sima->flag & SI_SYNC_UVSEL */
for (efa= em->faces.first; efa; efa= efa->next) {
if (efa->tmp.l) {
tf = CustomData_em_get(&em->fdata, efa->data, CD_MTFACE);
if (select) {
SIMA_FACESEL_SET(efa, tf);
} else {
SIMA_FACESEL_UNSET(efa, tf);
}
}
}
}
}
*/
void pin_tface_uv(int mode)
{

@ -475,141 +475,30 @@ 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;
int screenUV[2], nverts, i, ok = 1;
rcti rect;
lasso_select_boundbox(&rect, mcords, moves);
if (draw_uvs_face_check()) { /* Face Center Sel */
float cent[2];
/* selecting UV Faces with some modes requires us to change
* the selection in other faces (depending on the stickt mode)
*
* This only needs to be done when the Mesh is not used for selection
* (So for sticky modes - vertex or location based)
* This shoud be a generic function - so Ill make one but it will
* Only be used by this at the moment.
* */
if ((G.sima->flag & SI_SYNC_UVSEL)==0 && G.sima->sticky == SI_STICKY_VERTEX) {
/* tag all verts as untouched,
* then touch the ones that have a face center in the loop
* and select all MTFace UV's that use a touched vert */
EditVert *eve;
for (eve= em->verts.first; eve; eve= eve->next)
eve->tmp.l = 0;
ok = 0;
for (efa= em->faces.first; efa; efa= efa->next) {
/* assume not touched */
efa->tmp.l = 0;
tf = CustomData_em_get(&em->fdata, efa->data, CD_MTFACE);
if (SIMA_FACEDRAW_CHECK(efa, tf)) {
if ((select) != (SIMA_FACESEL_CHECK(efa, tf))) {
tface_center(tf, cent, (void *)efa->v4);
uvco_to_areaco_noclip(cent, screenUV);
if (BLI_in_rcti(&rect, screenUV[0], screenUV[1]) && lasso_inside(mcords, moves, screenUV[0], screenUV[1])) {
if (efa->v4) {
efa->v1->tmp.l= efa->v2->tmp.l= efa->v3->tmp.l= efa->v4->tmp.l=1;
} else {
efa->v1->tmp.l= efa->v2->tmp.l= efa->v3->tmp.l= 1;
efa->tmp.l = ok = 1;
}
}
}
}
}
/* now select tagged verts */
for (efa= em->faces.first; efa; efa= efa->next) {
tf = CustomData_em_get(&em->fdata, efa->data, CD_MTFACE);
nverts= efa->v4? 4: 3;
for(i=0; i<nverts; i++) {
if ((*(&efa->v1 + i))->tmp.l) {
if (select) {
SIMA_UVSEL_SET(efa, tf, i);
} else {
SIMA_UVSEL_UNSET(efa, tf, i);
}
}
}
}
} else if ((G.sima->flag & SI_SYNC_UVSEL)==0 && G.sima->sticky == SI_STICKY_LOC) {
EditFace *efa_vlist;
MTFace *tf_vlist;
UvMapVert *vlist;
struct UvVertMap *vmap;
float limit[2];
//EditVert *eve; /* removed vert counting for now */
//int a;
/* (de)selects all tagged faces and deals with sticky modes */
if (ok)
uvface_setsel__internal(select);
get_connected_limit_tface_uv(limit);
EM_init_index_arrays(0, 0, 1);
vmap= make_uv_vert_map_EM(0, 0, limit);
/* verts are numbered above in make_uv_vert_map_EM, make sure this stays true! */
/*for (a=0, eve= em->verts.first; eve; a++, eve= eve->next)
eve->tmp.l = a; */
if(vmap == NULL)
return;
for (efa= em->faces.first; efa; efa= efa->next) {
tf = CustomData_em_get(&em->fdata, efa->data, CD_MTFACE);
if ((select) != (SIMA_FACESEL_CHECK(efa, tf))) {
tface_center(tf, cent, (void *)efa->v4);
uvco_to_areaco_noclip(cent, screenUV);
if (BLI_in_rcti(&rect, screenUV[0], screenUV[1]) && lasso_inside(mcords, moves, screenUV[0], screenUV[1])) {
nverts= efa->v4? 4: 3;
for(i=0; i<nverts; i++) {
if (select) {
SIMA_UVSEL_SET(efa, tf, i);
} else {
SIMA_UVSEL_UNSET(efa, tf, i);
}
vlist= get_uv_map_vert_EM(vmap, (*(&efa->v1 + i))->tmp.l);
while (vlist) {
if (!vlist->separate) {
efa_vlist = EM_get_face_for_index(vlist->f);
if (efa != efa_vlist) {
tf_vlist = CustomData_em_get(&em->fdata, efa_vlist->data, CD_MTFACE);
if (select) {
SIMA_UVSEL_SET(efa_vlist, tf_vlist, vlist->tfindex);
} else {
SIMA_UVSEL_UNSET(efa_vlist, tf_vlist, vlist->tfindex);
}
}
}
vlist = vlist->next;
}
}
}
}
}
EM_free_index_arrays();
free_uv_vert_map_EM(vmap);
} else { /* SI_STICKY_DISABLE or G.sima->flag & SI_SYNC_UVSEL */
for (efa= em->faces.first; efa; efa= efa->next) {
if ((tf=(MTFace *)efa->tmp.p)) {
if ((select) != (SIMA_FACESEL_CHECK(efa, tf))) {
tface_center(tf, cent, (void *)efa->v4);
uvco_to_areaco_noclip(cent, screenUV);
if (BLI_in_rcti(&rect, screenUV[0], screenUV[1]) && lasso_inside(mcords, moves, screenUV[0], screenUV[1])) {
if (select) {
SIMA_FACESEL_SET(efa, tf);
} else {
SIMA_FACESEL_UNSET(efa, tf);
}
}
}
}
}
}
} else { /* Vert Sel*/
for (efa= em->faces.first; efa; efa= efa->next) {
tf = CustomData_em_get(&em->fdata, efa->data, CD_MTFACE);
@ -630,7 +519,7 @@ static void do_lasso_select_mesh_uv(short mcords[][2], short moves, short select
}
}
}
if (G.sima->flag & SI_SYNC_UVSEL) {
if (ok && G.sima->flag & SI_SYNC_UVSEL) {
if (select) EM_select_flush();
else EM_deselect_flush();
}

@ -2338,6 +2338,9 @@ static void winqreadview3dspace(ScrArea *sa, void *spacedata, BWinEvent *evt)
if((G.qual & LR_CTRLKEY) && G.obedit->type==OB_MESH) {
convert_to_triface(G.qual & LR_SHIFTKEY);
allqueue(REDRAWVIEW3D, 0);
if (EM_texFaceCheck())
allqueue(REDRAWIMAGE, 0);
countall();
DAG_object_flush_update(G.scene, G.obedit, OB_RECALC_DATA);
}