[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [24061] trunk/blender/source/blender/ editors: face mask mode
Campbell Barton
ideasman42 at gmail.com
Thu Oct 22 21:17:46 CEST 2009
Revision: 24061
http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=24061
Author: campbellbarton
Date: 2009-10-22 21:17:46 +0200 (Thu, 22 Oct 2009)
Log Message:
-----------
face mask mode
- border select
- linked selection (Ctrl+L)
- select all
Modified Paths:
--------------
trunk/blender/source/blender/editors/include/ED_mesh.h
trunk/blender/source/blender/editors/mesh/editface.c
trunk/blender/source/blender/editors/sculpt_paint/paint_image.c
trunk/blender/source/blender/editors/sculpt_paint/paint_intern.h
trunk/blender/source/blender/editors/sculpt_paint/paint_ops.c
trunk/blender/source/blender/editors/sculpt_paint/paint_utils.c
trunk/blender/source/blender/editors/space_view3d/space_view3d.c
trunk/blender/source/blender/editors/space_view3d/view3d_select.c
Modified: trunk/blender/source/blender/editors/include/ED_mesh.h
===================================================================
--- trunk/blender/source/blender/editors/include/ED_mesh.h 2009-10-22 17:12:28 UTC (rev 24060)
+++ trunk/blender/source/blender/editors/include/ED_mesh.h 2009-10-22 19:17:46 UTC (rev 24061)
@@ -53,6 +53,7 @@
struct CustomData;
struct Material;
struct Object;
+struct recti;
#define EM_FGON_DRAW 1 // face flag
#define EM_FGON 2 // edge and face flag both
@@ -166,6 +167,9 @@
/* editface.c */
struct MTFace *EM_get_active_mtface(struct EditMesh *em, struct EditFace **act_efa, struct MCol **mcol, int sloppy);
int face_select(struct bContext *C, struct Object *ob, short mval[2], int extend);
+void face_borderselect(struct bContext *C, struct Object *ob, struct rcti *rect, int select);
+void deselectall_tface(struct Object *ob);
+void select_linked_tfaces(struct bContext *C, struct Object *ob, short mval[2], int mode);
/* object_vgroup.c */
Modified: trunk/blender/source/blender/editors/mesh/editface.c
===================================================================
--- trunk/blender/source/blender/editors/mesh/editface.c 2009-10-22 17:12:28 UTC (rev 24060)
+++ trunk/blender/source/blender/editors/mesh/editface.c 2009-10-22 19:17:46 UTC (rev 24061)
@@ -60,6 +60,7 @@
#include "BKE_texture.h"
#include "BKE_utildefines.h"
#include "BKE_customdata.h"
+#include "BKE_context.h"
#include "BIF_gl.h"
#include "BIF_glutil.h"
@@ -72,6 +73,7 @@
#endif
#include "ED_mesh.h"
+#include "ED_screen.h"
#include "ED_object.h"
#include "ED_view3d.h"
@@ -82,7 +84,6 @@
#include "mesh_intern.h"
/* ***************** XXX **************** */
-static void error() {}
static int pupmenu() {return 0;}
/* ***************** XXX **************** */
@@ -234,35 +235,156 @@
// XXX notifier! object_tface_flags_changed(OBACT, 0);
}
-void select_linked_tfaces(Scene *scene, View3D *v3d, int mode)
+/* Set tface seams based on edge data, uses hash table to find seam edges. */
+
+static void hash_add_face(EdgeHash *ehash, MFace *mf)
{
- Object *ob;
+ BLI_edgehash_insert(ehash, mf->v1, mf->v2, NULL);
+ BLI_edgehash_insert(ehash, mf->v2, mf->v3, NULL);
+ if(mf->v4) {
+ BLI_edgehash_insert(ehash, mf->v3, mf->v4, NULL);
+ BLI_edgehash_insert(ehash, mf->v4, mf->v1, NULL);
+ }
+ else
+ BLI_edgehash_insert(ehash, mf->v3, mf->v1, NULL);
+}
+
+
+void select_linked_tfaces_with_seams(int mode, Mesh *me, unsigned int index)
+{
+ MFace *mf;
+ int a, doit=1, mark=0;
+ char *linkflag;
+ EdgeHash *ehash, *seamhash;
+ MEdge *med;
+
+ ehash= BLI_edgehash_new();
+ seamhash = BLI_edgehash_new();
+ linkflag= MEM_callocN(sizeof(char)*me->totface, "linkflaguv");
+
+ for(med=me->medge, a=0; a < me->totedge; a++, med++)
+ if(med->flag & ME_SEAM)
+ BLI_edgehash_insert(seamhash, med->v1, med->v2, NULL);
+
+ if (mode==0 || mode==1) {
+ /* only put face under cursor in array */
+ mf= ((MFace*)me->mface) + index;
+ hash_add_face(ehash, mf);
+ linkflag[index]= 1;
+ }
+ else {
+ /* fill array by selection */
+ mf= me->mface;
+ for(a=0; a<me->totface; a++, mf++) {
+ if(mf->flag & ME_HIDE);
+ else if(mf->flag & ME_FACE_SEL) {
+ hash_add_face(ehash, mf);
+ linkflag[a]= 1;
+ }
+ }
+ }
+
+ while(doit) {
+ doit= 0;
+
+ /* expand selection */
+ mf= me->mface;
+ for(a=0; a<me->totface; a++, mf++) {
+ if(mf->flag & ME_HIDE)
+ continue;
+
+ if(!linkflag[a]) {
+ mark= 0;
+
+ if(!BLI_edgehash_haskey(seamhash, mf->v1, mf->v2))
+ if(BLI_edgehash_haskey(ehash, mf->v1, mf->v2))
+ mark= 1;
+ if(!BLI_edgehash_haskey(seamhash, mf->v2, mf->v3))
+ if(BLI_edgehash_haskey(ehash, mf->v2, mf->v3))
+ mark= 1;
+ if(mf->v4) {
+ if(!BLI_edgehash_haskey(seamhash, mf->v3, mf->v4))
+ if(BLI_edgehash_haskey(ehash, mf->v3, mf->v4))
+ mark= 1;
+ if(!BLI_edgehash_haskey(seamhash, mf->v4, mf->v1))
+ if(BLI_edgehash_haskey(ehash, mf->v4, mf->v1))
+ mark= 1;
+ }
+ else if(!BLI_edgehash_haskey(seamhash, mf->v3, mf->v1))
+ if(BLI_edgehash_haskey(ehash, mf->v3, mf->v1))
+ mark = 1;
+
+ if(mark) {
+ linkflag[a]= 1;
+ hash_add_face(ehash, mf);
+ doit= 1;
+ }
+ }
+ }
+
+ }
+
+ BLI_edgehash_free(ehash, NULL);
+ BLI_edgehash_free(seamhash, NULL);
+
+ if(mode==0 || mode==2) {
+ for(a=0, mf=me->mface; a<me->totface; a++, mf++)
+ if(linkflag[a])
+ mf->flag |= ME_FACE_SEL;
+ else
+ mf->flag &= ~ME_FACE_SEL;
+ }
+ else if(mode==1) {
+ for(a=0, mf=me->mface; a<me->totface; a++, mf++)
+ if(linkflag[a] && (mf->flag & ME_FACE_SEL))
+ break;
+
+ if (a<me->totface) {
+ for(a=0, mf=me->mface; a<me->totface; a++, mf++)
+ if(linkflag[a])
+ mf->flag &= ~ME_FACE_SEL;
+ }
+ else {
+ for(a=0, mf=me->mface; a<me->totface; a++, mf++)
+ if(linkflag[a])
+ mf->flag |= ME_FACE_SEL;
+ }
+ }
+
+ MEM_freeN(linkflag);
+
+ // BIF_undo_push("Select linked UV face");
+ // object_tface_flags_changed(OBACT, 0);
+}
+
+void select_linked_tfaces(bContext *C, Object *ob, short mval[2], int mode)
+{
Mesh *me;
- short mval[2];
unsigned int index=0;
- ob = OBACT;
me = get_mesh(ob);
if(me==0 || me->totface==0) return;
if (mode==0 || mode==1) {
- if (!(ob->lay & v3d->lay))
- error("The active object is not in this layer");
-
-// XXX getmouseco_areawin(mval);
- if (!facesel_face_pick(v3d, me, mval, &index, 1)) return;
+ // XXX - Causes glitches, not sure why
+ /*
+ if (!facesel_face_pick(C, me, mval, &index, 1))
+ return;
+ */
}
-// XXX unwrapper.c select_linked_tfaces_with_seams(mode, me, index);
+ select_linked_tfaces_with_seams(mode, me, index);
+
+ object_facesel_flush_dm(ob);
}
-void deselectall_tface(Scene *scene)
+void deselectall_tface(Object *ob)
{
Mesh *me;
MFace *mface;
int a, sel;
-
- me= get_mesh(OBACT);
+
+ me= get_mesh(ob);
if(me==0) return;
mface= me->mface;
@@ -288,7 +410,7 @@
mface++;
}
- object_facesel_flush_dm(OBACT);
+ object_facesel_flush_dm(ob);
// XXX notifier! object_tface_flags_changed(OBACT, 0);
}
@@ -693,73 +815,63 @@
return 1;
}
-void face_borderselect(Scene *scene, ScrArea *sa, ARegion *ar)
+void face_borderselect(struct bContext *C, Object *ob, rcti *rect, int select)
{
Mesh *me;
MFace *mface;
- rcti rect;
struct ImBuf *ibuf;
unsigned int *rt;
- int a, sx, sy, index, val= 0;
+ int a, sx, sy, index;
char *selar;
- me= get_mesh(OBACT);
+ ViewContext vc;
+ view3d_set_viewcontext(C, &vc);
+
+ me= get_mesh(ob);
if(me==0) return;
if(me->totface==0) return;
-
-// XXX val= get_border(&rect, 3);
-
- if(val) {
- /* without this border select often fails */
-#if 0 /* XXX untested in 2.5 */
- if (v3d->flag & V3D_NEEDBACKBUFDRAW) {
- check_backbuf();
- persp(PERSP_VIEW);
- }
-#endif
-
- selar= MEM_callocN(me->totface+1, "selar");
-
- sx= (rect.xmax-rect.xmin+1);
- sy= (rect.ymax-rect.ymin+1);
- if(sx*sy<=0) return;
- ibuf = IMB_allocImBuf(sx,sy,32,IB_rect,0);
- rt = ibuf->rect;
- glReadPixels(rect.xmin+ar->winrct.xmin, rect.ymin+ar->winrct.ymin, sx, sy, GL_RGBA, GL_UNSIGNED_BYTE, ibuf->rect);
- if(ENDIAN_ORDER==B_ENDIAN) IMB_convert_rgba_to_abgr(ibuf);
+ selar= MEM_callocN(me->totface+1, "selar");
- a= sx*sy;
- while(a--) {
- if(*rt) {
- index= WM_framebuffer_to_index(*rt);
- if(index<=me->totface) selar[index]= 1;
- }
- rt++;
+ sx= (rect->xmax-rect->xmin+1);
+ sy= (rect->ymax-rect->ymin+1);
+ if(sx*sy<=0) return;
+
+ view3d_validate_backbuf(&vc);
+
+ ibuf = IMB_allocImBuf(sx,sy,32,IB_rect,0);
+ rt = ibuf->rect;
+ glReadPixels(rect->xmin+vc.ar->winrct.xmin, rect->ymin+vc.ar->winrct.ymin, sx, sy, GL_RGBA, GL_UNSIGNED_BYTE, ibuf->rect);
+ if(ENDIAN_ORDER==B_ENDIAN) IMB_convert_rgba_to_abgr(ibuf);
+
+ a= sx*sy;
+ while(a--) {
+ if(*rt) {
+ index= WM_framebuffer_to_index(*rt);
+ if(index<=me->totface) selar[index]= 1;
}
-
- mface= me->mface;
- for(a=1; a<=me->totface; a++, mface++) {
- if(selar[a]) {
- if(mface->flag & ME_HIDE);
- else {
- if(val==LEFTMOUSE) mface->flag |= ME_FACE_SEL;
- else mface->flag &= ~ME_FACE_SEL;
- }
+ rt++;
+ }
+
+ mface= me->mface;
+ for(a=1; a<=me->totface; a++, mface++) {
+ if(selar[a]) {
+ if(mface->flag & ME_HIDE);
+ else {
+ if(select) mface->flag |= ME_FACE_SEL;
+ else mface->flag &= ~ME_FACE_SEL;
}
}
-
- IMB_freeImBuf(ibuf);
- MEM_freeN(selar);
+ }
+ IMB_freeImBuf(ibuf);
+ MEM_freeN(selar);
+
// XXX notifier! object_tface_flags_changed(OBACT, 0);
- }
#ifdef __APPLE__
glReadBuffer(GL_BACK);
#endif
- object_facesel_flush_dm(OBACT);
+ object_facesel_flush_dm(ob);
}
-
-
Modified: trunk/blender/source/blender/editors/sculpt_paint/paint_image.c
===================================================================
--- trunk/blender/source/blender/editors/sculpt_paint/paint_image.c 2009-10-22 17:12:28 UTC (rev 24060)
+++ trunk/blender/source/blender/editors/sculpt_paint/paint_image.c 2009-10-22 19:17:46 UTC (rev 24061)
@@ -5254,6 +5254,5 @@
int facemask_paint_poll(bContext *C)
{
- Object *obact = CTX_data_active_object(C);
- return paint_facesel_test(obact);
+ return paint_facesel_test(CTX_data_active_object(C));
}
Modified: trunk/blender/source/blender/editors/sculpt_paint/paint_intern.h
===================================================================
--- trunk/blender/source/blender/editors/sculpt_paint/paint_intern.h 2009-10-22 17:12:28 UTC (rev 24060)
+++ trunk/blender/source/blender/editors/sculpt_paint/paint_intern.h 2009-10-22 19:17:46 UTC (rev 24061)
@@ -94,6 +94,10 @@
void paint_sample_color(struct Scene *scene, struct ARegion *ar, int x, int y);
void BRUSH_OT_curve_preset(struct wmOperatorType *ot);
+void PAINT_OT_face_select_linked(struct wmOperatorType *ot);
+void PAINT_OT_face_select_linked_pick(struct wmOperatorType *ot);
+void PAINT_OT_face_deselect_all(struct wmOperatorType *ot);
+
int facemask_paint_poll(struct bContext *C);
#endif /* ED_PAINT_INTERN_H */
Modified: trunk/blender/source/blender/editors/sculpt_paint/paint_ops.c
===================================================================
--- trunk/blender/source/blender/editors/sculpt_paint/paint_ops.c 2009-10-22 17:12:28 UTC (rev 24060)
+++ trunk/blender/source/blender/editors/sculpt_paint/paint_ops.c 2009-10-22 19:17:46 UTC (rev 24061)
@@ -133,6 +133,11 @@
WM_operatortype_append(PAINT_OT_vertex_paint_toggle);
WM_operatortype_append(PAINT_OT_vertex_paint);
WM_operatortype_append(PAINT_OT_vertex_color_set);
+
+ /* face-select */
+ WM_operatortype_append(PAINT_OT_face_select_linked);
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list