Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoseph Eagar <joeedh@gmail.com>2009-08-28 14:59:16 +0400
committerJoseph Eagar <joeedh@gmail.com>2009-08-28 14:59:16 +0400
commit89f02849823badb44993e59347afcbdece394a94 (patch)
treead832f6c3bc0f1af5bfa62a2b57f3d699229f7a3
parent771a4dee0bf8d20208098cfe2809927425cc267e (diff)
Shift-G (select similar) is now bmeshafied for vert select mode.
The patch was by Wael El Oraiby.
-rw-r--r--source/blender/bmesh/bmesh_operators.h7
-rw-r--r--source/blender/bmesh/intern/bmesh_opdefines.c17
-rw-r--r--source/blender/bmesh/intern/bmesh_operators_private.h1
-rw-r--r--source/blender/bmesh/operators/utils.c113
-rw-r--r--source/blender/editors/mesh/bmesh_select.c165
5 files changed, 167 insertions, 136 deletions
diff --git a/source/blender/bmesh/bmesh_operators.h b/source/blender/bmesh/bmesh_operators.h
index f5be0f3be91..59ddb26fb30 100644
--- a/source/blender/bmesh/bmesh_operators.h
+++ b/source/blender/bmesh/bmesh_operators.h
@@ -43,6 +43,13 @@ enum {
SIMEDGE_SHARP,
};
+/* similar vertex selection slot values */
+enum {
+ SIMVERT_NORMAL = 0,
+ SIMVERT_FACE,
+ SIMVERT_VGROUP,
+};
+
extern BMOpDefine *opdefines[];
extern int bmesh_total_ops;
diff --git a/source/blender/bmesh/intern/bmesh_opdefines.c b/source/blender/bmesh/intern/bmesh_opdefines.c
index acde51dd2eb..b8e8e86ffaa 100644
--- a/source/blender/bmesh/intern/bmesh_opdefines.c
+++ b/source/blender/bmesh/intern/bmesh_opdefines.c
@@ -645,6 +645,22 @@ BMOpDefine def_similaredges = {
0
};
+/*
+ Similar vertices select
+
+ Select similar vertices (normal, face, vertex group,....).
+*/
+BMOpDefine def_similarverts = {
+ "similarverts",
+ {{BMOP_OPSLOT_ELEMENT_BUF, "verts"}, /* input vertices */
+ {BMOP_OPSLOT_ELEMENT_BUF, "vertout"}, /* output vertices */
+ {BMOP_OPSLOT_INT, "type"}, /* type of selection */
+ {BMOP_OPSLOT_FLT, "thresh"}, /* threshold of selection */
+ {0} /*null-terminating sentinel*/},
+ bmesh_similarverts_exec,
+ 0
+};
+
BMOpDefine *opdefines[] = {
&def_splitop,
&def_dupeop,
@@ -687,6 +703,7 @@ BMOpDefine *opdefines[] = {
&def_collapse,
&def_similarfaces,
&def_similaredges,
+ &def_similarverts,
};
int bmesh_total_ops = (sizeof(opdefines) / sizeof(void*));
diff --git a/source/blender/bmesh/intern/bmesh_operators_private.h b/source/blender/bmesh/intern/bmesh_operators_private.h
index 31d20bef8ee..f8e0685fa15 100644
--- a/source/blender/bmesh/intern/bmesh_operators_private.h
+++ b/source/blender/bmesh/intern/bmesh_operators_private.h
@@ -48,4 +48,5 @@ void bmesh_pointmerge_exec(BMesh *bm, BMOperator *op);
void bmesh_collapse_exec(BMesh *bm, BMOperator *op);
void bmesh_similarfaces_exec(BMesh *bm, BMOperator *op);
void bmesh_similaredges_exec(BMesh *bm, BMOperator *op);
+void bmesh_similarverts_exec(BMesh *bm, BMOperator *op);
#endif
diff --git a/source/blender/bmesh/operators/utils.c b/source/blender/bmesh/operators/utils.c
index 4fc4e7dcf56..8517c4e155e 100644
--- a/source/blender/bmesh/operators/utils.c
+++ b/source/blender/bmesh/operators/utils.c
@@ -839,3 +839,116 @@ void bmesh_similaredges_exec(BMesh *bm, BMOperator *op)
BMO_Flag_To_Slot(bm, op, "edgeout", EDGE_MARK, BM_EDGE);
}
+/******************************************************************************
+** Similar Vertices
+******************************************************************************/
+#define VERT_MARK 1
+
+typedef struct tmp_vert_ext {
+ BMVert *v;
+ union {
+ int num_faces; /* adjacent faces */
+ MDeformVert *dvert; /* deform vertex */
+ };
+} tmp_vert_ext;
+
+/*
+** select similar vertices: the choices are in the enum in source/blender/bmesh/bmesh_operators.h
+** choices are normal, face, vertex group...
+*/
+void bmesh_similarverts_exec(BMesh *bm, BMOperator *op)
+{
+ BMOIter vs_iter; /* selected verts iterator */
+ BMIter v_iter; /* mesh verts iterator */
+ BMVert *vs; /* selected vertex */
+ BMVert *v; /* mesh vertex */
+ tmp_vert_ext *v_ext = NULL;
+ int *indices = NULL;
+ int num_total = 0, num_sels = 0, i = 0, idx = 0;
+ int type = BMO_Get_Int(op, "type");
+ float thresh = BMO_Get_Float(op, "thresh");
+
+ num_total = BM_Count_Element(bm, BM_VERT);
+
+ /* iterate through all selected edges and mark them */
+ BMO_ITER(vs, &vs_iter, bm, op, "verts", BM_VERT) {
+ BMO_SetFlag(bm, vs, VERT_MARK);
+ num_sels++;
+ }
+
+ /* allocate memory for the selected vertices indices and for all temporary vertices */
+ indices = (int*)MEM_mallocN(sizeof(int) * num_sels, "vertex indices");
+ v_ext = (tmp_vert_ext*)MEM_mallocN(sizeof(tmp_vert_ext) * num_total, "vertex extra");
+
+ /* loop through all the vertices and fill the vertices/indices structure */
+ BM_ITER(v, &v_iter, bm, BM_VERTS_OF_MESH, NULL) {
+ v_ext[i].v = v;
+ if (BMO_TestFlag(bm, v, VERT_MARK)) {
+ indices[idx] = i;
+ idx++;
+ }
+
+ switch( type ) {
+ case SIMVERT_FACE:
+ /* calling BM_Vert_FaceCount every time is time consumming, so call it only once per vertex */
+ v_ext[i].num_faces = BM_Vert_FaceCount(v);
+ break;
+
+ case SIMVERT_VGROUP:
+ if( CustomData_has_layer(&(bm->vdata),CD_MDEFORMVERT) ) {
+ v_ext[i].dvert = CustomData_bmesh_get(&bm->vdata, v_ext[i].v->head.data, CD_MDEFORMVERT);
+ } else v_ext[i].dvert = NULL;
+ break;
+ }
+
+ i++;
+ }
+
+ /* select the vertices if any */
+ for( i = 0; i < num_total; i++ ) {
+ v = v_ext[i].v;
+ if( !BMO_TestFlag(bm, v, VERT_MARK) && !BM_TestHFlag(v, BM_HIDDEN) ) {
+ int cont = 1;
+ for( idx = 0; idx < num_sels && cont == 1; idx++ ) {
+ vs = v_ext[indices[idx]].v;
+ switch( type ) {
+ case SIMVERT_NORMAL:
+ /* compare the angle between the normals */
+ if( VecAngle2(v->no, vs->no) / 180.0 <= thresh ) {
+ BMO_SetFlag(bm, v, VERT_MARK);
+ cont = 0;
+
+ }
+ break;
+ case SIMVERT_FACE:
+ /* number of adjacent faces */
+ if( v_ext[i].num_faces == v_ext[indices[idx]].num_faces ) {
+ BMO_SetFlag(bm, v, VERT_MARK);
+ cont = 0;
+ }
+ break;
+
+ case SIMVERT_VGROUP:
+ if( v_ext[i].dvert != NULL && v_ext[indices[idx]].dvert != NULL ) {
+ int v1, v2;
+ for( v1 = 0; v1 < v_ext[i].dvert->totweight && cont == 1; v1++ ) {
+ for( v2 = 0; v2 < v_ext[indices[idx]].dvert->totweight; v2++ ) {
+ if( v_ext[i].dvert->dw[v1].def_nr == v_ext[indices[idx]].dvert->dw[v2].def_nr ) {
+ BMO_SetFlag(bm, v, VERT_MARK);
+ cont = 0;
+ break;
+ }
+ }
+ }
+ }
+ break;
+ }
+ }
+ }
+ }
+
+ MEM_freeN(indices);
+ MEM_freeN(v_ext);
+
+ BMO_Flag_To_Slot(bm, op, "vertout", VERT_MARK, BM_VERT);
+}
diff --git a/source/blender/editors/mesh/bmesh_select.c b/source/blender/editors/mesh/bmesh_select.c
index 0cc7bfe5849..2eb76870e22 100644
--- a/source/blender/editors/mesh/bmesh_select.c
+++ b/source/blender/editors/mesh/bmesh_select.c
@@ -975,13 +975,9 @@ VERT GROUP
mode 3: same vertex groups
*/
-#define SIMVERT_NORMAL 0
-#define SIMVERT_FACE 1
-#define SIMVERT_VGROUP 2
-
static EnumPropertyItem prop_simvertex_types[] = {
{SIMVERT_NORMAL, "NORMAL", 0, "Normal", ""},
- {SIMVERT_FACE, "FACE", 0, "Amount of Vertices in Face", ""},
+ {SIMVERT_FACE, "FACE", 0, "Amount of Adjacent Faces", ""},
{SIMVERT_VGROUP, "VGROUP", 0, "Vertex Groups", ""},
{0, NULL, 0, NULL, NULL}
};
@@ -989,141 +985,38 @@ static EnumPropertyItem prop_simvertex_types[] = {
static int similar_vert_select_exec(bContext *C, wmOperator *op)
{
-#if 0
- Scene *scene= CTX_data_scene(C);
- Object *obedit= CTX_data_edit_object(C);
- Mesh *me= obedit->data;
- EditMesh *em= BKE_mesh_get_editmesh(me);
- EditVert *eve, *base_eve=NULL;
- unsigned int selcount=0; /* count how many new edges we select*/
-
- /*count how many visible selected edges there are,
- so we can return when there are none left */
- unsigned int deselcount=0;
- int mode= RNA_enum_get(op->ptr, "type");
-
- short ok=0;
- float thresh= scene->toolsettings->select_thresh;
-
- for(eve= em->verts.first; eve; eve= eve->next) {
- if (!eve->h) {
- if (eve->f & SELECT) {
- eve->f1=1;
- ok=1;
- } else {
- eve->f1=0;
- deselcount++;
- }
- /* set all eve->tmp.l to 0 we use them later.*/
- eve->tmp.l=0;
- }
-
- }
-
- if (!ok || !deselcount) { /* no data selected OR no more data to select*/
- BKE_mesh_end_editmesh(me, em);
- return 0;
- }
-
- if(mode == SIMVERT_FACE) {
- /* store face users */
- EditFace *efa;
-
- /* count how many faces each edge uses use tmp->l */
- for(efa= em->faces.first; efa; efa= efa->next) {
- efa->v1->tmp.l++;
- efa->v2->tmp.l++;
- efa->v3->tmp.l++;
- if (efa->v4) efa->v4->tmp.l++;
- }
- }
-
-
- for(base_eve= em->verts.first; base_eve; base_eve= base_eve->next) {
- if (base_eve->f1) {
-
- if(mode == SIMVERT_NORMAL) {
- float angle;
- for(eve= em->verts.first; eve; eve= eve->next) {
- if (!(eve->f & SELECT) && !eve->h) {
- angle= VecAngle2(base_eve->no, eve->no);
- if (angle/180.0<=thresh) {
- eve->f |= SELECT;
- selcount++;
- deselcount--;
- if (!deselcount) {/*have we selected all posible faces?, if so return*/
- BKE_mesh_end_editmesh(me, em);
- return selcount;
- }
- }
- }
- }
- }
- else if(mode == SIMVERT_FACE) {
- for(eve= em->verts.first; eve; eve= eve->next) {
- if (
- !(eve->f & SELECT) &&
- !eve->h &&
- base_eve->tmp.l==eve->tmp.l
- ) {
- eve->f |= SELECT;
- selcount++;
- deselcount--;
- if (!deselcount) {/*have we selected all posible faces?, if so return*/
- BKE_mesh_end_editmesh(me, em);
- return selcount;
- }
- }
- }
- }
- else if(mode == SIMVERT_VGROUP) {
- MDeformVert *dvert, *base_dvert;
- short i, j; /* weight index */
+ Scene *scene = CTX_data_scene(C);
+ Object *ob = CTX_data_edit_object(C);
+ BMEditMesh *em = ((Mesh*)ob->data)->edit_btmesh;
+ BMOperator bmop;
+ /* get the type from RNA */
+ int type = RNA_enum_get(op->ptr, "type");
+ float thresh = scene->toolsettings->select_thresh;
- base_dvert= CustomData_em_get(&em->vdata, base_eve->data,
- CD_MDEFORMVERT);
+ /* initialize the bmop using EDBM api, which does various ui error reporting and other stuff */
+ EDBM_InitOpf(em, &bmop, op, "similarverts verts=%hv type=%d thresh=%f", BM_SELECT, type, thresh);
- if (!base_dvert || base_dvert->totweight == 0) {
- BKE_mesh_end_editmesh(me, em);
- return selcount;
- }
-
- for(eve= em->verts.first; eve; eve= eve->next) {
- dvert= CustomData_em_get(&em->vdata, eve->data,
- CD_MDEFORMVERT);
-
- if (dvert && !(eve->f & SELECT) && !eve->h && dvert->totweight) {
- /* do the extra check for selection in the following if, so were not
- checking verts that may be alredy selected */
- for (i=0; base_dvert->totweight >i && !(eve->f & SELECT); i++) {
- for (j=0; dvert->totweight >j; j++) {
- if (base_dvert->dw[i].def_nr==dvert->dw[j].def_nr) {
- eve->f |= SELECT;
- selcount++;
- deselcount--;
- if (!deselcount) { /*have we selected all posible faces?, if so return*/
- BKE_mesh_end_editmesh(me, em);
- return selcount;
- }
- break;
- }
- }
- }
- }
- }
- }
- }
- } /* end basevert loop */
+ /* execute the operator */
+ BMO_Exec_Op(em->bm, &bmop);
- if(selcount) {
- WM_event_add_notifier(C, NC_OBJECT|ND_GEOM_SELECT, obedit);
- BKE_mesh_end_editmesh(me, em);
- return OPERATOR_FINISHED;
- }
+ /* clear the existing selection */
+ EDBM_clear_flag_all(em, BM_SELECT);
- BKE_mesh_end_editmesh(me, em);
-#endif
- return OPERATOR_CANCELLED;
+ /* select the output */
+ BMO_HeaderFlag_Buffer(em->bm, &bmop, "vertout", BM_SELECT, BM_ALL);
+
+ /* finish the operator */
+ if( !EDBM_FinishOp(em, &bmop, op, 1) )
+ return OPERATOR_CANCELLED;
+
+ EDBM_selectmode_flush(em);
+
+ /* dependencies graph and notification stuff */
+ DAG_object_flush_update(scene, ob, OB_RECALC_DATA);
+ WM_event_add_notifier(C, NC_OBJECT | ND_GEOM_SELECT, ob);
+
+ /* we succeeded */
+ return OPERATOR_FINISHED;
}
static int select_similar_exec(bContext *C, wmOperator *op)