Blender V5.3
view3d_select.cc
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2008 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
8
9#include <cfloat>
10#include <cstring>
11#include <optional>
12
13#include "DNA_action_types.h"
14#include "DNA_armature_types.h"
15#include "DNA_curve_types.h"
16#include "DNA_mesh_types.h"
17#include "DNA_meshdata_types.h"
18#include "DNA_meta_types.h"
19#include "DNA_object_types.h"
21#include "DNA_scene_types.h"
22#include "DNA_tracking_types.h"
23
24#include "MEM_guardedalloc.h"
25
26#include "BLI_bitmap.hh"
27#include "BLI_function_ref.hh"
28#include "BLI_lasso_2d.hh"
29#include "BLI_listbase.hh"
30#include "BLI_math_bits.hh"
31#include "BLI_math_geom_c.hh"
32#include "BLI_rect.hh"
33#include "BLI_span.hh"
34#include "BLI_string_utf8.hh"
35#include "BLI_task.hh"
36#include "BLI_utildefines.hh"
37#include "BLI_vector.hh"
38
39#include "BLT_translation.hh"
40
41#include "BKE_action.hh"
42#include "BKE_armature.hh"
43#include "BKE_attribute.hh"
44#include "BKE_context.hh"
45#include "BKE_crazyspace.hh"
46#include "BKE_curve.hh"
47#include "BKE_curves.hh"
48#include "BKE_editmesh.hh"
49#include "BKE_grease_pencil.hh"
50#include "BKE_layer.hh"
51#include "BKE_main.hh"
52#include "BKE_mball.hh"
53#include "BKE_mesh.hh"
54#include "BKE_object.hh"
55#include "BKE_paint.hh"
56#include "BKE_tracking.hh"
57#include "BKE_workspace.hh"
58
59#include "WM_api.hh"
60#include "WM_toolsystem.hh"
61#include "WM_types.hh"
62
63#include "RNA_access.hh"
64#include "RNA_define.hh"
65#include "RNA_enum_types.hh"
66
67#include "ED_armature.hh"
68#include "ED_curve.hh"
69#include "ED_curves.hh"
70#include "ED_grease_pencil.hh"
71#include "ED_lattice.hh"
72#include "ED_mball.hh"
73#include "ED_mesh.hh"
74#include "ED_object.hh"
75#include "ED_outliner.hh"
76#include "ED_particle.hh"
77#include "ED_pointcloud.hh"
78#include "ED_screen.hh"
79#include "ED_select_utils.hh"
80#include "ED_uvedit.hh"
81
82#include "UI_interface.hh"
83#include "UI_resources.hh"
84
85#include "GPU_matrix.hh"
86#include "GPU_select.hh"
87
88#include "DEG_depsgraph.hh"
90
91#include "DRW_select_buffer.hh"
92
93#include "ANIM_armature.hh"
94
95#include "view3d_intern.hh" /* own include */
96
97// #include "BLI_time_utildefines.hh"
98
99namespace blender {
100
102
103/* -------------------------------------------------------------------- */
106
108{
109 return 75.0f * U.pixelsize;
110}
111
113{
114 /* TODO: should return whether there is valid context to continue. */
115 ViewContext vc = {};
116 vc.C = C;
117 vc.region = CTX_wm_region(C);
118 vc.bmain = CTX_data_main(C);
119 vc.depsgraph = depsgraph;
120 vc.scene = CTX_data_scene(C);
122 vc.v3d = CTX_wm_view3d(C);
123 vc.win = CTX_wm_window(C);
127 return vc;
128}
129
131{
132 vc->obact = obact;
133 /* See public docstring for rationale on checking the existing values first. */
134 if (vc->obedit) {
136 vc->obedit = obact;
137 if (vc->em) {
139 }
140 }
141}
142
144
145/* -------------------------------------------------------------------- */
148
149static bool object_deselect_all_visible(const Main &bmain,
150 const Scene *scene,
151 ViewLayer *view_layer,
152 View3D *v3d)
153{
154 bool changed = false;
155 BKE_view_layer_synced_ensure(bmain, scene, view_layer);
156 for (Base &base : *BKE_view_layer_object_bases_get(view_layer)) {
157 if (base.flag & BASE_SELECTED) {
158 if (BASE_SELECTABLE(v3d, &base)) {
160 changed = true;
161 }
162 }
163 }
164 return changed;
165}
166
167/* deselect all except b */
168static bool object_deselect_all_except(const Main &bmain,
169 const Scene *scene,
170 ViewLayer *view_layer,
171 Base *b)
172{
173 bool changed = false;
174 BKE_view_layer_synced_ensure(bmain, scene, view_layer);
175 for (Base &base : *BKE_view_layer_object_bases_get(view_layer)) {
176 if (base.flag & BASE_SELECTED) {
177 if (b != &base) {
179 changed = true;
180 }
181 }
182 }
183 return changed;
184}
185
187
188/* -------------------------------------------------------------------- */
198
202
203static void editselect_buf_cache_init(const ViewContext *vc, short select_mode)
204{
205 if (vc->obedit) {
207 *vc->bmain, vc->scene, vc->view_layer, vc->v3d);
208
209 DRW_select_buffer_context_create(vc->depsgraph, bases, select_mode);
210 }
211 else {
212 /* Use for paint modes, currently only a single object at a time. */
213 if (vc->obact) {
216 DRW_select_buffer_context_create(vc->depsgraph, {base}, select_mode);
217 }
218 }
219}
220
222{
223 MEM_SAFE_DELETE(esel->select_bitmap);
224}
225
226static void editselect_buf_cache_free_voidp(void *esel_voidp)
227{
228 editselect_buf_cache_free(static_cast<EditSelectBuf_Cache *>(esel_voidp));
229 MEM_delete(static_cast<EditSelectBuf_Cache *>(esel_voidp));
230}
231
233 const ViewContext *vc,
234 short select_mode)
235{
237 wm_userdata->data = esel;
239 wm_userdata->use_free = true;
240 editselect_buf_cache_init(vc, select_mode);
241}
242
244
245/* -------------------------------------------------------------------- */
248
250 Depsgraph *depsgraph,
251 Object *ob,
252 BMesh *bm,
253 UVSyncSelectFromMesh *uv_selctx,
254 const eSelectOp sel_op)
255{
256 BMVert *eve;
257 BMIter iter;
258 bool changed = false;
259
260 const BLI_bitmap *select_bitmap = esel->select_bitmap;
262 if (index == 0) {
263 return false;
264 }
265
266 index -= 1;
267 BM_ITER_MESH (eve, &iter, bm, BM_VERTS_OF_MESH) {
269 const bool is_select = BM_elem_flag_test(eve, BM_ELEM_SELECT);
270 const bool is_inside = BLI_BITMAP_TEST_BOOL(select_bitmap, index);
271 const int sel_op_result = ED_select_op_action_deselected(sel_op, is_select, is_inside);
272 if (sel_op_result != -1) {
273 BM_vert_select_set(bm, eve, sel_op_result);
274 if (uv_selctx) {
275 uv_selctx->vert_select_set(eve, sel_op_result);
276 }
277
278 changed = true;
279 }
280 }
281 index++;
282 }
283 return changed;
284}
285
287 Depsgraph *depsgraph,
288 Object *ob,
289 BMesh *bm,
290 UVSyncSelectFromMesh *uv_selctx,
291 const eSelectOp sel_op)
292{
293 BMEdge *eed;
294 BMIter iter;
295 bool changed = false;
296
297 const BLI_bitmap *select_bitmap = esel->select_bitmap;
299 if (index == 0) {
300 return false;
301 }
302
303 index -= 1;
304 BM_ITER_MESH (eed, &iter, bm, BM_EDGES_OF_MESH) {
306 const bool is_select = BM_elem_flag_test(eed, BM_ELEM_SELECT);
307 const bool is_inside = BLI_BITMAP_TEST_BOOL(select_bitmap, index);
308 const int sel_op_result = ED_select_op_action_deselected(sel_op, is_select, is_inside);
309 if (sel_op_result != -1) {
310 BM_edge_select_set(bm, eed, sel_op_result);
311 changed = true;
312
313 if (uv_selctx) {
314 uv_selctx->edge_select_set(eed, sel_op_result);
315 }
316 }
317 }
318 index++;
319 }
320 return changed;
321}
322
324 Depsgraph *depsgraph,
325 Object *ob,
326 BMesh *bm,
327 UVSyncSelectFromMesh *uv_selctx,
328 const eSelectOp sel_op)
329{
330 BMFace *efa;
331 BMIter iter;
332 bool changed = false;
333
334 const BLI_bitmap *select_bitmap = esel->select_bitmap;
336 if (index == 0) {
337 return false;
338 }
339
340 index -= 1;
341 BM_ITER_MESH (efa, &iter, bm, BM_FACES_OF_MESH) {
343 const bool is_select = BM_elem_flag_test(efa, BM_ELEM_SELECT);
344 const bool is_inside = BLI_BITMAP_TEST_BOOL(select_bitmap, index);
345 const int sel_op_result = ED_select_op_action_deselected(sel_op, is_select, is_inside);
346 if (sel_op_result != -1) {
347 BM_face_select_set(bm, efa, sel_op_result);
348 if (uv_selctx) {
349 uv_selctx->face_select_set(efa, sel_op_result);
350 }
351
352 changed = true;
353 }
354 }
355 index++;
356 }
357 return changed;
358}
359
360/* object mode, edbm_ prefix is confusing here, rename? */
363 const eSelectOp sel_op)
364{
365 bool changed = false;
366
367 const BLI_bitmap *select_bitmap = esel->select_bitmap;
368
369 bke::MutableAttributeAccessor attributes = mesh->attributes_for_write();
371 ".select_vert", bke::AttrDomain::Point);
372 const VArray<bool> hide_vert = *attributes.lookup_or_default<bool>(
373 ".hide_vert", bke::AttrDomain::Point, false);
374
375 for (int index = 0; index < mesh->verts_num; index++) {
376 if (!hide_vert[index]) {
377 const bool is_select = select_vert.span[index];
378 const bool is_inside = BLI_BITMAP_TEST_BOOL(select_bitmap, index);
379 const int sel_op_result = ED_select_op_action_deselected(sel_op, is_select, is_inside);
380 if (sel_op_result != -1) {
381 select_vert.span[index] = sel_op_result == 1;
382 changed = true;
383 }
384 }
385 }
386 select_vert.finish();
387 return changed;
388}
389
390/* object mode, edbm_ prefix is confusing here, rename? */
393 const eSelectOp sel_op)
394{
395 bool changed = false;
396
397 const BLI_bitmap *select_bitmap = esel->select_bitmap;
398
399 bke::MutableAttributeAccessor attributes = mesh->attributes_for_write();
401 ".select_poly", bke::AttrDomain::Face);
402 const VArray<bool> hide_poly = *attributes.lookup_or_default<bool>(
403 ".hide_poly", bke::AttrDomain::Face, false);
404
405 for (int index = 0; index < mesh->faces_num; index++) {
406 if (!hide_poly[index]) {
407 const bool is_select = select_poly.span[index];
408 const bool is_inside = BLI_BITMAP_TEST_BOOL(select_bitmap, index);
409 const int sel_op_result = ED_select_op_action_deselected(sel_op, is_select, is_inside);
410 if (sel_op_result != -1) {
411 select_poly.span[index] = sel_op_result == 1;
412 changed = true;
413 }
414 }
415 }
416 select_poly.finish();
417 return changed;
418}
419
421
422/* -------------------------------------------------------------------- */
425
444
446 const ViewContext *vc,
447 const rcti *rect,
448 const Span<int2> mcoords,
449 const eSelectOp sel_op)
450{
451 r_data->vc = vc;
452
453 r_data->rect = rect;
454 r_data->rect_fl = &r_data->_rect_fl;
455 BLI_rctf_rcti_copy(&r_data->_rect_fl, rect);
456
457 r_data->mcoords = mcoords;
458 r_data->sel_op = sel_op;
459 /* SELECT by default, but can be changed if needed (only few cases use and respect this). */
461
462 /* runtime */
463 r_data->pass = 0;
464 r_data->is_done = false;
465 r_data->is_changed = false;
466}
467
469{
471 return false;
472 }
473 if (Object *ob = CTX_data_active_object(C)) {
474 if (ob->mode & OB_MODE_EDIT) {
475 return ob->type != OB_FONT;
476 }
479 }
480 if (ob->mode & OB_MODE_WEIGHT_PAINT) {
482 }
483 }
484
485 return true;
486}
487
488/* helper also for box_select */
489static bool edge_fully_inside_rect(const rctf *rect, const float v1[2], const float v2[2])
490{
491 return BLI_rctf_isect_pt_v(rect, v1) && BLI_rctf_isect_pt_v(rect, v2);
492}
493
494static bool edge_inside_rect(const rctf *rect, const float v1[2], const float v2[2])
495{
496 int d1, d2, d3, d4;
497
498 /* check points in rect */
499 if (edge_fully_inside_rect(rect, v1, v2)) {
500 return true;
501 }
502
503 /* check points completely out rect */
504 if (v1[0] < rect->xmin && v2[0] < rect->xmin) {
505 return false;
506 }
507 if (v1[0] > rect->xmax && v2[0] > rect->xmax) {
508 return false;
509 }
510 if (v1[1] < rect->ymin && v2[1] < rect->ymin) {
511 return false;
512 }
513 if (v1[1] > rect->ymax && v2[1] > rect->ymax) {
514 return false;
515 }
516
517 /* simple check lines intersecting. */
518 d1 = (v1[1] - v2[1]) * (v1[0] - rect->xmin) + (v2[0] - v1[0]) * (v1[1] - rect->ymin);
519 d2 = (v1[1] - v2[1]) * (v1[0] - rect->xmin) + (v2[0] - v1[0]) * (v1[1] - rect->ymax);
520 d3 = (v1[1] - v2[1]) * (v1[0] - rect->xmax) + (v2[0] - v1[0]) * (v1[1] - rect->ymax);
521 d4 = (v1[1] - v2[1]) * (v1[0] - rect->xmax) + (v2[0] - v1[0]) * (v1[1] - rect->ymin);
522
523 if (d1 < 0 && d2 < 0 && d3 < 0 && d4 < 0) {
524 return false;
525 }
526 if (d1 > 0 && d2 > 0 && d3 > 0 && d4 > 0) {
527 return false;
528 }
529
530 return true;
531}
532
533static void do_lasso_select_pose__do_tag(void *user_data,
534 bPoseChannel *pchan,
535 const float screen_co_a[2],
536 const float screen_co_b[2])
537{
538 LassoSelectUserData *data = static_cast<LassoSelectUserData *>(user_data);
539 const bArmature *arm = id_cast<bArmature *>(data->vc->obact->data);
540 if (!animrig::bone_is_selectable(arm, pchan)) {
541 return;
542 }
543
544 if (BLI_rctf_isect_segment(data->rect_fl, screen_co_a, screen_co_b) &&
545 BLI_lasso_is_edge_inside(data->mcoords, UNPACK2(screen_co_a), UNPACK2(screen_co_b), INT_MAX))
546 {
548 data->is_changed = true;
549 }
550}
551static void do_lasso_tag_pose(const ViewContext *vc, const Span<int2> mcoords)
552{
554 rcti rect;
555
556 if ((vc->obact->type != OB_ARMATURE) || (vc->obact->pose == nullptr)) {
557 return;
558 }
559
560 BLI_lasso_boundbox(&rect, mcoords);
561
562 view3d_userdata_lassoselect_init(&data, vc, &rect, mcoords, static_cast<eSelectOp>(0));
563
565
566 /* Treat bones as clipped segments (no joints). */
569 &data,
571}
572
574 const Span<int2> mcoords,
575 const eSelectOp sel_op)
576{
577 View3D *v3d = vc->v3d;
578
579 bool changed = false;
580 if (SEL_OP_USE_PRE_DESELECT(sel_op)) {
581 changed |= object_deselect_all_visible(*vc->bmain, vc->scene, vc->view_layer, vc->v3d);
582 }
585 if (BASE_SELECTABLE(v3d, &base)) { /* Use this to avoid unnecessary lasso look-ups. */
586 float region_co[2];
587 const bool is_select = base.flag & BASE_SELECTED;
588 const bool is_inside = (ED_view3d_project_base(vc->region, &base, region_co) ==
591 int(region_co[0]),
592 int(region_co[1]),
593 /* Dummy value. */
594 INT_MAX);
595 const int sel_op_result = ED_select_op_action_deselected(sel_op, is_select, is_inside);
596 if (sel_op_result != -1) {
599 changed = true;
600 }
601 }
602 }
603
604 if (changed) {
607 }
608 return changed;
609}
610
615{
616 auto bases_tag_and_append_fn = [](Vector<Base *> &bases, Base *base) {
617 Object *ob = base->object;
618 bArmature *arm = id_cast<bArmature *>(ob->data);
619 for (bPoseChannel &pchan : ob->pose->chanbase) {
621 }
622 arm->id.tag |= ID_TAG_DOIT;
623 ob->id.tag &= ~ID_TAG_DOIT;
624 bases.append(base);
625 };
626
627 Vector<Base *> bases;
628
629 /* Special case, pose + weight paint mode. */
630 if (vc->obact && (vc->obact->mode & OB_MODE_WEIGHT_PAINT)) {
632 BLI_assert(ob_pose != nullptr); /* Caller is expected to check. */
633 Base *base = BKE_view_layer_base_find(vc->view_layer, ob_pose);
634 if (base) {
635 bases_tag_and_append_fn(bases, base);
636 }
637 }
638 else {
640 vc->bmain, vc->scene, vc->view_layer, vc->v3d, OB_ARMATURE, OB_MODE_POSE, base_iter)
641 {
642 bases_tag_and_append_fn(bases, base_iter);
643 }
645 }
646 return bases;
647}
648
650{
651 bool changed_multi = false;
652
653 if (SEL_OP_USE_PRE_DESELECT(sel_op)) {
654 for (const int i : bases.index_range()) {
655 Base *base_iter = bases[i];
656 Object *ob_iter = base_iter->object;
657 if (ED_pose_deselect_all(ob_iter, SEL_DESELECT, false)) {
659 changed_multi = true;
660 }
661 }
662 }
663
664 for (const int i : bases.index_range()) {
665 Base *base_iter = bases[i];
666 Object *ob_iter = base_iter->object;
667 bArmature *arm = id_cast<bArmature *>(ob_iter->data);
668
669 bool changed = false;
670 for (bPoseChannel &pchan : ob_iter->pose->chanbase) {
671 Bone *bone = pchan.bone_get(*ob_iter);
672 if ((bone->flag & BONE_UNSELECTABLE) == 0) {
673 const bool is_select = pchan.flag & POSE_SELECTED;
674 const bool is_inside = pchan.runtime.flag & POSE_RUNTIME_IN_SELECTION_AREA;
675 const int sel_op_result = ED_select_op_action_deselected(sel_op, is_select, is_inside);
676 if (sel_op_result != -1) {
677 SET_FLAG_FROM_TEST(pchan.flag, sel_op_result, POSE_SELECTED);
678 if (sel_op_result == 0) {
679 if (arm->act_bone == bone) {
680 arm->act_bone = nullptr;
681 }
682 }
683 changed = true;
684 }
685 }
686 }
687 if (changed) {
689 changed_multi = true;
690 }
691 }
692 return changed_multi;
693}
694
695static bool do_lasso_select_pose(const ViewContext *vc,
696 const Span<int2> mcoords,
697 const eSelectOp sel_op)
698{
700
701 ViewContext vc_temp = *vc;
702
703 for (const int i : bases.index_range()) {
704 Base *base_iter = bases[i];
705 Object *ob_iter = base_iter->object;
706 ED_view3d_viewcontext_init_object(&vc_temp, ob_iter);
707 do_lasso_tag_pose(&vc_temp, mcoords);
708 }
709
710 const bool changed_multi = do_pose_tag_select_op_exec(bases, sel_op);
711 if (changed_multi) {
714 }
715
716 return changed_multi;
717}
718
719static void do_lasso_select_mesh__doSelectVert(void *user_data,
720 BMVert *eve,
721 const float screen_co[2],
722 int /*index*/)
723{
724 LassoSelectUserData *data = static_cast<LassoSelectUserData *>(user_data);
725 const bool is_select = BM_elem_flag_test(eve, BM_ELEM_SELECT);
726 const bool is_inside = (BLI_rctf_isect_pt_v(data->rect_fl, screen_co) &&
728 data->mcoords, screen_co[0], screen_co[1], IS_CLIPPED));
729 const int sel_op_result = ED_select_op_action_deselected(data->sel_op, is_select, is_inside);
730 if (sel_op_result != -1) {
731 BM_vert_select_set(data->bm, eve, sel_op_result);
732 if (data->uv_selctx) {
733 data->uv_selctx->vert_select_set(eve, sel_op_result);
734 }
735
736 data->is_changed = true;
737 }
738}
745 BMEdge *eed,
746 const float screen_co_a[2],
747 const float screen_co_b[2],
748 int index)
749{
751 user_data);
752 LassoSelectUserData *data = data_for_edge->data;
753 bool is_visible = true;
754 if (data_for_edge->backbuf_offset) {
755 uint bitmap_inedx = data_for_edge->backbuf_offset + index - 1;
756 is_visible = BLI_BITMAP_TEST_BOOL(data_for_edge->esel->select_bitmap, bitmap_inedx);
757 }
758
759 const bool is_select = BM_elem_flag_test(eed, BM_ELEM_SELECT);
760 const bool is_inside =
761 (is_visible && edge_fully_inside_rect(data->rect_fl, screen_co_a, screen_co_b) &&
762 BLI_lasso_is_point_inside(data->mcoords, UNPACK2(screen_co_a), IS_CLIPPED) &&
763 BLI_lasso_is_point_inside(data->mcoords, UNPACK2(screen_co_b), IS_CLIPPED));
764 const int sel_op_result = ED_select_op_action_deselected(data->sel_op, is_select, is_inside);
765 if (sel_op_result != -1) {
766 BM_edge_select_set(data->bm, eed, sel_op_result);
767 if (data->uv_selctx) {
768 data->uv_selctx->edge_select_set(eed, sel_op_result);
769 }
770
771 data->is_done = true;
772 data->is_changed = true;
773 }
774}
776 BMEdge *eed,
777 const float screen_co_a[2],
778 const float screen_co_b[2],
779 int index)
780{
782 user_data);
783 LassoSelectUserData *data = data_for_edge->data;
784 bool is_visible = true;
785 if (data_for_edge->backbuf_offset) {
786 uint bitmap_inedx = data_for_edge->backbuf_offset + index - 1;
787 is_visible = BLI_BITMAP_TEST_BOOL(data_for_edge->esel->select_bitmap, bitmap_inedx);
788 }
789
790 const bool is_select = BM_elem_flag_test(eed, BM_ELEM_SELECT);
791 const bool is_inside = (is_visible && BLI_lasso_is_edge_inside(data->mcoords,
792 UNPACK2(screen_co_a),
793 UNPACK2(screen_co_b),
794 IS_CLIPPED));
795 const int sel_op_result = ED_select_op_action_deselected(data->sel_op, is_select, is_inside);
796 if (sel_op_result != -1) {
797 BM_edge_select_set(data->bm, eed, sel_op_result);
798 if (data->uv_selctx) {
799 data->uv_selctx->edge_select_set(eed, sel_op_result);
800 }
801
802 data->is_changed = true;
803 }
804}
805
806static void do_lasso_select_mesh__doSelectFace(void *user_data,
807 BMFace *efa,
808 const float screen_co[2],
809 int /*index*/)
810{
811 LassoSelectUserData *data = static_cast<LassoSelectUserData *>(user_data);
812 const bool is_select = BM_elem_flag_test(efa, BM_ELEM_SELECT);
813 const bool is_inside = (BLI_rctf_isect_pt_v(data->rect_fl, screen_co) &&
815 data->mcoords, screen_co[0], screen_co[1], IS_CLIPPED));
816 const int sel_op_result = ED_select_op_action_deselected(data->sel_op, is_select, is_inside);
817 if (sel_op_result != -1) {
818 BM_face_select_set(data->bm, efa, sel_op_result);
819 if (data->uv_selctx) {
820 data->uv_selctx->face_select_set(efa, sel_op_result);
821 }
822
823 data->is_changed = true;
824 }
825}
826
827static bool do_lasso_select_mesh(const ViewContext *vc,
828 wmGenericUserData *wm_userdata,
829 const Span<int2> mcoords,
830 const eSelectOp sel_op)
831{
834 rcti rect;
835
838
839 BLI_lasso_boundbox(&rect, mcoords);
840
841 view3d_userdata_lassoselect_init(&data, vc, &rect, mcoords, sel_op);
842 data.bm = bm;
843
844 if (SEL_OP_USE_PRE_DESELECT(sel_op)) {
845 if (bm->totvertsel) {
847 data.is_changed = true;
848 }
849 }
850
851 std::unique_ptr<UVSyncSelectFromMesh> uv_selctx = UVSyncSelectFromMesh::create_if_needed(*ts,
852 *bm);
853 data.uv_selctx = uv_selctx.get();
854
855 /* for non zbuf projections, don't change the GL state */
857
859
860 const bool use_zbuf = !XRAY_FLAG_ENABLED(vc->v3d);
861
862 EditSelectBuf_Cache *esel = static_cast<EditSelectBuf_Cache *>(wm_userdata->data);
863 if (use_zbuf) {
864 if (wm_userdata->data == nullptr) {
866 esel = static_cast<EditSelectBuf_Cache *>(wm_userdata->data);
868 vc->depsgraph, vc->region, vc->v3d, mcoords, &rect, nullptr);
869 }
870 }
871
872 if (ts->selectmode & SCE_SELECT_VERTEX) {
873 if (use_zbuf) {
875 esel, vc->depsgraph, vc->obedit, bm, data.uv_selctx, sel_op);
876 }
877 else {
880 }
881 }
882 if (ts->selectmode & SCE_SELECT_EDGE) {
883 /* Does both use_zbuf and non-use_zbuf versions (need screen cos for both) */
884 LassoSelectUserData_ForMeshEdge data_for_edge{};
885 data_for_edge.data = &data;
886 data_for_edge.esel = use_zbuf ? esel : nullptr;
888 vc->depsgraph, vc->obedit, SCE_SELECT_EDGE) :
889 0;
890
891 const eV3DProjTest clip_flag = V3D_PROJ_TEST_CLIP_NEAR |
892 (use_zbuf ? eV3DProjTest(0) : V3D_PROJ_TEST_CLIP_BB);
893 /* Fully inside. */
895 vc, do_lasso_select_mesh__doSelectEdge_pass0, &data_for_edge, clip_flag);
896 if (data.is_done == false) {
897 /* Fall back to partially inside.
898 * Clip content to account for edges partially behind the view. */
901 &data_for_edge,
903 }
904 }
905
906 if (ts->selectmode & SCE_SELECT_FACE) {
907 if (use_zbuf) {
909 esel, vc->depsgraph, vc->obedit, bm, data.uv_selctx, sel_op);
910 }
911 else {
914 }
915 }
916
917 if (data.is_changed) {
919 }
920
921 if (data.uv_selctx) {
922 data.uv_selctx->apply();
923 }
924
925 return data.is_changed;
926}
927
928static void do_lasso_select_curve__doSelect(void *user_data,
929 Nurb * /*nu*/,
930 BPoint *bp,
931 BezTriple *bezt,
932 int beztindex,
933 bool handles_visible,
934 const float screen_co[2])
935{
936 LassoSelectUserData *data = static_cast<LassoSelectUserData *>(user_data);
937
938 const bool is_inside = BLI_lasso_is_point_inside(
939 data->mcoords, screen_co[0], screen_co[1], IS_CLIPPED);
940 if (bp) {
941 const bool is_select = bp->f1 & SELECT;
942 const int sel_op_result = ED_select_op_action_deselected(data->sel_op, is_select, is_inside);
943 if (sel_op_result != -1) {
944 SET_FLAG_FROM_TEST(bp->f1, sel_op_result, data->select_flag);
945 data->is_changed = true;
946 }
947 }
948 else {
949 if (!handles_visible) {
950 /* can only be (beztindex == 1) here since handles are hidden */
951 const bool is_select = bezt->f2 & SELECT;
952 const int sel_op_result = ED_select_op_action_deselected(data->sel_op, is_select, is_inside);
953 if (sel_op_result != -1) {
954 SET_FLAG_FROM_TEST(bezt->f2, sel_op_result, data->select_flag);
955 }
956 bezt->f1 = bezt->f3 = bezt->f2;
957 data->is_changed = true;
958 }
959 else {
960 eBezTriple_Flag *flag_p = (&bezt->f1) + beztindex;
961 const bool is_select = *flag_p & SELECT;
962 const int sel_op_result = ED_select_op_action_deselected(data->sel_op, is_select, is_inside);
963 if (sel_op_result != -1) {
964 SET_FLAG_FROM_TEST(*flag_p, sel_op_result, data->select_flag);
965 data->is_changed = true;
966 }
967 }
968 }
969}
970
971static bool do_lasso_select_curve(const ViewContext *vc,
972 const Span<int2> mcoords,
973 const eSelectOp sel_op)
974{
975 const bool deselect_all = (sel_op == SEL_OP_SET);
977 rcti rect;
978
979 BLI_lasso_boundbox(&rect, mcoords);
980
981 view3d_userdata_lassoselect_init(&data, vc, &rect, mcoords, sel_op);
982
983 Curve *curve = id_cast<Curve *>(vc->obedit->data);
984 ListBaseT<Nurb> *nurbs = BKE_curve_editNurbs_get(curve);
985
986 /* For deselect all, items to be selected are tagged with temp flag. Clear that first. */
987 if (deselect_all) {
989 data.select_flag = BEZT_FLAG_TEMP_TAG;
990 }
991
992 ED_view3d_init_mats_rv3d(vc->obedit, vc->rv3d); /* for foreach's screen/vert projection */
994
995 /* Deselect items that were not added to selection (indicated by temp flag). */
996 if (deselect_all) {
999 }
1000
1001 if (data.is_changed) {
1002 BKE_curve_nurb_vert_active_validate(id_cast<Curve *>(vc->obedit->data));
1003 }
1004 return data.is_changed;
1005}
1006
1007static void do_lasso_select_lattice__doSelect(void *user_data,
1008 BPoint *bp,
1009 const float screen_co[2])
1010{
1011 LassoSelectUserData *data = static_cast<LassoSelectUserData *>(user_data);
1012 const bool is_select = bp->f1 & SELECT;
1013 const bool is_inside = (BLI_rctf_isect_pt_v(data->rect_fl, screen_co) &&
1015 data->mcoords, screen_co[0], screen_co[1], IS_CLIPPED));
1016 const int sel_op_result = ED_select_op_action_deselected(data->sel_op, is_select, is_inside);
1017 if (sel_op_result != -1) {
1018 SET_FLAG_FROM_TEST(bp->f1, sel_op_result, SELECT);
1019 data->is_changed = true;
1020 }
1021}
1023 const Span<int2> mcoords,
1024 const eSelectOp sel_op)
1025{
1027 rcti rect;
1028
1029 BLI_lasso_boundbox(&rect, mcoords);
1030
1031 view3d_userdata_lassoselect_init(&data, vc, &rect, mcoords, sel_op);
1032
1033 if (SEL_OP_USE_PRE_DESELECT(sel_op)) {
1034 data.is_changed |= ED_lattice_flags_set(vc->obedit, 0);
1035 }
1036
1037 ED_view3d_init_mats_rv3d(vc->obedit, vc->rv3d); /* for foreach's screen/vert projection */
1040 return data.is_changed;
1041}
1042
1043static void do_lasso_select_armature__doSelectBone(void *user_data,
1044 EditBone *ebone,
1045 const float screen_co_a[2],
1046 const float screen_co_b[2])
1047{
1048 LassoSelectUserData *data = static_cast<LassoSelectUserData *>(user_data);
1049 const bArmature *arm = id_cast<const bArmature *>(data->vc->obedit->data);
1050 if (!animrig::bone_is_visible(arm, ebone)) {
1051 return;
1052 }
1053
1054 int is_ignore_flag = 0;
1055 int is_inside_flag = 0;
1056
1057 if (screen_co_a[0] != IS_CLIPPED) {
1058 if (BLI_rcti_isect_pt(data->rect, UNPACK2(screen_co_a)) &&
1059 BLI_lasso_is_point_inside(data->mcoords, UNPACK2(screen_co_a), INT_MAX))
1060 {
1061 is_inside_flag |= BONESEL_ROOT;
1062 }
1063 }
1064 else {
1065 is_ignore_flag |= BONESEL_ROOT;
1066 }
1067
1068 if (screen_co_b[0] != IS_CLIPPED) {
1069 if (BLI_rcti_isect_pt(data->rect, UNPACK2(screen_co_b)) &&
1070 BLI_lasso_is_point_inside(data->mcoords, UNPACK2(screen_co_b), INT_MAX))
1071 {
1072 is_inside_flag |= BONESEL_TIP;
1073 }
1074 }
1075 else {
1076 is_ignore_flag |= BONESEL_TIP;
1077 }
1078
1079 if (is_ignore_flag == 0) {
1080 if (is_inside_flag == (BONE_ROOTSEL | BONE_TIPSEL) ||
1082 data->mcoords, UNPACK2(screen_co_a), UNPACK2(screen_co_b), INT_MAX))
1083 {
1084 is_inside_flag |= BONESEL_BONE;
1085 }
1086 }
1087
1088 ebone->temp.i = is_inside_flag | (is_ignore_flag >> 16);
1089}
1091 EditBone *ebone,
1092 const float screen_co_a[2],
1093 const float screen_co_b[2])
1094{
1095 LassoSelectUserData *data = static_cast<LassoSelectUserData *>(user_data);
1096 bArmature *arm = id_cast<bArmature *>(data->vc->obedit->data);
1097 if (!animrig::bone_is_visible(arm, ebone)) {
1098 return;
1099 }
1100
1101 const int is_ignore_flag = ebone->temp.i << 16;
1102 int is_inside_flag = ebone->temp.i & ~0xFFFF;
1103
1104 /* - When #BONESEL_BONE is set, there is nothing to do.
1105 * - When #BONE_ROOTSEL or #BONE_TIPSEL have been set - they take priority over bone selection.
1106 */
1107 if (is_inside_flag & (BONESEL_BONE | BONE_ROOTSEL | BONE_TIPSEL)) {
1108 return;
1109 }
1110
1111 if (BLI_lasso_is_edge_inside(data->mcoords, UNPACK2(screen_co_a), UNPACK2(screen_co_b), INT_MAX))
1112 {
1113 is_inside_flag |= BONESEL_BONE;
1114 }
1115
1116 ebone->temp.i = is_inside_flag | (is_ignore_flag >> 16);
1117}
1118
1120 const Span<int2> mcoords,
1121 const eSelectOp sel_op)
1122{
1124 rcti rect;
1125
1126 BLI_lasso_boundbox(&rect, mcoords);
1127
1128 view3d_userdata_lassoselect_init(&data, vc, &rect, mcoords, sel_op);
1129
1130 if (SEL_OP_USE_PRE_DESELECT(sel_op)) {
1132 }
1133
1134 bArmature *arm = id_cast<bArmature *>(vc->obedit->data);
1135
1137
1139
1140 /* Operate on fully visible (non-clipped) points. */
1143
1144 /* Operate on bones as segments clipped to the viewport bounds
1145 * (needed to handle bones with both points outside the view).
1146 * A separate pass is needed since clipped coordinates can't be used for selecting joints. */
1149 &data,
1151
1152 data.is_changed |= ED_armature_edit_select_op_from_tagged(arm, sel_op);
1153
1154 if (data.is_changed) {
1156 }
1157 return data.is_changed;
1158}
1159
1160static void do_lasso_select_mball__doSelectElem(void *user_data,
1161 MetaElem *ml,
1162 const float screen_co[2])
1163{
1164 LassoSelectUserData *data = static_cast<LassoSelectUserData *>(user_data);
1165 const bool is_select = ml->flag & SELECT;
1166 const bool is_inside = (BLI_rctf_isect_pt_v(data->rect_fl, screen_co) &&
1168 data->mcoords, screen_co[0], screen_co[1], INT_MAX));
1169 const int sel_op_result = ED_select_op_action_deselected(data->sel_op, is_select, is_inside);
1170 if (sel_op_result != -1) {
1171 SET_FLAG_FROM_TEST(ml->flag, sel_op_result, MB_SELECT);
1172 data->is_changed = true;
1173 }
1174}
1175static bool do_lasso_select_meta(const ViewContext *vc,
1176 const Span<int2> mcoords,
1177 const eSelectOp sel_op)
1178{
1180 rcti rect;
1181
1182 MetaBall *mb = id_cast<MetaBall *>(vc->obedit->data);
1183
1184 BLI_lasso_boundbox(&rect, mcoords);
1185
1186 view3d_userdata_lassoselect_init(&data, vc, &rect, mcoords, sel_op);
1187
1188 if (SEL_OP_USE_PRE_DESELECT(sel_op)) {
1189 data.is_changed |= BKE_mball_deselect_all(mb);
1190 }
1191
1193
1196
1197 return data.is_changed;
1198}
1199
1201 const Span<int2> mcoords,
1202 const eSelectOp sel_op)
1203{
1204 Object *object = (vc->obedit ? vc->obedit : vc->obact);
1205 const Object *ob_eval = DEG_get_evaluated(vc->depsgraph, object);
1206 const GreasePencil &grease_pencil = *id_cast<GreasePencil *>(object->data);
1208 vc->scene->toolsettings, object);
1209
1211 vc,
1212 sel_op,
1214 const IndexMask &mask,
1215 const StringRef attribute_name,
1216 IndexMaskMemory &memory) {
1219 const bke::crazyspace::GeometryDeformation deformation =
1221 ob_eval, *object, info.drawing);
1222 const IndexMask visible_handle_elements =
1224 *object,
1225 info.drawing,
1226 info.layer_index,
1227 selection_domain,
1229 memory);
1230 const float4x4 layer_to_world = layer.to_world_space(*ob_eval);
1232 layer_to_world);
1233
1235 curves,
1236 deformation,
1237 projection,
1238 mask,
1239 visible_handle_elements,
1240 selection_domain,
1241 attribute_name,
1242 mcoords,
1243 memory);
1244 });
1245}
1246
1247static bool curves_select_lasso(const ViewContext &vc,
1248 const Object *object,
1249 const Span<int2> mcoords,
1250 const eSelectOp sel_op)
1251{
1252 Curves &curves_id = *id_cast<Curves *>(object->data);
1253 bke::CurvesGeometry &curves = curves_id.geometry.wrap();
1256 const bke::AttrDomain selection_domain = bke::AttrDomain(curves_id.selection_domain);
1257 const float4x4 projection = ED_view3d_ob_project_mat_get(vc.rv3d, object);
1258 const IndexRange elements(curves.attributes().domain_size(selection_domain));
1259
1261 vc, curves, deformation, projection, elements, elements, selection_domain, mcoords, sel_op);
1262}
1263
1265 const Span<int2> mcoords,
1266 const eSelectOp sel_op)
1267{
1268 const Object *object = (vc.obedit ? vc.obedit : vc.obact);
1269 return curves_select_lasso(vc, object, mcoords, sel_op);
1270}
1271
1277 const float screen_co[2],
1278 int index)
1279{
1281 static_cast<LassoSelectUserData_ForMeshObjectVert *>(user_data);
1282 LassoSelectUserData *data = &mesh_data->lasso_data;
1283 const bool is_select = mesh_data->select_vert[index];
1284 const bool is_inside = (BLI_rctf_isect_pt_v(data->rect_fl, screen_co) &&
1286 data->mcoords, screen_co[0], screen_co[1], IS_CLIPPED));
1287 const int sel_op_result = ED_select_op_action_deselected(data->sel_op, is_select, is_inside);
1288 if (sel_op_result != -1) {
1289 mesh_data->select_vert[index] = sel_op_result == 1;
1290 data->is_changed = true;
1291 }
1292}
1294 wmGenericUserData *wm_userdata,
1295 const Span<int2> mcoords,
1296 const eSelectOp sel_op)
1297{
1298 const bool use_zbuf = !XRAY_ENABLED(vc->v3d);
1299 Object *ob = vc->obact;
1300 Mesh *mesh = id_cast<Mesh *>(ob->data);
1301 rcti rect;
1302
1303 if (mesh == nullptr || mesh->verts_num == 0) {
1304 return false;
1305 }
1306
1307 bool changed = false;
1308 if (SEL_OP_USE_PRE_DESELECT(sel_op)) {
1309 /* flush selection at the end */
1310 changed |= paintvert_deselect_all_visible(ob, SEL_DESELECT, false);
1311 }
1312
1313 BLI_lasso_boundbox(&rect, mcoords);
1314
1315 EditSelectBuf_Cache *esel = static_cast<EditSelectBuf_Cache *>(wm_userdata->data);
1316 if (use_zbuf) {
1317 if (wm_userdata->data == nullptr) {
1319 esel = static_cast<EditSelectBuf_Cache *>(wm_userdata->data);
1321 vc->depsgraph, vc->region, vc->v3d, mcoords, &rect, nullptr);
1322 }
1323 }
1324
1325 if (use_zbuf) {
1326 if (esel->select_bitmap != nullptr) {
1327 changed |= edbm_backbuf_check_and_select_verts_obmode(mesh, esel, sel_op);
1328 }
1329 }
1330 else {
1331 bke::MutableAttributeAccessor attributes = mesh->attributes_for_write();
1332 bke::SpanAttributeWriter<bool> select_vert = attributes.lookup_or_add_for_write_span<bool>(
1333 ".select_vert", bke::AttrDomain::Point);
1334
1336 data.select_vert = select_vert.span;
1337
1338 view3d_userdata_lassoselect_init(&data.lasso_data, vc, &rect, mcoords, sel_op);
1339
1341
1344
1345 changed |= data.lasso_data.is_changed;
1346 select_vert.finish();
1347 }
1348
1349 if (changed) {
1350 if (SEL_OP_CAN_DESELECT(sel_op)) {
1352 }
1355 }
1356
1357 return changed;
1358}
1360 wmGenericUserData *wm_userdata,
1361 const Span<int2> mcoords,
1362 const eSelectOp sel_op)
1363{
1364 Object *ob = vc->obact;
1365 Mesh *mesh = id_cast<Mesh *>(ob->data);
1366 rcti rect;
1367
1368 if (mesh == nullptr || mesh->faces_num == 0) {
1369 return false;
1370 }
1371
1372 bool changed = false;
1373 if (SEL_OP_USE_PRE_DESELECT(sel_op)) {
1374 /* flush selection at the end */
1375 changed |= paintface_deselect_all_visible(vc->C, ob, SEL_DESELECT, false);
1376 }
1377
1378 BLI_lasso_boundbox(&rect, mcoords);
1379
1380 EditSelectBuf_Cache *esel = static_cast<EditSelectBuf_Cache *>(wm_userdata->data);
1381 if (esel == nullptr) {
1383 esel = static_cast<EditSelectBuf_Cache *>(wm_userdata->data);
1385 vc->depsgraph, vc->region, vc->v3d, mcoords, &rect, nullptr);
1386 }
1387
1388 if (esel->select_bitmap) {
1389 changed |= edbm_backbuf_check_and_select_faces_obmode(mesh, esel, sel_op);
1390 }
1391
1392 if (changed) {
1393 paintface_flush_flags(vc->C, ob, true, false);
1394 }
1395 return changed;
1396}
1397
1399 ViewContext *vc,
1400 const Span<int2> mcoords,
1401 const eSelectOp sel_op)
1402{
1404 bool changed_multi = false;
1405
1406 wmGenericUserData wm_userdata_buf = {nullptr, nullptr, false};
1407 wmGenericUserData *wm_userdata = &wm_userdata_buf;
1408
1409 if (vc->obedit == nullptr) { /* Object Mode */
1411 changed_multi |= do_lasso_select_paintface(vc, wm_userdata, mcoords, sel_op);
1412 }
1413 else if (BKE_paint_select_vert_test(ob)) {
1414 changed_multi |= do_lasso_select_paintvert(vc, wm_userdata, mcoords, sel_op);
1415 }
1417 changed_multi |= do_lasso_select_grease_pencil(vc, mcoords, sel_op);
1418 }
1419 else if (ob && (ob->mode & OB_MODE_SCULPT_CURVES) && (ob->type == OB_CURVES)) {
1420 changed_multi = do_curves_sculpt_lasso_select(*vc, mcoords, sel_op);
1421 if (changed_multi) {
1424 }
1425 }
1426 else if (ob && (ob->mode & OB_MODE_PARTICLE_EDIT)) {
1427 changed_multi |= PE_lasso_select(C,
1428 reinterpret_cast<const int (*)[2]>(mcoords.data()),
1429 mcoords.size(),
1430 sel_op) != OPERATOR_CANCELLED;
1431 }
1432 else if (ob &&
1433 ((ob->mode & OB_MODE_POSE) | ((ob->mode & OB_MODE_WEIGHT_PAINT) &&
1435 {
1436 changed_multi |= do_lasso_select_pose(vc, mcoords, sel_op);
1437 if (changed_multi) {
1439 }
1440 }
1441 else if (ob &&
1443 {
1444 /* pass */
1445 }
1446 else {
1447 changed_multi |= do_lasso_select_objects(vc, mcoords, sel_op);
1448 if (changed_multi) {
1450 }
1451 }
1452 }
1453 else { /* Edit Mode */
1454 if (vc->obedit->type == OB_MESH) {
1456 }
1457
1459 vc->bmain, vc->scene, vc->view_layer, vc->v3d, ob->type, ob->mode, ob_iter)
1460 {
1462 bool changed = false;
1463
1464 switch (vc->obedit->type) {
1465 case OB_MESH:
1466 changed = do_lasso_select_mesh(vc, wm_userdata, mcoords, sel_op);
1467 break;
1468 case OB_CURVES_LEGACY:
1469 case OB_SURF:
1470 changed = do_lasso_select_curve(vc, mcoords, sel_op);
1471 break;
1472 case OB_LATTICE:
1473 changed = do_lasso_select_lattice(vc, mcoords, sel_op);
1474 break;
1475 case OB_ARMATURE:
1476 changed = do_lasso_select_armature(vc, mcoords, sel_op);
1477 if (changed) {
1479 }
1480 break;
1481 case OB_MBALL:
1482 changed = do_lasso_select_meta(vc, mcoords, sel_op);
1483 break;
1484 case OB_CURVES: {
1485 changed = curves_select_lasso(*vc, vc->obedit, mcoords, sel_op);
1486 if (changed) {
1489 }
1490 break;
1491 }
1492 case OB_POINTCLOUD: {
1493 PointCloud &pointcloud = *id_cast<PointCloud *>(vc->obedit->data);
1494 const float4x4 projection = ED_view3d_ob_project_mat_get(vc->rv3d, vc->obedit);
1496 pointcloud, *vc->region, projection, mcoords, sel_op);
1497 if (changed) {
1498 /* Use #ID_RECALC_GEOMETRY instead of #ID_RECALC_SELECT because it is handled as a
1499 * generic attribute for now. */
1502 }
1503 break;
1504 }
1505 case OB_GREASE_PENCIL: {
1506 changed = do_lasso_select_grease_pencil(vc, mcoords, sel_op);
1507 break;
1508 }
1509 default:
1510 BLI_assert_msg(0, "lasso select on incorrect object type");
1511 break;
1512 }
1513
1514 if (changed) {
1517 changed_multi = true;
1518 }
1519 }
1521 }
1522
1523 WM_generic_user_data_free(wm_userdata);
1524
1525 return changed_multi;
1526}
1527
1528/* lasso operator gives properties, but since old code works
1529 * with short array we convert */
1531{
1533 if (mcoords.is_empty()) {
1534 return OPERATOR_PASS_THROUGH;
1535 }
1536
1537 Depsgraph *depsgraph = CTX_data_ensure_evaluated_depsgraph(C);
1540
1541 /* setup view context for argument to callbacks */
1542 ViewContext vc = ED_view3d_viewcontext_init(C, depsgraph);
1543
1544 eSelectOp sel_op = static_cast<eSelectOp>(RNA_enum_get(op->ptr, "mode"));
1545 bool changed_multi = view3d_lasso_select(C, &vc, mcoords, sel_op);
1546
1547 if (changed_multi) {
1548 return OPERATOR_FINISHED;
1549 }
1550 return OPERATOR_CANCELLED;
1551}
1552
1554{
1555 ot->name = "Lasso Select";
1556 ot->description = "Select items using lasso selection";
1557 ot->idname = "VIEW3D_OT_select_lasso";
1558
1564
1565 /* flags */
1567
1568 /* properties */
1571}
1572
1574
1575/* -------------------------------------------------------------------- */
1578
1579/* The max number of menu items in an object select menu */
1586
1587#define SEL_MENU_SIZE 22
1589
1590/* special (crappy) operator only for menu select */
1592 PointerRNA * /*ptr*/,
1593 PropertyRNA * /*prop*/,
1594 bool *r_free)
1595{
1596 EnumPropertyItem *item = nullptr, item_tmp = {0};
1597 int totitem = 0;
1598 int i = 0;
1599
1600 /* Don't need context but avoid API doc-generation using this. */
1601 if (C == nullptr || object_mouse_select_menu_data[i].idname[0] == '\0') {
1603 }
1604
1605 for (; i < SEL_MENU_SIZE && object_mouse_select_menu_data[i].idname[0] != '\0'; i++) {
1606 item_tmp.name = object_mouse_select_menu_data[i].idname;
1607 item_tmp.identifier = object_mouse_select_menu_data[i].idname;
1608 item_tmp.value = i;
1609 item_tmp.icon = object_mouse_select_menu_data[i].icon;
1610 RNA_enum_item_add(&item, &totitem, &item_tmp);
1611 }
1612
1613 RNA_enum_item_end(&item, &totitem);
1614 *r_free = true;
1615
1616 return item;
1617}
1618
1620{
1621 const int name_index = RNA_enum_get(op->ptr, "name");
1622 const bool extend = RNA_boolean_get(op->ptr, "extend");
1623 const bool deselect = RNA_boolean_get(op->ptr, "deselect");
1624 const bool toggle = RNA_boolean_get(op->ptr, "toggle");
1625 bool changed = false;
1626 const char *name = object_mouse_select_menu_data[name_index].idname;
1627
1628 const Main *bmain = CTX_data_main(C);
1629 View3D *v3d = CTX_wm_view3d(C);
1630 Scene *scene = CTX_data_scene(C);
1631 ViewLayer *view_layer = CTX_data_view_layer(C);
1632 BKE_view_layer_synced_ensure(*bmain, scene, view_layer);
1633 const Base *oldbasact = BKE_view_layer_active_base_get(view_layer);
1634
1635 Base *basact = nullptr;
1636 CTX_DATA_BEGIN (C, Base *, base, selectable_bases) {
1637 /* This is a bit dodgy, there should only be ONE object with this name,
1638 * but library objects can mess this up. */
1639 if (STREQ(name, base->object->id.name + 2)) {
1640 basact = base;
1641 break;
1642 }
1643 }
1645
1646 if (basact == nullptr) {
1647 return OPERATOR_CANCELLED;
1648 }
1649 UNUSED_VARS_NDEBUG(v3d);
1650 BLI_assert(BASE_SELECTABLE(v3d, basact));
1651
1652 if (extend) {
1654 changed = true;
1655 }
1656 else if (deselect) {
1658 changed = true;
1659 }
1660 else if (toggle) {
1661 if (basact->flag & BASE_SELECTED) {
1662 if (basact == oldbasact) {
1664 changed = true;
1665 }
1666 }
1667 else {
1669 changed = true;
1670 }
1671 }
1672 else {
1673 object_deselect_all_except(*bmain, scene, view_layer, basact);
1675 changed = true;
1676 }
1677
1678 if (oldbasact != basact) {
1680 }
1681
1682 /* weak but ensures we activate menu again before using the enum */
1684
1685 /* undo? */
1686 if (changed) {
1687 Scene *scene = CTX_data_scene(C);
1690
1692
1693 return OPERATOR_FINISHED;
1694 }
1695 return OPERATOR_CANCELLED;
1696}
1697
1699{
1700 if (RNA_boolean_get(ptr, "deselect")) {
1701 return CTX_IFACE_(BLT_I18NCONTEXT_OPERATOR_DEFAULT, "Deselect Object");
1702 }
1703 if (RNA_boolean_get(ptr, "toggle")) {
1704 return CTX_IFACE_(BLT_I18NCONTEXT_OPERATOR_DEFAULT, "Toggle Object Selection");
1705 }
1706 return CTX_IFACE_(BLT_I18NCONTEXT_OPERATOR_DEFAULT, "Select Object");
1707}
1708
1710{
1711 PropertyRNA *prop;
1712
1713 /* identifiers */
1714 ot->name = "Select Menu";
1715 ot->description = "Menu object selection";
1716 ot->idname = "VIEW3D_OT_select_menu";
1717
1718 /* API callbacks. */
1719 ot->invoke = WM_menu_invoke;
1722
1723 /* flags */
1725
1726 /* #Object.id.name to select (dynamic enum). */
1727 prop = RNA_def_enum(ot->srna, "name", rna_enum_dummy_NULL_items, 0, "Object Name", "");
1730 ot->prop = prop;
1731
1732 prop = RNA_def_boolean(ot->srna, "extend", false, "Extend", "");
1734 prop = RNA_def_boolean(ot->srna, "deselect", false, "Deselect", "");
1736 prop = RNA_def_boolean(ot->srna, "toggle", false, "Toggle", "");
1738}
1739
1744 const ViewContext *vc,
1745 const Span<GPUSelectResult> hit_results,
1746 const int mval[2],
1747 const SelectPick_Params &params,
1748 Base **r_basact)
1749{
1750
1751 const float mval_fl[2] = {float(mval[0]), float(mval[1])};
1752 /* Distance from object center to use for selection. */
1753 const float dist_threshold_sq = square_f(15 * U.pixelsize);
1754 int base_count = 0;
1755
1756 struct BaseRefWithDepth {
1757 BaseRefWithDepth *next, *prev;
1758 Base *base;
1760 uint depth_id;
1761 };
1762 ListBaseT<BaseRefWithDepth> base_ref_list = {nullptr, nullptr};
1763
1764 /* handle base->object->select_id */
1765 CTX_DATA_BEGIN (C, Base *, base, selectable_bases) {
1766 bool ok = false;
1767 uint depth_id;
1768
1769 /* two selection methods, the CTRL select uses max dist of 15 */
1770 if (!hit_results.is_empty()) {
1771 for (const GPUSelectResult &hit_result : hit_results) {
1772 /* index was converted */
1773 if (base->object->runtime->select_id == (hit_result.id & ~0xFFFF0000)) {
1774 ok = true;
1775 depth_id = hit_result.depth;
1776 break;
1777 }
1778 }
1779 }
1780 else {
1781 float region_co[2];
1782 if (ED_view3d_project_base(vc->region, base, region_co) == V3D_PROJ_RET_OK) {
1783 const float dist_test_sq = len_squared_v2v2(mval_fl, region_co);
1784 if (dist_test_sq < dist_threshold_sq) {
1785 ok = true;
1786 /* Match GPU depth logic, as the float is always positive, it can be sorted as an int. */
1787 depth_id = float_as_uint(dist_test_sq);
1788 }
1789 }
1790 }
1791
1792 if (ok) {
1793 base_count++;
1794 BaseRefWithDepth *base_ref = MEM_new_zeroed<BaseRefWithDepth>(__func__);
1795 base_ref->base = base;
1796 base_ref->depth_id = depth_id;
1797 BLI_addtail(&base_ref_list, static_cast<void *>(base_ref));
1798 }
1799 }
1801
1802 *r_basact = nullptr;
1803
1804 if (base_count == 0) {
1805 return false;
1806 }
1807 if (base_count == 1) {
1808 Base *base = (base_ref_list.first())->base;
1809 base_ref_list.free_no_destruct();
1810 *r_basact = base;
1811 return false;
1812 }
1813
1814 /* Sort by depth or distance to cursor. */
1815 BLI_listbase_sort(&base_ref_list, [](const void *a, const void *b) {
1816 return int(static_cast<const BaseRefWithDepth *>(a)->depth_id >
1817 static_cast<const BaseRefWithDepth *>(b)->depth_id);
1818 });
1819
1820 while (base_count > SEL_MENU_SIZE) {
1821 BLI_freelinkN(&base_ref_list, base_ref_list.last());
1822 base_count -= 1;
1823 }
1824
1825 /* UI, full in static array values that we later use in an enum function */
1826
1828
1829 for (const auto [i, base_ref] : base_ref_list.enumerate()) {
1830 Base *base = base_ref.base;
1831 Object *ob = base->object;
1832 const char *name = ob->id.name + 2;
1833
1836 }
1837
1838 wmOperatorType *ot = WM_operatortype_find("VIEW3D_OT_select_menu", false);
1839
1841 RNA_boolean_set(&ptr, "extend", params.sel_op == SEL_OP_ADD);
1842 RNA_boolean_set(&ptr, "deselect", params.sel_op == SEL_OP_SUB);
1843 RNA_boolean_set(&ptr, "toggle", params.sel_op == SEL_OP_XOR);
1846
1847 base_ref_list.free_no_destruct();
1848 return true;
1849}
1850
1852{
1853 const int name_index = RNA_enum_get(op->ptr, "name");
1854
1855 SelectPick_Params params{};
1857
1858 View3D *v3d = CTX_wm_view3d(C);
1859 const Main *bmain = CTX_data_main(C);
1860 Scene *scene = CTX_data_scene(C);
1861 ViewLayer *view_layer = CTX_data_view_layer(C);
1862 BKE_view_layer_synced_ensure(*bmain, scene, view_layer);
1863 const Base *oldbasact = BKE_view_layer_active_base_get(view_layer);
1864
1865 Base *basact = object_mouse_select_menu_data[name_index].base_ptr;
1866
1867 if (basact == nullptr) {
1868 return OPERATOR_CANCELLED;
1869 }
1870
1871 BLI_assert(BASE_SELECTABLE(v3d, basact));
1872
1873 if (basact->object->mode & OB_MODE_EDIT) {
1874 EditBone *ebone = static_cast<EditBone *>(object_mouse_select_menu_data[name_index].item_ptr);
1875 ED_armature_edit_select_pick_bone(C, basact, ebone, BONE_SELECTED, params);
1876 }
1877 else {
1878 bPoseChannel *pchan = static_cast<bPoseChannel *>(
1881 *bmain, scene, view_layer, v3d, basact->object, pchan, params);
1882 }
1883
1884 /* Weak but ensures we activate the menu again before using the enum. */
1886
1887 /* We make the armature selected:
1888 * Not-selected active object in pose-mode won't work well for tools. */
1890
1893
1894 /* In weight-paint, we use selected bone to select vertex-group,
1895 * so don't switch to new active object. */
1896 if (oldbasact) {
1897 if (basact->object->mode & OB_MODE_EDIT) {
1898 /* Pass. */
1899 }
1900 else if (oldbasact->object->mode & OB_MODE_ALL_WEIGHT_PAINT) {
1901 /* Prevent activating.
1902 * Selection causes this to be considered the 'active' pose in weight-paint mode.
1903 * Eventually this limitation may be removed.
1904 * For now, de-select all other pose objects deforming this mesh. */
1905 ED_armature_pose_select_in_wpaint_mode(*bmain, scene, view_layer, basact);
1906 }
1907 else {
1908 if (oldbasact != basact) {
1910 }
1911 }
1912 }
1913
1914 /* Undo? */
1918
1920
1921 return OPERATOR_FINISHED;
1922}
1923
1925{
1926 PropertyRNA *prop;
1927
1928 /* identifiers */
1929 ot->name = "Select Menu";
1930 ot->description = "Menu bone selection";
1931 ot->idname = "VIEW3D_OT_bone_select_menu";
1932
1933 /* API callbacks. */
1934 ot->invoke = WM_menu_invoke;
1936
1937 /* flags */
1939
1940 /* #Object.id.name to select (dynamic enum). */
1941 prop = RNA_def_enum(ot->srna, "name", rna_enum_dummy_NULL_items, 0, "Bone Name", "");
1944 ot->prop = prop;
1945
1946 prop = RNA_def_boolean(ot->srna, "extend", false, "Extend", "");
1948 prop = RNA_def_boolean(ot->srna, "deselect", false, "Deselect", "");
1950 prop = RNA_def_boolean(ot->srna, "toggle", false, "Toggle", "");
1952}
1953
1958 const Span<GPUSelectResult> hit_results,
1959 const bool is_editmode,
1960 const SelectPick_Params &params)
1961{
1962 int bone_count = 0;
1963
1964 struct BoneRefWithDepth {
1965 BoneRefWithDepth *next, *prev;
1966 Base *base;
1967 union {
1968 EditBone *ebone;
1969 bPoseChannel *pchan;
1970 void *bone_ptr;
1971 };
1973 uint depth_id;
1974 };
1975 ListBaseT<BoneRefWithDepth> bone_ref_list = {nullptr, nullptr};
1976
1977 Set<void *> added_bones;
1978
1979 /* Select logic taken from #ed_armature_pick_bone_from_selectbuffer_impl
1980 * in `armature_select.cc`. */
1981 for (const GPUSelectResult &hit_result : hit_results) {
1982 void *bone_ptr = nullptr;
1983 Base *bone_base = nullptr;
1984 uint select_id = hit_result.id;
1985
1986 if (!(select_id & BONESEL_ANY)) {
1987 /* To avoid including objects in selection. */
1988 continue;
1989 }
1990
1991 select_id &= ~BONESEL_ANY;
1992 const uint hit_object = select_id & 0xFFFF;
1993
1994 /* Find the hit bone base (armature object). */
1995 CTX_DATA_BEGIN (C, Base *, base, selectable_bases) {
1996 if (base->object->runtime->select_id == hit_object) {
1997 bone_base = base;
1998 break;
1999 }
2000 }
2002
2003 if (!bone_base) {
2004 continue;
2005 }
2006
2007 /* Determine what the current bone is */
2008 if (is_editmode) {
2009 const uint hit_bone = (select_id & ~BONESEL_ANY) >> 16;
2010 bArmature *arm = id_cast<bArmature *>(bone_base->object->data);
2011 EditBone *ebone = static_cast<EditBone *>(BLI_findlink(arm->edbo, hit_bone));
2012 if (ebone && !(ebone->flag & BONE_UNSELECTABLE)) {
2013 bone_ptr = ebone;
2014 }
2015 }
2016 else {
2017 const uint hit_bone = (select_id & ~BONESEL_ANY) >> 16;
2018 bPoseChannel *pchan = static_cast<bPoseChannel *>(
2019 BLI_findlink(&bone_base->object->pose->chanbase, hit_bone));
2020 if (pchan && !(pchan->bone_get(*bone_base->object)->flag & BONE_UNSELECTABLE)) {
2021 bone_ptr = pchan;
2022 }
2023 }
2024
2025 if (!bone_ptr) {
2026 continue;
2027 }
2028 /* We can hit a bone multiple times, so make sure we are not adding an already included bone
2029 * to the list. */
2030 const bool is_duplicate_bone = added_bones.contains(bone_ptr);
2031
2032 if (!is_duplicate_bone) {
2033 bone_count++;
2034 BoneRefWithDepth *bone_ref = MEM_new_zeroed<BoneRefWithDepth>(__func__);
2035 bone_ref->base = bone_base;
2036 bone_ref->bone_ptr = bone_ptr;
2037 bone_ref->depth_id = hit_result.depth;
2038 BLI_addtail(&bone_ref_list, static_cast<void *>(bone_ref));
2039
2040 added_bones.add(bone_ptr);
2041 }
2042 }
2043
2044 if (bone_count == 0) {
2045 return false;
2046 }
2047 if (bone_count == 1) {
2048 bone_ref_list.free_no_destruct();
2049 return false;
2050 }
2051
2052 /* Sort by depth or distance to cursor. */
2053 BLI_listbase_sort(&bone_ref_list, [](const void *a, const void *b) {
2054 return int(static_cast<const BoneRefWithDepth *>(a)->depth_id >
2055 static_cast<const BoneRefWithDepth *>(b)->depth_id);
2056 });
2057
2058 while (bone_count > SEL_MENU_SIZE) {
2059 BLI_freelinkN(&bone_ref_list, bone_ref_list.last());
2060 bone_count -= 1;
2061 }
2062
2063 /* UI, full in static array values that we later use in an enum function */
2065
2066 for (const auto [i, bone_ref] : bone_ref_list.enumerate()) {
2067 char *name;
2068
2069 object_mouse_select_menu_data[i].base_ptr = bone_ref.base;
2070
2071 if (is_editmode) {
2072 EditBone *ebone = bone_ref.ebone;
2073 object_mouse_select_menu_data[i].item_ptr = static_cast<void *>(ebone);
2074 name = ebone->name;
2075 }
2076 else {
2077 bPoseChannel *pchan = bone_ref.pchan;
2078 object_mouse_select_menu_data[i].item_ptr = static_cast<void *>(pchan);
2079 name = pchan->name;
2080 }
2081
2083 object_mouse_select_menu_data[i].icon = ICON_BONE_DATA;
2084 }
2085
2086 wmOperatorType *ot = WM_operatortype_find("VIEW3D_OT_bone_select_menu", false);
2087
2089 RNA_boolean_set(&ptr, "extend", params.sel_op == SEL_OP_ADD);
2090 RNA_boolean_set(&ptr, "deselect", params.sel_op == SEL_OP_SUB);
2091 RNA_boolean_set(&ptr, "toggle", params.sel_op == SEL_OP_XOR);
2094
2095 bone_ref_list.free_no_destruct();
2096 return true;
2097}
2098
2099static bool selectbuffer_has_bones(const Span<GPUSelectResult> hit_results)
2100{
2101 for (const GPUSelectResult &hit_result : hit_results) {
2102 if (ED_armature_selectresult_is_bone(hit_result)) {
2103 return true;
2104 }
2105 }
2106 return false;
2107}
2108
2114{
2115 for (const GPUSelectResult &hit_result : hit_results) {
2116 if (hit_result.id & 0xFFFF0000) {
2117 return true;
2118 }
2119 }
2120 return false;
2121}
2122
2123/* utility function for mixed_bones_object_selectbuffer */
2124static int selectbuffer_ret_hits_15(MutableSpan<GPUSelectResult> /*hit_results*/, const int hits15)
2125{
2126 return hits15;
2127}
2128
2130 const int hits15,
2131 const int hits9)
2132{
2133 const int ofs = hits15;
2134 /* Shift results to beginning. */
2135 hit_results.slice(0, hits9).copy_from(hit_results.slice(ofs, hits9));
2136 return hits9;
2137}
2138
2140 const int hits15,
2141 const int hits9,
2142 const int hits5)
2143{
2144 const int ofs = hits15 + hits9;
2145 /* Shift results to beginning. */
2146 hit_results.slice(0, hits5).copy_from(hit_results.slice(ofs, hits5));
2147 return hits5;
2148}
2149
2159 GPUSelectBuffer *buffer,
2160 const int mval[2],
2161 eV3DSelectObjectFilter select_filter,
2162 bool do_nearest,
2163 bool do_nearest_xray,
2164 const bool do_material_slot_selection)
2165{
2166 rcti rect;
2167 int hits15, hits9 = 0, hits5 = 0;
2168 bool has_bones15 = false, has_bones9 = false, has_bones5 = false;
2169
2171 int hits = 0;
2172
2173 if (do_nearest_xray) {
2174 select_mode = VIEW3D_SELECT_PICK_ALL;
2175 }
2176
2177 /* we _must_ end cache before return, use 'goto finally' */
2179
2180 GPUSelectStorage &storage = buffer->storage;
2181 BLI_rcti_init_pt_radius(&rect, mval, 14);
2182 hits15 = view3d_gpu_select_ex(vc,
2183 buffer,
2184 &rect,
2185 select_mode,
2186 select_filter,
2188 do_material_slot_selection);
2189 if (hits15 == 1) {
2190 hits = selectbuffer_ret_hits_15(storage.as_mutable_span(), hits15);
2191 goto finally;
2192 }
2193 else if (hits15 > 0) {
2194 int ofs;
2195 has_bones15 = selectbuffer_has_bones(storage.as_span().slice(0, hits15));
2196
2197 ofs = hits15;
2198 BLI_rcti_init_pt_radius(&rect, mval, 9);
2199 hits9 = view3d_gpu_select(vc, buffer, &rect, select_mode, select_filter, eV3DSelectShape::BOX);
2200 if (hits9 == 1) {
2201 hits = selectbuffer_ret_hits_9(storage.as_mutable_span(), hits15, hits9);
2202 goto finally;
2203 }
2204 else if (hits9 > 0) {
2205 has_bones9 = selectbuffer_has_bones(storage.as_span().slice(ofs, hits9));
2206
2207 ofs += hits9;
2208 BLI_rcti_init_pt_radius(&rect, mval, 5);
2209 hits5 = view3d_gpu_select(
2210 vc, buffer, &rect, select_mode, select_filter, eV3DSelectShape::BOX);
2211 if (hits5 == 1) {
2212 hits = selectbuffer_ret_hits_5(storage.as_mutable_span(), hits15, hits9, hits5);
2213 goto finally;
2214 }
2215 else if (hits5 > 0) {
2216 has_bones5 = selectbuffer_has_bones(storage.as_span().slice(ofs, hits5));
2217 }
2218 }
2219
2220 if (has_bones5) {
2221 hits = selectbuffer_ret_hits_5(storage.as_mutable_span(), hits15, hits9, hits5);
2222 goto finally;
2223 }
2224 else if (has_bones9) {
2225 hits = selectbuffer_ret_hits_9(storage.as_mutable_span(), hits15, hits9);
2226 goto finally;
2227 }
2228 else if (has_bones15) {
2229 hits = selectbuffer_ret_hits_15(storage.as_mutable_span(), hits15);
2230 goto finally;
2231 }
2232
2233 if (hits5 > 0) {
2234 hits = selectbuffer_ret_hits_5(storage.as_mutable_span(), hits15, hits9, hits5);
2235 goto finally;
2236 }
2237 else if (hits9 > 0) {
2238 hits = selectbuffer_ret_hits_9(storage.as_mutable_span(), hits15, hits9);
2239 goto finally;
2240 }
2241 else {
2242 hits = selectbuffer_ret_hits_15(storage.as_mutable_span(), hits15);
2243 goto finally;
2244 }
2245 }
2246
2247finally:
2249 return hits;
2250}
2251
2253 GPUSelectBuffer *buffer,
2254 const int mval[2],
2255 eV3DSelectObjectFilter select_filter,
2256 bool use_cycle,
2257 bool enumerate,
2258 bool *r_do_nearest)
2259{
2260 bool do_nearest = false;
2261 View3D *v3d = vc->v3d;
2262
2263 /* define if we use solid nearest select or not */
2264 if (use_cycle) {
2265 /* Update the coordinates (even if the return value isn't used). */
2266 const bool has_motion = WM_cursor_test_motion_and_update(mval);
2267 if (!XRAY_ACTIVE(v3d)) {
2268 do_nearest = has_motion;
2269 }
2270 }
2271 else {
2272 if (!XRAY_ACTIVE(v3d)) {
2273 do_nearest = true;
2274 }
2275 }
2276
2277 if (r_do_nearest) {
2278 *r_do_nearest = do_nearest;
2279 }
2280
2281 do_nearest = do_nearest && !enumerate;
2282
2284 vc, buffer, mval, select_filter, do_nearest, true, false);
2285
2286 return hits;
2287}
2288
2297 const GPUSelectBuffer &buffer,
2298 int hits,
2299 bool do_nearest,
2300 bool has_bones,
2301 bool do_bones_get_priotity,
2302 int *r_select_id_subelem)
2303{
2304 Scene *scene = vc->scene;
2305 ViewLayer *view_layer = vc->view_layer;
2306 View3D *v3d = vc->v3d;
2307 int a;
2308
2309 bool found = false;
2310 int select_id = 0;
2311 int select_id_subelem = 0;
2312
2313 if (do_nearest) {
2314 uint min = 0xFFFFFFFF;
2315 int hit_index = -1;
2316
2317 if (has_bones && do_bones_get_priotity) {
2318 /* we skip non-bone hits */
2319 for (a = 0; a < hits; a++) {
2320 if (min > buffer.storage[a].depth && (buffer.storage[a].id & 0xFFFF0000)) {
2321 min = buffer.storage[a].depth;
2322 hit_index = a;
2323 }
2324 }
2325 }
2326 else {
2327
2328 for (a = 0; a < hits; a++) {
2329 /* Any object. */
2330 if (min > buffer.storage[a].depth) {
2331 min = buffer.storage[a].depth;
2332 hit_index = a;
2333 }
2334 }
2335 }
2336
2337 if (hit_index != -1) {
2338 select_id = buffer.storage[hit_index].id & 0xFFFF;
2339 select_id_subelem = (buffer.storage[hit_index].id & 0xFFFF0000) >> 16;
2340 found = true;
2341 /* No need to set `min` to `buffer.storage[hit_index].depth`, it's not used from now on. */
2342 }
2343 }
2344 else {
2345
2346 GPUSelectStorage buffer_sorted = buffer.storage;
2347 {
2348 buffer_sorted.resize(hits);
2349 /* Remove non-bone objects. */
2350 if (has_bones && do_bones_get_priotity) {
2351 /* Loop backwards to reduce re-ordering. */
2352 for (a = hits - 1; a >= 0; a--) {
2353 if ((buffer_sorted[a].id & 0xFFFF0000) == 0) {
2354 buffer_sorted[a] = buffer_sorted[--hits];
2355 }
2356 }
2357 }
2358 qsort(buffer_sorted.data(), hits, sizeof(GPUSelectResult), gpu_select_buffer_depth_id_cmp);
2359 }
2360
2361 int hit_index = -1;
2362
2363 /* It's possible there are no hits (all objects contained bones). */
2364 if (hits > 0) {
2365 /* Only exclude active object when it is selected. */
2366 BKE_view_layer_synced_ensure(*vc->bmain, scene, view_layer);
2367 Base *base = BKE_view_layer_active_base_get(view_layer);
2368 if (base && (base->flag & BASE_SELECTED)) {
2369 const int select_id_active = base->object->runtime->select_id;
2370 for (int i_next = 0, i_prev = hits - 1; i_next < hits; i_prev = i_next++) {
2371 if ((select_id_active == (buffer_sorted[i_prev].id & 0xFFFF)) &&
2372 (select_id_active != (buffer_sorted[i_next].id & 0xFFFF)))
2373 {
2374 hit_index = i_next;
2375 break;
2376 }
2377 }
2378 }
2379
2380 /* When the active object is unselected or not in `buffer`, use the nearest. */
2381 if (hit_index == -1) {
2382 /* Just pick the nearest. */
2383 hit_index = 0;
2384 }
2385 }
2386
2387 if (hit_index != -1) {
2388 select_id = buffer_sorted[hit_index].id & 0xFFFF;
2389 select_id_subelem = (buffer_sorted[hit_index].id & 0xFFFF0000) >> 16;
2390 found = true;
2391 }
2392 }
2393
2394 Base *basact = nullptr;
2395 if (found) {
2396 BKE_view_layer_synced_ensure(*vc->bmain, scene, view_layer);
2397 for (Base &base : *BKE_view_layer_object_bases_get(view_layer)) {
2398 if (has_bones ? BASE_VISIBLE(v3d, &base) : BASE_SELECTABLE(v3d, &base)) {
2399 if (base.object->runtime->select_id == select_id) {
2400 basact = &base;
2401 break;
2402 }
2403 }
2404 }
2405
2406 if (basact && r_select_id_subelem) {
2407 *r_select_id_subelem = select_id_subelem;
2408 }
2409 }
2410
2411 return basact;
2412}
2413
2414static Base *mouse_select_object_center(const ViewContext *vc, Base *startbase, const int mval[2])
2415{
2416 ARegion *region = vc->region;
2417 Scene *scene = vc->scene;
2418 ViewLayer *view_layer = vc->view_layer;
2419 View3D *v3d = vc->v3d;
2420
2421 BKE_view_layer_synced_ensure(*vc->bmain, scene, view_layer);
2422 Base *oldbasact = BKE_view_layer_active_base_get(view_layer);
2423
2424 const float mval_fl[2] = {float(mval[0]), float(mval[1])};
2425 float dist = ED_view3d_select_dist_px() * 1.3333f;
2426 Base *basact = nullptr;
2427
2428 /* Put the active object at a disadvantage to cycle through other objects. */
2429 const float penalty_dist = 10.0f * UI_SCALE_FAC;
2430 Base *base = startbase;
2431 while (base) {
2432 if (BASE_SELECTABLE(v3d, base)) {
2433 float screen_co[2];
2435 base->object->object_to_world().location(),
2436 screen_co,
2438 {
2439 float dist_test = len_manhattan_v2v2(mval_fl, screen_co);
2440 if (base == oldbasact) {
2441 dist_test += penalty_dist;
2442 }
2443 if (dist_test < dist) {
2444 dist = dist_test;
2445 basact = base;
2446 }
2447 }
2448 }
2449 base = base->next;
2450
2451 if (base == nullptr) {
2452 base = BKE_view_layer_object_bases_get(view_layer)->first();
2453 }
2454 if (base == startbase) {
2455 break;
2456 }
2457 }
2458 return basact;
2459}
2460
2462 const int mval[2],
2463 int *r_material_slot)
2464{
2465 Depsgraph *depsgraph = CTX_data_ensure_evaluated_depsgraph(C);
2466 Base *basact = nullptr;
2467 GPUSelectBuffer buffer;
2468
2469 /* setup view context for argument to callbacks */
2472
2473 const ViewContext vc = ED_view3d_viewcontext_init(C, depsgraph);
2474
2475 const bool do_nearest = !XRAY_ACTIVE(vc.v3d);
2476 const bool do_material_slot_selection = r_material_slot != nullptr;
2477 const int hits = mixed_bones_object_selectbuffer(
2478 &vc, &buffer, mval, VIEW3D_SELECT_FILTER_NOP, do_nearest, false, do_material_slot_selection);
2479
2480 if (hits > 0) {
2481 const bool has_bones = (r_material_slot == nullptr) &&
2482 selectbuffer_has_bones(buffer.storage.as_span().slice(0, hits));
2483 basact = mouse_select_eval_buffer(
2484 &vc, buffer, hits, do_nearest, has_bones, true, r_material_slot);
2485 }
2486
2487 return basact;
2488}
2489
2491{
2492 return ed_view3d_give_base_under_cursor_ex(C, mval, nullptr);
2493}
2494
2496{
2498 if (base) {
2499 return base->object;
2500 }
2501 return nullptr;
2502}
2503
2505 const int mval[2],
2506 int *r_material_slot)
2507{
2508 Base *base = ed_view3d_give_base_under_cursor_ex(C, mval, r_material_slot);
2509 if (base) {
2510 return base->object;
2511 }
2512 return nullptr;
2513}
2514
2516{
2517 return ED_view3d_give_object_under_cursor(C, mval) != nullptr;
2518}
2519
2521{
2522 for (MovieTrackingObject &tracking_object : tracking->objects) {
2523 for (MovieTrackingTrack &track : tracking_object.tracks) {
2525 }
2526 }
2527}
2528
2530 Scene *scene,
2531 Base *basact,
2532 MovieClip *clip,
2533 const GPUSelectBuffer &buffer,
2534 const short hits,
2535 const SelectPick_Params &params)
2536{
2537 bool changed = false;
2538 bool found = false;
2539
2540 MovieTracking *tracking = &clip->tracking;
2541 ListBaseT<MovieTrackingTrack> *tracksbase = nullptr;
2542 MovieTrackingTrack *track = nullptr;
2543
2544 for (int i = 0; i < hits; i++) {
2545 const int select_id = buffer.storage[i].id;
2546
2547 /* If there's bundles in buffer select bundles first,
2548 * so non-camera elements should be ignored in buffer. */
2549 if (basact->object->runtime->select_id != (select_id & 0xFFFF)) {
2550 continue;
2551 }
2552 /* Index of bundle is 1<<16-based. if there's no "bone" index
2553 * in height word, this buffer value belongs to camera. not to bundle. */
2554 if ((select_id & 0xFFFF0000) == 0) {
2555 continue;
2556 }
2557
2559 &clip->tracking, select_id >> 16, &tracksbase);
2560 found = true;
2561 break;
2562 }
2563
2564 /* Note `params.deselect_all` is ignored for tracks as in this case
2565 * all objects will be de-selected (not tracks). */
2566 if (params.sel_op == SEL_OP_SET) {
2567 if ((found && params.select_passthrough) && TRACK_SELECTED(track)) {
2568 found = false;
2569 }
2570 else if (found /* `|| params.deselect_all` */) {
2571 /* Deselect everything. */
2572 deselect_all_tracks(tracking);
2573 changed = true;
2574 }
2575 }
2576
2577 if (found) {
2578 switch (params.sel_op) {
2579 case SEL_OP_ADD: {
2580 BKE_tracking_track_select(tracksbase, track, TRACK_AREA_ALL, true);
2581 break;
2582 }
2583 case SEL_OP_SUB: {
2585 break;
2586 }
2587 case SEL_OP_XOR: {
2588 if (TRACK_SELECTED(track)) {
2590 }
2591 else {
2592 BKE_tracking_track_select(tracksbase, track, TRACK_AREA_ALL, true);
2593 }
2594 break;
2595 }
2596 case SEL_OP_SET: {
2597 BKE_tracking_track_select(tracksbase, track, TRACK_AREA_ALL, false);
2598 break;
2599 }
2600 case SEL_OP_AND: {
2601 BLI_assert_unreachable(); /* Doesn't make sense for picking. */
2602 break;
2603 }
2604 }
2605
2610
2611 changed = true;
2612 }
2613
2614 return changed || found;
2615}
2616
2630 const int mval[2],
2631 const SelectPick_Params &params,
2632 const bool center,
2633 const bool enumerate,
2634 const bool object_only)
2635{
2636 Depsgraph *depsgraph = CTX_data_ensure_evaluated_depsgraph(C);
2637 /* Setup view context for argument to callbacks. */
2638 ViewContext vc = ED_view3d_viewcontext_init(C, depsgraph);
2639
2640 const Main *bmain = CTX_data_main(C);
2641 Scene *scene = vc.scene;
2642 View3D *v3d = vc.v3d;
2643
2644 /* Menu activation may find a base to make active (if it only finds a single item to select). */
2645 Base *basact_override = nullptr;
2646
2647 const bool is_obedit = (vc.obedit != nullptr);
2648 if (object_only) {
2649 /* Signal for #view3d_gpu_select to skip edit-mode objects. */
2650 vc.obedit = nullptr;
2651 }
2652
2653 /* Set for GPU depth buffer picking, leave null when selecting by center. */
2654 struct GPUData {
2655 GPUSelectBuffer buffer;
2656 int hits;
2657 bool do_nearest;
2658 bool has_bones;
2659 bool has_sub_object;
2660 } *gpu = nullptr;
2661
2662 /* First handle menu selection, early exit if a menu opens
2663 * since this takes ownership of the selection action.
2664 *
2665 * Even when there is no menu `basact_override` may be set to avoid having to re-find
2666 * the item under the cursor. */
2667
2668 if (center == false) {
2669 gpu = MEM_new<GPUData>(__func__);
2670 gpu->do_nearest = false;
2671 gpu->has_bones = false;
2672 gpu->has_sub_object = false;
2673
2674 /* If objects have pose-mode set, the bones are in the same selection buffer. */
2675 const eV3DSelectObjectFilter select_filter =
2676 ((object_only == false) ? ED_view3d_select_filter_from_mode(scene, v3d, vc.obact) :
2679 &vc, &gpu->buffer, mval, select_filter, true, enumerate, &gpu->do_nearest);
2680 gpu->has_bones = (object_only && gpu->hits > 0) ?
2681 false :
2682 selectbuffer_has_bones(gpu->buffer.storage.as_span().slice(0, gpu->hits));
2683 gpu->has_sub_object = (object_only && gpu->hits > 0) ?
2684 false :
2686 gpu->buffer.storage.as_span().slice(0, gpu->hits));
2687 }
2688
2689 /* First handle menu selection, early exit when a menu was opened.
2690 * Otherwise fall through to regular selection. */
2691 if (enumerate) {
2692 bool has_menu = false;
2693 if (center) {
2694 if (object_mouse_select_menu(C, &vc, {}, mval, params, &basact_override)) {
2695 has_menu = true;
2696 }
2697 }
2698 else {
2699 if (gpu->hits != 0) {
2700 const Span<GPUSelectResult> hit_results = gpu->buffer.storage.as_span().slice(0,
2701 gpu->hits);
2702 if (gpu->has_bones && bone_mouse_select_menu(C, hit_results, false, params)) {
2703 has_menu = true;
2704 }
2705 else if (object_mouse_select_menu(C, &vc, hit_results, mval, params, &basact_override)) {
2706 has_menu = true;
2707 }
2708 }
2709 }
2710
2711 /* Let the menu handle any further actions. */
2712 if (has_menu) {
2713 if (gpu != nullptr) {
2714 MEM_delete(gpu);
2715 }
2716 return false;
2717 }
2718 }
2719
2720 /* No menu, continue with selection. */
2721
2722 ViewLayer *view_layer = vc.view_layer;
2723 BKE_view_layer_synced_ensure(*vc.bmain, scene, view_layer);
2724 /* Don't set when the context has no active object (hidden), see: #60807. */
2725 const Base *oldbasact = vc.obact ? BKE_view_layer_active_base_get(view_layer) : nullptr;
2726 /* Always start list from `basact` when cycling the selection. */
2727 Base *startbase = (oldbasact && oldbasact->next) ?
2728 oldbasact->next :
2729 BKE_view_layer_object_bases_get(view_layer)->first();
2730
2731 /* The next object's base to make active. */
2732 Base *basact = nullptr;
2733 const eObjectMode object_mode = oldbasact ? oldbasact->object->mode : OB_MODE_OBJECT;
2734 /* For the most part this is equivalent to `(object_mode & OB_MODE_POSE) != 0`
2735 * however this logic should also run with weight-paint + pose selection.
2736 * Without this, selection in weight-paint mode can de-select armatures which isn't useful,
2737 * see: #101686. */
2738 const bool has_pose_old = (oldbasact &&
2740
2741 /* When enabled, don't attempt any further selection. */
2742 bool handled = false;
2743
2744 /* Split `changed` into data-types so their associated updates can be properly performed.
2745 * This is also needed as multiple changes may happen at once.
2746 * Selecting a pose-bone or track can also select the object for example */
2747 bool changed_object = false;
2748 bool changed_pose = false;
2749 bool changed_track = false;
2750
2751 /* Handle setting the new base active (even when `handled == true`). */
2752 bool use_activate_selected_base = false;
2753
2754 if (center) {
2755 if (basact_override) {
2756 basact = basact_override;
2757 }
2758 else {
2759 basact = mouse_select_object_center(&vc, startbase, mval);
2760 }
2761 }
2762 else {
2763 if (basact_override) {
2764 basact = basact_override;
2765 }
2766 else {
2767 /* Regarding bone priority.
2768 *
2769 * - When in pose-bone, it's useful that any selection containing a bone
2770 * gets priority over other geometry (background scenery for example).
2771 *
2772 * - When in object-mode, don't prioritize bones as it would cause
2773 * pose-objects behind other objects to get priority
2774 * (mainly noticeable when #SCE_OBJECT_MODE_LOCK is disabled).
2775 *
2776 * This way prioritizing based on pose-mode has a bias to stay in pose-mode
2777 * without having to enforce this through locking the object mode. */
2778 bool do_bones_get_priotity = has_pose_old;
2779
2780 basact = (gpu->hits > 0) ? mouse_select_eval_buffer(&vc,
2781 gpu->buffer,
2782 gpu->hits,
2783 gpu->do_nearest,
2784 gpu->has_bones,
2785 do_bones_get_priotity,
2786 nullptr) :
2787 nullptr;
2788 }
2789
2790 /* See comment for `has_pose_old`, the same rationale applies here. */
2791 const bool has_pose_new = (basact &&
2793 /* Select camera-tracks. */
2794 if ((gpu->hits > 0) && gpu->has_sub_object && basact && (basact->object->type == OB_CAMERA)) {
2795 MovieClip *clip = BKE_object_movieclip_get(scene, basact->object, false);
2796 if (clip != nullptr) {
2798 C, scene, basact, clip, gpu->buffer, gpu->hits, params))
2799 {
2801 /* Don't set `handled` here as the object activation may be necessary. */
2802 changed_object = true;
2803
2804 changed_track = true;
2805 }
2806 else {
2807 /* Fallback to regular object selection if no new bundles were selected,
2808 * allows to select object parented to reconstruction object. */
2809 basact = mouse_select_eval_buffer(
2810 &vc, gpu->buffer, gpu->hits, gpu->do_nearest, false, false, nullptr);
2811 }
2812 }
2813 /* Prevent track selecting to pass on to object selecting. */
2814 if (basact == oldbasact) {
2815 handled = true;
2816 }
2817 }
2818 /* Select pose-bones. */
2819 else if (((gpu->hits > 0) && gpu->has_bones) ||
2820 /* Special case, even when there are no hits, pose logic may de-select all bones. */
2821 ((gpu->hits == 0) && has_pose_old))
2822 {
2823 /* Regarding the `basact` null checks.
2824 * While it's unlikely there are GPU hits *without* `basact` being found,
2825 * it's possible looking up the selection index fails, see: #143161. */
2826 if ((basact || oldbasact) &&
2828 scene,
2829 view_layer,
2830 v3d,
2831 basact ? basact : const_cast<Base *>(oldbasact),
2832 gpu->buffer.storage.data(),
2833 gpu->hits,
2834 params,
2835 gpu->do_nearest))
2836 {
2837
2838 changed_pose = true;
2839
2840 /* When there is no `baseact` this will have operated on `oldbasact`,
2841 * allowing #SelectPick_Params.deselect_all work in pose-mode.
2842 * In this case no object operations are needed. */
2843 if (basact == nullptr) {
2844 handled = true;
2845 }
2846 else {
2847 /* By convention the armature-object is selected when in pose-mode.
2848 * While leaving it unselected will work, leaving pose-mode would leave the object
2849 * active + unselected which isn't ideal when performing other actions on the object. */
2851 changed_object = true;
2852
2855
2856 /* In weight-paint, we use selected bone to select vertex-group.
2857 * In this case the active object mustn't change as it would leave weight-paint mode. */
2858 if (oldbasact) {
2859 if (oldbasact->object->mode & OB_MODE_ALL_WEIGHT_PAINT) {
2860 /* Prevent activating.
2861 * Selection causes this to be considered the 'active' pose in weight-paint mode.
2862 * Eventually this limitation may be removed.
2863 * For now, de-select all other pose objects deforming this mesh. */
2864 ED_armature_pose_select_in_wpaint_mode(*bmain, scene, view_layer, basact);
2865
2866 handled = true;
2867 }
2868 else if (has_pose_old && has_pose_new) {
2869 /* Within pose-mode, keep the current selection when switching pose bones,
2870 * this is noticeable when in pose mode with multiple objects at once.
2871 * Where selecting the bone of a different object would de-select this one.
2872 * After that, exiting pose-mode would only have the active armature selected.
2873 * This matches multi-object edit-mode behavior. */
2874 handled = true;
2875
2876 if (oldbasact != basact) {
2877 use_activate_selected_base = true;
2878 }
2879 }
2880 else {
2881 /* Don't set `handled` here as the object selection may be necessary
2882 * when starting out in object-mode and moving into pose-mode,
2883 * when moving from pose to object-mode using object selection also makes sense. */
2884 }
2885 }
2886 }
2887 }
2888 /* Prevent bone selecting to pass on to object selecting. */
2889 if (basact == oldbasact) {
2890 handled = true;
2891 }
2892 }
2893 }
2894
2895 bool changed_object_mode = false;
2896
2897 if (handled == false) {
2899 /* No special logic in edit-mode. */
2900 if (is_obedit == false) {
2901 if (basact && !BKE_object_is_mode_compat(basact->object, object_mode)) {
2902 if (object_mode == OB_MODE_OBJECT) {
2903 Main *bmain = vc.bmain;
2904 ed::object::mode_generic_exit(bmain, vc.depsgraph, scene, basact->object);
2905 }
2906 if (!BKE_object_is_mode_compat(basact->object, object_mode)) {
2907 basact = nullptr;
2908 }
2909 }
2910
2911 /* Disallow switching modes,
2912 * special exception for edit-mode - vertex-parent operator. */
2913 if (basact && oldbasact) {
2914 if ((oldbasact->object->mode != basact->object->mode) &&
2915 (oldbasact->object->mode & basact->object->mode) == 0)
2916 {
2917 basact = nullptr;
2918 }
2919 }
2920 }
2921 }
2922 else {
2923 if (basact) {
2924 if (!BKE_object_is_mode_compat(basact->object, object_mode)) {
2925 changed_object_mode = true;
2926 }
2927 }
2928 else if (object_mode != OB_MODE_OBJECT) {
2929 changed_object_mode = true;
2930 }
2931 }
2932 }
2933
2934 /* Ensure code above doesn't change the active base. This code is already fairly involved,
2935 * it's best if changing the active object is localized to a single place. */
2936 BLI_assert(oldbasact == (vc.obact ? BKE_view_layer_active_base_get(view_layer) : nullptr));
2937
2938 if (handled) {
2939 /* Pass. */
2940 }
2941 else if (basact && vc.obedit) {
2942 /* Only do the select (use for setting vertex parents & hooks).
2943 * In edit-mode do not activate. */
2944 object_deselect_all_except(*vc.bmain, scene, view_layer, basact);
2946
2947 changed_object = true;
2948 }
2949 else {
2950 /* Object-mode (pose mode will have been handled already)
2951 * unless entering pose-mode from object selection (handled by `changed_object_mode`). */
2952
2953 /* NOTE(@ideasman42): When select changes object-mode it doesn't make sense to use
2954 * pass-through.
2955 *
2956 * - When object-mode locking is disabled:
2957 * Selecting another already selected object does not need to make it active,
2958 * allowing a cursor-drag to move this objects as well as other selected objects.
2959 * - When object-mode locking is enabled:
2960 * Selecting an object in a different mode (typically pose-mode) must prioritize
2961 * entering that mode which requires making the object active, further, the selection
2962 * before switching modes wont make sense in the newly entered mode,
2963 * so it makes sense to disable pass-through logic in this case.
2964 *
2965 * See: #115181 for details. */
2966 const bool select_passthrough = params.select_passthrough && (changed_object_mode == false);
2967
2968 bool found = (basact != nullptr) && BASE_SELECTABLE(v3d, basact);
2969 if (params.sel_op == SEL_OP_SET) {
2970 if ((found && select_passthrough) && (basact->flag & BASE_SELECTED)) {
2971 found = false;
2972 }
2973 else if (found || params.deselect_all) {
2974 /* Deselect everything. */
2975 /* `basact` may be nullptr. */
2976 if (object_deselect_all_except(*vc.bmain, scene, view_layer, basact)) {
2977 changed_object = true;
2978 }
2979 }
2980 }
2981
2982 if (found) {
2983 use_activate_selected_base |= (oldbasact != basact) && (is_obedit == false);
2984
2985 switch (params.sel_op) {
2986 case SEL_OP_ADD: {
2988 break;
2989 }
2990 case SEL_OP_SUB: {
2992 break;
2993 }
2994 case SEL_OP_XOR: {
2995 if (basact->flag & BASE_SELECTED) {
2996 /* Keep selected if the base is to be activated. */
2997 if (use_activate_selected_base == false) {
2999 }
3000 }
3001 else {
3003 }
3004 break;
3005 }
3006 case SEL_OP_SET: {
3007 /* Deselect has already been performed. */
3009 break;
3010 }
3011 case SEL_OP_AND: {
3012 BLI_assert_unreachable(); /* Doesn't make sense for picking. */
3013 break;
3014 }
3015 }
3016
3017 changed_object = true;
3018 }
3019 }
3020
3021 /* Perform the activation even when 'handled', since this is used to ensure
3022 * the object from the pose-bone selected is also activated. */
3023 if (use_activate_selected_base && (basact != nullptr)) {
3024 changed_object = true;
3025 ed::object::base_activate(C, basact); /* adds notifier */
3026 if ((scene->toolsettings->object_flag & SCE_OBJECT_MODE_LOCK) == 0) {
3028 }
3029 }
3030
3031 if (changed_object) {
3034
3036 }
3037
3038 if (changed_pose) {
3040 }
3041
3042 if (gpu != nullptr) {
3043 MEM_delete(gpu);
3044 }
3045
3046 return (changed_object || changed_pose || changed_track);
3047}
3048
3056 const int mval[2],
3057 const SelectPick_Params &params,
3058 Object *obact)
3059{
3060 View3D *v3d = CTX_wm_view3d(C);
3061 const bool use_zbuf = !XRAY_ENABLED(v3d);
3062
3063 Mesh *mesh = id_cast<Mesh *>(obact->data); /* already checked for nullptr */
3064 uint index = 0;
3065 bool changed = false;
3066
3067 bool found = ED_mesh_pick_vert(C, obact, mval, ED_MESH_PICK_DEFAULT_VERT_DIST, use_zbuf, &index);
3068
3069 bke::MutableAttributeAccessor attributes = mesh->attributes_for_write();
3070 bke::AttributeWriter<bool> select_vert = attributes.lookup_or_add_for_write<bool>(
3071 ".select_vert", bke::AttrDomain::Point);
3072
3073 if (params.sel_op == SEL_OP_SET) {
3074 if ((found && params.select_passthrough) && select_vert.varray[index]) {
3075 found = false;
3076 }
3077 else if (found || params.deselect_all) {
3078 /* Deselect everything. */
3079 changed |= paintface_deselect_all_visible(C, obact, SEL_DESELECT, false);
3080 }
3081 }
3082
3083 if (found) {
3084 switch (params.sel_op) {
3085 case SEL_OP_ADD: {
3086 select_vert.varray.set(index, true);
3087 break;
3088 }
3089 case SEL_OP_SUB: {
3090 select_vert.varray.set(index, false);
3091 break;
3092 }
3093 case SEL_OP_XOR: {
3094 select_vert.varray.set(index, !select_vert.varray[index]);
3095 break;
3096 }
3097 case SEL_OP_SET: {
3099 select_vert.varray.set(index, true);
3100 break;
3101 }
3102 case SEL_OP_AND: {
3103 BLI_assert_unreachable(); /* Doesn't make sense for picking. */
3104 break;
3105 }
3106 }
3107
3108 /* update mselect */
3109 if (select_vert.varray[index]) {
3111 }
3112 else {
3114 }
3115
3116 select_vert.finish();
3117
3118 paintvert_flush_flags(obact);
3119
3120 changed = true;
3121 }
3122 else {
3123 select_vert.finish();
3124 }
3125
3126 if (changed) {
3128 }
3129
3130 return changed || found;
3131}
3132
3137
3143static bool pointcloud_select_pick(bContext &C, const int2 mval, const SelectPick_Params &params)
3144{
3145 using namespace blender::ed;
3146 Depsgraph *depsgraph = CTX_data_ensure_evaluated_depsgraph(&C);
3147 /* Setup view context for argument to callbacks. */
3148 const ViewContext vc = ED_view3d_viewcontext_init(&C, depsgraph);
3149
3151 *vc.bmain, vc.scene, vc.view_layer, vc.v3d);
3152
3154 bases.index_range(),
3155 1L,
3157 [&](const IndexRange range, const ClosestPointCloud &init) {
3158 ClosestPointCloud new_closest = init;
3159 for (Base *base : bases.as_span().slice(range)) {
3160 Object &object = *base->object;
3161 PointCloud &pointcloud = *id_cast<PointCloud *>(object.data);
3162 const float4x4 projection = ED_view3d_ob_project_mat_get(vc.rv3d, &object);
3163
3164 std::optional<pointcloud::FindClosestData> new_closest_elem =
3166 pointcloud.positions(),
3167 projection,
3168 IndexMask(pointcloud.totpoint),
3169 float2(mval),
3171 new_closest.elem);
3172 if (new_closest_elem) {
3173 new_closest.elem = *new_closest_elem;
3174 new_closest.pointcloud = &pointcloud;
3175 }
3176 }
3177 return new_closest;
3178 },
3179 [](const ClosestPointCloud &a, const ClosestPointCloud &b) {
3180 return (a.elem.distance_sq < b.elem.distance_sq) ? a : b;
3181 });
3182
3183 Array<bool> changed(bases.size(), false);
3184 if (params.deselect_all || params.sel_op == SEL_OP_SET) {
3185 threading::parallel_for(bases.index_range(), 1L, [&](const IndexRange range) {
3186 for (const int i : range) {
3187 PointCloud &pointcloud = *id_cast<PointCloud *>(bases[i]->object->data);
3188 if (!pointcloud::has_anything_selected(pointcloud)) {
3189 continue;
3190 }
3191
3192 bke::GSpanAttributeWriter selection = pointcloud::ensure_selection_attribute(
3193 pointcloud, bke::AttrType::Bool);
3194 pointcloud::fill_selection_false(selection.span, IndexMask(pointcloud.totpoint));
3195 selection.finish();
3196
3197 changed[i] = true;
3198 }
3199 });
3200
3201 for (const int i : bases.index_range()) {
3202 if (changed[i]) {
3203 PointCloud &pointcloud = *id_cast<PointCloud *>(bases[i]->object->data);
3204 /* Use #ID_RECALC_GEOMETRY instead of #ID_RECALC_SELECT because it is handled as a
3205 * generic attribute for now. */
3208 }
3209 }
3210 }
3211
3212 if (!closest.pointcloud) {
3213 return changed.as_span().contains(true);
3214 }
3215
3216 bke::GSpanAttributeWriter selection = pointcloud::ensure_selection_attribute(
3217 *closest.pointcloud, bke::AttrType::Bool);
3218 curves::apply_selection_operation_at_index(selection.span, closest.elem.index, params.sel_op);
3219 selection.finish();
3220
3221 /* Use #ID_RECALC_GEOMETRY instead of #ID_RECALC_SELECT because it is handled as a
3222 * generic attribute for now. */
3225
3226 return true;
3227}
3228
3234
3240static bool ed_curves_select_pick(bContext &C, const int mval[2], const SelectPick_Params &params)
3241{
3242 Depsgraph *depsgraph = CTX_data_ensure_evaluated_depsgraph(&C);
3243 /* Setup view context for argument to callbacks. */
3244 const ViewContext vc = ED_view3d_viewcontext_init(&C, depsgraph);
3245
3247 *vc.bmain, vc.scene, vc.view_layer, vc.v3d);
3248
3249 Curves &active_curves_id = *id_cast<Curves *>(vc.obedit->data);
3250 const bke::AttrDomain selection_domain = bke::AttrDomain(active_curves_id.selection_domain);
3251
3253 bases.index_range(),
3254 1L,
3256 [&](const IndexRange range, const ClosestCurveDataBlock &init) {
3257 ClosestCurveDataBlock new_closest = init;
3258 for (Base *base : bases.as_span().slice(range)) {
3259 Object &curves_ob = *base->object;
3260 Curves &curves_id = *id_cast<Curves *>(curves_ob.data);
3263 const bke::CurvesGeometry &curves = curves_id.geometry.wrap();
3264 const float4x4 projection = ED_view3d_ob_project_mat_get(vc.rv3d, &curves_ob);
3265 const IndexMask elements(curves.attributes().domain_size(selection_domain));
3266 const auto range_consumer =
3267 [&](IndexRange range, Span<float3> positions, StringRef selection_attribute_name) {
3268 IndexMask mask = elements.slice_content(range);
3269
3270 std::optional<ed::curves::FindClosestData> new_closest_elem =
3272 curves.points_by_curve(),
3273 positions,
3274 curves.cyclic(),
3275 projection,
3276 mask,
3277 selection_domain,
3278 mval,
3279 new_closest.elem);
3280 if (new_closest_elem) {
3281 new_closest.selection_attribute_name = selection_attribute_name;
3282 new_closest.elem = *new_closest_elem;
3283 new_closest.curves_id = &curves_id;
3284 }
3285 };
3286
3287 if (selection_domain == bke::AttrDomain::Point) {
3289 curves,
3290 deformation,
3292 range_consumer);
3293 }
3294 else if (selection_domain == bke::AttrDomain::Curve) {
3296 curves, deformation, eHandleDisplay::CURVE_HANDLE_NONE, range_consumer);
3297 };
3298 }
3299 return new_closest;
3300 },
3301 [](const ClosestCurveDataBlock &a, const ClosestCurveDataBlock &b) {
3302 return (a.elem.distance_sq < b.elem.distance_sq) ? a : b;
3303 });
3304
3305 Array<bool> changed(bases.size(), false);
3306 if (params.deselect_all || params.sel_op == SEL_OP_SET) {
3307 threading::parallel_for(bases.index_range(), 1L, [&](const IndexRange range) {
3308 for (const int i : range) {
3309 Curves &curves_id = *id_cast<Curves *>(bases[i]->object->data);
3310 bke::CurvesGeometry &curves = curves_id.geometry.wrap();
3311 if (!ed::curves::has_anything_selected(curves, selection_domain)) {
3312 continue;
3313 }
3314
3315 ed::curves::foreach_selection_attribute_writer(
3316 curves, selection_domain, [](bke::GSpanAttributeWriter &selection) {
3317 ed::curves::fill_selection_false(selection.span);
3318 });
3319
3320 changed[i] = true;
3321 }
3322 });
3323
3324 for (const int i : bases.index_range()) {
3325 if (changed[i]) {
3326 Curves &curves_id = *id_cast<Curves *>(bases[i]->object->data);
3327 /* Use #ID_RECALC_GEOMETRY instead of #ID_RECALC_SELECT because it is handled as a
3328 * generic attribute for now. */
3329 DEG_id_tag_update(&curves_id.id, ID_RECALC_GEOMETRY);
3330 WM_event_add_notifier(&C, NC_GEOM | ND_DATA, &curves_id);
3331 }
3332 }
3333 }
3334
3335 if (!closest.curves_id) {
3336 return changed.as_span().contains(true);
3337 }
3338
3339 if (selection_domain == bke::AttrDomain::Point) {
3341 closest.curves_id->geometry.wrap(),
3344 closest.selection_attribute_name);
3346 selection.span, closest.elem.index, params.sel_op);
3347 selection.finish();
3348 }
3349 else if (selection_domain == bke::AttrDomain::Curve) {
3351 closest.curves_id->geometry.wrap(),
3353 [&](bke::GSpanAttributeWriter &selection) {
3354 ed::curves::apply_selection_operation_at_index(
3355 selection.span, closest.elem.index, params.sel_op);
3356 });
3357 }
3358
3359 /* Use #ID_RECALC_GEOMETRY instead of #ID_RECALC_SELECT because it is handled as a
3360 * generic attribute for now. */
3363
3364 return true;
3365}
3366
3373
3380 const int mval[2],
3381 const SelectPick_Params &params)
3382{
3383 Depsgraph *depsgraph = CTX_data_ensure_evaluated_depsgraph(C);
3384 /* Setup view context for argument to callbacks. */
3385 const ViewContext vc = ED_view3d_viewcontext_init(C, depsgraph);
3386 Object *object = (vc.obedit ? vc.obedit : vc.obact);
3387
3388 /* Collect editable drawings. */
3389 const Object *ob_eval = DEG_get_evaluated(vc.depsgraph, object);
3390 GreasePencil &grease_pencil = *id_cast<GreasePencil *>(object->data);
3393
3394 /* Get selection domain from tool settings. */
3396 vc.scene->toolsettings, object);
3397
3399 drawings.index_range(),
3400 1L,
3402 [&](const IndexRange range, const ClosestGreasePencilDrawing &init) {
3403 ClosestGreasePencilDrawing new_closest = init;
3404 for (const int i : range) {
3405 ed::greasepencil::MutableDrawingInfo info = drawings[i];
3407 /* Get deformation by modifiers. */
3410 ob_eval, *object, info.drawing);
3411
3412 IndexMaskMemory memory;
3414 *object, info, selection_domain, memory);
3415 if (elements.is_empty()) {
3416 continue;
3417 }
3418 const IndexMask visible_handle_elements =
3420 *object,
3421 info.drawing,
3422 info.layer_index,
3423 selection_domain,
3425 memory);
3426 const bke::CurvesGeometry &curves = info.drawing.strokes();
3427 const float4x4 layer_to_world = layer.to_world_space(*ob_eval);
3429 layer_to_world);
3430 const auto range_consumer = [&](const IndexRange range,
3431 const Span<float3> positions,
3432 const StringRef selection_attribute_name) {
3433 const IndexMask mask = ((selection_attribute_name == ".selection") ?
3434 elements :
3435 visible_handle_elements)
3436 .slice_content(range);
3437
3438 std::optional<ed::curves::FindClosestData> new_closest_elem =
3440 curves.points_by_curve(),
3441 positions,
3442 curves.cyclic(),
3443 projection,
3444 mask,
3445 selection_domain,
3446 mval,
3447 new_closest.elem);
3448 if (new_closest_elem) {
3449 new_closest.selection_attribute_name = selection_attribute_name;
3450 new_closest.elem = *new_closest_elem;
3451 new_closest.info_index = i;
3452 new_closest.drawing = &info.drawing;
3453 }
3454 };
3455
3456 if (selection_domain == bke::AttrDomain::Point) {
3458 curves,
3459 deformation,
3461 range_consumer);
3462 }
3463 else if (selection_domain == bke::AttrDomain::Curve) {
3465 curves, deformation, eHandleDisplay::CURVE_HANDLE_NONE, range_consumer);
3466 };
3467 }
3468 return new_closest;
3469 },
3471 return (a.elem.distance_sq < b.elem.distance_sq) ? a : b;
3472 });
3473
3474 std::atomic<bool> deselected = false;
3475 if (params.deselect_all || params.sel_op == SEL_OP_SET) {
3476 threading::parallel_for(drawings.index_range(), 1L, [&](const IndexRange range) {
3477 for (const int i : range) {
3478 ed::greasepencil::MutableDrawingInfo info = drawings[i];
3479 IndexMaskMemory memory;
3480 const IndexMask elements = ed::greasepencil::retrieve_editable_elements(
3481 *object, info, selection_domain, memory);
3482 if (elements.is_empty()) {
3483 continue;
3484 }
3485 bke::CurvesGeometry &curves = info.drawing.strokes_for_write();
3486 if (!ed::curves::has_anything_selected(curves, selection_domain, elements)) {
3487 continue;
3488 }
3489
3490 ed::curves::foreach_selection_attribute_writer(
3491 curves, selection_domain, [](bke::GSpanAttributeWriter &selection) {
3492 ed::curves::fill_selection_false(selection.span);
3493 });
3494
3495 deselected = true;
3496 }
3497 });
3498 }
3499
3500 if (!closest.drawing) {
3501 if (deselected) {
3502 /* Use #ID_RECALC_GEOMETRY instead of #ID_RECALC_SELECT because it is handled as a
3503 * generic attribute for now. */
3506 }
3507 return deselected;
3508 }
3509
3510 const IndexMask selection_mask = IndexRange::from_single(closest.elem.index);
3511
3513 params.sel_op,
3515 const IndexMask & /*universe*/,
3516 StringRef attribute_name,
3517 IndexMaskMemory & /*memory*/) -> IndexMask {
3518 /* Selection update mask is already known, but only applies
3519 * to a specific drawing. */
3520 if (&info.drawing == closest.drawing &&
3521 attribute_name == closest.selection_attribute_name) {
3522 return selection_mask;
3523 }
3524 return {};
3525 });
3526
3527 /* Use #ID_RECALC_GEOMETRY instead of #ID_RECALC_SELECT because it is handled as a
3528 * generic attribute for now. */
3531
3532 return true;
3533}
3534
3536{
3537 Scene *scene = CTX_data_scene(C);
3538 Object *obedit = CTX_data_edit_object(C);
3540
3541 Depsgraph *depsgraph = CTX_data_ensure_evaluated_depsgraph(C);
3542 const ViewContext vc = ED_view3d_viewcontext_init(C, depsgraph);
3543
3545
3546 bool center = RNA_boolean_get(op->ptr, "center");
3547 bool enumerate = RNA_boolean_get(op->ptr, "enumerate");
3548 /* Only force object select for edit-mode to support vertex parenting,
3549 * or paint-select to allow pose bone select with vert/face select. */
3550 bool object_only = (RNA_boolean_get(op->ptr, "object") &&
3551 (obedit || BKE_paint_select_elem_test(obact) ||
3552 /* so its possible to select bones in weight-paint mode (LMB select) */
3553 (obact && (obact->mode & OB_MODE_ALL_WEIGHT_PAINT) &&
3555
3556 /* This could be called "changed_or_found" since this is true when there is an element
3557 * under the cursor to select, even if it happens that the selection & active state doesn't
3558 * actually change. This is important so undo pushes are predictable. */
3559 bool changed = false;
3560 int mval[2];
3561
3562 if (object_only) {
3563 obedit = nullptr;
3564 obact = nullptr;
3565
3566 /* ack, this is incorrect but to do this correctly we would need an
3567 * alternative edit-mode/object-mode keymap, this copies the functionality
3568 * from 2.4x where Ctrl+Select in edit-mode does object select only. */
3569 center = false;
3570 }
3571
3572 if (obedit && enumerate) {
3573 /* Enumerate makes no sense in edit-mode unless also explicitly picking objects or bones.
3574 * Pass the event through so the event may be handled by loop-select for example. See: #100204.
3575 */
3576 if (obedit->type != OB_ARMATURE) {
3578 }
3579 }
3580
3581 RNA_int_get_array(op->ptr, "location", mval);
3582
3585
3586 if (obedit && object_only == false) {
3587 if (obedit->type == OB_MESH) {
3588 changed = EDBM_select_pick(C, mval, params);
3589 }
3590 else if (obedit->type == OB_ARMATURE) {
3591 if (enumerate) {
3592 GPUSelectBuffer buffer;
3593 const int hits = mixed_bones_object_selectbuffer(
3594 &vc, &buffer, mval, VIEW3D_SELECT_FILTER_NOP, false, true, false);
3595 changed = bone_mouse_select_menu(
3596 C, buffer.storage.as_span().take_front(hits), true, params);
3597 }
3598 if (!changed) {
3599 changed = ED_armature_edit_select_pick(C, mval, params);
3600 }
3601 }
3602 else if (obedit->type == OB_LATTICE) {
3603 changed = ED_lattice_select_pick(C, mval, params);
3604 }
3605 else if (ELEM(obedit->type, OB_CURVES_LEGACY, OB_SURF)) {
3606 changed = ED_curve_editnurb_select_pick(C, mval, ED_view3d_select_dist_px(), params);
3607 }
3608 else if (obedit->type == OB_MBALL) {
3609 changed = ED_mball_select_pick(C, mval, params);
3610 }
3611 else if (obedit->type == OB_FONT) {
3612 changed = ED_curve_editfont_select_pick(C, mval, params);
3613 }
3614 else if (obedit->type == OB_POINTCLOUD) {
3615 changed = pointcloud_select_pick(*C, mval, params);
3616 }
3617 else if (obedit->type == OB_CURVES) {
3618 changed = ed_curves_select_pick(*C, mval, params);
3619 }
3620 else if (obedit->type == OB_GREASE_PENCIL) {
3621 changed = ed_grease_pencil_select_pick(C, mval, params);
3622 }
3623 }
3624 else if (obact && obact->mode & OB_MODE_PARTICLE_EDIT) {
3625 changed = PE_mouse_particles(C, mval, params);
3626 }
3627 else if (obact && BKE_paint_select_face_test(obact)) {
3628 changed = paintface_mouse_select(C, mval, params, obact);
3629 }
3630 else if (BKE_paint_select_vert_test(obact)) {
3631 changed = ed_wpaint_vertex_select_pick(C, mval, params, obact);
3632 }
3633 else if (BKE_paint_select_grease_pencil_test(obact)) {
3634 changed = ed_grease_pencil_select_pick(C, mval, params);
3635 }
3636 else {
3637 changed = ed_object_select_pick(C, mval, params, center, enumerate, object_only);
3638 }
3639
3640 /* Pass-through flag may be cleared, see #WM_operator_flag_only_pass_through_on_press. */
3641
3642 /* Pass-through allows tweaks
3643 * FINISHED to signal one operator worked */
3644 if (changed) {
3647 }
3648 /* Nothing selected, just passthrough. */
3650}
3651
3653{
3654 RNA_int_set_array(op->ptr, "location", event->mval);
3655
3656 const wmOperatorStatus retval = view3d_select_exec(C, op);
3657
3658 return WM_operator_flag_only_pass_through_on_press(retval, event);
3659}
3660
3662{
3663 PropertyRNA *prop;
3664
3665 /* identifiers */
3666 ot->name = "Select";
3667 ot->description = "Select and activate item(s)";
3668 ot->idname = "VIEW3D_OT_select";
3669
3670 /* API callbacks. */
3675
3676 /* flags */
3677 ot->flag = OPTYPE_UNDO;
3678
3679 /* properties */
3681
3682 prop = RNA_def_boolean(
3683 ot->srna,
3684 "center",
3685 false,
3686 "Center",
3687 "Use the object center when selecting, in edit mode used to extend object selection");
3689 prop = RNA_def_boolean(ot->srna,
3690 "enumerate",
3691 false,
3692 "Enumerate",
3693 "List objects under the mouse (object mode only)");
3695 prop = RNA_def_boolean(
3696 ot->srna, "object", false, "Object", "Use object selection (edit mode only)");
3698
3699 prop = RNA_def_int_vector(ot->srna,
3700 "location",
3701 2,
3702 nullptr,
3703 INT_MIN,
3704 INT_MAX,
3705 "Location",
3706 "Mouse location",
3707 INT_MIN,
3708 INT_MAX);
3710}
3711
3713
3714/* -------------------------------------------------------------------- */
3717
3734
3736 const ViewContext *vc,
3737 const rcti *rect,
3738 const eSelectOp sel_op)
3739{
3740 r_data->vc = vc;
3741
3742 r_data->rect = rect;
3743 r_data->rect_fl = &r_data->_rect_fl;
3744 BLI_rctf_rcti_copy(&r_data->_rect_fl, rect);
3745
3746 r_data->sel_op = sel_op;
3747 /* SELECT by default, but can be changed if needed (only few cases use and respect this). */
3748 r_data->select_flag = BEZT_FLAG_SELECT;
3749
3750 /* runtime */
3751 r_data->is_done = false;
3752 r_data->is_changed = false;
3753}
3754
3755bool edge_inside_circle(const float cent[2],
3756 float radius,
3757 const float screen_co_a[2],
3758 const float screen_co_b[2])
3759{
3760 const float radius_squared = radius * radius;
3761 return (dist_squared_to_line_segment_v2(cent, screen_co_a, screen_co_b) < radius_squared);
3762}
3763
3768static void do_paintvert_box_select__doSelectVert(void *user_data,
3769 const float screen_co[2],
3770 int index)
3771{
3773 static_cast<BoxSelectUserData_ForMeshObjectVert *>(user_data);
3774 BoxSelectUserData *data = &mesh_data->box_data;
3775 const bool is_select = mesh_data->select_vert[index];
3776 const bool is_inside = BLI_rctf_isect_pt_v(data->rect_fl, screen_co);
3777 const int sel_op_result = ED_select_op_action_deselected(data->sel_op, is_select, is_inside);
3778 if (sel_op_result != -1) {
3779 mesh_data->select_vert[index] = sel_op_result == 1;
3780 data->is_changed = true;
3781 }
3782}
3784 wmGenericUserData *wm_userdata,
3785 const rcti *rect,
3786 const eSelectOp sel_op)
3787{
3788 const bool use_zbuf = !XRAY_ENABLED(vc->v3d);
3789
3790 Mesh *mesh = id_cast<Mesh *>(vc->obact->data);
3791 if ((mesh == nullptr) || (mesh->verts_num == 0)) {
3792 return false;
3793 }
3794
3795 bool changed = false;
3796 if (SEL_OP_USE_PRE_DESELECT(sel_op)) {
3797 changed |= paintvert_deselect_all_visible(vc->obact, SEL_DESELECT, false);
3798 }
3799
3800 if (BLI_rcti_is_empty(rect)) {
3801 /* pass */
3802 }
3803 else if (use_zbuf) {
3804 EditSelectBuf_Cache *esel = static_cast<EditSelectBuf_Cache *>(wm_userdata->data);
3805 if (wm_userdata->data == nullptr) {
3807 esel = static_cast<EditSelectBuf_Cache *>(wm_userdata->data);
3809 vc->depsgraph, vc->region, vc->v3d, rect, nullptr);
3810 }
3811 if (esel->select_bitmap != nullptr) {
3812 changed |= edbm_backbuf_check_and_select_verts_obmode(mesh, esel, sel_op);
3813 }
3814 }
3815 else {
3816 bke::MutableAttributeAccessor attributes = mesh->attributes_for_write();
3817 bke::SpanAttributeWriter<bool> select_vert = attributes.lookup_or_add_for_write_span<bool>(
3818 ".select_vert", bke::AttrDomain::Point);
3819
3821 data.select_vert = select_vert.span;
3822
3823 view3d_userdata_boxselect_init(&data.box_data, vc, rect, sel_op);
3824
3826
3829 changed |= data.box_data.is_changed;
3830 select_vert.finish();
3831 }
3832
3833 if (changed) {
3834 if (SEL_OP_CAN_DESELECT(sel_op)) {
3836 }
3839 }
3840 return changed;
3841}
3842
3844 wmGenericUserData *wm_userdata,
3845 const rcti *rect,
3846 eSelectOp sel_op)
3847{
3848 Object *ob = vc->obact;
3849 Mesh *mesh;
3850
3852 if ((mesh == nullptr) || (mesh->faces_num == 0)) {
3853 return false;
3854 }
3855
3856 bool changed = false;
3857 if (SEL_OP_USE_PRE_DESELECT(sel_op)) {
3858 changed |= paintface_deselect_all_visible(vc->C, vc->obact, SEL_DESELECT, false);
3859 }
3860
3861 if (BLI_rcti_is_empty(rect)) {
3862 /* pass */
3863 }
3864 else {
3865 EditSelectBuf_Cache *esel = static_cast<EditSelectBuf_Cache *>(wm_userdata->data);
3866 if (wm_userdata->data == nullptr) {
3868 esel = static_cast<EditSelectBuf_Cache *>(wm_userdata->data);
3870 vc->depsgraph, vc->region, vc->v3d, rect, nullptr);
3871 }
3872 if (esel->select_bitmap != nullptr) {
3873 changed |= edbm_backbuf_check_and_select_faces_obmode(mesh, esel, sel_op);
3874 }
3875 }
3876
3877 if (changed) {
3878 paintface_flush_flags(vc->C, vc->obact, true, false);
3879 }
3880 return changed;
3881}
3882
3883static void do_nurbs_box_select__doSelect(void *user_data,
3884 Nurb * /*nu*/,
3885 BPoint *bp,
3886 BezTriple *bezt,
3887 int beztindex,
3888 bool handles_visible,
3889 const float screen_co[2])
3890{
3891 BoxSelectUserData *data = static_cast<BoxSelectUserData *>(user_data);
3892
3893 const bool is_inside = BLI_rctf_isect_pt_v(data->rect_fl, screen_co);
3894 if (bp) {
3895 const bool is_select = bp->f1 & SELECT;
3896 const int sel_op_result = ED_select_op_action_deselected(data->sel_op, is_select, is_inside);
3897 if (sel_op_result != -1) {
3898 SET_FLAG_FROM_TEST(bp->f1, sel_op_result, data->select_flag);
3899 data->is_changed = true;
3900 }
3901 }
3902 else {
3903 if (!handles_visible) {
3904 /* can only be (beztindex == 1) here since handles are hidden */
3905 const bool is_select = bezt->f2 & SELECT;
3906 const int sel_op_result = ED_select_op_action_deselected(data->sel_op, is_select, is_inside);
3907 if (sel_op_result != -1) {
3908 SET_FLAG_FROM_TEST(bezt->f2, sel_op_result, data->select_flag);
3909 data->is_changed = true;
3910 }
3911 bezt->f1 = bezt->f3 = bezt->f2;
3912 }
3913 else {
3914 eBezTriple_Flag *flag_p = (&bezt->f1) + beztindex;
3915 const bool is_select = *flag_p & SELECT;
3916 const int sel_op_result = ED_select_op_action_deselected(data->sel_op, is_select, is_inside);
3917 if (sel_op_result != -1) {
3918 SET_FLAG_FROM_TEST(*flag_p, sel_op_result, data->select_flag);
3919 data->is_changed = true;
3920 }
3921 }
3922 }
3923}
3924static bool do_nurbs_box_select(const ViewContext *vc, const rcti *rect, const eSelectOp sel_op)
3925{
3926 const bool deselect_all = (sel_op == SEL_OP_SET);
3928
3929 view3d_userdata_boxselect_init(&data, vc, rect, sel_op);
3930
3931 Curve *curve = id_cast<Curve *>(vc->obedit->data);
3932 ListBaseT<Nurb> *nurbs = BKE_curve_editNurbs_get(curve);
3933
3934 /* For deselect all, items to be selected are tagged with temp flag. Clear that first. */
3935 if (deselect_all) {
3937 data.select_flag = BEZT_FLAG_TEMP_TAG;
3938 }
3939
3940 ED_view3d_init_mats_rv3d(vc->obedit, vc->rv3d); /* for foreach's screen/vert projection */
3942
3943 /* Deselect items that were not added to selection (indicated by temp flag). */
3944 if (deselect_all) {
3947 }
3948
3950
3951 return data.is_changed;
3952}
3953
3954static void do_lattice_box_select__doSelect(void *user_data, BPoint *bp, const float screen_co[2])
3955{
3956 BoxSelectUserData *data = static_cast<BoxSelectUserData *>(user_data);
3957 const bool is_select = bp->f1 & SELECT;
3958 const bool is_inside = BLI_rctf_isect_pt_v(data->rect_fl, screen_co);
3959 const int sel_op_result = ED_select_op_action_deselected(data->sel_op, is_select, is_inside);
3960 if (sel_op_result != -1) {
3961 SET_FLAG_FROM_TEST(bp->f1, sel_op_result, SELECT);
3962 data->is_changed = true;
3963 }
3964}
3965static bool do_lattice_box_select(const ViewContext *vc, const rcti *rect, const eSelectOp sel_op)
3966{
3968
3969 view3d_userdata_boxselect_init(&data, vc, rect, sel_op);
3970
3971 if (SEL_OP_USE_PRE_DESELECT(sel_op)) {
3972 data.is_changed |= ED_lattice_flags_set(vc->obedit, 0);
3973 }
3974
3975 ED_view3d_init_mats_rv3d(vc->obedit, vc->rv3d); /* for foreach's screen/vert projection */
3978
3979 return data.is_changed;
3980}
3981
3982static void do_mesh_box_select__doSelectVert(void *user_data,
3983 BMVert *eve,
3984 const float screen_co[2],
3985 int /*index*/)
3986{
3987 BoxSelectUserData *data = static_cast<BoxSelectUserData *>(user_data);
3988 const bool is_select = BM_elem_flag_test(eve, BM_ELEM_SELECT);
3989 const bool is_inside = BLI_rctf_isect_pt_v(data->rect_fl, screen_co);
3990 const int sel_op_result = ED_select_op_action_deselected(data->sel_op, is_select, is_inside);
3991 if (sel_op_result != -1) {
3992 BM_vert_select_set(data->bm, eve, sel_op_result);
3993 if (data->uv_selctx) {
3994 data->uv_selctx->vert_select_set(eve, sel_op_result);
3995 }
3996
3997 data->is_changed = true;
3998 }
3999}
4005
4008static void do_mesh_box_select__doSelectEdge_pass0(void *user_data,
4009 BMEdge *eed,
4010 const float screen_co_a[2],
4011 const float screen_co_b[2],
4012 int index)
4013{
4014 BoxSelectUserData_ForMeshEdge *data_for_edge = static_cast<BoxSelectUserData_ForMeshEdge *>(
4015 user_data);
4016 BoxSelectUserData *data = data_for_edge->data;
4017 bool is_visible = true;
4018 if (data_for_edge->backbuf_offset) {
4019 uint bitmap_inedx = data_for_edge->backbuf_offset + index - 1;
4020 is_visible = BLI_BITMAP_TEST_BOOL(data_for_edge->esel->select_bitmap, bitmap_inedx);
4021 }
4022
4023 const bool is_select = BM_elem_flag_test(eed, BM_ELEM_SELECT);
4024 const bool is_inside = (is_visible &&
4025 edge_fully_inside_rect(data->rect_fl, screen_co_a, screen_co_b));
4026 const int sel_op_result = ED_select_op_action_deselected(data->sel_op, is_select, is_inside);
4027 if (sel_op_result != -1) {
4028 BM_edge_select_set(data->bm, eed, sel_op_result);
4029 if (data->uv_selctx) {
4030 data->uv_selctx->edge_select_set(eed, sel_op_result);
4031 }
4032
4033 data->is_done = true;
4034 data->is_changed = true;
4035 }
4036}
4037
4040static void do_mesh_box_select__doSelectEdge_pass1(void *user_data,
4041 BMEdge *eed,
4042 const float screen_co_a[2],
4043 const float screen_co_b[2],
4044 int index)
4045{
4046 BoxSelectUserData_ForMeshEdge *data_for_edge = static_cast<BoxSelectUserData_ForMeshEdge *>(
4047 user_data);
4048 BoxSelectUserData *data = data_for_edge->data;
4049 bool is_visible = true;
4050 if (data_for_edge->backbuf_offset) {
4051 uint bitmap_inedx = data_for_edge->backbuf_offset + index - 1;
4052 is_visible = BLI_BITMAP_TEST_BOOL(data_for_edge->esel->select_bitmap, bitmap_inedx);
4053 }
4054
4055 const bool is_select = BM_elem_flag_test(eed, BM_ELEM_SELECT);
4056 const bool is_inside = (is_visible && edge_inside_rect(data->rect_fl, screen_co_a, screen_co_b));
4057 const int sel_op_result = ED_select_op_action_deselected(data->sel_op, is_select, is_inside);
4058 if (sel_op_result != -1) {
4059 BM_edge_select_set(data->bm, eed, sel_op_result);
4060 if (data->uv_selctx) {
4061 data->uv_selctx->edge_select_set(eed, sel_op_result);
4062 }
4063
4064 data->is_changed = true;
4065 }
4066}
4067static void do_mesh_box_select__doSelectFace(void *user_data,
4068 BMFace *efa,
4069 const float screen_co[2],
4070 int /*index*/)
4071{
4072 BoxSelectUserData *data = static_cast<BoxSelectUserData *>(user_data);
4073 const bool is_select = BM_elem_flag_test(efa, BM_ELEM_SELECT);
4074 const bool is_inside = BLI_rctf_isect_pt_v(data->rect_fl, screen_co);
4075 const int sel_op_result = ED_select_op_action_deselected(data->sel_op, is_select, is_inside);
4076 if (sel_op_result != -1) {
4077 BM_face_select_set(data->bm, efa, sel_op_result);
4078 if (data->uv_selctx) {
4079 data->uv_selctx->face_select_set(efa, sel_op_result);
4080 }
4081
4082 data->is_changed = true;
4083 }
4084}
4085static bool do_mesh_box_select(const ViewContext *vc,
4086 wmGenericUserData *wm_userdata,
4087 const rcti *rect,
4088 const eSelectOp sel_op)
4089{
4091 ToolSettings *ts = vc->scene->toolsettings;
4093
4094 view3d_userdata_boxselect_init(&data, vc, rect, sel_op);
4095 data.bm = bm;
4096
4097 if (SEL_OP_USE_PRE_DESELECT(sel_op)) {
4098 if (bm->totvertsel) {
4100 data.is_changed = true;
4101 }
4102 }
4103
4104 std::unique_ptr<UVSyncSelectFromMesh> uv_selctx = UVSyncSelectFromMesh::create_if_needed(*ts,
4105 *bm);
4106 data.uv_selctx = uv_selctx.get();
4107
4108 /* for non zbuf projections, don't change the GL state */
4110
4112
4113 const bool use_zbuf = !XRAY_FLAG_ENABLED(vc->v3d);
4114
4115 EditSelectBuf_Cache *esel = static_cast<EditSelectBuf_Cache *>(wm_userdata->data);
4116 if (use_zbuf) {
4117 if (wm_userdata->data == nullptr) {
4119 esel = static_cast<EditSelectBuf_Cache *>(wm_userdata->data);
4121 vc->depsgraph, vc->region, vc->v3d, rect, nullptr);
4122 }
4123 }
4124
4125 if (ts->selectmode & SCE_SELECT_VERTEX) {
4126 if (use_zbuf) {
4128 esel, vc->depsgraph, vc->obedit, bm, data.uv_selctx, sel_op);
4129 }
4130 else {
4133 }
4134 }
4135 if (ts->selectmode & SCE_SELECT_EDGE) {
4136 /* Does both use_zbuf and non-use_zbuf versions (need screen cos for both) */
4138 cb_data.data = &data;
4139 cb_data.esel = use_zbuf ? esel : nullptr;
4141 vc->depsgraph, vc->obedit, SCE_SELECT_EDGE) :
4142 0;
4143
4144 const eV3DProjTest clip_flag = V3D_PROJ_TEST_CLIP_NEAR |
4145 (use_zbuf ? eV3DProjTest(0) : V3D_PROJ_TEST_CLIP_BB);
4146 /* Fully inside. */
4148 vc, do_mesh_box_select__doSelectEdge_pass0, &cb_data, clip_flag);
4149 if (data.is_done == false) {
4150 /* Fall back to partially inside.
4151 * Clip content to account for edges partially behind the view. */
4154 &cb_data,
4156 }
4157 }
4158
4159 if (ts->selectmode & SCE_SELECT_FACE) {
4160 if (use_zbuf) {
4162 esel, vc->depsgraph, vc->obedit, bm, data.uv_selctx, sel_op);
4163 }
4164 else {
4167 }
4168 }
4169
4170 if (data.is_changed) {
4172 }
4173
4174 if (data.uv_selctx) {
4175 data.uv_selctx->apply();
4176 }
4177
4178 return data.is_changed;
4179}
4180
4181static bool do_meta_box_select(const ViewContext *vc, const rcti *rect, const eSelectOp sel_op)
4182{
4183 Object *ob = vc->obedit;
4184 MetaBall *mb = id_cast<MetaBall *>(ob->data);
4185 MetaElem *ml;
4186 int a;
4187 bool changed = false;
4188
4189 GPUSelectBuffer buffer;
4190 int hits;
4191
4192 hits = view3d_gpu_select(
4194
4195 if (SEL_OP_USE_PRE_DESELECT(sel_op)) {
4196 changed |= BKE_mball_deselect_all(mb);
4197 }
4198
4199 int metaelem_id = 0;
4200 for (ml = mb->editelems->first(); ml; ml = ml->next, metaelem_id += 0x10000) {
4201 bool is_inside_radius = false;
4202 bool is_inside_stiff = false;
4203
4204 for (a = 0; a < hits; a++) {
4205 const int select_id = buffer.storage[a].id;
4206
4207 if (select_id == -1) {
4208 continue;
4209 }
4210
4211 const uint hit_object = select_id & 0xFFFF;
4212 if (vc->obedit->runtime->select_id != hit_object) {
4213 continue;
4214 }
4215
4216 if (metaelem_id != (select_id & 0xFFFF0000 & ~MBALLSEL_ANY)) {
4217 continue;
4218 }
4219
4220 if (select_id & MBALLSEL_RADIUS) {
4221 is_inside_radius = true;
4222 break;
4223 }
4224
4225 if (select_id & MBALLSEL_STIFF) {
4226 is_inside_stiff = true;
4227 break;
4228 }
4229 }
4230 const int flag_prev = ml->flag;
4231 if (is_inside_radius) {
4232 ml->flag |= MB_SCALE_RAD;
4233 }
4234 if (is_inside_stiff) {
4235 ml->flag &= ~MB_SCALE_RAD;
4236 }
4237
4238 const bool is_select = (ml->flag & SELECT);
4239 const bool is_inside = is_inside_radius || is_inside_stiff;
4240
4241 const int sel_op_result = ED_select_op_action_deselected(sel_op, is_select, is_inside);
4242 if (sel_op_result != -1) {
4243 SET_FLAG_FROM_TEST(ml->flag, sel_op_result, MB_SELECT);
4244 }
4245 changed |= (flag_prev != ml->flag);
4246 }
4247
4248 return changed;
4249}
4250
4251static bool do_armature_box_select(const ViewContext *vc, const rcti *rect, const eSelectOp sel_op)
4252{
4253 bool changed = false;
4254 int a;
4255
4256 GPUSelectBuffer buffer;
4257 int hits;
4258
4259 hits = view3d_gpu_select(
4261
4263 *vc->bmain, vc->scene, vc->view_layer, vc->v3d);
4264
4265 if (SEL_OP_USE_PRE_DESELECT(sel_op)) {
4267 }
4268
4269 for (Base *base : bases) {
4270 Object *obedit = base->object;
4271 obedit->id.tag &= ~ID_TAG_DOIT;
4272
4273 bArmature *arm = id_cast<bArmature *>(obedit->data);
4275 }
4276
4277 /* first we only check points inside the border */
4278 for (a = 0; a < hits; a++) {
4279 GPUSelectResult &hit_result = buffer.storage[a];
4280 if (!ED_armature_selectresult_is_bone(hit_result)) {
4281 continue;
4282 }
4283
4284 const int select_id = hit_result.id;
4285 if (select_id != -1) {
4286 EditBone *ebone;
4287 Base *base_edit = ED_armature_base_and_ebone_from_select_buffer(bases, select_id, &ebone);
4288 ebone->temp.i |= select_id & BONESEL_ANY;
4289 base_edit->object->id.tag |= ID_TAG_DOIT;
4290 }
4291 }
4292
4293 for (Base *base : bases) {
4294 Object *obedit = base->object;
4295 if (obedit->id.tag & ID_TAG_DOIT) {
4296 obedit->id.tag &= ~ID_TAG_DOIT;
4297 changed |= ED_armature_edit_select_op_from_tagged(id_cast<bArmature *>(obedit->data),
4298 sel_op);
4299 }
4300 }
4301
4302 return changed;
4303}
4304
4309static int gpu_bone_select_buffer_cmp(const void *sel_a_p, const void *sel_b_p)
4310{
4311 /* NOTE: this is endianness-sensitive.
4312 * GPUSelectResult values are always expected to be little-endian. */
4313 uint sel_a = (static_cast<GPUSelectResult *>(const_cast<void *>(sel_a_p)))->id;
4314 uint sel_b = (static_cast<GPUSelectResult *>(const_cast<void *>(sel_b_p)))->id;
4315
4316 if (sel_a < sel_b) {
4317 return -1;
4318 }
4319 if (sel_a > sel_b) {
4320 return 1;
4321 }
4322 return 0;
4323}
4324
4330
4332 const ViewContext *vc,
4333 const rcti *rect,
4334 const eSelectOp sel_op)
4335{
4336 View3D *v3d = vc->v3d;
4337
4338 GPUSelectBuffer buffer;
4340 vc->scene, v3d, vc->obact);
4341 const int hits = view3d_gpu_select(
4342 vc, &buffer, rect, VIEW3D_SELECT_ALL, select_filter, eV3DSelectShape::BOX);
4344 for (Base &base : *BKE_view_layer_object_bases_get(vc->view_layer)) {
4345 base.object->id.tag &= ~ID_TAG_DOIT;
4346 }
4347
4348 bool changed = false;
4349 if (SEL_OP_USE_PRE_DESELECT(sel_op)) {
4350 changed |= object_deselect_all_visible(*vc->bmain, vc->scene, vc->view_layer, vc->v3d);
4351 }
4352
4353 ListBaseT<Base> *object_bases = BKE_view_layer_object_bases_get(vc->view_layer);
4354 if ((hits == -1) && !SEL_OP_USE_OUTSIDE(sel_op)) {
4355 if (changed) {
4357 return true;
4358 }
4359 }
4360
4361 Map<uint32_t, Base *> base_by_object_select_id;
4362 for (Base &base : *object_bases) {
4363 if (BASE_SELECTABLE(v3d, &base)) {
4364 const uint32_t select_id = base.object->runtime->select_id;
4365 if ((select_id & 0x0000FFFF) != 0) {
4366 const uint hit_object = select_id & 0xFFFF;
4367 base_by_object_select_id.add(hit_object, &base);
4368 }
4369 }
4370 }
4371
4372 /* The draw order doesn't always match the order we populate the engine, see: #51695. */
4373 qsort(buffer.storage.data(), hits, sizeof(GPUSelectResult), gpu_bone_select_buffer_cmp);
4374
4375 Set<Base *> bases_inside;
4376 for (const GPUSelectResult *buf_iter = buffer.storage.data(), *buf_end = buf_iter + hits;
4377 buf_iter < buf_end;
4378 buf_iter++)
4379 {
4380 const uint32_t select_id = buf_iter->id;
4381 const uint32_t hit_object = select_id & 0xFFFF;
4382 if (Base *base = base_by_object_select_id.lookup_default(hit_object, nullptr)) {
4383 bases_inside.add(base);
4384 }
4385 }
4386
4387 for (Base *base = object_bases->first(); base && hits; base = base->next) {
4388 if (BASE_SELECTABLE(v3d, base)) {
4389 const bool is_select = base->flag & BASE_SELECTED;
4390 const bool is_inside = bases_inside.contains(base);
4391 const int sel_op_result = ED_select_op_action_deselected(sel_op, is_select, is_inside);
4392 if (sel_op_result != -1) {
4395 changed = true;
4396 }
4397 }
4398 }
4399
4400 if (changed) {
4402 }
4403 return changed;
4404}
4405
4406/*
4407 * NOTE(@theeth): Regarding the logic use here.
4408 * The buffer and #ListBaseT have the same relative order, which makes the selection
4409 * very simple. Loop through both data sets at the same time, if the color
4410 * is the same as the object, we have a hit and can move to the next color
4411 * and object pair, if not, just move to the next object,
4412 * keeping the same color until we have a hit. */
4414 const int hits,
4415 const Span<Base *> bases)
4416{
4417 if (hits <= 0) {
4418 /* No need to loop if there's no hit. */
4419 return;
4420 }
4421
4422 /* The draw order doesn't always match the order we populate the engine, see: #51695. */
4423 qsort(buffer.storage.data(), hits, sizeof(GPUSelectResult), gpu_bone_select_buffer_cmp);
4424
4425 for (const GPUSelectResult *buf_iter = buffer.storage.data(), *buf_end = buf_iter + hits;
4426 buf_iter < buf_end;
4427 buf_iter++)
4428 {
4429 if (!ED_armature_selectresult_is_bone(*buf_iter)) {
4430 continue;
4431 }
4432
4433 bPoseChannel *pose_bone;
4434 Base *base = ED_armature_base_and_pchan_from_select_buffer(bases, buf_iter->id, &pose_bone);
4435
4436 if (base == nullptr) {
4437 continue;
4438 }
4439
4440 /* Loop over contiguous bone hits for 'base'. */
4441 for (; buf_iter != buf_end; buf_iter++) {
4442 /* should never fail */
4443 if (pose_bone != nullptr) {
4444 base->object->id.tag |= ID_TAG_DOIT;
4446 }
4447
4448 /* Select the next bone if we're not switching bases. */
4449 if (buf_iter + 1 != buf_end) {
4450 const GPUSelectResult *col_next = buf_iter + 1;
4451 if ((base->object->runtime->select_id & 0x0000FFFF) != (col_next->id & 0x0000FFFF)) {
4452 break;
4453 }
4454 if (base->object->pose != nullptr) {
4455 const uint hit_bone = (col_next->id & ~BONESEL_ANY) >> 16;
4456 bPoseChannel *next = static_cast<bPoseChannel *>(
4457 BLI_findlink(&base->object->pose->chanbase, hit_bone));
4458 pose_bone = next;
4459 }
4460 else {
4461 pose_bone = nullptr;
4462 }
4463 }
4464 }
4465 }
4466}
4467
4469 const ViewContext *vc,
4470 const rcti *rect,
4471 const eSelectOp sel_op)
4472{
4474
4475 /* Selection buffer has bones potentially too. */
4476 GPUSelectBuffer buffer;
4478 vc->scene, vc->v3d, vc->obact);
4479 const int hits = view3d_gpu_select(
4480 vc, &buffer, rect, VIEW3D_SELECT_ALL, select_filter, eV3DSelectShape::BOX);
4481 process_pose_bone_hits(buffer, hits, bases);
4482
4483 const bool changed_multi = do_pose_tag_select_op_exec(bases, sel_op);
4484 if (changed_multi) {
4487 }
4488
4489 return changed_multi;
4490}
4491
4493 const rcti *rect,
4494 const eSelectOp sel_op)
4495{
4496 Object *object = (vc->obedit ? vc->obedit : vc->obact);
4497 const Object *ob_eval = DEG_get_evaluated(vc->depsgraph, object);
4498 const GreasePencil &grease_pencil = *id_cast<GreasePencil *>(object->data);
4500 vc->scene->toolsettings, object);
4501
4503 vc,
4504 sel_op,
4506 const IndexMask &mask,
4507 const StringRef attribute_name,
4508 IndexMaskMemory &memory) {
4511 const bke::crazyspace::GeometryDeformation deformation =
4513 ob_eval, *object, info.drawing);
4514 const IndexMask visible_handle_elements =
4516 *object,
4517 info.drawing,
4518 info.layer_index,
4519 selection_domain,
4521 memory);
4522 const float4x4 layer_to_world = layer.to_world_space(*ob_eval);
4524 layer_to_world);
4525
4526 return ed::curves::select_box_mask(*vc,
4527 curves,
4528 deformation,
4529 projection,
4530 mask,
4531 visible_handle_elements,
4532 selection_domain,
4533 attribute_name,
4534 *rect,
4535 memory);
4536 });
4537}
4538
4539static bool do_curves_select_box(const ViewContext &vc,
4540 const Object *object,
4541 const rcti *rect,
4542 const eSelectOp sel_op)
4543{
4544 Curves &curves_id = *id_cast<Curves *>(object->data);
4545 bke::CurvesGeometry &curves = curves_id.geometry.wrap();
4548 const bke::AttrDomain selection_domain = bke::AttrDomain(curves_id.selection_domain);
4549 const float4x4 projection = ED_view3d_ob_project_mat_get(vc.rv3d, object);
4550 const IndexRange elements(curves.attributes().domain_size(selection_domain));
4551
4553 vc, curves, deformation, projection, elements, elements, selection_domain, *rect, sel_op);
4554}
4555
4557 const rcti *rect,
4558 const eSelectOp sel_op)
4559{
4560 const Object *object = (vc.obedit ? vc.obedit : vc.obact);
4561 return do_curves_select_box(vc, object, rect, sel_op);
4562}
4563
4565{
4566 Depsgraph *depsgraph = CTX_data_ensure_evaluated_depsgraph(C);
4567 rcti rect;
4568 bool changed_multi = false;
4569
4570 wmGenericUserData wm_userdata_buf = {nullptr, nullptr, false};
4571 wmGenericUserData *wm_userdata = &wm_userdata_buf;
4572
4575
4576 /* setup view context for argument to callbacks */
4577 ViewContext vc = ED_view3d_viewcontext_init(C, depsgraph);
4578
4579 eSelectOp sel_op = static_cast<eSelectOp>(RNA_enum_get(op->ptr, "mode"));
4581
4582 if (vc.obedit) {
4584 vc.bmain, vc.scene, vc.view_layer, vc.v3d, vc.obedit->type, vc.obedit->mode, ob_iter)
4585 {
4587 bool changed = false;
4588
4589 switch (vc.obedit->type) {
4590 case OB_MESH:
4592 changed = do_mesh_box_select(&vc, wm_userdata, &rect, sel_op);
4593 if (changed) {
4596 }
4597 break;
4598 case OB_CURVES_LEGACY:
4599 case OB_SURF:
4600 changed = do_nurbs_box_select(&vc, &rect, sel_op);
4601 if (changed) {
4604 }
4605 break;
4606 case OB_MBALL:
4607 changed = do_meta_box_select(&vc, &rect, sel_op);
4608 if (changed) {
4611 }
4612 break;
4613 case OB_ARMATURE:
4614 changed = do_armature_box_select(&vc, &rect, sel_op);
4615 if (changed) {
4619 }
4620 break;
4621 case OB_LATTICE:
4622 changed = do_lattice_box_select(&vc, &rect, sel_op);
4623 if (changed) {
4626 }
4627 break;
4628 case OB_CURVES: {
4629 changed = do_curves_select_box(vc, vc.obedit, &rect, sel_op);
4630 if (changed) {
4633 }
4634 break;
4635 }
4636 case OB_POINTCLOUD: {
4637 PointCloud &pointcloud = *id_cast<PointCloud *>(vc.obedit->data);
4638 const float4x4 projection = ED_view3d_ob_project_mat_get(vc.rv3d, vc.obedit);
4639 changed = ed::pointcloud::select_box(pointcloud, *vc.region, projection, rect, sel_op);
4640 if (changed) {
4641 /* Use #ID_RECALC_GEOMETRY instead of #ID_RECALC_SELECT because it is handled as a
4642 * generic attribute for now. */
4645 }
4646 break;
4647 }
4648 case OB_GREASE_PENCIL: {
4649 changed = do_grease_pencil_box_select(&vc, &rect, sel_op);
4650 break;
4651 }
4652 default:
4653 BLI_assert_msg(0, "box select on incorrect object type");
4654 break;
4655 }
4656 changed_multi |= changed;
4657 }
4659 }
4660 else { /* No edit-mode, unified for bones and objects. */
4661 if (vc.obact && BKE_paint_select_face_test(vc.obact)) {
4662 changed_multi = do_paintface_box_select(&vc, wm_userdata, &rect, sel_op);
4663 }
4664 else if (vc.obact && BKE_paint_select_vert_test(vc.obact)) {
4665 changed_multi = do_paintvert_box_select(&vc, wm_userdata, &rect, sel_op);
4666 }
4667 else if (vc.obact && BKE_paint_select_grease_pencil_test(vc.obact)) {
4668 changed_multi = do_grease_pencil_box_select(&vc, &rect, sel_op);
4669 }
4670 else if (vc.obact && (vc.obact->mode & OB_MODE_SCULPT_CURVES) && (vc.obact->type == OB_CURVES))
4671 {
4672 changed_multi = do_curves_sculpt_box_select(vc, &rect, sel_op);
4673 if (changed_multi) {
4676 }
4677 }
4678 else if (vc.obact && vc.obact->mode & OB_MODE_PARTICLE_EDIT) {
4679 changed_multi = PE_box_select(C, &rect, sel_op);
4680 }
4681 else if (vc.obact && ((vc.obact->mode & OB_MODE_POSE) ||
4682 ((vc.obact->mode & OB_MODE_WEIGHT_PAINT) &&
4684 {
4685 changed_multi = do_pose_box_select(C, &vc, &rect, sel_op);
4686 if (changed_multi) {
4688 }
4689 }
4690 else { /* object mode with none active */
4691 changed_multi = do_object_box_select(C, &vc, &rect, sel_op);
4692 if (changed_multi) {
4694 }
4695 }
4696 }
4697
4698 WM_generic_user_data_free(wm_userdata);
4699
4700 if (changed_multi) {
4701 return OPERATOR_FINISHED;
4702 }
4703 return OPERATOR_CANCELLED;
4704}
4705
4707{
4708 /* identifiers */
4709 ot->name = "Box Select";
4710 ot->description = "Select items using box selection";
4711 ot->idname = "VIEW3D_OT_select_box";
4712
4713 /* API callbacks. */
4719
4720 /* flags */
4721 ot->flag = OPTYPE_UNDO;
4722
4723 /* rna */
4726}
4727
4729
4730/* -------------------------------------------------------------------- */
4733
4737 int mval[2];
4738 float mval_fl[2];
4739 float radius;
4742
4744 BMesh *bm = nullptr;
4746
4747 /* runtime */
4749};
4750
4752 const ViewContext *vc,
4753 const bool select,
4754 const int mval[2],
4755 const float rad)
4756{
4757 r_data->vc = vc;
4758 r_data->select = select;
4759 copy_v2_v2_int(r_data->mval, mval);
4760 r_data->mval_fl[0] = mval[0];
4761 r_data->mval_fl[1] = mval[1];
4762
4763 r_data->radius = rad;
4764 r_data->radius_squared = rad * rad;
4765
4766 /* SELECT by default, but can be changed if needed (only few cases use and respect this). */
4767 r_data->select_flag = BEZT_FLAG_SELECT;
4768
4769 /* runtime */
4770 r_data->is_changed = false;
4771}
4772
4773static void mesh_circle_doSelectVert(void *user_data,
4774 BMVert *eve,
4775 const float screen_co[2],
4776 int /*index*/)
4777{
4778 CircleSelectUserData *data = static_cast<CircleSelectUserData *>(user_data);
4779
4780 if (len_squared_v2v2(data->mval_fl, screen_co) <= data->radius_squared) {
4781 BM_vert_select_set(data->bm, eve, data->select);
4782 if (data->uv_selctx) {
4783 data->uv_selctx->vert_select_set(eve, data->select);
4784 }
4785
4786 data->is_changed = true;
4787 }
4788}
4789static void mesh_circle_doSelectEdge(void *user_data,
4790 BMEdge *eed,
4791 const float screen_co_a[2],
4792 const float screen_co_b[2],
4793 int /*index*/)
4794{
4795 CircleSelectUserData *data = static_cast<CircleSelectUserData *>(user_data);
4796
4797 if (edge_inside_circle(data->mval_fl, data->radius, screen_co_a, screen_co_b)) {
4798 BM_edge_select_set(data->bm, eed, data->select);
4799 if (data->uv_selctx) {
4800 data->uv_selctx->edge_select_set(eed, data->select);
4801 }
4802
4803 data->is_changed = true;
4804 }
4805}
4806static void mesh_circle_doSelectFace(void *user_data,
4807 BMFace *efa,
4808 const float screen_co[2],
4809 int /*index*/)
4810{
4811 CircleSelectUserData *data = static_cast<CircleSelectUserData *>(user_data);
4812
4813 if (len_squared_v2v2(data->mval_fl, screen_co) <= data->radius_squared) {
4814 BM_face_select_set(data->bm, efa, data->select);
4815 if (data->uv_selctx) {
4816 data->uv_selctx->face_select_set(efa, data->select);
4817 }
4818
4819 data->is_changed = true;
4820 }
4821}
4822
4823static bool mesh_circle_select(const ViewContext *vc,
4824 wmGenericUserData *wm_userdata,
4825 eSelectOp sel_op,
4826 const int mval[2],
4827 float rad)
4828{
4829 ToolSettings *ts = vc->scene->toolsettings;
4833
4834 bool changed = false;
4835 if (SEL_OP_USE_PRE_DESELECT(sel_op)) {
4836 if (bm->totvertsel) {
4838 bm->totvertsel = 0;
4839 bm->totedgesel = 0;
4840 bm->totfacesel = 0;
4841 changed = true;
4842 }
4843 }
4844
4845 std::unique_ptr<UVSyncSelectFromMesh> uv_selctx = UVSyncSelectFromMesh::create_if_needed(*ts,
4846 *bm);
4847 data.uv_selctx = uv_selctx.get();
4848
4849 const bool select = (sel_op != SEL_OP_SUB);
4850
4851 ED_view3d_init_mats_rv3d(vc->obedit, vc->rv3d); /* for foreach's screen/vert projection */
4852
4854 data.bm = bm;
4855
4856 const bool use_zbuf = !XRAY_FLAG_ENABLED(vc->v3d);
4857
4858 if (use_zbuf) {
4859 if (wm_userdata->data == nullptr) {
4861 }
4862 }
4863 EditSelectBuf_Cache *esel = static_cast<EditSelectBuf_Cache *>(wm_userdata->data);
4864
4865 if (use_zbuf) {
4866 if (esel->select_bitmap == nullptr) {
4868 vc->depsgraph, vc->region, vc->v3d, mval, int(rad + 1.0f), nullptr);
4869 }
4870 }
4871
4872 if (ts->selectmode & SCE_SELECT_VERTEX) {
4873 if (use_zbuf) {
4874 if (esel->select_bitmap != nullptr) {
4876 esel, vc->depsgraph, vc->obedit, bm, data.uv_selctx, select ? SEL_OP_ADD : SEL_OP_SUB);
4877 }
4878 }
4879 else {
4881 }
4882 }
4883
4884 if (ts->selectmode & SCE_SELECT_EDGE) {
4885 if (use_zbuf) {
4886 if (esel->select_bitmap != nullptr) {
4888 esel, vc->depsgraph, vc->obedit, bm, data.uv_selctx, select ? SEL_OP_ADD : SEL_OP_SUB);
4889 }
4890 }
4891 else {
4893 vc,
4895 &data,
4897 }
4898 }
4899
4900 if (ts->selectmode & SCE_SELECT_FACE) {
4901 if (use_zbuf) {
4902 if (esel->select_bitmap != nullptr) {
4904 esel, vc->depsgraph, vc->obedit, bm, data.uv_selctx, select ? SEL_OP_ADD : SEL_OP_SUB);
4905 }
4906 }
4907 else {
4909 }
4910 }
4911
4912 changed |= data.is_changed;
4913
4914 if (changed) {
4916 }
4917
4918 if (data.uv_selctx) {
4919 data.uv_selctx->apply();
4920 }
4921
4922 return changed;
4923}
4924
4926 wmGenericUserData *wm_userdata,
4927 const eSelectOp sel_op,
4928 const int mval[2],
4929 float rad)
4930{
4932 Object *ob = vc->obact;
4933 Mesh *mesh = id_cast<Mesh *>(ob->data);
4934
4935 bool changed = false;
4936 if (SEL_OP_USE_PRE_DESELECT(sel_op)) {
4937 /* flush selection at the end */
4938 changed |= paintface_deselect_all_visible(vc->C, ob, SEL_DESELECT, false);
4939 }
4940
4941 if (wm_userdata->data == nullptr) {
4943 }
4944
4945 {
4946 EditSelectBuf_Cache *esel = static_cast<EditSelectBuf_Cache *>(wm_userdata->data);
4948 vc->depsgraph, vc->region, vc->v3d, mval, int(rad + 1.0f), nullptr);
4949 if (esel->select_bitmap != nullptr) {
4950 changed |= edbm_backbuf_check_and_select_faces_obmode(mesh, esel, sel_op);
4951 MEM_delete(esel->select_bitmap);
4952 esel->select_bitmap = nullptr;
4953 }
4954 }
4955
4956 if (changed) {
4957 paintface_flush_flags(vc->C, ob, true, false);
4958 }
4959 return changed;
4960}
4961
4967 const float screen_co[2],
4968 int index)
4969{
4971 static_cast<CircleSelectUserData_ForMeshObjectVert *>(user_data);
4972 CircleSelectUserData *data = &mesh_data->circle_data;
4973
4974 if (len_squared_v2v2(data->mval_fl, screen_co) <= data->radius_squared) {
4975 mesh_data->select_vert[index] = data->select;
4976 data->is_changed = true;
4977 }
4978}
4980 wmGenericUserData *wm_userdata,
4981 const eSelectOp sel_op,
4982 const int mval[2],
4983 float rad)
4984{
4986 const bool use_zbuf = !XRAY_ENABLED(vc->v3d);
4987 Object *ob = vc->obact;
4988 Mesh *mesh = id_cast<Mesh *>(ob->data);
4989 // CircleSelectUserData data = {nullptr}; /* UNUSED. */
4990
4991 bool changed = false;
4992 if (SEL_OP_USE_PRE_DESELECT(sel_op)) {
4993 /* Flush selection at the end. */
4994 changed |= paintvert_deselect_all_visible(ob, SEL_DESELECT, false);
4995 }
4996
4997 const bool select = (sel_op != SEL_OP_SUB);
4998
4999 if (use_zbuf) {
5000 if (wm_userdata->data == nullptr) {
5002 }
5003 }
5004
5005 if (use_zbuf) {
5006 EditSelectBuf_Cache *esel = static_cast<EditSelectBuf_Cache *>(wm_userdata->data);
5008 vc->depsgraph, vc->region, vc->v3d, mval, int(rad + 1.0f), nullptr);
5009 if (esel->select_bitmap != nullptr) {
5010 changed |= edbm_backbuf_check_and_select_verts_obmode(mesh, esel, sel_op);
5011 MEM_delete(esel->select_bitmap);
5012 esel->select_bitmap = nullptr;
5013 }
5014 }
5015 else {
5016 bke::MutableAttributeAccessor attributes = mesh->attributes_for_write();
5017 bke::SpanAttributeWriter<bool> select_vert = attributes.lookup_or_add_for_write_span<bool>(
5018 ".select_vert", bke::AttrDomain::Point);
5019
5021 data.select_vert = select_vert.span;
5022
5023 ED_view3d_init_mats_rv3d(vc->obact, vc->rv3d); /* for foreach's screen/vert projection */
5024
5025 view3d_userdata_circleselect_init(&data.circle_data, vc, select, mval, rad);
5028 changed |= data.circle_data.is_changed;
5029 select_vert.finish();
5030 }
5031
5032 if (changed) {
5033 if (sel_op == SEL_OP_SUB) {
5035 }
5038 }
5039 return changed;
5040}
5041
5042static void nurbscurve_circle_doSelect(void *user_data,
5043 Nurb * /*nu*/,
5044 BPoint *bp,
5045 BezTriple *bezt,
5046 int beztindex,
5047 bool /*handles_visible*/,
5048 const float screen_co[2])
5049{
5050 CircleSelectUserData *data = static_cast<CircleSelectUserData *>(user_data);
5051
5052 if (len_squared_v2v2(data->mval_fl, screen_co) <= data->radius_squared) {
5053 if (bp) {
5054 SET_FLAG_FROM_TEST(bp->f1, data->select, data->select_flag);
5055 }
5056 else {
5057 if (beztindex == 0) {
5058 SET_FLAG_FROM_TEST(bezt->f1, data->select, data->select_flag);
5059 }
5060 else if (beztindex == 1) {
5061 SET_FLAG_FROM_TEST(bezt->f2, data->select, data->select_flag);
5062 }
5063 else {
5064 SET_FLAG_FROM_TEST(bezt->f3, data->select, data->select_flag);
5065 }
5066 }
5067 data->is_changed = true;
5068 }
5069}
5071 const eSelectOp sel_op,
5072 const int mval[2],
5073 float rad)
5074{
5075 const bool select = (sel_op != SEL_OP_SUB);
5076 const bool deselect_all = (sel_op == SEL_OP_SET);
5078
5080
5081 Curve *curve = id_cast<Curve *>(vc->obedit->data);
5082 ListBaseT<Nurb> *nurbs = BKE_curve_editNurbs_get(curve);
5083
5084 /* For deselect all, items to be selected are tagged with temp flag. Clear that first. */
5085 if (deselect_all) {
5087 data.select_flag = BEZT_FLAG_TEMP_TAG;
5088 }
5089
5090 ED_view3d_init_mats_rv3d(vc->obedit, vc->rv3d); /* for foreach's screen/vert projection */
5092
5093 /* Deselect items that were not added to selection (indicated by temp flag). */
5094 if (deselect_all) {
5097 }
5098
5099 BKE_curve_nurb_vert_active_validate(id_cast<Curve *>(vc->obedit->data));
5100
5101 return data.is_changed;
5102}
5103
5104static void latticecurve_circle_doSelect(void *user_data, BPoint *bp, const float screen_co[2])
5105{
5106 CircleSelectUserData *data = static_cast<CircleSelectUserData *>(user_data);
5107
5108 if (len_squared_v2v2(data->mval_fl, screen_co) <= data->radius_squared) {
5109 bp->f1 = data->select ? (bp->f1 | SELECT) : (bp->f1 & ~SELECT);
5110 data->is_changed = true;
5111 }
5112}
5114 const eSelectOp sel_op,
5115 const int mval[2],
5116 float rad)
5117{
5119 const bool select = (sel_op != SEL_OP_SUB);
5120
5122
5123 if (SEL_OP_USE_PRE_DESELECT(sel_op)) {
5124 data.is_changed |= ED_lattice_flags_set(vc->obedit, 0);
5125 }
5126 ED_view3d_init_mats_rv3d(vc->obedit, vc->rv3d); /* for foreach's screen/vert projection */
5127
5129
5130 return data.is_changed;
5131}
5132
5134 const ViewContext *vc,
5135 const eSelectOp sel_op,
5136 const int2 mval,
5137 const float radius)
5138{
5140
5141 /* Selection buffer has bones potentially too. */
5142 GPUSelectBuffer buffer;
5144 vc->scene, vc->v3d, vc->obact);
5145 rcti rect;
5146 BLI_rcti_init_pt_radius(&rect, mval, radius);
5147 const int hits = view3d_gpu_select(
5148 vc, &buffer, &rect, VIEW3D_SELECT_ALL, select_filter, eV3DSelectShape::CIRCLE);
5149 process_pose_bone_hits(buffer, hits, bases);
5150
5151 const bool changed_multi = do_pose_tag_select_op_exec(bases, sel_op);
5152 if (changed_multi) {
5155 }
5156
5157 return changed_multi;
5158}
5159
5163static bool armature_circle_doSelectJoint(void *user_data,
5164 EditBone *ebone,
5165 const float screen_co[2],
5166 bool head)
5167{
5168 CircleSelectUserData *data = static_cast<CircleSelectUserData *>(user_data);
5169
5170 if (len_squared_v2v2(data->mval_fl, screen_co) <= data->radius_squared) {
5171 if (head) {
5172 if (data->select) {
5173 ebone->flag |= BONE_ROOTSEL;
5174 }
5175 else {
5176 ebone->flag &= ~BONE_ROOTSEL;
5177 }
5178 }
5179 else {
5180 if (data->select) {
5181 ebone->flag |= BONE_TIPSEL;
5182 }
5183 else {
5184 ebone->flag &= ~BONE_TIPSEL;
5185 }
5186 }
5187 return true;
5188 }
5189 return false;
5190}
5192 EditBone *ebone,
5193 const float screen_co_a[2],
5194 const float screen_co_b[2])
5195{
5196 CircleSelectUserData *data = static_cast<CircleSelectUserData *>(user_data);
5197 const bArmature *arm = id_cast<const bArmature *>(data->vc->obedit->data);
5198 if (!(data->select ? EBONE_SELECTABLE(arm, ebone) : animrig::bone_is_visible(arm, ebone))) {
5199 return;
5200 }
5201
5202 /* When true, ignore in the next pass. */
5203 ebone->temp.i = false;
5204
5205 bool is_point_done = false;
5206 bool is_edge_done = false;
5207 int points_proj_tot = 0;
5208
5209 /* Project head location to screen-space. */
5210 if (screen_co_a[0] != IS_CLIPPED) {
5211 points_proj_tot++;
5212 if (armature_circle_doSelectJoint(data, ebone, screen_co_a, true)) {
5213 is_point_done = true;
5214 }
5215 }
5216
5217 /* Project tail location to screen-space. */
5218 if (screen_co_b[0] != IS_CLIPPED) {
5219 points_proj_tot++;
5220 if (armature_circle_doSelectJoint(data, ebone, screen_co_b, false)) {
5221 is_point_done = true;
5222 }
5223 }
5224
5225 /* check if the head and/or tail is in the circle
5226 * - the call to check also does the selection already
5227 */
5228
5229 /* only if the endpoints didn't get selected, deal with the middle of the bone too
5230 * It works nicer to only do this if the head or tail are not in the circle,
5231 * otherwise there is no way to circle select joints alone */
5232 if ((is_point_done == false) && (points_proj_tot == 2) &&
5233 edge_inside_circle(data->mval_fl, data->radius, screen_co_a, screen_co_b))
5234 {
5236 is_edge_done = true;
5237 data->is_changed = true;
5238 }
5239
5240 if (is_point_done || is_edge_done) {
5241 ebone->temp.i = true;
5242 }
5243
5244 data->is_changed |= is_point_done;
5245}
5247 EditBone *ebone,
5248 const float screen_co_a[2],
5249 const float screen_co_b[2])
5250{
5251 CircleSelectUserData *data = static_cast<CircleSelectUserData *>(user_data);
5252 bArmature *arm = id_cast<bArmature *>(data->vc->obedit->data);
5253
5254 if (!(data->select ? EBONE_SELECTABLE(arm, ebone) : animrig::bone_is_visible(arm, ebone))) {
5255 return;
5256 }
5257
5258 /* Set in the first pass, needed so circle select prioritizes joints. */
5259 if (ebone->temp.i != 0) {
5260 return;
5261 }
5262
5263 if (edge_inside_circle(data->mval_fl, data->radius, screen_co_a, screen_co_b)) {
5265 data->is_changed = true;
5266 }
5267}
5269 const eSelectOp sel_op,
5270 const int mval[2],
5271 float rad)
5272{
5274 bArmature *arm = id_cast<bArmature *>(vc->obedit->data);
5275
5276 const bool select = (sel_op != SEL_OP_SUB);
5277
5279
5280 if (SEL_OP_USE_PRE_DESELECT(sel_op)) {
5282 }
5283
5285
5286 /* Operate on fully visible (non-clipped) points. */
5289
5290 /* Operate on bones as segments clipped to the viewport bounds
5291 * (needed to handle bones with both points outside the view).
5292 * A separate pass is needed since clipped coordinates can't be used for selecting joints. */
5295 &data,
5297
5298 if (data.is_changed) {
5301 }
5302 return data.is_changed;
5303}
5304
5305static void do_circle_select_mball__doSelectElem(void *user_data,
5306 MetaElem *ml,
5307 const float screen_co[2])
5308{
5309 CircleSelectUserData *data = static_cast<CircleSelectUserData *>(user_data);
5310
5311 if (len_squared_v2v2(data->mval_fl, screen_co) <= data->radius_squared) {
5312 if (data->select) {
5313 ml->flag |= MB_SELECT;
5314 }
5315 else {
5316 ml->flag &= ~MB_SELECT;
5317 }
5318 data->is_changed = true;
5319 }
5320}
5321static bool mball_circle_select(const ViewContext *vc,
5322 const eSelectOp sel_op,
5323 const int mval[2],
5324 float rad)
5325{
5327
5328 const bool select = (sel_op != SEL_OP_SUB);
5329
5331
5332 if (SEL_OP_USE_PRE_DESELECT(sel_op)) {
5333 data.is_changed |= BKE_mball_deselect_all(id_cast<MetaBall *>(vc->obedit->data));
5334 }
5335
5337
5340 return data.is_changed;
5341}
5342
5344 const eSelectOp sel_op,
5345 const int mval[2],
5346 const float rad)
5347{
5348 Object *object = (vc->obedit ? vc->obedit : vc->obact);
5349 const Object *ob_eval = DEG_get_evaluated(vc->depsgraph, object);
5350 const GreasePencil &grease_pencil = *id_cast<GreasePencil *>(object->data);
5352 vc->scene->toolsettings, object);
5353
5355 vc,
5356 sel_op,
5358 const IndexMask &mask,
5359 const StringRef attribute_name,
5360 IndexMaskMemory &memory) {
5363 const bke::crazyspace::GeometryDeformation deformation =
5365 ob_eval, *object, info.drawing);
5366 const IndexMask visible_handle_elements =
5368 *object,
5369 info.drawing,
5370 info.layer_index,
5371 selection_domain,
5373 memory);
5374 const float4x4 layer_to_world = layer.to_world_space(*ob_eval);
5376 layer_to_world);
5377
5379 curves,
5380 deformation,
5381 projection,
5382 mask,
5383 visible_handle_elements,
5384 selection_domain,
5385 attribute_name,
5386 int2(mval),
5387 rad,
5388 memory);
5389 });
5390}
5391
5392static bool curves_select_circle(const ViewContext &vc,
5393 const Object *object,
5394 const eSelectOp sel_op,
5395 const int mval[2],
5396 const float radius)
5397{
5398 Curves &curves_id = *id_cast<Curves *>(object->data);
5399 bke::CurvesGeometry &curves = curves_id.geometry.wrap();
5402 const bke::AttrDomain selection_domain = bke::AttrDomain(curves_id.selection_domain);
5403 const float4x4 projection = ED_view3d_ob_project_mat_get(vc.rv3d, object);
5404 const IndexRange elements(curves.attributes().domain_size(selection_domain));
5405
5406 return ed::curves::select_circle(vc,
5407 curves,
5408 deformation,
5409 projection,
5410 elements,
5411 elements,
5412 selection_domain,
5413 int2(mval),
5414 radius,
5415 sel_op);
5416}
5417
5419 const eSelectOp sel_op,
5420 const int mval[2],
5421 const float radius)
5422{
5423 const Object *object = (vc.obedit ? vc.obedit : vc.obact);
5424 return curves_select_circle(vc, object, sel_op, mval, radius);
5425}
5426
5431 const ViewContext *vc,
5432 wmGenericUserData *wm_userdata,
5433 const eSelectOp sel_op,
5434 const int mval[2],
5435 float rad)
5436{
5437 bool changed = false;
5439 switch (vc->obedit->type) {
5440 case OB_MESH:
5441 changed = mesh_circle_select(vc, wm_userdata, sel_op, mval, rad);
5442 break;
5443 case OB_CURVES_LEGACY:
5444 case OB_SURF:
5445 changed = nurbscurve_circle_select(vc, sel_op, mval, rad);
5446 break;
5447 case OB_LATTICE:
5448 changed = lattice_circle_select(vc, sel_op, mval, rad);
5449 break;
5450 case OB_ARMATURE:
5451 changed = armature_circle_select(vc, sel_op, mval, rad);
5452 if (changed) {
5454 }
5455 break;
5456 case OB_MBALL:
5457 changed = mball_circle_select(vc, sel_op, mval, rad);
5458 break;
5459 case OB_CURVES: {
5460 changed = curves_select_circle(*vc, vc->obedit, sel_op, mval, rad);
5461 if (changed) {
5464 }
5465 break;
5466 }
5467 case OB_POINTCLOUD: {
5468 PointCloud &pointcloud = *id_cast<PointCloud *>(vc->obedit->data);
5469 const float4x4 projection = ED_view3d_ob_project_mat_get(vc->rv3d, vc->obedit);
5471 pointcloud, *vc->region, projection, mval, rad, sel_op);
5472 if (changed) {
5473 /* Use #ID_RECALC_GEOMETRY instead of #ID_RECALC_SELECT because it is handled as a
5474 * generic attribute for now. */
5477 }
5478 break;
5479 }
5480 case OB_GREASE_PENCIL:
5481 changed = grease_pencil_circle_select(vc, sel_op, mval, rad);
5482 break;
5483
5484 default:
5485 BLI_assert(0);
5486 break;
5487 }
5488
5489 if (changed) {
5492 }
5493 return changed;
5494}
5495
5496static bool object_circle_select(const ViewContext *vc,
5497 const eSelectOp sel_op,
5498 const int mval[2],
5499 float rad)
5500{
5502 Scene *scene = vc->scene;
5503 ViewLayer *view_layer = vc->view_layer;
5504 View3D *v3d = vc->v3d;
5505
5506 const float radius_squared = rad * rad;
5507 const float mval_fl[2] = {float(mval[0]), float(mval[1])};
5508
5509 bool changed = false;
5510 if (SEL_OP_USE_PRE_DESELECT(sel_op)) {
5511 changed |= object_deselect_all_visible(*vc->bmain, vc->scene, vc->view_layer, vc->v3d);
5512 }
5513 const bool select = (sel_op != SEL_OP_SUB);
5514 const int select_flag = select ? BASE_SELECTED : 0;
5515 BKE_view_layer_synced_ensure(*vc->bmain, scene, view_layer);
5516 for (Base &base : *BKE_view_layer_object_bases_get(view_layer)) {
5517 if (BASE_SELECTABLE(v3d, &base) && ((base.flag & BASE_SELECTED) != select_flag)) {
5518 float screen_co[2];
5520 base.object->object_to_world().location(),
5521 screen_co,
5523 {
5524 if (len_squared_v2v2(mval_fl, screen_co) <= radius_squared) {
5526 changed = true;
5527 }
5528 }
5529 }
5530 }
5531
5532 return changed;
5533}
5534
5535/* not a real operator, only for circle test */
5536static void view3d_circle_select_recalc(void *user_data)
5537{
5538 bContext *C = static_cast<bContext *>(user_data);
5539 Object *obedit_active = CTX_data_edit_object(C);
5540
5541 if (obedit_active) {
5542 switch (obedit_active->type) {
5543 case OB_MESH: {
5546 vc.bmain, vc.scene, vc.view_layer, vc.v3d, vc.obact->type, vc.obact->mode, ob_iter)
5547 {
5551 }
5553 break;
5554 }
5555
5556 default: {
5557 /* TODO: investigate if this is needed for other object types. */
5559 break;
5560 }
5561 }
5562 }
5563}
5564
5566 wmOperator *op,
5567 const wmEvent *event)
5568{
5570 if (result & OPERATOR_FINISHED) {
5572 }
5573 return result;
5574}
5575
5581
5583{
5584 Depsgraph *depsgraph = CTX_data_ensure_evaluated_depsgraph(C);
5585 const int radius = RNA_int_get(op->ptr, "radius");
5586 const int mval[2] = {RNA_int_get(op->ptr, "x"), RNA_int_get(op->ptr, "y")};
5587
5588 /* Allow each selection type to allocate their own data that's used between executions. */
5589 wmGesture *gesture = static_cast<wmGesture *>(op->customdata); /* nullptr when non-modal. */
5590 wmGenericUserData wm_userdata_buf = {nullptr, nullptr, false};
5591 wmGenericUserData *wm_userdata = gesture ? &gesture->user_data : &wm_userdata_buf;
5592
5593 const eSelectOp sel_op = ED_select_op_modal(
5594 static_cast<eSelectOp>(RNA_enum_get(op->ptr, "mode")), WM_gesture_is_modal_first(gesture));
5595
5596 ViewContext vc = ED_view3d_viewcontext_init(C, depsgraph);
5597
5598 Object *obact = vc.obact;
5599 Object *obedit = vc.obedit;
5600
5601 if (obedit || BKE_paint_select_elem_test(obact) ||
5602 (obact && (obact->mode & (OB_MODE_POSE | OB_MODE_SCULPT_CURVES))))
5603 {
5605 if (obedit == nullptr) {
5607 }
5608 else {
5609 if (vc.obedit->type == OB_MESH) {
5611 }
5612 }
5613
5615 vc.bmain, vc.scene, vc.view_layer, vc.v3d, obact->type, obact->mode, ob_iter)
5616 {
5618
5619 obact = vc.obact;
5620 obedit = vc.obedit;
5621
5622 if (obedit) {
5623 obedit_circle_select(C, &vc, wm_userdata, sel_op, mval, float(radius));
5624 }
5625 else if (BKE_paint_select_face_test(obact)) {
5626 paint_facesel_circle_select(&vc, wm_userdata, sel_op, mval, float(radius));
5627 }
5628 else if (BKE_paint_select_vert_test(obact)) {
5629 paint_vertsel_circle_select(&vc, wm_userdata, sel_op, mval, float(radius));
5630 }
5631 else if (BKE_paint_select_grease_pencil_test(obact)) {
5632 grease_pencil_circle_select(&vc, sel_op, mval, float(radius));
5633 }
5634 else if ((obact->mode & OB_MODE_SCULPT_CURVES) && (obact->type == OB_CURVES)) {
5635 const bool changed = do_curves_sculpt_circle_select(vc, sel_op, mval, float(radius));
5636 if (changed) {
5639 }
5640 }
5641 else if (obact->mode & OB_MODE_POSE) {
5642 pose_circle_select(C, &vc, sel_op, mval, float(radius));
5644 }
5645 else {
5646 BLI_assert(0);
5647 }
5648 }
5650 }
5651 else if (obact && (obact->mode & OB_MODE_PARTICLE_EDIT)) {
5652 if (PE_circle_select(C, wm_userdata, sel_op, mval, float(radius))) {
5653 return OPERATOR_FINISHED;
5654 }
5655 return OPERATOR_CANCELLED;
5656 }
5657 else if (obact && obact->mode & OB_MODE_SCULPT) {
5658 return OPERATOR_CANCELLED;
5659 }
5660 else if (Object *obact_pose = (obact && (obact->mode & OB_MODE_WEIGHT_PAINT)) ?
5662 nullptr)
5663 {
5664 ED_view3d_viewcontext_init_object(&vc, obact_pose);
5665 pose_circle_select(C, &vc, sel_op, mval, float(radius));
5667 }
5668 else {
5669 if (object_circle_select(&vc, sel_op, mval, float(radius))) {
5672
5674 }
5675 }
5676
5677 /* Otherwise this is freed by the gesture. */
5678 if (wm_userdata == &wm_userdata_buf) {
5679 WM_generic_user_data_free(wm_userdata);
5680 }
5681 else {
5682 EditSelectBuf_Cache *esel = static_cast<EditSelectBuf_Cache *>(wm_userdata->data);
5683 if (esel && esel->select_bitmap) {
5684 MEM_delete(esel->select_bitmap);
5685 esel->select_bitmap = nullptr;
5686 }
5687 }
5688
5689 return OPERATOR_FINISHED;
5690}
5691
5693{
5694 ot->name = "Circle Select";
5695 ot->description = "Select items using circle selection";
5696 ot->idname = "VIEW3D_OT_select_circle";
5697
5704
5705 /* flags */
5706 ot->flag = OPTYPE_UNDO;
5707
5708 /* properties */
5711}
5712
5714
5715} // namespace blender
Functions to deal with Armatures.
Blender kernel action and pose functionality.
#define CTX_DATA_BEGIN(C, Type, instance, member)
#define CTX_DATA_END
Low-level operations for curves.
Low-level operations for grease pencil.
#define FOREACH_BASE_IN_MODE_BEGIN(_bmain, _scene, _view_layer, _v3d, _object_type, _object_mode, _instance)
Definition BKE_layer.hh:436
#define FOREACH_BASE_IN_MODE_END
Definition BKE_layer.hh:454
#define FOREACH_OBJECT_IN_MODE_BEGIN(_bmain, _scene, _view_layer, _v3d, _object_type, _object_mode, _instance)
Definition BKE_layer.hh:470
#define FOREACH_OBJECT_IN_MODE_END
Definition BKE_layer.hh:477
#define SELECT
Definition BKE_mask.hh:19
General operations, lookup, etc. for blender objects.
#define TRACK_SELECTED(track)
#define BLI_BITMAP_TEST_BOOL(_bitmap, _index)
Definition BLI_bitmap.hh:73
#define CTX_IFACE_(context, msgid)
#define BLT_I18NCONTEXT_OPERATOR_DEFAULT
#define MAX_ID_NAME
Definition DNA_ID.h:367
#define OB_MODE_ALL_WEIGHT_PAINT
Object is a sort of wrapper for general info.
#define BASE_VISIBLE(v3d, base)
#define UI_SCALE_FAC
#define BONESEL_ANY
#define BONESEL_ROOT
#define BONESEL_TIP
#define BONESEL_BONE
#define EBONE_SELECTABLE(arm, ebone)
#define MBALLSEL_ANY
Definition ED_mball.hh:66
#define MBALLSEL_STIFF
Definition ED_mball.hh:64
#define MBALLSEL_RADIUS
Definition ED_mball.hh:65
#define ED_MESH_PICK_DEFAULT_VERT_DIST
Definition ED_mesh.hh:666
#define SEL_OP_USE_PRE_DESELECT(sel_op)
#define SEL_OP_CAN_DESELECT(sel_op)
#define SEL_OP_USE_OUTSIDE(sel_op)
#define V3D_PROJ_TEST_CLIP_CONTENT_DEFAULT
Definition ED_view3d.hh:331
#define XRAY_ENABLED(v3d)
#define XRAY_ACTIVE(v3d)
#define IS_CLIPPED
Definition ED_view3d.hh:269
#define V3D_PROJ_TEST_CLIP_DEFAULT
Definition ED_view3d.hh:325
#define XRAY_FLAG_ENABLED(v3d)
Read Blender memory allocation and freeing.
#define C
Definition RandGen.cpp:29
#define NC_GEOM
Definition WM_types.hh:406
#define ND_DATA
Definition WM_types.hh:552
#define NC_MOVIECLIP
Definition WM_types.hh:410
#define ND_OB_SELECT
Definition WM_types.hh:461
#define NC_SCENE
Definition WM_types.hh:391
#define ND_SELECT
Definition WM_types.hh:551
#define ND_BONE_ACTIVE
Definition WM_types.hh:483
#define ND_BONE_SELECT
Definition WM_types.hh:491
#define NC_OBJECT
Definition WM_types.hh:392
#define UNPACK2(a)
#define BLI_assert_unreachable()
#define UNUSED_VARS_NDEBUG(...)
#define SET_FLAG_FROM_TEST(value, test, flag)
#define ELEM(...)
#define BLI_assert_msg(a, msg)
#define STREQ(a, b)
#define BM_elem_flag_test(ele, hflag)
#define BM_ITER_MESH(ele, iter, bm, itype)
#define BMSelectFlushFlag_All
bool closest(btVector3 &v)
bool is_empty() const
Definition BLI_array.hh:275
static constexpr IndexRange from_single(const int64_t index)
bool add(const Key &key, const Value &value)
Definition BLI_map.hh:295
Value lookup_default(const Key &key, const Value &default_value) const
Definition BLI_map.hh:570
constexpr MutableSpan slice(const int64_t start, const int64_t size) const
Definition BLI_span.hh:579
constexpr IndexRange index_range() const
Definition BLI_span.hh:676
bool contains(const Key &key) const
Definition BLI_set.hh:310
bool add(const Key &key)
Definition BLI_set.hh:248
constexpr const T * data() const
Definition BLI_span.hh:219
constexpr int64_t size() const
Definition BLI_span.hh:256
constexpr bool is_empty() const
Definition BLI_span.hh:264
static std::unique_ptr< UVSyncSelectFromMesh > create_if_needed(const ToolSettings &ts, BMesh &bm)
int64_t size() const
void append(const T &value)
IndexRange index_range() const
void resize(const int64_t new_size)
Span< T > as_span() const
GAttributeReader lookup_or_default(StringRef name, AttrDomain domain, AttrType data_type, const void *default_value=nullptr) const
GSpanAttributeWriter lookup_or_add_for_write_span(StringRef name, AttrDomain domain, AttrType data_type, const AttributeInit &initializer=AttributeInitDefaultValue())
GAttributeWriter lookup_or_add_for_write(StringRef name, AttrDomain domain, AttrType data_type, const AttributeInit &initializer=AttributeInitDefaultValue())
bke::CurvesGeometry & strokes_for_write()
const bke::CurvesGeometry & strokes() const
constexpr void copy_from(Span< T > values) const
void vert_select_set(BMVert *v, bool value)
void face_select_set(BMFace *f, bool value)
void edge_select_set(BMEdge *f, bool value)
IndexMask slice_content(IndexRange range) const
#define INT_MAX
#define storage(slot, qualifiers)
#define layer
bool bone_is_visible(const bArmature *armature, const Bone *bone)
bool bone_is_selectable(const bArmature *armature, const bke::PChanBoneConst pchanbone)
GeometryDeformation get_evaluated_grease_pencil_drawing_deformation(const Object *ob_eval, const Object &ob_orig, const bke::greasepencil::Drawing &drawing_orig)
GeometryDeformation get_evaluated_curves_deformation(const Object *ob_eval, const Object &ob_orig)
void apply_selection_operation_at_index(GMutableSpan selection, const int index, const eSelectOp sel_op)
void foreach_selectable_point_range(const bke::CurvesGeometry &curves, const bke::crazyspace::GeometryDeformation &deformation, eHandleDisplay handle_display, SelectionRangeFn range_consumer)
IndexMask select_circle_mask(const ViewContext &vc, const bke::CurvesGeometry &curves, const bke::crazyspace::GeometryDeformation &deformation, const float4x4 &projection, const IndexMask &selection_mask, const IndexMask &bezier_mask, const bke::AttrDomain selection_domain, const StringRef attribute_name, const int2 coord, const float radius, IndexMaskMemory &memory)
void foreach_selectable_curve_range(const bke::CurvesGeometry &curves, const bke::crazyspace::GeometryDeformation &deformation, eHandleDisplay handle_display, SelectionRangeFn range_consumer)
void foreach_selection_attribute_writer(bke::CurvesGeometry &curves, bke::AttrDomain selection_domain, FunctionRef< void(bke::GSpanAttributeWriter &selection)> fn)
IndexMask select_lasso_mask(const ViewContext &vc, const bke::CurvesGeometry &curves, const bke::crazyspace::GeometryDeformation &deformation, const float4x4 &projection, const IndexMask &selection_mask, const IndexMask &bezier_mask, const bke::AttrDomain selection_domain, const StringRef attribute_name, const Span< int2 > lasso_coords, IndexMaskMemory &memory)
bool select_circle(const ViewContext &vc, bke::CurvesGeometry &curves, const bke::crazyspace::GeometryDeformation &deformation, const float4x4 &projection, const IndexMask &selection_mask, const IndexMask &bezier_mask, const bke::AttrDomain selection_domain, const int2 coord, const float radius, const eSelectOp sel_op)
std::optional< FindClosestData > closest_elem_find_screen_space(const ViewContext &vc, const OffsetIndices< int > points_by_curve, const Span< float3 > positions, const VArray< bool > &cyclic, const float4x4 &projection, const IndexMask &mask, const bke::AttrDomain domain, const int2 coord, const FindClosestData &initial_closest)
IndexMask select_box_mask(const ViewContext &vc, const bke::CurvesGeometry &curves, const bke::crazyspace::GeometryDeformation &deformation, const float4x4 &projection, const IndexMask &selection_mask, const IndexMask &bezier_mask, const bke::AttrDomain selection_domain, const StringRef attribute_name, const rcti &rect, IndexMaskMemory &memory)
bool select_lasso(const ViewContext &vc, bke::CurvesGeometry &curves, const bke::crazyspace::GeometryDeformation &deformation, const float4x4 &projection, const IndexMask &selection_mask, const IndexMask &bezier_mask, const bke::AttrDomain selection_domain, const Span< int2 > lasso_coords, const eSelectOp sel_op)
bke::GSpanAttributeWriter ensure_selection_attribute(bke::CurvesGeometry &curves, bke::AttrDomain selection_domain, bke::AttrType create_type, StringRef attribute_name)
bool select_box(const ViewContext &vc, bke::CurvesGeometry &curves, const bke::crazyspace::GeometryDeformation &deformation, const float4x4 &projection, const IndexMask &selection_mask, const IndexMask &bezier_mask, const bke::AttrDomain selection_domain, const rcti &rect, const eSelectOp sel_op)
bool selection_update(const ViewContext *vc, const eSelectOp sel_op, SelectionUpdateFunc select_operation)
IndexMask retrieve_editable_elements(Object &object, const MutableDrawingInfo &info, const bke::AttrDomain selection_domain, IndexMaskMemory &memory)
Vector< MutableDrawingInfo > retrieve_editable_drawings(const Scene &scene, GreasePencil &grease_pencil)
IndexMask retrieve_visible_bezier_handle_elements(Object &object, const bke::greasepencil::Drawing &drawing, const int layer_index, const bke::AttrDomain selection_domain, const eHandleDisplay handle_display, IndexMaskMemory &memory)
void base_activate(bContext *C, Base *base)
void base_select(Base *base, eObjectSelect_Mode mode)
void mode_generic_exit(Main *bmain, Depsgraph *depsgraph, Scene *scene, Object *ob)
bool select_box(PointCloud &pointcloud, const ARegion &region, const float4x4 &projection, const rcti &rect, const eSelectOp sel_op)
Definition selection.cc:158
bool select_lasso(PointCloud &pointcloud, const ARegion &region, const float4x4 &projection, const Span< int2 > lasso_coords, const eSelectOp sel_op)
Definition selection.cc:177
bool select_circle(PointCloud &pointcloud, const ARegion &region, const float4x4 &projection, const int2 coord, const float radius, const eSelectOp sel_op)
Definition selection.cc:206
std::optional< FindClosestData > find_closest_point_to_screen_co(const ARegion &region, const Span< float3 > positions, const float4x4 &projection, const IndexMask &points_mask, const float2 mouse_pos, const float radius, const FindClosestData &initial_closest)
Definition selection.cc:236
void parallel_for(const IndexRange range, const int64_t grain_size, const Function &function, const TaskSizeHints &size_hints=detail::TaskSizeHints_Static(1))
Definition BLI_task.hh:69
Value parallel_reduce(IndexRange range, int64_t grain_size, const Value &identity, const Function &function, const Reduction &reduction)
Definition BLI_task.hh:127
int icon_from_id(const ID *id)
BMesh Iterators.
static bool do_lattice_box_select(const ViewContext *vc, const rcti *rect, const eSelectOp sel_op)
void WM_main_add_notifier(uint type, void *reference)
void EDBM_flag_disable_all(BMesh *bm, char hflag)
UserDef U
Definition blender.cc:58
BLI_assert(slot->slot_subtype.map==BMO_OP_SLOT_SUBTYPE_MAP_FLT)
void RNA_def_enum_funcs(PropertyRNA *prop, EnumPropertyItemFunc itemfunc)
std::string ED_select_circle_get_name(wmOperatorType *ot, PointerRNA *ptr)
static bool selectbuffer_has_bones(const Span< GPUSelectResult > hit_results)
@ V3D_PROJ_RET_OK
Definition ED_view3d.hh:273
static int selectbuffer_ret_hits_15(MutableSpan< GPUSelectResult >, const int hits15)
wmOperatorStatus WM_menu_invoke(bContext *C, wmOperator *op, const wmEvent *)
void RNA_enum_item_add(EnumPropertyItem **items, int *totitem, const EnumPropertyItem *item)
static bool do_curves_sculpt_lasso_select(const ViewContext &vc, const Span< int2 > mcoords, const eSelectOp sel_op)
static void do_lasso_select_mesh__doSelectVert(void *user_data, BMVert *eve, const float screen_co[2], int)
Base * ED_armature_base_and_ebone_from_select_buffer(const Span< Base * > bases, const uint select_id, EditBone **r_ebone)
static bool do_paintface_box_select(const ViewContext *vc, wmGenericUserData *wm_userdata, const rcti *rect, eSelectOp sel_op)
static void do_mesh_box_select__doSelectEdge_pass1(void *user_data, BMEdge *eed, const float screen_co_a[2], const float screen_co_b[2], int index)
static bool edbm_backbuf_check_and_select_verts(EditSelectBuf_Cache *esel, Depsgraph *depsgraph, Object *ob, BMesh *bm, UVSyncSelectFromMesh *uv_selctx, const eSelectOp sel_op)
MINLINE void copy_v2_v2_int(int r[2], const int a[2])
void WM_operator_properties_gesture_circle(wmOperatorType *ot)
int RNA_enum_get(PointerRNA *ptr, const char *name)
static int mixed_bones_object_selectbuffer_extended(const ViewContext *vc, GPUSelectBuffer *buffer, const int mval[2], eV3DSelectObjectFilter select_filter, bool use_cycle, bool enumerate, bool *r_do_nearest)
bool EDBM_select_pick(bContext *C, const int mval[2], const SelectPick_Params &params)
static bool do_curves_select_box(const ViewContext &vc, const Object *object, const rcti *rect, const eSelectOp sel_op)
static wmOperatorStatus view3d_box_select_exec(bContext *C, wmOperator *op)
void view3d_gpu_select_cache_end()
static bool object_deselect_all_visible(const Main &bmain, const Scene *scene, ViewLayer *view_layer, View3D *v3d)
bool ED_armature_edit_select_pick(bContext *C, const int mval[2], const SelectPick_Params &params)
void EDBM_selectmode_flush(BMesh *bm, short selectmode)
bool BLI_rctf_isect_pt_v(const struct rctf *rect, const float xy[2])
BMesh * BKE_editmesh_bmesh_get_for_write(Mesh *mesh)
Definition editmesh.cc:79
static wmOperatorStatus view3d_circle_select_exec(bContext *C, wmOperator *op)
eSelectOp ED_select_op_from_operator(PointerRNA *ptr) ATTR_WARN_UNUSED_RESULT
ViewContext ED_view3d_viewcontext_init(bContext *C, Depsgraph *depsgraph)
wmOperatorStatus WM_gesture_box_invoke(bContext *C, wmOperator *op, const wmEvent *event)
wmOperatorStatus WM_operator_flag_only_pass_through_on_press(wmOperatorStatus retval, const wmEvent *event)
unsigned int uint
Definition BKE_text.h:55
static void deselect_all_tracks(MovieTracking *tracking)
void ED_outliner_select_sync_from_pose_bone_tag(bContext *C)
void paintvert_tag_select_update(bContext *C, Object *ob)
Definition editface.cc:1026
bool ED_armature_selectresult_is_bone(const GPUSelectResult &hit_result)
static int selectbuffer_ret_hits_9(MutableSpan< GPUSelectResult > hit_results, const int hits15, const int hits9)
static void do_lasso_select_mball__doSelectElem(void *user_data, MetaElem *ml, const float screen_co[2])
eSelectOp ED_select_op_modal(eSelectOp sel_op, bool is_first)
static void do_circle_select_armature__doSelectBone_clip_content(void *user_data, EditBone *ebone, const float screen_co_a[2], const float screen_co_b[2])
static Base * ed_view3d_give_base_under_cursor_ex(bContext *C, const int mval[2], int *r_material_slot)
static bool view3d_selectable_data(bContext *C)
static bool do_meta_box_select(const ViewContext *vc, const rcti *rect, const eSelectOp sel_op)
static bool do_lasso_select_paintvert(const ViewContext *vc, wmGenericUserData *wm_userdata, const Span< int2 > mcoords, const eSelectOp sel_op)
static void mesh_circle_doSelectFace(void *user_data, BMFace *efa, const float screen_co[2], int)
bool PE_box_select(bContext *C, const rcti *rect, int sel_op)
void WM_operator_properties_free(PointerRNA *ptr)
static void view3d_circle_select_cancel(bContext *C, wmOperator *op)
static bool do_curves_sculpt_circle_select(const ViewContext &vc, const eSelectOp sel_op, const int mval[2], const float radius)
static bool do_nurbs_box_select(const ViewContext *vc, const rcti *rect, const eSelectOp sel_op)
void BKE_object_update_select_id(Main *bmain)
Definition object.cc:5676
static bool do_grease_pencil_box_select(const ViewContext *vc, const rcti *rect, const eSelectOp sel_op)
static bool do_lasso_select_grease_pencil(const ViewContext *vc, const Span< int2 > mcoords, const eSelectOp sel_op)
float4x4 ED_view3d_ob_project_mat_get(const RegionView3D *rv3d, const Object *ob)
void BKE_mesh_mselect_active_set(Mesh *mesh, int index, eMSelect_Type type)
bool ED_armature_edit_deselect_all_visible_multi_ex(const Span< Base * > bases)
void WM_gesture_lasso_cancel(bContext *C, wmOperator *op)
static SelMenuItemF object_mouse_select_menu_data[SEL_MENU_SIZE]
static bool edge_fully_inside_rect(const rctf *rect, const float v1[2], const float v2[2])
uint * DRW_select_buffer_bitmap_from_rect(Depsgraph *depsgraph, ARegion *region, View3D *v3d, const rcti *rect, uint *r_bitmap_len)
static Base * mouse_select_object_center(const ViewContext *vc, Base *startbase, const int mval[2])
Object * ED_view3d_give_material_slot_under_cursor(bContext *C, const int mval[2], int *r_material_slot)
void armature_foreachScreenBone(const ViewContext *vc, void(*func)(void *user_data, EditBone *ebone, const float screen_co_a[2], const float screen_co_b[2]), void *user_data, eV3DProjTest clip_flag)
uint DRW_select_buffer_context_offset_for_object_elem(Depsgraph *depsgraph, Object *object, char elem_type)
static void do_lasso_select_curve__doSelect(void *user_data, Nurb *, BPoint *bp, BezTriple *bezt, int beztindex, bool handles_visible, const float screen_co[2])
static wmOperatorStatus bone_select_menu_exec(bContext *C, wmOperator *op)
static bool edbm_backbuf_check_and_select_edges(EditSelectBuf_Cache *esel, Depsgraph *depsgraph, Object *ob, BMesh *bm, UVSyncSelectFromMesh *uv_selctx, const eSelectOp sel_op)
static bool armature_circle_doSelectJoint(void *user_data, EditBone *ebone, const float screen_co[2], bool head)
static void do_lasso_select_armature__doSelectBone_clip_content(void *user_data, EditBone *ebone, const float screen_co_a[2], const float screen_co_b[2])
static bool do_lasso_select_paintface(const ViewContext *vc, wmGenericUserData *wm_userdata, const Span< int2 > mcoords, const eSelectOp sel_op)
bool paintvert_deselect_all_visible(Object *ob, int action, bool flush_flags)
Definition editface.cc:1032
static void editselect_buf_cache_init(const ViewContext *vc, short select_mode)
char * BLI_strncpy_utf8(char *__restrict dst, const char *__restrict src, size_t dst_maxncpy) ATTR_NONNULL(1
static wmOperatorStatus view3d_circle_select_modal(bContext *C, wmOperator *op, const wmEvent *event)
PropertyRNA * RNA_def_enum(StructOrFunctionRNA *cont_, const char *identifier, const EnumPropertyItem *items, const int default_value, const char *ui_name, const char *ui_description)
static void mesh_circle_doSelectVert(void *user_data, BMVert *eve, const float screen_co[2], int)
PropertyRNA * RNA_def_int_vector(StructOrFunctionRNA *cont_, const char *identifier, const int len, const int *default_value, const int hardmin, const int hardmax, const char *ui_name, const char *ui_description, const int softmin, const int softmax)
PointerRNA WM_operator_properties_create_ptr(wmOperatorType *ot)
void VIEW3D_OT_select_circle(wmOperatorType *ot)
static bool do_pose_box_select(bContext *C, const ViewContext *vc, const rcti *rect, const eSelectOp sel_op)
static bool edbm_backbuf_check_and_select_faces_obmode(Mesh *mesh, EditSelectBuf_Cache *esel, const eSelectOp sel_op)
int RNA_int_get(PointerRNA *ptr, const char *name)
wmWindow * CTX_wm_window(const bContext *C)
void view3d_operator_needs_gpu(const bContext *C)
static bool paint_facesel_circle_select(const ViewContext *vc, wmGenericUserData *wm_userdata, const eSelectOp sel_op, const int mval[2], float rad)
Base * BKE_view_layer_active_base_get(ViewLayer *view_layer)
static void do_paintvert_box_select__doSelectVert(void *user_data, const float screen_co[2], int index)
void mesh_foreachScreenEdge_clip_bb_segment(const ViewContext *vc, void(*func)(void *user_data, BMEdge *eed, const float screen_co_a[2], const float screen_co_b[2], int index), void *user_data, eV3DProjTest clip_flag)
static bool curves_select_lasso(const ViewContext &vc, const Object *object, const Span< int2 > mcoords, const eSelectOp sel_op)
static bool pointcloud_select_pick(bContext &C, const int2 mval, const SelectPick_Params &params)
void mball_foreachScreenElem(const ViewContext *vc, void(*func)(void *user_data, MetaElem *ml, const float screen_co[2]), void *user_data, eV3DProjTest clip_flag)
wmOperatorStatus WM_gesture_lasso_modal(bContext *C, wmOperator *op, const wmEvent *event)
static void do_circle_select_armature__doSelectBone(void *user_data, EditBone *ebone, const float screen_co_a[2], const float screen_co_b[2])
void BKE_nurbList_flag_set(ListBaseT< Nurb > *editnurb, eBezTriple_Flag flag, bool set)
Definition curve.cc:4376
static bool do_object_box_select(bContext *C, const ViewContext *vc, const rcti *rect, const eSelectOp sel_op)
MINLINE unsigned int float_as_uint(float f)
MatBase< float, 4, 4 > float4x4
static bool ed_wpaint_vertex_select_pick(bContext *C, const int mval[2], const SelectPick_Params &params, Object *obact)
bool BLI_lasso_is_point_inside(Span< int2 > mcoords, int sx, int sy, int error_value)
Definition lasso_2d.cc:42
void WM_gesture_circle_cancel(bContext *C, wmOperator *op)
static void editselect_buf_cache_init_with_generic_userdata(wmGenericUserData *wm_userdata, const ViewContext *vc, short select_mode)
static wmOperatorStatus view3d_select_invoke(bContext *C, wmOperator *op, const wmEvent *event)
MovieClip * BKE_object_movieclip_get(Scene *scene, const Object *ob, bool use_default)
Definition object.cc:5154
static bool object_circle_select(const ViewContext *vc, const eSelectOp sel_op, const int mval[2], float rad)
int gpu_select_buffer_depth_id_cmp(const void *sel_a_p, const void *sel_b_p)
static void do_lasso_select_mesh__doSelectEdge_pass1(void *user_data, BMEdge *eed, const float screen_co_a[2], const float screen_co_b[2], int index)
void BLI_rctf_rcti_copy(struct rctf *dst, const struct rcti *src)
static void do_lasso_select_pose__do_tag(void *user_data, bPoseChannel *pchan, const float screen_co_a[2], const float screen_co_b[2])
ViewLayer * CTX_data_view_layer(const bContext *C)
void ED_outliner_select_sync_from_object_tag(bContext *C)
void view3d_gpu_select_cache_begin()
void BKE_curve_nurb_vert_active_validate(Curve *cu)
Definition curve.cc:5092
bool ED_mball_select_pick(bContext *C, const int mval[2], const SelectPick_Params &params)
eV3DSelectObjectFilter
Definition ED_view3d.hh:990
@ VIEW3D_SELECT_FILTER_NOP
Definition ED_view3d.hh:992
bool ED_armature_edit_select_op_from_tagged(bArmature *arm, const int sel_op)
void ED_armature_ebone_listbase_temp_clear(ListBaseT< EditBone > *lb)
float dist_squared_to_line_segment_v2(const float p[2], const float l1[2], const float l2[2])
Definition math_geom.cc:307
void VIEW3D_OT_select(wmOperatorType *ot)
bool ED_curve_editfont_select_pick(bContext *C, const int mval[2], const SelectPick_Params &params)
Definition editfont.cc:2609
void ED_view3d_viewcontext_init_object(ViewContext *vc, Object *obact)
static void process_pose_bone_hits(GPUSelectBuffer &buffer, const int hits, const Span< Base * > bases)
bool ED_armature_pose_select_pick_bone(const Main &bmain, const Scene *scene, ViewLayer *view_layer, View3D *v3d, Object *ob, bPoseChannel *pchan, const SelectPick_Params &params)
Object * BKE_object_pose_armature_get_with_wpaint_check(Object *ob)
Definition object.cc:2527
static bool object_deselect_all_except(const Main &bmain, const Scene *scene, ViewLayer *view_layer, Base *b)
Base * ED_view3d_give_base_under_cursor(bContext *C, const int mval[2])
void pose_foreachScreenBone(const ViewContext *vc, void(*func)(void *user_data, bPoseChannel *pchan, const float screen_co_a[2], const float screen_co_b[2]), void *user_data, eV3DProjTest clip_flag)
void * BLI_findlink(const ListBase *listbase, int number) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1)
Definition listbase.cc:541
Base * ED_armature_base_and_pchan_from_select_buffer(const Span< Base * > bases, const uint select_id, bPoseChannel **r_pchan)
static int selectbuffer_ret_hits_5(MutableSpan< GPUSelectResult > hit_results, const int hits15, const int hits9, const int hits5)
unsigned int uint32_t
Definition BKE_text.h:81
static bool do_pose_tag_select_op_exec(MutableSpan< Base * > bases, const eSelectOp sel_op)
int PE_lasso_select(bContext *C, const int mcoords[][2], int mcoords_len, int sel_op)
MovieTrackingTrack * BKE_tracking_track_get_for_selection_index(MovieTracking *tracking, int selection_index, ListBaseT< MovieTrackingTrack > **r_tracksbase)
Definition tracking.cc:1031
void VIEW3D_OT_bone_select_menu(wmOperatorType *ot)
static void do_lasso_select_mesh__doSelectFace(void *user_data, BMFace *efa, const float screen_co[2], int)
void RNA_int_set_array(PointerRNA *ptr, const char *name, const int *values)
eV3DProjStatus ED_view3d_project_base(const ARegion *region, Base *base, float r_co[2])
VecBase< int32_t, 2 > int2
static void view3d_userdata_circleselect_init(CircleSelectUserData *r_data, const ViewContext *vc, const bool select, const int mval[2], const float rad)
VecBase< float, 2 > float2
bool ED_armature_edit_select_pick_bone(bContext *C, Base *basact, EditBone *ebone, const eBone_Flag selmask, const SelectPick_Params &params)
static bool nurbscurve_circle_select(const ViewContext *vc, const eSelectOp sel_op, const int mval[2], float rad)
void * MEM_new_zeroed(size_t len, const char *str) ATTR_WARN_UNUSED_RESULT ATTR_ALLOC_SIZE(1) ATTR_NONNULL(2)
static bool paint_vertsel_circle_select(const ViewContext *vc, wmGenericUserData *wm_userdata, const eSelectOp sel_op, const int mval[2], float rad)
void DRW_select_buffer_context_create(Depsgraph *depsgraph, Span< Base * > bases, short select_mode)
static wmOperatorStatus view3d_lasso_select_exec(bContext *C, wmOperator *op)
int ED_select_op_action_deselected(eSelectOp sel_op, bool is_select, bool is_inside)
uint * DRW_select_buffer_bitmap_from_circle(Depsgraph *depsgraph, ARegion *region, View3D *v3d, const int center[2], int radius, uint *r_bitmap_len)
Vector< GPUSelectResult, 2500 > GPUSelectStorage
Definition GPU_select.hh:47
void DEG_id_tag_update(ID *id, unsigned int flags)
@ OB_MODE_TEXTURE_PAINT
@ OB_MODE_SCULPT_GREASE_PENCIL
@ OB_MODE_SCULPT_CURVES
@ OB_MODE_PARTICLE_EDIT
BMesh const char void * data
void BKE_mesh_mselect_validate(Mesh *mesh)
void RNA_int_get_array(PointerRNA *ptr, const char *name, int *values)
Mesh * BKE_mesh_from_object(Object *ob)
Object * BKE_object_pose_armature_get(Object *ob)
Definition object.cc:2507
T * DEG_get_evaluated(const Depsgraph *depsgraph, T *id)
void ED_armature_edit_sync_selection(ListBaseT< EditBone > *edbo)
void meshobject_foreachScreenVert(const ViewContext *vc, void(*func)(void *user_data, const float screen_co[2], int index), void *user_data, eV3DProjTest clip_flag)
eV3DSelectObjectFilter ED_view3d_select_filter_from_mode(const Scene *scene, const View3D *v3d, const Object *obact)
bool ED_pose_deselect_all(Object *ob, int select_mode, const bool ignore_visibility)
bool BKE_paint_select_elem_test(const Object *ob)
Depsgraph * CTX_data_ensure_evaluated_depsgraph(const bContext *C, bool rna_write_check=false)
@ VIEW3D_SELECT_PICK_NEAREST
Definition ED_view3d.hh:987
@ VIEW3D_SELECT_PICK_ALL
Definition ED_view3d.hh:985
@ VIEW3D_SELECT_ALL
Definition ED_view3d.hh:983
Object * CTX_data_edit_object(const bContext *C)
static bool ed_object_select_pick(bContext *C, const int mval[2], const SelectPick_Params &params, const bool center, const bool enumerate, const bool object_only)
static bool do_lasso_select_meta(const ViewContext *vc, const Span< int2 > mcoords, const eSelectOp sel_op)
void BM_face_select_set(BMesh *bm, BMFace *f, const bool select)
Select Face.
static const EnumPropertyItem * object_select_menu_enum_itemf(bContext *C, PointerRNA *, PropertyRNA *, bool *r_free)
eV3DProjStatus ED_view3d_project_float_global(const ARegion *region, const float co[3], float r_co[2], eV3DProjTest flag)
bool BKE_nurbList_flag_set_from_flag(ListBaseT< Nurb > *editnurb, eBezTriple_Flag from_flag, eBezTriple_Flag flag)
Definition curve.cc:4411
void WM_operator_properties_border_to_rcti(wmOperator *op, rcti *r_rect)
static bool grease_pencil_circle_select(const ViewContext *vc, const eSelectOp sel_op, const int mval[2], const float rad)
static void view3d_userdata_boxselect_init(BoxSelectUserData *r_data, const ViewContext *vc, const rcti *rect, const eSelectOp sel_op)
wmOperatorStatus WM_gesture_circle_invoke(bContext *C, wmOperator *op, const wmEvent *event)
static bool selectbuffer_has_sub_object(const Span< GPUSelectResult > hit_results)
void WM_toolsystem_update_from_context_view3d(bContext *C)
void BLI_freelinkN(ListBase *listbase, void *vlink) ATTR_NONNULL(1)
Definition listbase.cc:277
static bool object_mouse_select_menu(bContext *C, const ViewContext *vc, const Span< GPUSelectResult > hit_results, const int mval[2], const SelectPick_Params &params, Base **r_basact)
void VIEW3D_OT_select_lasso(wmOperatorType *ot)
static void editselect_buf_cache_free_voidp(void *esel_voidp)
void WM_operator_properties_mouse_select(wmOperatorType *ot)
bool BKE_view_layer_synced_ensure(const Main &bmain, const Scene *scene, ViewLayer *view_layer)
static wmOperatorStatus object_select_menu_exec(bContext *C, wmOperator *op)
static bool do_armature_box_select(const ViewContext *vc, const rcti *rect, const eSelectOp sel_op)
static bool do_paintvert_box_select(const ViewContext *vc, wmGenericUserData *wm_userdata, const rcti *rect, const eSelectOp sel_op)
void ED_armature_pose_select_in_wpaint_mode(const Main &bmain, const Scene *scene, ViewLayer *view_layer, Base *base_select)
static bool bone_mouse_select_menu(bContext *C, const Span< GPUSelectResult > hit_results, const bool is_editmode, const SelectPick_Params &params)
bool ED_operator_view3d_active(bContext *C)
void WM_operator_properties_gesture_box(wmOperatorType *ot)
static void do_circle_select_mball__doSelectElem(void *user_data, MetaElem *ml, const float screen_co[2])
bool PE_circle_select(bContext *C, wmGenericUserData *wm_userdata, int sel_op, const int mval[2], float rad)
static bool obedit_circle_select(bContext *C, const ViewContext *vc, wmGenericUserData *wm_userdata, const eSelectOp sel_op, const int mval[2], float rad)
bool paintface_deselect_all_visible(bContext *C, Object *ob, int action, bool flush_flags)
Definition editface.cc:613
static bool do_mesh_box_select(const ViewContext *vc, wmGenericUserData *wm_userdata, const rcti *rect, const eSelectOp sel_op)
void RNA_enum_item_end(EnumPropertyItem **items, int *totitem)
RegionView3D * CTX_wm_region_view3d(const bContext *C)
bool ED_armature_pose_select_pick_with_buffer(const Main &bmain, const Scene *scene, ViewLayer *view_layer, View3D *v3d, Base *base, const GPUSelectResult *hit_results, const int hits, const SelectPick_Params &params, bool do_nearest)
bool ED_curve_editnurb_select_pick(bContext *C, const int mval[2], const int dist_px, const SelectPick_Params &params)
bool BKE_paint_select_face_test(const Object *ob)
bool BLI_rcti_is_empty(const struct rcti *rect)
bool RNA_boolean_get(PointerRNA *ptr, const char *name)
static bool do_lasso_select_pose(const ViewContext *vc, const Span< int2 > mcoords, const eSelectOp sel_op)
static bool mball_circle_select(const ViewContext *vc, const eSelectOp sel_op, const int mval[2], float rad)
static std::string object_select_menu_get_name(wmOperatorType *, PointerRNA *ptr)
void ED_view3d_init_mats_rv3d(const Object *ob, RegionView3D *rv3d)
static bool ed_curves_select_pick(bContext &C, const int mval[2], const SelectPick_Params &params)
const EnumPropertyItem rna_enum_dummy_NULL_items[]
Definition rna_rna.cc:28
void paintvert_flush_flags(Object *ob)
Definition editface.cc:774
static void do_lasso_select_mesh__doSelectEdge_pass0(void *user_data, BMEdge *eed, const float screen_co_a[2], const float screen_co_b[2], int index)
bool PE_mouse_particles(bContext *C, const int mval[2], const SelectPick_Params &params)
void WM_event_add_notifier(const bContext *C, uint type, void *reference)
void RNA_boolean_set(PointerRNA *ptr, const char *name, bool value)
void BM_vert_select_set(BMesh *bm, BMVert *v, const bool select)
Select Vert.
static void editselect_buf_cache_free(EditSelectBuf_Cache *esel)
void void BLI_listbase_sort(ListBase *listbase, int(*cmp)(const void *, const void *)) ATTR_NONNULL(1
Definition listbase.cc:319
static wmOperatorStatus view3d_select_exec(bContext *C, wmOperator *op)
void ED_pose_bone_select_tag_update(Object *ob)
static bool do_curves_sculpt_box_select(const ViewContext &vc, const rcti *rect, const eSelectOp sel_op)
void mesh_foreachScreenVert(const ViewContext *vc, void(*func)(void *user_data, BMVert *eve, const float screen_co[2], int index), void *user_data, eV3DProjTest clip_flag)
BMEditMesh * BKE_editmesh_from_object(Object *ob)
Return the BMEditMesh for a given object.
Definition editmesh.cc:59
bool BKE_object_is_in_editmode(const Object *ob)
Definition object.cc:1898
static void object_select_tag_updates(bContext &C, Scene &scene)
bool ED_armature_edit_deselect_all_visible(Object *obedit)
bke::AttrDomain ED_grease_pencil_selection_domain_get(const ToolSettings *tool_settings, const Object *object)
wmOperatorType * WM_operatortype_find(const char *idname, bool quiet)
wmOperatorStatus WM_gesture_box_modal(bContext *C, wmOperator *op, const wmEvent *event)
ViewContext em_setup_viewcontext(bContext *C)
void RNA_def_property_flag(PropertyRNA *prop, PropertyFlag flag)
static void do_lasso_select_lattice__doSelect(void *user_data, BPoint *bp, const float screen_co[2])
bool edge_inside_circle(const float cent[2], float radius, const float screen_co_a[2], const float screen_co_b[2])
MINLINE float len_manhattan_v2v2(const float a[2], const float b[2]) ATTR_WARN_UNUSED_RESULT
static bool ed_object_select_pick_camera_track(bContext *C, Scene *scene, Base *basact, MovieClip *clip, const GPUSelectBuffer &buffer, const short hits, const SelectPick_Params &params)
static bool do_lasso_select_objects(const ViewContext *vc, const Span< int2 > mcoords, const eSelectOp sel_op)
static bool ed_grease_pencil_select_pick(bContext *C, const int mval[2], const SelectPick_Params &params)
static void paint_vertsel_circle_select_doSelectVert(void *user_data, const float screen_co[2], int index)
static bool do_lasso_select_lattice(const ViewContext *vc, const Span< int2 > mcoords, const eSelectOp sel_op)
void BLI_addtail(ListBase *listbase, void *vlink) ATTR_NONNULL(1)
Definition listbase.cc:118
static bool edge_inside_rect(const rctf *rect, const float v1[2], const float v2[2])
unsigned int BLI_bitmap
Definition BLI_bitmap.hh:15
Main * CTX_data_main(const bContext *C)
wmOperatorStatus WM_gesture_lasso_invoke(bContext *C, wmOperator *op, const wmEvent *event)
static void do_mesh_box_select__doSelectVert(void *user_data, BMVert *eve, const float screen_co[2], int)
ATTR_WARN_UNUSED_RESULT const BMVert * v2
static void latticecurve_circle_doSelect(void *user_data, BPoint *bp, const float screen_co[2])
static void view3d_userdata_lassoselect_init(LassoSelectUserData *r_data, const ViewContext *vc, const rcti *rect, const Span< int2 > mcoords, const eSelectOp sel_op)
static void do_mesh_box_select__doSelectEdge_pass0(void *user_data, BMEdge *eed, const float screen_co_a[2], const float screen_co_b[2], int index)
bool BKE_mball_deselect_all(MetaBall *mb)
Definition mball.cc:601
static void do_lasso_tag_pose(const ViewContext *vc, const Span< int2 > mcoords)
static Vector< Base * > do_pose_tag_select_op_prepare(const ViewContext *vc)
static Base * mouse_select_eval_buffer(const ViewContext *vc, const GPUSelectBuffer &buffer, int hits, bool do_nearest, bool has_bones, bool do_bones_get_priotity, int *r_select_id_subelem)
@ ID_RECALC_SELECT
Definition DNA_ID.h:1101
@ ID_RECALC_GEOMETRY
Definition DNA_ID.h:1074
@ ID_RECALC_BASE_FLAGS
Definition DNA_ID.h:1104
wmOperatorStatus WM_operator_name_call_ptr(bContext *C, wmOperatorType *ot, wm::OpCallContext context, PointerRNA *properties, const wmEvent *event)
@ PROP_SKIP_SAVE
Definition RNA_types.hh:414
@ PROP_ENUM_NO_TRANSLATE
Definition RNA_types.hh:502
@ PROP_HIDDEN
Definition RNA_types.hh:408
Array< int2 > WM_gesture_lasso_path_to_array(bContext *, wmOperator *op)
@ V3D_PROJ_TEST_CLIP_NEAR
Definition ED_view3d.hh:298
@ V3D_PROJ_TEST_CLIP_BB
Definition ED_view3d.hh:296
bool ED_operator_region_view3d_active(bContext *C)
void WM_gesture_box_cancel(bContext *C, wmOperator *op)
Base * BKE_view_layer_base_find(ViewLayer *view_layer, Object *ob)
static int gpu_bone_select_buffer_cmp(const void *sel_a_p, const void *sel_b_p)
@ ID_TAG_DOIT
Definition DNA_ID.h:1029
static bool edbm_backbuf_check_and_select_faces(EditSelectBuf_Cache *esel, Depsgraph *depsgraph, Object *ob, BMesh *bm, UVSyncSelectFromMesh *uv_selctx, const eSelectOp sel_op)
static int mixed_bones_object_selectbuffer(const ViewContext *vc, GPUSelectBuffer *buffer, const int mval[2], eV3DSelectObjectFilter select_filter, bool do_nearest, bool do_nearest_xray, const bool do_material_slot_selection)
static bool armature_circle_select(const ViewContext *vc, const eSelectOp sel_op, const int mval[2], float rad)
MINLINE float square_f(float a)
float4x4 ED_view3d_ob_project_mat_get_from_obmat(const RegionView3D *rv3d, const float4x4 &obmat)
void ED_outliner_select_sync_from_edit_bone_tag(bContext *C)
static bool do_lasso_select_curve(const ViewContext *vc, const Span< int2 > mcoords, const eSelectOp sel_op)
Vector< Base * > BKE_view_layer_array_from_bases_in_edit_mode_unique_data(const Main &bmain, const Scene *scene, ViewLayer *view_layer, const View3D *v3d)
Object * ED_view3d_give_object_under_cursor(bContext *C, const int mval[2])
void WM_operator_properties_select_operation_simple(wmOperatorType *ot)
bool ED_lattice_select_pick(bContext *C, const int mval[2], const SelectPick_Params &params)
ListBaseT< Nurb > * BKE_curve_editNurbs_get(Curve *cu)
Definition curve.cc:441
void paintface_flush_flags(bContext *C, Object *ob, bool flush_selection, bool flush_hidden)
Definition editface.cc:42
void mesh_foreachScreenFace(const ViewContext *vc, void(*func)(void *user_data, BMFace *efa, const float screen_co[2], int index), void *user_data, eV3DProjTest clip_flag)
Scene * CTX_data_scene(const bContext *C)
static bool lattice_circle_select(const ViewContext *vc, const eSelectOp sel_op, const int mval[2], float rad)
bool WM_cursor_test_motion_and_update(const int mval[2])
bool BKE_paint_select_grease_pencil_test(const Object *ob)
int view3d_gpu_select_ex(const ViewContext *vc, GPUSelectBuffer *buffer, const rcti *input, eV3DSelectMode select_mode, eV3DSelectObjectFilter select_filter, eV3DSelectShape select_shape, bool do_material_slot_selection)
void VIEW3D_OT_select_box(wmOperatorType *ot)
void BKE_tracking_track_deselect(MovieTrackingTrack *track, eTrackArea area)
Definition tracking.cc:1222
static bool edbm_backbuf_check_and_select_verts_obmode(Mesh *mesh, EditSelectBuf_Cache *esel, const eSelectOp sel_op)
@ OPTYPE_REGISTER
Definition WM_types.hh:188
@ OPTYPE_UNDO
Definition WM_types.hh:190
@ OPTYPE_DEPENDS_ON_CURSOR
Definition WM_types.hh:228
bool BLI_rcti_isect_pt(const struct rcti *rect, int x, int y)
bool paintface_mouse_select(bContext *C, const int mval[2], const SelectPick_Params &params, Object *ob)
Definition editface.cc:709
bool BKE_paint_select_vert_test(const Object *ob)
bool WM_gesture_is_modal_first(const wmGesture *gesture)
static void do_lasso_select_meshobject__doSelectVert(void *user_data, const float screen_co[2], int index)
PropertyRNA * RNA_def_boolean(StructOrFunctionRNA *cont_, const char *identifier, const bool default_value, const char *ui_name, const char *ui_description)
static void do_lattice_box_select__doSelect(void *user_data, BPoint *bp, const float screen_co[2])
static void do_mesh_box_select__doSelectFace(void *user_data, BMFace *efa, const float screen_co[2], int)
SelectPick_Params ED_select_pick_params_from_operator(PointerRNA *ptr) ATTR_NONNULL(1)
static void do_lasso_select_armature__doSelectBone(void *user_data, EditBone *ebone, const float screen_co_a[2], const float screen_co_b[2])
float ED_view3d_select_dist_px()
static bool curves_select_circle(const ViewContext &vc, const Object *object, const eSelectOp sel_op, const int mval[2], const float radius)
static bool do_lasso_select_mesh(const ViewContext *vc, wmGenericUserData *wm_userdata, const Span< int2 > mcoords, const eSelectOp sel_op)
bool ED_mesh_pick_vert(bContext *C, Object *ob, const int mval[2], uint dist_px, bool use_zbuf, uint *r_index)
Definition meshtools.cc:774
MINLINE float len_squared_v2v2(const float a[2], const float b[2]) ATTR_WARN_UNUSED_RESULT
Vector< Base * > BKE_view_layer_array_from_bases_in_edit_mode(const Main &bmain, const Scene *scene, ViewLayer *view_layer, const View3D *v3d)
bool BLI_lasso_is_edge_inside(Span< int2 > mcoords, int x0, int y0, int x1, int y1, int error_value)
Definition lasso_2d.cc:56
wmOperatorStatus WM_gesture_circle_modal(bContext *C, wmOperator *op, const wmEvent *event)
void BLI_rcti_init_pt_radius(struct rcti *rect, const int xy[2], int size)
Definition rct.cc:480
static bool view3d_lasso_select(bContext *C, ViewContext *vc, const Span< int2 > mcoords, const eSelectOp sel_op)
void nurbs_foreachScreenVert(const ViewContext *vc, void(*func)(void *user_data, Nurb *nu, BPoint *bp, BezTriple *bezt, int beztindex, bool handle_visible, const float screen_co[2]), void *user_data, eV3DProjTest clip_flag)
void WM_generic_user_data_free(wmGenericUserData *wm_userdata)
Definition wm_utils.cc:47
uint * DRW_select_buffer_bitmap_from_poly(Depsgraph *depsgraph, ARegion *region, View3D *v3d, Span< int2 > poly, const rcti *rect, uint *r_bitmap_len)
bool BKE_object_is_mode_compat(const Object *ob, eObjectMode object_mode)
Definition object.cc:2058
static bool do_lasso_select_armature(const ViewContext *vc, const Span< int2 > mcoords, const eSelectOp sel_op)
int view3d_gpu_select(const ViewContext *vc, GPUSelectBuffer *buffer, const rcti *input, eV3DSelectMode select_mode, eV3DSelectObjectFilter select_filter, eV3DSelectShape select_shape)
Object * CTX_data_active_object(const bContext *C)
std::string ED_select_pick_get_name(wmOperatorType *ot, PointerRNA *ptr)
static void view3d_circle_select_recalc(void *user_data)
@ POSE_RUNTIME_IN_SELECTION_AREA
ARegion * CTX_wm_region(const bContext *C)
static void mesh_circle_doSelectEdge(void *user_data, BMEdge *eed, const float screen_co_a[2], const float screen_co_b[2], int)
void GPU_matrix_set(const float m[4][4])
bool BLI_rctf_isect_segment(const struct rctf *rect, const float s1[2], const float s2[2])
static void nurbscurve_circle_doSelect(void *user_data, Nurb *, BPoint *bp, BezTriple *bezt, int beztindex, bool, const float screen_co[2])
void BLI_lasso_boundbox(rcti *rect, Span< int2 > mcoords)
Definition lasso_2d.cc:21
ListBaseT< Base > * BKE_view_layer_object_bases_get(ViewLayer *view_layer)
static bool mesh_circle_select(const ViewContext *vc, wmGenericUserData *wm_userdata, eSelectOp sel_op, const int mval[2], float rad)
void WM_operator_properties_select_operation(wmOperatorType *ot)
bool ED_lattice_flags_set(Object *obedit, int flag)
View3D * CTX_wm_view3d(const bContext *C)
bool ED_view3d_is_object_under_cursor(bContext *C, const int mval[2])
void lattice_foreachScreenVert(const ViewContext *vc, void(*func)(void *user_data, BPoint *bp, const float screen_co[2]), void *user_data, eV3DProjTest clip_flag)
static void do_nurbs_box_select__doSelect(void *user_data, Nurb *, BPoint *bp, BezTriple *bezt, int beztindex, bool handles_visible, const float screen_co[2])
void BKE_tracking_track_select(ListBaseT< MovieTrackingTrack > *tracksbase, MovieTrackingTrack *track, eTrackArea area, bool extend)
Definition tracking.cc:1195
void VIEW3D_OT_select_menu(wmOperatorType *ot)
void BM_mesh_select_mode_flush_ex(BMesh *bm, const short selectmode, BMSelectFlushFlag flag)
Select Mode Flush.
void WM_operator_properties_gesture_lasso(wmOperatorType *ot)
static bool pose_circle_select(bContext *C, const ViewContext *vc, const eSelectOp sel_op, const int2 mval, const float radius)
void BM_edge_select_set(BMesh *bm, BMEdge *e, const bool select)
Select Edge.
KERNEL_FEATURE_LIGHT_PASSES KERNEL_FEATURE_PATH_GUIDING float
#define min(a, b)
Definition sort.cc:38
struct Object * object
struct Base * next
eBezTriple_Flag f2
eBezTriple_Flag f3
eBezTriple_Flag f1
UVSyncSelectFromMesh * uv_selctx
UVSyncSelectFromMesh * uv_selctx
ed::curves::FindClosestData elem
bke::greasepencil::Drawing * drawing
ed::curves::FindClosestData elem
ed::pointcloud::FindClosestData elem
union blender::EditBone::@252003325204232231327014100071366025164067232113 temp
GPUSelectStorage storage
Definition GPU_select.hh:49
char name[258]
Definition DNA_ID.h:433
UVSyncSelectFromMesh * uv_selctx
ListBaseT< MetaElem > * editelems
struct MetaElem * next
eMetaElem_Flag flag
struct MovieTracking tracking
ListBaseT< MovieTrackingTrack > tracks
ListBaseT< MovieTrackingObject > objects
bke::ObjectRuntime * runtime
struct bPose * pose
struct ToolSettings * toolsettings
char idname[MAX_ID_NAME - 2]
eHandleDisplay handle_display
View3DOverlay overlay
ViewLayer * view_layer
Definition ED_view3d.hh:80
RegionView3D * rv3d
Definition ED_view3d.hh:86
BMEditMesh * em
Definition ED_view3d.hh:87
Depsgraph * depsgraph
Definition ED_view3d.hh:78
ListBaseT< EditBone > * edbo
bPoseChannelRuntimeFlag flag
struct bPoseChannel_Runtime runtime
ListBaseT< bPoseChannel > chanbase
wmGenericUserDataFreeFn free_fn
Definition WM_types.hh:151
wmOperatorStatus(*) exec(bContext *C, wmOperator *op) ATTR_WARN_UNUSED_RESULT
Definition WM_types.hh:1125
const char * description
Definition WM_types.hh:1115
void(*) cancel(bContext *C, wmOperator *op)
Definition WM_types.hh:1149
bool(*) poll(bContext *C) ATTR_WARN_UNUSED_RESULT
Definition WM_types.hh:1165
wmOperatorStatus(*) invoke(bContext *C, wmOperator *op, const wmEvent *event) ATTR_WARN_UNUSED_RESULT
Definition WM_types.hh:1141
wmOperatorStatus(*) modal(bContext *C, wmOperator *op, const wmEvent *event) ATTR_WARN_UNUSED_RESULT
Definition WM_types.hh:1157
std::string(*) get_name(wmOperatorType *ot, PointerRNA *ptr)
Definition WM_types.hh:1191
#define SEL_MENU_SIZE