184
185
unsigned int bm_solidoffs = 0, bm_wireoffs = 0, bm_vertoffs = 0; /* set in drawobject.c ... for colorindices */
186
187
/* facilities for border select and circle select */
187
static char *selbuf = NULL;
188
static BLI_bitmap *selbuf = NULL;
190
static BLI_bitmap *edbm_backbuf_alloc(const int size)
192
return BLI_BITMAP_NEW(size, "selbuf");
189
195
/* reads rect, and builds selection array for quick lookup */
190
196
/* returns if all is OK */
207
213
/* build selection lookup */
208
selbuf = MEM_callocN(bm_vertoffs + 1, "selbuf");
214
selbuf = edbm_backbuf_alloc(bm_vertoffs + 1);
210
216
a = (xmax - xmin + 1) * (ymax - ymin + 1);
212
if (*dr > 0 && *dr <= bm_vertoffs)
218
if (*dr > 0 && *dr <= bm_vertoffs) {
219
BLI_BITMAP_SET(selbuf, *dr);
216
223
IMB_freeImBuf(buf);
220
int EDBM_backbuf_check(unsigned int index)
227
bool EDBM_backbuf_check(unsigned int index)
222
229
/* odd logic, if selbuf is NULL we assume no zbuf-selection is enabled
223
230
* and just ignore the depth buffer, this is error prone since its possible
224
231
* code doesn't set the depth buffer by accident, but leave for now. - Campbell */
225
if (selbuf == NULL) return 1;
227
235
if (index > 0 && index <= bm_vertoffs)
228
return selbuf[index];
236
return BLI_BITMAP_GET_BOOL(selbuf, index);
232
241
void EDBM_backbuf_free(void)
286
295
edbm_mask_lasso_px_cb, &lasso_mask_data);
288
297
/* build selection lookup */
289
selbuf = MEM_callocN(bm_vertoffs + 1, "selbuf");
298
selbuf = edbm_backbuf_alloc(bm_vertoffs + 1);
291
300
a = (xmax - xmin + 1) * (ymax - ymin + 1);
293
if (*dr > 0 && *dr <= bm_vertoffs && *dr_mask == true) selbuf[*dr] = 1;
302
if (*dr > 0 && *dr <= bm_vertoffs && *dr_mask == true) {
303
BLI_BITMAP_SET(selbuf, *dr);
296
307
IMB_freeImBuf(buf);
328
339
/* build selection lookup */
329
selbuf = MEM_callocN(bm_vertoffs + 1, "selbuf");
340
selbuf = edbm_backbuf_alloc(bm_vertoffs + 1);
330
341
radsq = rads * rads;
331
342
for (yc = -rads; yc <= rads; yc++) {
332
343
for (xc = -rads; xc <= rads; xc++, dr++) {
333
344
if (xc * xc + yc * yc < radsq) {
334
if (*dr > 0 && *dr <= bm_vertoffs) selbuf[*dr] = 1;
345
if (*dr > 0 && *dr <= bm_vertoffs) {
346
BLI_BITMAP_SET(selbuf, *dr);
379
392
static bool findnearestvert__backbufIndextest(void *handle, unsigned int index)
381
394
BMEditMesh *em = (BMEditMesh *)handle;
382
BMVert *eve = BM_vert_at_index(em->bm, index - 1);
395
BMVert *eve = BM_vert_at_index_find(em->bm, index - 1);
383
396
return !(eve && BM_elem_flag_test(eve, BM_ELEM_SELECT));
423
436
static int lastSelectedIndex = 0;
424
437
static BMVert *lastSelected = NULL;
426
if (lastSelected && BM_vert_at_index(vc->em->bm, lastSelectedIndex) != lastSelected) {
439
if (lastSelected && BM_vert_at_index_find(vc->em->bm, lastSelectedIndex) != lastSelected) {
427
440
lastSelectedIndex = 0;
428
441
lastSelected = NULL;
499
512
view3d_validate_backbuf(vc);
501
514
index = view3d_sample_backbuf_rect(vc, vc->mval, 50, bm_solidoffs, bm_wireoffs, &distance, 0, NULL, NULL);
502
eed = index ? BM_edge_at_index(vc->em->bm, index - 1) : NULL;
515
eed = index ? BM_edge_at_index_find(vc->em->bm, index - 1) : NULL;
504
517
if (eed && distance < *r_dist) {
505
518
*r_dist = distance;
572
585
view3d_validate_backbuf(vc);
574
587
index = view3d_sample_backbuf(vc, vc->mval[0], vc->mval[1]);
575
efa = index ? BM_face_at_index(vc->em->bm, index - 1) : NULL;
588
efa = index ? BM_face_at_index_find(vc->em->bm, index - 1) : NULL;
578
591
struct { float mval_fl[2]; float dist; BMFace *toFace; } data;
599
612
static int lastSelectedIndex = 0;
600
613
static BMFace *lastSelected = NULL;
602
if (lastSelected && BM_face_at_index(vc->em->bm, lastSelectedIndex) != lastSelected) {
615
if (lastSelected && BM_face_at_index_find(vc->em->bm, lastSelectedIndex) != lastSelected) {
603
616
lastSelectedIndex = 0;
604
617
lastSelected = NULL;
1859
1871
BM_ITER_MESH (efa, &iter, em->bm, BM_FACES_OF_MESH) {
1860
BM_elem_flag_set(efa, BM_ELEM_TAG, (BM_elem_flag_test(efa, BM_ELEM_SELECT) &&
1861
!BM_elem_flag_test(efa, BM_ELEM_HIDDEN)));
1872
BM_elem_flag_set(efa, BM_ELEM_TAG, BM_elem_flag_test(efa, BM_ELEM_SELECT));
1878
1889
if (BM_elem_flag_test(efa, BM_ELEM_TAG)) {
1879
1890
for (efa = BMW_begin(&walker, efa); efa; efa = BMW_step(&walker)) {
1880
1891
BM_face_select_set(bm, efa, true);
1892
BM_elem_flag_disable(efa, BM_ELEM_TAG);
1891
1905
BM_ITER_MESH (v, &iter, em->bm, BM_VERTS_OF_MESH) {
1892
if (BM_elem_flag_test(v, BM_ELEM_SELECT)) {
1893
BM_elem_flag_enable(v, BM_ELEM_TAG);
1896
BM_elem_flag_disable(v, BM_ELEM_TAG);
1906
BM_elem_flag_set(v, BM_ELEM_TAG, BM_elem_flag_test(v, BM_ELEM_SELECT));
1900
1909
BMW_init(&walker, em->bm, BMW_SHELL,
1906
1915
if (BM_elem_flag_test(v, BM_ELEM_TAG)) {
1907
1916
for (e = BMW_begin(&walker, v); e; e = BMW_step(&walker)) {
1908
1917
BM_edge_select_set(em->bm, e, true);
1918
BM_elem_flag_disable(e, BM_ELEM_TAG);
2693
2703
Object *obedit = CTX_data_edit_object(C);
2694
2704
BMEditMesh *em = BKE_editmesh_from_object(obedit);
2705
const bool select = (RNA_enum_get(op->ptr, "action") == SEL_SELECT);
2699
2706
const float randfac = RNA_float_get(op->ptr, "percent") / 100.0f;
2701
if (!RNA_boolean_get(op->ptr, "extend"))
2702
EDBM_flag_disable_all(em, BM_ELEM_SELECT);
2704
2710
if (em->selectmode & SCE_SELECT_VERTEX) {
2705
2712
BM_ITER_MESH (eve, &iter, em->bm, BM_VERTS_OF_MESH) {
2706
2713
if (!BM_elem_flag_test(eve, BM_ELEM_HIDDEN) && BLI_frand() < randfac) {
2707
BM_vert_select_set(em->bm, eve, true);
2714
BM_vert_select_set(em->bm, eve, select);
2710
EDBM_selectmode_flush(em);
2712
2718
else if (em->selectmode & SCE_SELECT_EDGE) {
2713
2720
BM_ITER_MESH (eed, &iter, em->bm, BM_EDGES_OF_MESH) {
2714
2721
if (!BM_elem_flag_test(eed, BM_ELEM_HIDDEN) && BLI_frand() < randfac) {
2715
BM_edge_select_set(em->bm, eed, true);
2722
BM_edge_select_set(em->bm, eed, select);
2718
EDBM_selectmode_flush(em);
2721
2728
BM_ITER_MESH (efa, &iter, em->bm, BM_FACES_OF_MESH) {
2722
2729
if (!BM_elem_flag_test(efa, BM_ELEM_HIDDEN) && BLI_frand() < randfac) {
2723
BM_face_select_set(em->bm, efa, true);
2730
BM_face_select_set(em->bm, efa, select);
2736
/* was EDBM_select_flush, but it over select in edge/face mode */
2726
2737
EDBM_selectmode_flush(em);
2740
EDBM_deselect_flush(em);
2729
2743
WM_event_add_notifier(C, NC_GEOM | ND_SELECT, obedit->data);
2749
2763
RNA_def_float_percentage(ot->srna, "percent", 50.f, 0.0f, 100.0f,
2750
2764
"Percent", "Percentage of elements to select randomly", 0.f, 100.0f);
2751
RNA_def_boolean(ot->srna, "extend", false, "Extend", "Extend the selection");
2765
WM_operator_properties_select_action_simple(ot, SEL_SELECT);
2754
2768
static int edbm_select_ungrouped_poll(bContext *C)
2761
2775
if ((em->selectmode & SCE_SELECT_VERTEX) == 0) {
2762
2776
CTX_wm_operator_poll_msg_set(C, "Must be in vertex selection mode");
2764
else if (obedit->defbase.first == NULL || cd_dvert_offset == -1) {
2778
else if (BLI_listbase_is_empty(&obedit->defbase) || cd_dvert_offset == -1) {
2765
2779
CTX_wm_operator_poll_msg_set(C, "No weights/vertex groups on object");
3058
3072
static int verg_radial(const void *va, const void *vb)
3060
BMEdge *e1 = *((void **)va);
3061
BMEdge *e2 = *((void **)vb);
3074
BMEdge *e_a = *((BMEdge **)va);
3075
BMEdge *e_b = *((BMEdge **)vb);
3064
a = BM_edge_face_count(e1);
3065
b = BM_edge_face_count(e2);
3067
if (a > b) return -1;
3068
if (a == b) return 0;
3069
if (a < b) return 1;
3078
a = BM_edge_face_count(e_a);
3079
b = BM_edge_face_count(e_b);
3081
if (a > b) return -1;
3082
if (a < b) return 1;
3074
static int loop_find_regions(BMEditMesh *em, int selbigger)
3086
static int loop_find_regions(BMEditMesh *em, const bool selbigger)
3076
3088
SmallHash visithash;
3078
BMEdge *e, **edges = NULL;
3079
BLI_array_declare(edges);
3090
const int edges_len = em->bm->totedgesel;
3081
3093
int count = 0, i;
3083
BLI_smallhash_init(&visithash);
3095
BLI_smallhash_init_ex(&visithash, edges_len);
3096
edges = MEM_mallocN(sizeof(*edges) * edges_len, __func__);
3085
3098
BM_ITER_MESH (f, &iter, em->bm, BM_FACES_OF_MESH) {
3086
3099
BM_elem_flag_disable(f, BM_ELEM_TAG);
3089
3103
BM_ITER_MESH (e, &iter, em->bm, BM_EDGES_OF_MESH) {
3090
3104
if (BM_elem_flag_test(e, BM_ELEM_SELECT)) {
3091
BLI_array_append(edges, e);
3092
3106
BM_elem_flag_enable(e, BM_ELEM_TAG);
3099
3113
/* sort edges by radial cycle length */
3100
qsort(edges, BLI_array_count(edges), sizeof(void *), verg_radial);
3114
qsort(edges, edges_len, sizeof(*edges), verg_radial);
3102
for (i = 0; i < BLI_array_count(edges); i++) {
3116
for (i = 0; i < edges_len; i++) {
3105
3119
BMFace **region = NULL, **region_out;