Blender V5.3
armature_select.cc
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2001-2002 NaN Holding BV. All rights reserved.
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
9
10#include "DNA_armature_types.h"
11#include "DNA_object_types.h"
12#include "DNA_scene_types.h"
13
14#include "BLI_listbase.hh"
15#include "BLI_math_matrix_c.hh"
16#include "BLI_math_vector_c.hh"
17#include "BLI_rect.hh"
18#include "BLI_string_utils.hh"
19
20#include "BKE_action.hh"
21#include "BKE_armature.hh"
22#include "BKE_context.hh"
23#include "BKE_layer.hh"
24#include "BKE_object.hh"
25#include "BKE_object_types.hh"
26#include "BKE_report.hh"
27
28#include "RNA_access.hh"
29#include "RNA_define.hh"
30
31#include "WM_api.hh"
32#include "WM_types.hh"
33
34#include "ED_armature.hh"
35#include "ED_object.hh"
36#include "ED_outliner.hh"
37#include "ED_screen.hh"
38#include "ED_select_utils.hh"
39#include "ED_view3d.hh"
40
41#include "DEG_depsgraph.hh"
42
43#include "GPU_select.hh"
44
45#include "ANIM_armature.hh"
47#include "ANIM_bonecolor.hh"
48
49#include "armature_intern.hh"
50
51namespace blender {
52
53/* utility macros for storing a temp int in the bone (selection flag) */
54#define EBONE_PREV_FLAG_GET(ebone) ((void)0, (ebone)->temp.i)
55#define EBONE_PREV_FLAG_SET(ebone, val) ((ebone)->temp.i = val)
56
57/* -------------------------------------------------------------------- */
60
62{
63 /* A selectable bone should have a "sub_object_id" been encoded in the select id. */
64 if ((hit_result.id & 0xFFFF0000) == 0) {
65 return false;
66 }
67 /* A selectable bone should be dawn with either:
68 * #BONESEL_ROOT, #BONESEL_TIP or #BONESEL_BONE encoded in the select id. */
69 if ((hit_result.id & BONESEL_ANY) == 0) {
70 return false;
71 }
72
73 return true;
74}
75
77 const uint select_id,
78 EditBone **r_ebone)
79{
80 const uint hit_object = select_id & 0xFFFF;
81 Base *base = nullptr;
82 EditBone *ebone = nullptr;
83 /* TODO(@ideasman42): optimize, eg: sort & binary search. */
84 for (Base *base_iter : bases) {
85 if (base_iter->object->runtime->select_id == hit_object) {
86 base = base_iter;
87 break;
88 }
89 }
90 if (base != nullptr) {
91 const uint hit_bone = (select_id & ~BONESEL_ANY) >> 16;
92 bArmature *arm = id_cast<bArmature *>(base->object->data);
93 ebone = static_cast<EditBone *>(BLI_findlink(arm->edbo, hit_bone));
94 }
95 *r_ebone = ebone;
96 return base;
97}
98
100 const uint select_id,
101 EditBone **r_ebone)
102{
103 const uint hit_object = select_id & 0xFFFF;
104 Object *ob = nullptr;
105 EditBone *ebone = nullptr;
106 /* TODO(@ideasman42): optimize, eg: sort & binary search. */
107 for (Object *object_iter : objects) {
108 if (object_iter->runtime->select_id == hit_object) {
109 ob = object_iter;
110 break;
111 }
112 }
113 if (ob != nullptr) {
114 const uint hit_bone = (select_id & ~BONESEL_ANY) >> 16;
115 bArmature *arm = id_cast<bArmature *>(ob->data);
116 ebone = static_cast<EditBone *>(BLI_findlink(arm->edbo, hit_bone));
117 }
118 *r_ebone = ebone;
119 return ob;
120}
121
123 const uint select_id,
124 bPoseChannel **r_pchan)
125{
126 const uint hit_object = select_id & 0xFFFF;
127 Base *base = nullptr;
128 bPoseChannel *pchan = nullptr;
129 /* TODO(@ideasman42): optimize, eg: sort & binary search. */
130 for (Base *base_iter : bases) {
131 if (base_iter->object->runtime->select_id == hit_object) {
132 base = base_iter;
133 break;
134 }
135 }
136 if (base != nullptr) {
137 if (base->object->pose != nullptr) {
138 const uint hit_bone = (select_id & ~BONESEL_ANY) >> 16;
139 /* pchan may be nullptr. */
140 pchan = static_cast<bPoseChannel *>(BLI_findlink(&base->object->pose->chanbase, hit_bone));
141 }
142 }
143 *r_pchan = pchan;
144 return base;
145}
146
148 const uint select_id,
149 Bone **r_bone)
150{
151 bPoseChannel *pchan = nullptr;
152 Base *base = ED_armature_base_and_pchan_from_select_buffer(bases, select_id, &pchan);
153 *r_bone = pchan ? pchan->bone_get(*base->object) : nullptr;
154 return base;
155}
156
158
159/* -------------------------------------------------------------------- */
167
168/* See if there are any selected bones in this buffer */
169/* only bones from base are checked on */
170static void *ed_armature_pick_bone_from_selectbuffer_impl(const bool is_editmode,
171 const Span<Base *> bases,
172 const Span<GPUSelectResult> hit_results,
173 bool findunsel,
174 bool do_nearest,
175 Base **r_base)
176{
177 bPoseChannel *pchan;
178 EditBone *ebone;
179 void *firstunSel = nullptr, *firstSel = nullptr, *data;
180 Base *firstunSel_base = nullptr, *firstSel_base = nullptr;
181 bool takeNext = false;
182 int minsel = 0xffffffff, minunsel = 0xffffffff;
183
184 Vector<GPUSelectResult> hit_results_sorted = hit_results;
185 qsort(hit_results_sorted.data(),
186 hit_results_sorted.size(),
187 sizeof(GPUSelectResult),
189
190 for (const GPUSelectResult &hit_result : hit_results_sorted) {
191 if (!ED_armature_selectresult_is_bone(hit_result)) {
192 continue;
193 }
194
195 uint hit_id = hit_result.id;
196
197 Base *base = nullptr;
198 bool sel;
199
200 hit_id &= ~BONESEL_ANY;
201 /* Determine what the current bone is */
202 if (is_editmode == false) {
203 base = ED_armature_base_and_pchan_from_select_buffer(bases, hit_id, &pchan);
204 if (pchan != nullptr) {
205 if (pchan->bone_get(*base->object)->flag & BONE_UNSELECTABLE) {
206 continue;
207 }
208 if (findunsel) {
209 sel = (pchan->flag & POSE_SELECTED);
210 }
211 else {
212 sel = !(pchan->flag & POSE_SELECTED);
213 }
214
215 data = pchan;
216 }
217 else {
218 data = nullptr;
219 sel = false;
220 }
221 }
222 else {
223 base = ED_armature_base_and_ebone_from_select_buffer(bases, hit_id, &ebone);
224 if (ebone->flag & BONE_UNSELECTABLE) {
225 continue;
226 }
227 if (findunsel) {
228 sel = (ebone->flag & BONE_SELECTED);
229 }
230 else {
231 sel = !(ebone->flag & BONE_SELECTED);
232 }
233
234 data = ebone;
235 }
236
237 if (data) {
238 if (sel) {
239 if (do_nearest) {
240 if (minsel > hit_result.depth) {
241 firstSel = data;
242 firstSel_base = base;
243 minsel = hit_result.depth;
244 }
245 }
246 else {
247 if (!firstSel) {
248 firstSel = data;
249 firstSel_base = base;
250 }
251 takeNext = true;
252 }
253 }
254 else {
255 if (do_nearest) {
256 if (minunsel > hit_result.depth) {
257 firstunSel = data;
258 firstunSel_base = base;
259 minunsel = hit_result.depth;
260 }
261 }
262 else {
263 if (!firstunSel) {
264 firstunSel = data;
265 firstunSel_base = base;
266 }
267 if (takeNext) {
268 *r_base = base;
269 return data;
270 }
271 }
272 }
273 }
274 }
275
276 if (firstunSel) {
277 *r_base = firstunSel_base;
278 return firstunSel;
279 }
280 *r_base = firstSel_base;
281 return firstSel;
282}
283
285 const GPUSelectResult *hit_results,
286 const int hits,
287 bool findunsel,
288 bool do_nearest,
289 Base **r_base)
290{
291 const bool is_editmode = true;
293 is_editmode, bases, {hit_results, hits}, findunsel, do_nearest, r_base));
294}
295
297 const GPUSelectResult *hit_results,
298 const int hits,
299 bool findunsel,
300 bool do_nearest,
301 Base **r_base)
302{
303 const bool is_editmode = false;
305 is_editmode, bases, {hit_results, hits}, findunsel, do_nearest, r_base));
306}
307
309 const GPUSelectResult *hit_results,
310 const int hits,
311 bool findunsel,
312 bool do_nearest,
313 Base **r_base)
314{
316 bases, hit_results, hits, findunsel, do_nearest, r_base);
317 return pchan ? pchan->bone_get(*(*r_base)->object) : nullptr;
318}
319
321
322/* -------------------------------------------------------------------- */
330
337 const bool is_editmode, bContext *C, const int xy[2], bool findunsel, Base **r_base)
338{
339 Depsgraph *depsgraph = CTX_data_ensure_evaluated_depsgraph(C);
340 rcti rect;
341 GPUSelectBuffer buffer;
342 int hits;
343
345 BLI_assert((vc.obedit != nullptr) == is_editmode);
346
347 BLI_rcti_init_pt_radius(&rect, xy, 0);
348
349 /* Don't use hits with this ID, (armature drawing uses this). */
350 const int select_id_ignore = -1;
351
353 &vc, &buffer, &rect, VIEW3D_SELECT_PICK_NEAREST, VIEW3D_SELECT_FILTER_NOP, select_id_ignore);
354
355 *r_base = nullptr;
356
357 if (hits > 0) {
358 Vector<Base *> bases;
359
360 if (vc.obedit != nullptr) {
362 *vc.bmain, vc.scene, vc.view_layer, vc.v3d);
363 }
364 else {
366 }
367
369 is_editmode, bases, buffer.storage.as_span().take_front(hits), findunsel, true, r_base);
370
371 return bone;
372 }
373 return nullptr;
374}
375
376EditBone *ED_armature_pick_ebone(bContext *C, const int xy[2], bool findunsel, Base **r_base)
377{
378 const bool is_editmode = true;
379 return static_cast<EditBone *>(
380 ed_armature_pick_bone_impl(is_editmode, C, xy, findunsel, r_base));
381}
382
383bPoseChannel *ED_armature_pick_pchan(bContext *C, const int xy[2], bool findunsel, Base **r_base)
384{
385 const bool is_editmode = false;
386 return static_cast<bPoseChannel *>(
387 ed_armature_pick_bone_impl(is_editmode, C, xy, findunsel, r_base));
388}
389
390Bone *ED_armature_pick_bone(bContext *C, const int xy[2], bool findunsel, Base **r_base)
391{
392 bPoseChannel *pchan = ED_armature_pick_pchan(C, xy, findunsel, r_base);
393 return pchan ? pchan->bone_get(*(*r_base)->object) : nullptr;
394}
395
397
398/* -------------------------------------------------------------------- */
405
411static bool armature_select_linked_impl(Object *ob, const bool select, const bool all_forks)
412{
413 bool changed = false;
414 bArmature *arm = id_cast<bArmature *>(ob->data);
415
416 /* Implementation note, this flood-fills selected bones with the 'TOUCH' flag,
417 * even though this is a loop-within a loop, walking up the parent chain only touches new bones.
418 * Bones that have been touched are skipped, so the complexity is OK. */
419
420 enum {
421 /* Bone has been walked over, its LINK value can be read. */
422 TOUCH = (1 << 0),
423 /* When TOUCH has been set, this flag can be checked to see if the bone is connected. */
424 LINK = (1 << 1),
425 };
426
427#define CHECK_PARENT(ebone) \
428\
429 (((ebone)->flag & BONE_CONNECTED) && \
430 ((ebone)->parent ? EBONE_SELECTABLE(arm, (ebone)->parent) : false))
431
432 for (EditBone &ebone : *arm->edbo) {
433 ebone.temp.i = 0;
434 }
435
436 /* Select parents. */
437 for (EditBone &ebone_iter : *arm->edbo) {
438 if (ebone_iter.temp.i & TOUCH) {
439 continue;
440 }
441 if ((ebone_iter.flag & BONE_DONE) == 0) {
442 continue;
443 }
444
445 ebone_iter.temp.i |= TOUCH | LINK;
446
447 /* We have an un-touched link. */
448 for (EditBone *ebone = &ebone_iter; ebone;
449 ebone = CHECK_PARENT(ebone) ? ebone->parent : nullptr)
450 {
452 changed = true;
453
454 if (all_forks) {
455 ebone->temp.i |= (TOUCH | LINK);
456 }
457 else {
458 ebone->temp.i |= TOUCH;
459 }
460 /* Don't walk onto links (messes up 'all_forks' logic). */
461 if (ebone->parent && ebone->parent->temp.i & LINK) {
462 break;
463 }
464 }
465 }
466
467 /* Select children. */
468 for (EditBone &ebone_iter : *arm->edbo) {
469 /* No need to 'touch' this bone as it won't be walked over when scanning up the chain. */
470 if (!CHECK_PARENT(&ebone_iter)) {
471 continue;
472 }
473 if (ebone_iter.temp.i & TOUCH) {
474 continue;
475 }
476
477 /* First check if we're marked. */
478 EditBone *ebone_touched_parent = nullptr;
479 for (EditBone *ebone = &ebone_iter; ebone;
480 ebone = CHECK_PARENT(ebone) ? ebone->parent : nullptr)
481 {
482 if (ebone->temp.i & TOUCH) {
483 ebone_touched_parent = ebone;
484 break;
485 }
486 ebone->temp.i |= TOUCH;
487 }
488
489 if ((ebone_touched_parent != nullptr) && (ebone_touched_parent->temp.i & LINK)) {
490 for (EditBone *ebone = &ebone_iter; ebone != ebone_touched_parent; ebone = ebone->parent) {
491 if ((ebone->temp.i & LINK) == 0) {
492 ebone->temp.i |= LINK;
494 changed = true;
495 }
496 }
497 }
498 }
499
500#undef CHECK_PARENT
501
502 if (changed) {
506 }
507
508 return changed;
509}
510
512
513/* -------------------------------------------------------------------- */
516
518{
519 const bool all_forks = RNA_boolean_get(op->ptr, "all_forks");
520
521 bool changed_multi = false;
522 const Main *bmain = CTX_data_main(C);
523 const Scene *scene = CTX_data_scene(C);
524 ViewLayer *view_layer = CTX_data_view_layer(C);
526 *bmain, scene, view_layer, CTX_wm_view3d(C));
527 for (Object *ob : objects) {
528 bArmature *arm = id_cast<bArmature *>(ob->data);
529
530 bool found = false;
531 for (EditBone &ebone : *arm->edbo) {
532 if (animrig::bone_is_visible(arm, &ebone) &&
534 {
535 ebone.flag |= BONE_DONE;
536 found = true;
537 }
538 else {
539 ebone.flag &= ~BONE_DONE;
540 }
541 }
542
543 if (found) {
544 if (armature_select_linked_impl(ob, true, all_forks)) {
545 changed_multi = true;
546 }
547 }
548 }
549
550 if (changed_multi) {
552 }
553 return OPERATOR_FINISHED;
554}
555
557{
558 /* identifiers */
559 ot->name = "Select Linked All";
560 ot->idname = "ARMATURE_OT_select_linked";
561 ot->description = "Select all bones linked by parent/child connections to the current selection";
562
563 /* API callbacks. */
566
567 /* flags */
569
570 /* Leave disabled by default as this matches pose mode. */
571 RNA_def_boolean(ot->srna, "all_forks", false, "All Forks", "Follow forks in the parents chain");
572}
573
575
576/* -------------------------------------------------------------------- */
579
581 wmOperator *op,
582 const wmEvent *event)
583{
584 const bool select = !RNA_boolean_get(op->ptr, "deselect");
585 const bool all_forks = RNA_boolean_get(op->ptr, "all_forks");
586
589
590 Base *base = nullptr;
591 EditBone *ebone_active = ED_armature_pick_ebone(C, event->mval, true, &base);
592
593 if (ebone_active == nullptr) {
594 return OPERATOR_CANCELLED;
595 }
596
597 bArmature *arm = id_cast<bArmature *>(base->object->data);
598 if (!EBONE_SELECTABLE(arm, ebone_active)) {
599 return OPERATOR_CANCELLED;
600 }
601
602 /* Initialize flags. */
603 for (EditBone &ebone : *arm->edbo) {
604 ebone.flag &= ~BONE_DONE;
605 }
606 ebone_active->flag |= BONE_DONE;
607
608 if (armature_select_linked_impl(base->object, select, all_forks)) {
610 }
611
612 return OPERATOR_FINISHED;
613}
614
619
621{
622 /* identifiers */
623 ot->name = "Select Linked";
624 ot->idname = "ARMATURE_OT_select_linked_pick";
625 ot->description = "(De)select bones linked by parent/child connections under the mouse cursor";
626
627 /* API callbacks. */
628 /* leave 'exec' unset */
631
632 /* flags */
634
635 RNA_def_boolean(ot->srna, "deselect", false, "Deselect", "");
636 /* Leave disabled by default as this matches pose mode. */
637 RNA_def_boolean(ot->srna, "all_forks", false, "All Forks", "Follow forks in the parents chain");
638}
639
641
642/* -------------------------------------------------------------------- */
645
646/* utility function for get_nearest_editbonepoint */
647static int selectbuffer_ret_hits_12(MutableSpan<GPUSelectResult> /*hit_results*/, const int hits12)
648{
649 return hits12;
650}
651
653 const int hits12,
654 const int hits5)
655{
656 const int ofs = hits12;
657 /* Shift results to beginning. */
658 hit_results.slice(0, hits5).copy_from(hit_results.slice(ofs, hits5));
659 return hits5;
660}
661
662/* does bones and points */
663/* note that BONE ROOT only gets drawn for root bones (or without IK) */
665 ViewContext *vc, bool findunsel, bool use_cycle, Base **r_base, eBone_Flag *r_selmask)
666{
667 GPUSelectBuffer buffer;
668 struct Result {
669 uint select_id;
670 Base *base;
671 EditBone *ebone;
672 };
673 Result *result = nullptr;
674 Result result_cycle{};
675 result_cycle.select_id = -1;
676 result_cycle.base = nullptr;
677 result_cycle.ebone = nullptr;
678 Result result_bias{};
679 result_bias.select_id = -1;
680 result_bias.base = nullptr;
681 result_bias.ebone = nullptr;
682
683 /* Find the bone after the current (selected) active bone, so as to bump up its chances in
684 * selection. this way overlapping bones will cycle selection state as with objects. */
685 Object *obedit_orig = vc->obedit;
686 EditBone *ebone_active_orig = id_cast<bArmature *>(obedit_orig->data)->act_edbone;
687 if (ebone_active_orig &&
688 (ebone_active_orig->flag & (BONE_SELECTED | BONE_ROOTSEL | BONE_TIPSEL)) == 0)
689 {
690 ebone_active_orig = nullptr;
691 }
692
693 if (ebone_active_orig == nullptr) {
694 use_cycle = false;
695 }
696
697 if (use_cycle) {
698 use_cycle = !WM_cursor_test_motion_and_update(vc->mval);
699 }
700
701 const bool do_nearest = !(XRAY_ACTIVE(vc->v3d) || use_cycle);
702
703 /* matching logic from 'mixed_bones_object_selectbuffer' */
704 int hits = 0;
705 /* Don't use hits with this ID, (armature drawing uses this). */
706 const int select_id_ignore = -1;
707
708 /* we _must_ end cache before return, use 'goto cache_end' */
710
711 {
713
715 rcti rect;
716 BLI_rcti_init_pt_radius(&rect, vc->mval, 12);
717 /* VIEW3D_SELECT_PICK_ALL needs to be used or unselectable bones can block selectability of
718 * bones further back. See #123963. */
719 const int hits12 = view3d_gpu_select_with_id_filter(
720 vc, &buffer, &rect, VIEW3D_SELECT_PICK_ALL, select_filter, select_id_ignore);
721
722 if (hits12 == 1) {
723 hits = selectbuffer_ret_hits_12(storage.as_mutable_span(), hits12);
724 goto cache_end;
725 }
726 else if (hits12 > 0) {
727 BLI_rcti_init_pt_radius(&rect, vc->mval, 5);
728 const int hits5 = view3d_gpu_select_with_id_filter(
729 vc, &buffer, &rect, VIEW3D_SELECT_PICK_ALL, select_filter, select_id_ignore);
730
731 if (hits5 == 1) {
732 hits = selectbuffer_ret_hits_5(storage.as_mutable_span(), hits12, hits5);
733 goto cache_end;
734 }
735
736 if (hits5 > 0) {
737 hits = selectbuffer_ret_hits_5(storage.as_mutable_span(), hits12, hits5);
738 goto cache_end;
739 }
740 else {
741 hits = selectbuffer_ret_hits_12(storage.as_mutable_span(), hits12);
742 goto cache_end;
743 }
744 }
745 }
746
747cache_end:
749
751 *vc->bmain, vc->scene, vc->view_layer, vc->v3d);
752 /* See if there are any selected bones in this group */
753 if (hits > 0) {
754 if (hits == 1) {
755 const GPUSelectResult &hit_result = buffer.storage[0];
756 if (ED_armature_selectresult_is_bone(hit_result)) {
758 bases, hit_result.id, &result_bias.ebone);
759 /* If this fails, selection code is setting the selection IDs incorrectly. */
760 BLI_assert(result_bias.base && result_bias.ebone);
761 if (result_bias.base != nullptr && result_bias.ebone != nullptr) {
762 result_bias.select_id = hit_result.id;
763 }
764 }
765 }
766 else {
767 int bias_max = INT_MIN;
768
769 /* Track Cycle Variables
770 * - Offset is always set to the active bone.
771 * - The object & bone indices subtracted by the 'offset.as_u32' value.
772 * Unsigned subtraction wrapping means we always select the next bone in the cycle.
773 */
774 struct {
775 union {
776 uint32_t as_u32;
777 struct {
778 /* NOTE: this is endianness-sensitive.
779 * In Big Endian the order of these two variable would have to be inverted. */
780 uint16_t bone;
781 uint16_t ob;
782 };
783 } offset, test, best;
784 } cycle_order;
785
786 if (use_cycle) {
787 bArmature *arm = id_cast<bArmature *>(obedit_orig->data);
788 int ob_index = obedit_orig->runtime->select_id & 0xFFFF;
789 int bone_index = BLI_findindex(arm->edbo, ebone_active_orig);
790 /* Offset from the current active bone, so we cycle onto the next. */
791 cycle_order.offset.ob = ob_index;
792 cycle_order.offset.bone = bone_index;
793 /* The value of the active bone (with offset subtracted, a signal to always overwrite). */
794 cycle_order.best.as_u32 = 0;
795 }
796
797 int min_depth = INT_MAX;
798 for (int i = 0; i < hits; i++) {
799 const GPUSelectResult &hit_result = buffer.storage[i];
800 if (!ED_armature_selectresult_is_bone(hit_result)) {
801 continue;
802 }
803
804 const uint select_id = hit_result.id;
805 Base *base = nullptr;
806 EditBone *ebone;
807 base = ED_armature_base_and_ebone_from_select_buffer(bases, select_id, &ebone);
808 /* If this fails, selection code is setting the selection ID's incorrectly. */
809 BLI_assert(base && ebone);
810
811 if (ebone->flag & BONE_UNSELECTABLE) {
812 continue;
813 }
814
815 /* Prioritized selection. */
816 {
817 int bias;
818 /* clicks on bone points get advantage */
819 if (select_id & (BONESEL_ROOT | BONESEL_TIP)) {
820 /* but also the unselected one */
821 if (findunsel) {
822 if ((select_id & BONESEL_ROOT) && (ebone->flag & BONE_ROOTSEL) == 0) {
823 bias = 4;
824 }
825 else if ((select_id & BONESEL_TIP) && (ebone->flag & BONE_TIPSEL) == 0) {
826 bias = 4;
827 }
828 else {
829 bias = 3;
830 }
831 }
832 else {
833 bias = 4;
834 }
835 }
836 else {
837 /* bone found */
838 if (findunsel) {
839 if ((ebone->flag & BONE_SELECTED) == 0) {
840 bias = 2;
841 }
842 else {
843 bias = 1;
844 }
845 }
846 else {
847 bias = 2;
848 }
849 }
850
851 if (bias > bias_max) {
852 bias_max = bias;
853
854 min_depth = hit_result.depth;
855 result_bias.select_id = select_id;
856 result_bias.base = base;
857 result_bias.ebone = ebone;
858 }
859 else if (bias == bias_max && do_nearest) {
860 if (min_depth > hit_result.depth) {
861 min_depth = hit_result.depth;
862 result_bias.select_id = select_id;
863 result_bias.base = base;
864 result_bias.ebone = ebone;
865 }
866 }
867 }
868
869 /* Cycle selected items (objects & bones). */
870 if (use_cycle) {
871 cycle_order.test.ob = select_id & 0xFFFF;
872 cycle_order.test.bone = (select_id & ~BONESEL_ANY) >> 16;
873 if (ebone == ebone_active_orig) {
874 BLI_assert(cycle_order.test.ob == cycle_order.offset.ob);
875 BLI_assert(cycle_order.test.bone == cycle_order.offset.bone);
876 }
877 /* Subtraction as a single value is needed to support cycling through bones
878 * from multiple objects. So once the last bone is selected,
879 * the bits for the bone index wrap into the object,
880 * causing the next object to be stepped onto. */
881 cycle_order.test.as_u32 -= cycle_order.offset.as_u32;
882
883 /* Even though this logic avoids stepping onto the active bone,
884 * always set the 'best' value for the first time.
885 * Otherwise ensure the value is the smallest it can be,
886 * relative to the active bone, as long as it's not the active bone. */
887 if ((cycle_order.best.as_u32 == 0) ||
888 (cycle_order.test.as_u32 && (cycle_order.test.as_u32 < cycle_order.best.as_u32)))
889 {
890 cycle_order.best = cycle_order.test;
891 result_cycle.select_id = select_id;
892 result_cycle.base = base;
893 result_cycle.ebone = ebone;
894 }
895 }
896 }
897 }
898
899 result = (use_cycle && result_cycle.ebone) ? &result_cycle : &result_bias;
900
901 if (result->select_id != -1) {
902 *r_base = result->base;
903
904 *r_selmask = eBone_Flag{};
905 if (result->select_id & BONESEL_ROOT) {
906 *r_selmask |= BONE_ROOTSEL;
907 }
908 if (result->select_id & BONESEL_TIP) {
909 *r_selmask |= BONE_TIPSEL;
910 }
911 if (result->select_id & BONESEL_BONE) {
912 *r_selmask |= BONE_SELECTED;
913 }
914 return result->ebone;
915 }
916 }
917 *r_selmask = eBone_Flag{};
918 *r_base = nullptr;
919 return nullptr;
920}
921
923
924/* -------------------------------------------------------------------- */
927
929{
930 bArmature *arm = id_cast<bArmature *>(obedit->data);
931 bool changed = false;
932 for (EditBone &ebone : *arm->edbo) {
933 if (ebone.flag & (BONE_SELECTED | BONE_TIPSEL | BONE_ROOTSEL)) {
935 changed = true;
936 }
937 }
938 return changed;
939}
940
942{
943 bArmature *arm = id_cast<bArmature *>(obedit->data);
944 bool changed = false;
945 for (EditBone &ebone : *arm->edbo) {
946 /* first and foremost, bone must be visible and selected */
947 if (animrig::bone_is_visible(arm, &ebone)) {
948 if (ebone.flag & (BONE_SELECTED | BONE_TIPSEL | BONE_ROOTSEL)) {
950 changed = true;
951 }
952 }
953 }
954
955 if (changed) {
957 }
958 return changed;
959}
960
962{
963 bool changed_multi = false;
964 for (Base *base : bases) {
965 Object *obedit = base->object;
966 changed_multi |= ED_armature_edit_deselect_all(obedit);
967 }
968 return changed_multi;
969}
970
972{
973 bool changed_multi = false;
974 for (Base *base : bases) {
975 Object *obedit = base->object;
976 changed_multi |= ED_armature_edit_deselect_all_visible(obedit);
977 }
978 return changed_multi;
979}
980
989
991
992/* -------------------------------------------------------------------- */
995
997 Base *basact,
998 EditBone *ebone,
999 const eBone_Flag selmask,
1000 const SelectPick_Params &params)
1001{
1002 const Main *bmain = CTX_data_main(C);
1003 const Scene *scene = CTX_data_scene(C);
1004 ViewLayer *view_layer = CTX_data_view_layer(C);
1005 View3D *v3d = CTX_wm_view3d(C);
1006 bool changed = false;
1007 bool found = false;
1008
1009 if (ebone) {
1010 bArmature *arm = id_cast<bArmature *>(basact->object->data);
1011 if (EBONE_SELECTABLE(arm, ebone)) {
1012 found = true;
1013 }
1014 }
1015
1016 if (params.sel_op == SEL_OP_SET) {
1017 if ((found && params.select_passthrough) &&
1018 (ED_armature_ebone_selectflag_get(ebone) & selmask))
1019 {
1020 found = false;
1021 }
1022 else if (found || params.deselect_all) {
1023 /* Deselect everything. */
1025 *bmain, scene, view_layer, v3d);
1027 changed = true;
1028 }
1029 }
1030
1031 if (found) {
1033 bArmature *arm = id_cast<bArmature *>(basact->object->data);
1034
1035 /* By definition the non-root connected bones have no root point drawn,
1036 * so a root selection needs to be delivered to the parent tip. */
1037
1038 if (selmask & BONE_SELECTED) {
1039 if (ebone->parent && (ebone->flag & BONE_CONNECTED)) {
1040
1041 /* Bone is in a chain. */
1042 switch (params.sel_op) {
1043 case SEL_OP_ADD: {
1044 /* Select this bone. */
1045 ebone->flag |= BONE_TIPSEL;
1046 ebone->parent->flag |= BONE_TIPSEL;
1047 break;
1048 }
1049 case SEL_OP_SUB: {
1050 /* Deselect this bone. */
1051 ebone->flag &= ~(BONE_TIPSEL | BONE_SELECTED);
1052 /* Only deselect parent tip if it is not selected. */
1053 if (!(ebone->parent->flag & BONE_SELECTED)) {
1054 ebone->parent->flag &= ~BONE_TIPSEL;
1055 }
1056 break;
1057 }
1058 case SEL_OP_XOR: {
1059 /* Toggle inverts this bone's selection. */
1060 if (ebone->flag & BONE_SELECTED) {
1061 /* Deselect this bone. */
1062 ebone->flag &= ~(BONE_TIPSEL | BONE_SELECTED);
1063 /* Only deselect parent tip if it is not selected. */
1064 if (!(ebone->parent->flag & BONE_SELECTED)) {
1065 ebone->parent->flag &= ~BONE_TIPSEL;
1066 }
1067 }
1068 else {
1069 /* Select this bone. */
1070 ebone->flag |= BONE_TIPSEL;
1071 ebone->parent->flag |= BONE_TIPSEL;
1072 }
1073 break;
1074 }
1075 case SEL_OP_SET: {
1076 /* Select this bone. */
1077 ebone->flag |= BONE_TIPSEL;
1078 ebone->parent->flag |= BONE_TIPSEL;
1079 break;
1080 }
1081 case SEL_OP_AND: {
1082 BLI_assert_unreachable(); /* Doesn't make sense for picking. */
1083 break;
1084 }
1085 }
1086 }
1087 else {
1088 switch (params.sel_op) {
1089 case SEL_OP_ADD: {
1090 ebone->flag |= (BONE_TIPSEL | BONE_ROOTSEL);
1091 break;
1092 }
1093 case SEL_OP_SUB: {
1094 ebone->flag &= ~(BONE_TIPSEL | BONE_ROOTSEL);
1095 break;
1096 }
1097 case SEL_OP_XOR: {
1098 /* Toggle inverts this bone's selection. */
1099 if (ebone->flag & BONE_SELECTED) {
1100 ebone->flag &= ~(BONE_TIPSEL | BONE_ROOTSEL);
1101 }
1102 else {
1103 ebone->flag |= (BONE_TIPSEL | BONE_ROOTSEL);
1104 }
1105 break;
1106 }
1107 case SEL_OP_SET: {
1108 ebone->flag |= (BONE_TIPSEL | BONE_ROOTSEL);
1109 break;
1110 }
1111 case SEL_OP_AND: {
1112 BLI_assert_unreachable(); /* Doesn't make sense for picking. */
1113 break;
1114 }
1115 }
1116 }
1117 }
1118 else {
1119 switch (params.sel_op) {
1120 case SEL_OP_ADD: {
1121 ebone->flag |= selmask;
1122 break;
1123 }
1124 case SEL_OP_SUB: {
1125 ebone->flag &= ~selmask;
1126 break;
1127 }
1128 case SEL_OP_XOR: {
1129 if (ebone->flag & selmask) {
1130 ebone->flag &= ~selmask;
1131 }
1132 else {
1133 ebone->flag |= selmask;
1134 }
1135 break;
1136 }
1137 case SEL_OP_SET: {
1138 ebone->flag |= selmask;
1139 break;
1140 }
1141 case SEL_OP_AND: {
1142 BLI_assert_unreachable(); /* Doesn't make sense for picking. */
1143 break;
1144 }
1145 }
1146 }
1147
1149
1150 /* Now check for active status. */
1152 arm->act_edbone = ebone;
1153 }
1154
1155 BKE_view_layer_synced_ensure(*bmain, scene, view_layer);
1156 if (BKE_view_layer_active_base_get(view_layer) != basact) {
1158 }
1159
1162 changed = true;
1163 }
1164
1165 if (changed) {
1167 }
1168
1169 return changed || found;
1170}
1171
1172bool ED_armature_edit_select_pick(bContext *C, const int mval[2], const SelectPick_Params &params)
1173
1174{
1175 Depsgraph *depsgraph = CTX_data_ensure_evaluated_depsgraph(C);
1176 EditBone *nearBone = nullptr;
1177 eBone_Flag selmask = eBone_Flag{};
1178 Base *basact = nullptr;
1179
1180 ViewContext vc = ED_view3d_viewcontext_init(C, depsgraph);
1181 vc.mval[0] = mval[0];
1182 vc.mval[1] = mval[1];
1183
1184 nearBone = get_nearest_editbonepoint(&vc, true, true, &basact, &selmask);
1185 return ED_armature_edit_select_pick_bone(C, basact, nearBone, selmask, params);
1186}
1187
1189
1190/* -------------------------------------------------------------------- */
1195
1197 EditBone *ebone,
1198 const eSelectOp sel_op,
1199 int is_ignore_flag,
1200 int is_inside_flag)
1201{
1202 BLI_assert(!(is_ignore_flag & ~(BONESEL_ROOT | BONESEL_TIP)));
1203 BLI_assert(!(is_inside_flag & ~(BONESEL_ROOT | BONESEL_TIP | BONESEL_BONE)));
1205 bool changed = false;
1206 bool is_point_done = false;
1207 int points_proj_tot = 0;
1208 BLI_assert(ebone->flag == ebone->temp.i);
1209 const eBone_Flag ebone_flag_prev = ebone->flag;
1210
1211 if ((is_ignore_flag & BONE_ROOTSEL) == 0) {
1212 points_proj_tot++;
1213 const bool is_select = ebone->flag & BONE_ROOTSEL;
1214 const bool is_inside = is_inside_flag & BONESEL_ROOT;
1215 const int sel_op_result = ED_select_op_action_deselected(sel_op, is_select, is_inside);
1216 if (sel_op_result != -1) {
1217 if (sel_op_result == 0 || EBONE_SELECTABLE(arm, ebone)) {
1218 SET_FLAG_FROM_TEST(ebone->flag, sel_op_result, BONE_ROOTSEL);
1219 }
1220 }
1221 is_point_done |= is_inside;
1222 }
1223
1224 if ((is_ignore_flag & BONE_TIPSEL) == 0) {
1225 points_proj_tot++;
1226 const bool is_select = ebone->flag & BONE_TIPSEL;
1227 const bool is_inside = is_inside_flag & BONESEL_TIP;
1228 const int sel_op_result = ED_select_op_action_deselected(sel_op, is_select, is_inside);
1229 if (sel_op_result != -1) {
1230 if (sel_op_result == 0 || EBONE_SELECTABLE(arm, ebone)) {
1231 SET_FLAG_FROM_TEST(ebone->flag, sel_op_result, BONE_TIPSEL);
1232 }
1233 }
1234 is_point_done |= is_inside;
1235 }
1236
1237 /* if one of points selected, we skip the bone itself */
1238 if ((is_point_done == false) && (points_proj_tot == 2)) {
1239 const bool is_select = ebone->flag & BONE_SELECTED;
1240 {
1241 const bool is_inside = is_inside_flag & BONESEL_BONE;
1242 const int sel_op_result = ED_select_op_action_deselected(sel_op, is_select, is_inside);
1243 if (sel_op_result != -1) {
1244 if (sel_op_result == 0 || EBONE_SELECTABLE(arm, ebone)) {
1246 ebone->flag, sel_op_result, BONE_SELECTED | BONE_ROOTSEL | BONE_TIPSEL);
1247 }
1248 }
1249 }
1250
1251 changed = true;
1252 }
1253 changed |= is_point_done;
1254
1255 if (ebone_flag_prev != ebone->flag) {
1256 ebone->temp.i = ebone->flag;
1257 ebone->flag = ebone_flag_prev;
1258 ebone->flag = ebone_flag_prev | BONE_DONE;
1259 changed = true;
1260 }
1261
1262 return changed;
1263}
1264
1266{
1267 bool changed = false;
1268
1269 /* Initialize flags. */
1270 {
1271 for (EditBone &ebone : *arm->edbo) {
1272
1273 /* Flush the parent flag to this bone
1274 * so we don't need to check the parent when adjusting the selection. */
1275 if ((ebone.flag & BONE_CONNECTED) && ebone.parent) {
1276 if (ebone.parent->flag & BONE_TIPSEL) {
1277 ebone.flag |= BONE_ROOTSEL;
1278 }
1279 else {
1280 ebone.flag &= ~BONE_ROOTSEL;
1281 }
1282
1283 /* Flush the 'temp.i' flag. */
1284 if (ebone.parent->temp.i & BONESEL_TIP) {
1285 ebone.temp.i |= BONESEL_ROOT;
1286 }
1287 }
1288 ebone.flag &= ~BONE_DONE;
1289 }
1290 }
1291
1292 /* Apply selection from bone selection flags. */
1293 for (EditBone &ebone : *arm->edbo) {
1294 if (ebone.temp.i != 0) {
1295 int is_ignore_flag = ((ebone.temp.i << 16) & (BONESEL_ROOT | BONESEL_TIP));
1296 int is_inside_flag = (ebone.temp.i & (BONESEL_ROOT | BONESEL_TIP | BONESEL_BONE));
1297
1298 /* Use as previous bone flag from now on. */
1299 ebone.temp.i = ebone.flag;
1300
1301 /* When there is a partial selection without both endpoints, only select an endpoint. */
1302 if ((is_inside_flag & BONESEL_BONE) &&
1303 ELEM(is_inside_flag & (BONESEL_ROOT | BONESEL_TIP), BONESEL_ROOT, BONESEL_TIP))
1304 {
1305 is_inside_flag &= ~BONESEL_BONE;
1306 }
1307
1309 arm, &ebone, eSelectOp(sel_op), is_ignore_flag, is_inside_flag);
1310 }
1311 }
1312
1313 if (changed) {
1314 /* Cleanup flags. */
1315 for (EditBone &ebone : *arm->edbo) {
1316 if (ebone.flag & BONE_DONE) {
1317 {
1318 const int tmp_i = ebone.temp.i;
1319 ebone.temp.i = int(ebone.flag);
1320 ebone.flag = eBone_Flag(tmp_i);
1321 }
1322 ebone.flag |= BONE_DONE;
1323 if ((ebone.flag & BONE_CONNECTED) && ebone.parent) {
1324 if ((ebone.parent->flag & BONE_DONE) == 0) {
1325 /* Checked below. */
1326 ebone.parent->temp.i = ebone.parent->flag;
1327 }
1328 }
1329 }
1330 }
1331
1332 for (EditBone &ebone : *arm->edbo) {
1333 if (ebone.flag & BONE_DONE) {
1334 if ((ebone.flag & BONE_CONNECTED) && ebone.parent) {
1335 bool is_parent_tip_changed = (ebone.parent->flag & BONE_TIPSEL) !=
1336 (ebone.parent->temp.i & BONE_TIPSEL);
1337 if ((ebone.temp.i & BONE_ROOTSEL) == 0) {
1338 if ((ebone.flag & BONE_ROOTSEL) != 0) {
1339 ebone.parent->flag |= BONE_TIPSEL;
1340 }
1341 }
1342 else {
1343 if ((ebone.flag & BONE_ROOTSEL) == 0) {
1344 ebone.parent->flag &= ~BONE_TIPSEL;
1345 }
1346 }
1347
1348 if (is_parent_tip_changed == false) {
1349 /* Keep tip selected if the parent remains selected. */
1350 if (ebone.parent->flag & BONE_SELECTED) {
1351 ebone.parent->flag |= BONE_TIPSEL;
1352 }
1353 }
1354 }
1355 ebone.flag &= ~BONE_DONE;
1356 }
1357 }
1358
1360 }
1361
1362 return changed;
1363}
1364
1366
1367/* -------------------------------------------------------------------- */
1370
1372{
1373 int action = RNA_enum_get(op->ptr, "action");
1374
1375 if (action == SEL_TOGGLE) {
1376 /* Determine if there are any selected bones
1377 * And therefore whether we are selecting or deselecting */
1378 action = SEL_SELECT;
1379 CTX_DATA_BEGIN (C, EditBone *, ebone, visible_bones) {
1380 if (ebone->flag & (BONE_SELECTED | BONE_TIPSEL | BONE_ROOTSEL)) {
1381 action = SEL_DESELECT;
1382 break;
1383 }
1384 }
1386 }
1387
1388 /* Set the flags. */
1389 CTX_DATA_BEGIN (C, EditBone *, ebone, visible_bones) {
1390 /* ignore bone if selection can't change */
1391 switch (action) {
1392 case SEL_SELECT:
1393 if ((ebone->flag & BONE_UNSELECTABLE) == 0) {
1394 ebone->flag |= (BONE_SELECTED | BONE_TIPSEL | BONE_ROOTSEL);
1395 if (ebone->parent && (ebone->flag & BONE_CONNECTED)) {
1396 ebone->parent->flag |= BONE_TIPSEL;
1397 }
1398 }
1399 break;
1400 case SEL_DESELECT:
1401 ebone->flag &= ~(BONE_SELECTED | BONE_TIPSEL | BONE_ROOTSEL);
1402 break;
1403 case SEL_INVERT:
1404 if (ebone->flag & BONE_SELECTED) {
1405 ebone->flag &= ~(BONE_SELECTED | BONE_TIPSEL | BONE_ROOTSEL);
1406 }
1407 else {
1408 if ((ebone->flag & BONE_UNSELECTABLE) == 0) {
1409 ebone->flag |= (BONE_SELECTED | BONE_TIPSEL | BONE_ROOTSEL);
1410 if (ebone->parent && (ebone->flag & BONE_CONNECTED)) {
1411 ebone->parent->flag |= BONE_TIPSEL;
1412 }
1413 }
1414 }
1415 break;
1416 }
1417 }
1419
1421
1423
1424 /* Tagging only one object to refresh drawing. */
1425 Object *obedit = CTX_data_edit_object(C);
1427
1428 return OPERATOR_FINISHED;
1429}
1430
1432{
1433 /* identifiers */
1434 ot->name = "(De)select All";
1435 ot->idname = "ARMATURE_OT_select_all";
1436 ot->description = "Toggle selection status of all bones";
1437
1438 /* API callbacks. */
1441
1442 /* flags */
1444
1446}
1447
1449
1450/* -------------------------------------------------------------------- */
1453
1454static void armature_select_more(bArmature *arm, EditBone *ebone)
1455{
1456 if ((EBONE_PREV_FLAG_GET(ebone) & (BONE_ROOTSEL | BONE_TIPSEL)) != 0) {
1457 if (EBONE_SELECTABLE(arm, ebone)) {
1458 ED_armature_ebone_select_set(ebone, true);
1459 }
1460 }
1461
1462 if (ebone->parent && (ebone->flag & BONE_CONNECTED)) {
1463 /* to parent */
1464 if ((EBONE_PREV_FLAG_GET(ebone) & BONE_ROOTSEL) != 0) {
1465 if (EBONE_SELECTABLE(arm, ebone->parent)) {
1468 }
1469 }
1470
1471 /* from parent (difference from select less) */
1472 if ((EBONE_PREV_FLAG_GET(ebone->parent) & BONE_TIPSEL) != 0) {
1473 if (EBONE_SELECTABLE(arm, ebone)) {
1475 }
1476 }
1477 }
1478}
1479
1480static void armature_select_less(bArmature * /*arm*/, EditBone *ebone)
1481{
1483 {
1484 ED_armature_ebone_select_set(ebone, false);
1485 }
1486
1487 if (ebone->parent && (ebone->flag & BONE_CONNECTED)) {
1488 /* to parent */
1489 if ((EBONE_PREV_FLAG_GET(ebone) & BONE_SELECTED) == 0) {
1491 }
1492
1493 /* from parent (difference from select more) */
1494 if ((EBONE_PREV_FLAG_GET(ebone->parent) & BONE_SELECTED) == 0) {
1496 }
1497 }
1498}
1499
1500static void armature_select_more_less(Object *ob, bool more)
1501{
1502 bArmature *arm = id_cast<bArmature *>(ob->data);
1503
1504 /* XXX(@ideasman42): eventually we shouldn't need this. */
1506
1507 /* count bones & store selection state */
1508 for (EditBone &ebone : *arm->edbo) {
1510 }
1511
1512 /* do selection */
1513 for (EditBone &ebone : *arm->edbo) {
1514 if (animrig::bone_is_visible(arm, &ebone)) {
1515 if (more) {
1516 armature_select_more(arm, &ebone);
1517 }
1518 else {
1519 armature_select_less(arm, &ebone);
1520 }
1521 }
1522 }
1523
1524 for (EditBone &ebone : *arm->edbo) {
1525 if (animrig::bone_is_visible(arm, &ebone)) {
1526 if (more == false) {
1527 if (ebone.flag & BONE_SELECTED) {
1528 ED_armature_ebone_select_set(&ebone, true);
1529 }
1530 }
1531 }
1532 ebone.temp.p = nullptr;
1533 }
1534
1536}
1537
1539
1540/* -------------------------------------------------------------------- */
1543
1545{
1546 const Main *bmain = CTX_data_main(C);
1547 const Scene *scene = CTX_data_scene(C);
1548 ViewLayer *view_layer = CTX_data_view_layer(C);
1550 *bmain, scene, view_layer, CTX_wm_view3d(C));
1551 for (Object *ob : objects) {
1552 armature_select_more_less(ob, true);
1555 }
1556
1558 return OPERATOR_FINISHED;
1559}
1560
1562{
1563 /* identifiers */
1564 ot->name = "Select More";
1565 ot->idname = "ARMATURE_OT_select_more";
1566 ot->description = "Select those bones connected to the initial selection";
1567
1568 /* API callbacks. */
1571
1572 /* flags */
1574}
1575
1577
1578/* -------------------------------------------------------------------- */
1581
1583{
1584 const Main *bmain = CTX_data_main(C);
1585 const Scene *scene = CTX_data_scene(C);
1586 ViewLayer *view_layer = CTX_data_view_layer(C);
1588 *bmain, scene, view_layer, CTX_wm_view3d(C));
1589 for (Object *ob : objects) {
1590 armature_select_more_less(ob, false);
1593 }
1594
1596 return OPERATOR_FINISHED;
1597}
1598
1600{
1601 /* identifiers */
1602 ot->name = "Select Less";
1603 ot->idname = "ARMATURE_OT_select_less";
1604 ot->description = "Deselect those bones at the boundary of each selection region";
1605
1606 /* API callbacks. */
1609
1610 /* flags */
1612}
1613
1615
1616/* -------------------------------------------------------------------- */
1619
1620enum {
1631};
1632
1634 {SIMEDBONE_CHILDREN, "CHILDREN", 0, "Children", ""},
1635 {SIMEDBONE_CHILDREN_IMMEDIATE, "CHILDREN_IMMEDIATE", 0, "Immediate Children", ""},
1636 {SIMEDBONE_SIBLINGS, "SIBLINGS", 0, "Siblings", ""},
1637 {SIMEDBONE_LENGTH, "LENGTH", 0, "Length", ""},
1638 {SIMEDBONE_DIRECTION, "DIRECTION", 0, "Direction (Y Axis)", ""},
1639 {SIMEDBONE_PREFIX, "PREFIX", 0, "Prefix", ""},
1640 {SIMEDBONE_SUFFIX, "SUFFIX", 0, "Suffix", ""},
1641 {SIMEDBONE_COLLECTION, "BONE_COLLECTION", 0, "Bone Collection", ""},
1642 {SIMEDBONE_COLOR, "COLOR", 0, "Color", ""},
1643 {SIMEDBONE_SHAPE, "SHAPE", 0, "Shape", ""},
1644 {0, nullptr, 0, nullptr, nullptr},
1645};
1646
1648{
1649 float v1[3], v2[3];
1650 mul_v3_mat3_m4v3(v1, ob->object_to_world().ptr(), ebone->head);
1651 mul_v3_mat3_m4v3(v2, ob->object_to_world().ptr(), ebone->tail);
1652 return len_squared_v3v3(v1, v2);
1653}
1654
1655static void select_similar_length(bContext *C, const float thresh)
1656{
1657 const Main *bmain = CTX_data_main(C);
1658 const Scene *scene = CTX_data_scene(C);
1659 ViewLayer *view_layer = CTX_data_view_layer(C);
1660 Object *ob_act = CTX_data_edit_object(C);
1661 EditBone *ebone_act = CTX_data_active_bone(C);
1662
1663 /* Thresh is always relative to current length. */
1664 const float len = bone_length_squared_worldspace_get(ob_act, ebone_act);
1665 const float len_min = len / (1.0f + (thresh - FLT_EPSILON));
1666 const float len_max = len * (1.0f + (thresh + FLT_EPSILON));
1667
1669 *bmain, scene, view_layer, CTX_wm_view3d(C));
1670 for (Object *ob : objects) {
1671 bArmature *arm = id_cast<bArmature *>(ob->data);
1672 bool changed = false;
1673
1674 for (EditBone &ebone : *arm->edbo) {
1675 if (EBONE_SELECTABLE(arm, &ebone)) {
1676 const float len_iter = bone_length_squared_worldspace_get(ob, &ebone);
1677 if ((len_iter > len_min) && (len_iter < len_max)) {
1678 ED_armature_ebone_select_set(&ebone, true);
1679 changed = true;
1680 }
1681 }
1682 }
1683
1684 if (changed) {
1687 }
1688 }
1689}
1690
1691static void bone_direction_worldspace_get(Object *ob, EditBone *ebone, float *r_dir)
1692{
1693 float v1[3], v2[3];
1694 copy_v3_v3(v1, ebone->head);
1695 copy_v3_v3(v2, ebone->tail);
1696
1697 mul_m4_v3(ob->object_to_world().ptr(), v1);
1698 mul_m4_v3(ob->object_to_world().ptr(), v2);
1699
1700 sub_v3_v3v3(r_dir, v1, v2);
1701 normalize_v3(r_dir);
1702}
1703
1704static void select_similar_direction(bContext *C, const float thresh)
1705{
1706 const Main *bmain = CTX_data_main(C);
1707 const Scene *scene = CTX_data_scene(C);
1708 ViewLayer *view_layer = CTX_data_view_layer(C);
1709 Object *ob_act = CTX_data_edit_object(C);
1710 EditBone *ebone_act = CTX_data_active_bone(C);
1711
1712 float dir_act[3];
1713 bone_direction_worldspace_get(ob_act, ebone_act, dir_act);
1714
1716 *bmain, scene, view_layer, CTX_wm_view3d(C));
1717 for (Object *ob : objects) {
1718 bArmature *arm = id_cast<bArmature *>(ob->data);
1719 bool changed = false;
1720
1721 for (EditBone &ebone : *arm->edbo) {
1722 if (EBONE_SELECTABLE(arm, &ebone)) {
1723 float dir[3];
1724 bone_direction_worldspace_get(ob, &ebone, dir);
1725
1726 if (angle_v3v3(dir_act, dir) / float(M_PI) < (thresh + FLT_EPSILON)) {
1727 ED_armature_ebone_select_set(&ebone, true);
1728 changed = true;
1729 }
1730 }
1731 }
1732
1733 if (changed) {
1737 }
1738 }
1739}
1740
1742{
1743 const Main *bmain = CTX_data_main(C);
1744 const Scene *scene = CTX_data_scene(C);
1745 ViewLayer *view_layer = CTX_data_view_layer(C);
1746 EditBone *ebone_act = CTX_data_active_bone(C);
1747
1748 /* Build a set of bone collection names, to allow cross-Armature selection. */
1749 Set<std::string> collection_names;
1750 for (BoneCollectionReference &bcoll_ref : ebone_act->bone_collections) {
1751 collection_names.add(bcoll_ref.bcoll->name);
1752 }
1753
1755 *bmain, scene, view_layer, CTX_wm_view3d(C));
1756 for (Object *ob : objects) {
1757 bArmature *arm = id_cast<bArmature *>(ob->data);
1758 bool changed = false;
1759
1760 for (EditBone &ebone : *arm->edbo) {
1761 if (!EBONE_SELECTABLE(arm, &ebone)) {
1762 continue;
1763 }
1764
1765 for (BoneCollectionReference &bcoll_ref : ebone.bone_collections) {
1766 if (!collection_names.contains(bcoll_ref.bcoll->name)) {
1767 continue;
1768 }
1769
1770 ED_armature_ebone_select_set(&ebone, true);
1771 changed = true;
1772 break;
1773 }
1774 }
1775
1776 if (changed) {
1779 }
1780 }
1781}
1783{
1784 const Main *bmain = CTX_data_main(C);
1785 const Scene *scene = CTX_data_scene(C);
1786 ViewLayer *view_layer = CTX_data_view_layer(C);
1787 EditBone *ebone_act = CTX_data_active_bone(C);
1788
1789 const animrig::BoneColor &active_bone_color = ebone_act->color.wrap();
1790
1792 *bmain, scene, view_layer, CTX_wm_view3d(C));
1793 for (Object *ob : objects) {
1794 bArmature *arm = id_cast<bArmature *>(ob->data);
1795 bool changed = false;
1796
1797 for (EditBone &ebone : *arm->edbo) {
1798 if (!EBONE_SELECTABLE(arm, &ebone)) {
1799 continue;
1800 }
1801
1802 const animrig::BoneColor &bone_color = ebone.color.wrap();
1803 if (bone_color != active_bone_color) {
1804 continue;
1805 }
1806
1807 ED_armature_ebone_select_set(&ebone, true);
1808 changed = true;
1809 }
1810
1811 if (changed) {
1814 }
1815 }
1816}
1817
1819{
1820 const Main *bmain = CTX_data_main(C);
1821 const Scene *scene = CTX_data_scene(C);
1822 ViewLayer *view_layer = CTX_data_view_layer(C);
1823 EditBone *ebone_act = CTX_data_active_bone(C);
1824
1825 char body_tmp[MAXBONENAME];
1826 char prefix_act[MAXBONENAME];
1827
1828 BLI_string_split_prefix(ebone_act->name, sizeof(ebone_act->name), prefix_act, body_tmp);
1829
1830 if (prefix_act[0] == '\0') {
1831 return;
1832 }
1833
1835 *bmain, scene, view_layer, CTX_wm_view3d(C));
1836 for (Object *ob : objects) {
1837 bArmature *arm = id_cast<bArmature *>(ob->data);
1838 bool changed = false;
1839
1840 /* Find matches */
1841 for (EditBone &ebone : *arm->edbo) {
1842 if (EBONE_SELECTABLE(arm, &ebone)) {
1843 char prefix_other[MAXBONENAME];
1844 BLI_string_split_prefix(ebone.name, sizeof(ebone.name), prefix_other, body_tmp);
1845 if (STREQ(prefix_act, prefix_other)) {
1846 ED_armature_ebone_select_set(&ebone, true);
1847 changed = true;
1848 }
1849 }
1850 }
1851
1852 if (changed) {
1855 }
1856 }
1857}
1858
1860{
1861 const Main *bmain = CTX_data_main(C);
1862 const Scene *scene = CTX_data_scene(C);
1863 ViewLayer *view_layer = CTX_data_view_layer(C);
1864 EditBone *ebone_act = CTX_data_active_bone(C);
1865
1866 char body_tmp[MAXBONENAME];
1867 char suffix_act[MAXBONENAME];
1868
1869 BLI_string_split_suffix(ebone_act->name, sizeof(ebone_act->name), body_tmp, suffix_act);
1870
1871 if (suffix_act[0] == '\0') {
1872 return;
1873 }
1874
1876 *bmain, scene, view_layer, CTX_wm_view3d(C));
1877 for (Object *ob : objects) {
1878 bArmature *arm = id_cast<bArmature *>(ob->data);
1879 bool changed = false;
1880
1881 /* Find matches */
1882 for (EditBone &ebone : *arm->edbo) {
1883 if (EBONE_SELECTABLE(arm, &ebone)) {
1884 char suffix_other[MAXBONENAME];
1885 BLI_string_split_suffix(ebone.name, sizeof(ebone.name), body_tmp, suffix_other);
1886 if (STREQ(suffix_act, suffix_other)) {
1887 ED_armature_ebone_select_set(&ebone, true);
1888 changed = true;
1889 }
1890 }
1891 }
1892
1893 if (changed) {
1896 }
1897 }
1898}
1899
1901static void select_similar_data_pchan(bContext *C, const size_t bytes_size, const int offset)
1902{
1903 Object *obedit = CTX_data_edit_object(C);
1904 bArmature *arm = id_cast<bArmature *>(obedit->data);
1905 EditBone *ebone_act = CTX_data_active_bone(C);
1906
1907 const bPoseChannel *pchan_active = BKE_pose_channel_find_name(obedit->pose, ebone_act->name);
1908
1909 /* This will mostly happen for corner cases where the user tried to access this
1910 * before having any valid pose data for the armature. */
1911 if (pchan_active == nullptr) {
1912 return;
1913 }
1914
1915 const char *data_active = reinterpret_cast<const char *> POINTER_OFFSET(pchan_active, offset);
1916 for (EditBone &ebone : *arm->edbo) {
1917 if (EBONE_SELECTABLE(arm, &ebone)) {
1918 const bPoseChannel *pchan = BKE_pose_channel_find_name(obedit->pose, ebone.name);
1919 if (pchan) {
1920 const char *data_test = reinterpret_cast<const char *> POINTER_OFFSET(pchan, offset);
1921 if (memcmp(data_active, data_test, bytes_size) == 0) {
1922 ED_armature_ebone_select_set(&ebone, true);
1923 }
1924 }
1925 }
1926 }
1927
1930}
1931
1932static void is_ancestor(EditBone *bone, EditBone *ancestor)
1933{
1934 if (ELEM(bone->temp.ebone, ancestor, nullptr)) {
1935 return;
1936 }
1937
1938 if (!ELEM(bone->temp.ebone->temp.ebone, nullptr, ancestor)) {
1939 is_ancestor(bone->temp.ebone, ancestor);
1940 }
1941
1942 bone->temp.ebone = bone->temp.ebone->temp.ebone;
1943}
1944
1946{
1947 Object *obedit = CTX_data_edit_object(C);
1948 bArmature *arm = id_cast<bArmature *>(obedit->data);
1949 EditBone *ebone_act = CTX_data_active_bone(C);
1950
1951 for (EditBone &ebone_iter : *arm->edbo) {
1952 ebone_iter.temp.ebone = ebone_iter.parent;
1953 }
1954
1955 for (EditBone &ebone_iter : *arm->edbo) {
1956 is_ancestor(&ebone_iter, ebone_act);
1957
1958 if (ebone_iter.temp.ebone == ebone_act && EBONE_SELECTABLE(arm, &ebone_iter)) {
1959 ED_armature_ebone_select_set(&ebone_iter, true);
1960 }
1961 }
1962
1965}
1966
1968{
1969 Object *obedit = CTX_data_edit_object(C);
1970 bArmature *arm = id_cast<bArmature *>(obedit->data);
1971 EditBone *ebone_act = CTX_data_active_bone(C);
1972
1973 for (EditBone &ebone_iter : *arm->edbo) {
1974 if (ebone_iter.parent == ebone_act && EBONE_SELECTABLE(arm, &ebone_iter)) {
1975 ED_armature_ebone_select_set(&ebone_iter, true);
1976 }
1977 }
1978
1981}
1982
1984{
1985 Object *obedit = CTX_data_edit_object(C);
1986 bArmature *arm = id_cast<bArmature *>(obedit->data);
1987 EditBone *ebone_act = CTX_data_active_bone(C);
1988
1989 if (ebone_act->parent == nullptr) {
1990 return;
1991 }
1992
1993 for (EditBone &ebone_iter : *arm->edbo) {
1994 if (ebone_iter.parent == ebone_act->parent && EBONE_SELECTABLE(arm, &ebone_iter)) {
1995 ED_armature_ebone_select_set(&ebone_iter, true);
1996 }
1997 }
1998
2001}
2002
2004{
2005 /* Get props */
2006 int type = RNA_enum_get(op->ptr, "type");
2007 float thresh = RNA_float_get(op->ptr, "threshold");
2008
2009 /* Check for active bone */
2010 if (CTX_data_active_bone(C) == nullptr) {
2011 BKE_report(op->reports, RPT_ERROR, "Operation requires an active bone");
2012 return OPERATOR_CANCELLED;
2013 }
2014
2015#define STRUCT_SIZE_AND_OFFSET(_struct, _member) \
2016 sizeof(_struct::_member), offsetof(_struct, _member)
2017
2018 switch (type) {
2019 case SIMEDBONE_CHILDREN:
2021 break;
2024 break;
2025 case SIMEDBONE_SIBLINGS:
2027 break;
2028 case SIMEDBONE_LENGTH:
2029 select_similar_length(C, thresh);
2030 break;
2032 select_similar_direction(C, thresh);
2033 break;
2034 case SIMEDBONE_PREFIX:
2036 break;
2037 case SIMEDBONE_SUFFIX:
2039 break;
2042 break;
2043 case SIMEDBONE_COLOR:
2045 break;
2046 case SIMEDBONE_SHAPE:
2048 break;
2049 }
2050
2051#undef STRUCT_SIZE_AND_OFFSET
2052
2054
2055 return OPERATOR_FINISHED;
2056}
2057
2059{
2060 /* identifiers */
2061 ot->name = "Select Similar";
2062 ot->idname = "ARMATURE_OT_select_similar";
2063
2064 /* callback functions */
2065 ot->invoke = WM_menu_invoke;
2068 ot->description = "Select similar bones by property types";
2069
2070 /* flags */
2072
2073 /* properties */
2074 ot->prop = RNA_def_enum(ot->srna, "type", prop_similar_types, SIMEDBONE_LENGTH, "Type", "");
2075 RNA_def_float(ot->srna, "threshold", 0.1f, 0.0f, 1.0f, "Threshold", "", 0.0f, 1.0f);
2076}
2077
2079
2080/* -------------------------------------------------------------------- */
2083
2084/* No need to convert to multi-objects. Just like we keep the non-active bones
2085 * selected we then keep the non-active objects untouched (selected/unselected). */
2087{
2089 EditBone *ebone_active;
2090 int direction = RNA_enum_get(op->ptr, "direction");
2091 const bool add_to_sel = RNA_boolean_get(op->ptr, "extend");
2092 bool changed = false;
2093 bArmature *arm = id_cast<bArmature *>(ob->data);
2094
2095 ebone_active = arm->act_edbone;
2096 if (ebone_active == nullptr) {
2097 return OPERATOR_CANCELLED;
2098 }
2099
2100 if (direction == BONE_SELECT_PARENT) {
2101 if (ebone_active->parent) {
2102 EditBone *ebone_parent;
2103
2104 ebone_parent = ebone_active->parent;
2105
2106 if (EBONE_SELECTABLE(arm, ebone_parent)) {
2107 arm->act_edbone = ebone_parent;
2108
2109 if (!add_to_sel) {
2110 ED_armature_ebone_select_set(ebone_active, false);
2111 }
2112 ED_armature_ebone_select_set(ebone_parent, true);
2113
2114 changed = true;
2115 }
2116 }
2117 }
2118 else { /* BONE_SELECT_CHILD */
2119 EditBone *ebone_child = nullptr;
2120 int pass;
2121
2122 /* first pass, only connected bones (the logical direct child) */
2123 for (pass = 0; pass < 2 && (ebone_child == nullptr); pass++) {
2124 for (EditBone &ebone_iter : *arm->edbo) {
2125 /* possible we have multiple children, some invisible */
2126 if (EBONE_SELECTABLE(arm, &ebone_iter)) {
2127 if (ebone_iter.parent == ebone_active) {
2128 if ((pass == 1) || (ebone_iter.flag & BONE_CONNECTED)) {
2129 ebone_child = &ebone_iter;
2130 break;
2131 }
2132 }
2133 }
2134 }
2135 }
2136
2137 if (ebone_child) {
2138 arm->act_edbone = ebone_child;
2139
2140 if (!add_to_sel) {
2141 ED_armature_ebone_select_set(ebone_active, false);
2142 }
2143 ED_armature_ebone_select_set(ebone_child, true);
2144
2145 changed = true;
2146 }
2147 }
2148
2149 if (changed == false) {
2150 return OPERATOR_CANCELLED;
2151 }
2152
2154
2156
2159
2160 return OPERATOR_FINISHED;
2161}
2162
2164{
2165 static const EnumPropertyItem direction_items[] = {
2166 {BONE_SELECT_PARENT, "PARENT", 0, "Select Parent", ""},
2167 {BONE_SELECT_CHILD, "CHILD", 0, "Select Child", ""},
2168 {0, nullptr, 0, nullptr, nullptr},
2169 };
2170
2171 /* identifiers */
2172 ot->name = "Select Hierarchy";
2173 ot->idname = "ARMATURE_OT_select_hierarchy";
2174 ot->description = "Select immediate parent/children of selected bones";
2175
2176 /* API callbacks. */
2179
2180 /* flags */
2182
2183 /* props */
2184 RNA_def_enum(ot->srna, "direction", direction_items, BONE_SELECT_PARENT, "Direction", "");
2185 RNA_def_boolean(ot->srna, "extend", false, "Extend", "Extend the selection");
2186}
2187
2189
2190/* -------------------------------------------------------------------- */
2193
2198{
2199 const Main *bmain = CTX_data_main(C);
2200 const Scene *scene = CTX_data_scene(C);
2201 ViewLayer *view_layer = CTX_data_view_layer(C);
2202 const bool active_only = RNA_boolean_get(op->ptr, "only_active");
2203 const bool extend = RNA_boolean_get(op->ptr, "extend");
2204
2206 *bmain, scene, view_layer, CTX_wm_view3d(C));
2207 for (Object *ob : objects) {
2208 bArmature *arm = id_cast<bArmature *>(ob->data);
2209
2210 EditBone *ebone_mirror_act = nullptr;
2211
2212 for (EditBone &ebone : *arm->edbo) {
2214 EBONE_PREV_FLAG_SET(&ebone, flag);
2215 }
2216
2217 for (EditBone &ebone : *arm->edbo) {
2218 if (EBONE_SELECTABLE(arm, &ebone)) {
2219 EditBone *ebone_mirror;
2220 eBone_Flag flag_new = extend ? eBone_Flag(EBONE_PREV_FLAG_GET(&ebone)) : eBone_Flag{};
2221
2222 if ((ebone_mirror = ED_armature_ebone_get_mirrored(arm->edbo, &ebone)) &&
2223 animrig::bone_is_visible(arm, ebone_mirror))
2224 {
2225 const eBone_Flag flag_mirror = eBone_Flag(EBONE_PREV_FLAG_GET(ebone_mirror));
2226 flag_new |= flag_mirror;
2227
2228 if (&ebone == arm->act_edbone) {
2229 ebone_mirror_act = ebone_mirror;
2230 }
2231
2232 /* skip all but the active or its mirror */
2233 if (active_only && !ELEM(arm->act_edbone, &ebone, ebone_mirror)) {
2234 continue;
2235 }
2236 }
2237
2238 ED_armature_ebone_selectflag_set(&ebone, flag_new);
2239 }
2240 }
2241
2242 if (ebone_mirror_act) {
2243 arm->act_edbone = ebone_mirror_act;
2244 }
2245
2247
2249
2252 }
2253
2254 return OPERATOR_FINISHED;
2255}
2256
2258{
2259 /* identifiers */
2260 ot->name = "Select Mirror";
2261 ot->idname = "ARMATURE_OT_select_mirror";
2262 ot->description = "Mirror the bone selection";
2263
2264 /* API callbacks. */
2267
2268 /* flags */
2270
2271 /* properties */
2273 ot->srna, "only_active", false, "Active Only", "Only operate on the active bone");
2274 RNA_def_boolean(ot->srna, "extend", false, "Extend", "Extend the selection");
2275}
2276
2278
2279/* -------------------------------------------------------------------- */
2282
2284 bArmature *arm, EditBone *ebone_parent, EditBone *ebone_child, bool use_parent, bool is_test)
2285{
2286 do {
2287
2288 if (!use_parent && (ebone_child == ebone_parent)) {
2289 break;
2290 }
2291
2292 if (is_test) {
2293 if (!EBONE_SELECTABLE(arm, ebone_child)) {
2294 return false;
2295 }
2296 }
2297 else {
2299 }
2300
2301 if (ebone_child == ebone_parent) {
2302 break;
2303 }
2304
2305 ebone_child = ebone_child->parent;
2306 } while (true);
2307
2308 return true;
2309}
2310
2312 wmOperator *op,
2313 const wmEvent *event)
2314{
2315 Object *obedit = CTX_data_edit_object(C);
2316 bArmature *arm = id_cast<bArmature *>(obedit->data);
2317 EditBone *ebone_src, *ebone_dst;
2318 EditBone *ebone_isect_parent = nullptr;
2319 EditBone *ebone_isect_child[2];
2320 bool changed;
2321 Base *base_dst = nullptr;
2322
2325
2326 ebone_src = arm->act_edbone;
2327 ebone_dst = ED_armature_pick_ebone(C, event->mval, false, &base_dst);
2328
2329 /* fall back to object selection */
2330 if (ELEM(nullptr, ebone_src, ebone_dst) || (ebone_src == ebone_dst)) {
2331 return OPERATOR_PASS_THROUGH;
2332 }
2333
2334 if (base_dst && base_dst->object != obedit) {
2335 /* Disconnected, ignore. */
2336 return OPERATOR_CANCELLED;
2337 }
2338
2339 ebone_isect_child[0] = ebone_src;
2340 ebone_isect_child[1] = ebone_dst;
2341
2342 /* ensure 'ebone_src' is the parent of 'ebone_dst', or set 'ebone_isect_parent' */
2343 if (ED_armature_ebone_is_child_recursive(ebone_src, ebone_dst)) {
2344 /* pass */
2345 }
2346 else if (ED_armature_ebone_is_child_recursive(ebone_dst, ebone_src)) {
2347 std::swap(ebone_src, ebone_dst);
2348 }
2349 else if ((ebone_isect_parent = ED_armature_ebone_find_shared_parent(ebone_isect_child, 2))) {
2350 /* pass */
2351 }
2352 else {
2353 /* disconnected bones */
2354 return OPERATOR_CANCELLED;
2355 }
2356
2357 if (ebone_isect_parent) {
2358 if (armature_shortest_path_select(arm, ebone_isect_parent, ebone_src, false, true) &&
2359 armature_shortest_path_select(arm, ebone_isect_parent, ebone_dst, false, true))
2360 {
2361 armature_shortest_path_select(arm, ebone_isect_parent, ebone_src, false, false);
2362 armature_shortest_path_select(arm, ebone_isect_parent, ebone_dst, false, false);
2363 changed = true;
2364 }
2365 else {
2366 /* unselectable */
2367 changed = false;
2368 }
2369 }
2370 else {
2371 if (armature_shortest_path_select(arm, ebone_src, ebone_dst, true, true)) {
2372 armature_shortest_path_select(arm, ebone_src, ebone_dst, true, false);
2373 changed = true;
2374 }
2375 else {
2376 /* unselectable */
2377 changed = false;
2378 }
2379 }
2380
2381 if (changed) {
2382 arm->act_edbone = ebone_dst;
2387
2388 return OPERATOR_FINISHED;
2389 }
2390
2391 BKE_report(op->reports, RPT_WARNING, "Unselectable bone in chain");
2392 return OPERATOR_CANCELLED;
2393}
2394
2396{
2397 /* identifiers */
2398 ot->name = "Pick Shortest Path";
2399 ot->idname = "ARMATURE_OT_shortest_path_pick";
2400 ot->description = "Select shortest path between two bones";
2401
2402 /* API callbacks. */
2405
2406 /* flags */
2408}
2409
2411
2412} // namespace blender
Functions to deal with Armatures.
C++ functions to deal with Armature collections (i.e. the successor of bone layers).
C++ part of the BoneColor DNA struct.
Blender kernel action and pose functionality.
#define CTX_DATA_BEGIN(C, Type, instance, member)
#define CTX_DATA_END
General operations, lookup, etc. for blender objects.
#define M_PI
#define MAXBONENAME
Object is a sort of wrapper for general info.
#define BONESEL_ANY
#define BONESEL_ROOT
#define BONE_SELECT_CHILD
#define BONESEL_TIP
#define BONE_SELECT_PARENT
#define BONESEL_BONE
#define EBONE_SELECTABLE(arm, ebone)
#define XRAY_ACTIVE(v3d)
#define C
Definition RandGen.cpp:29
#define ND_DATA
Definition WM_types.hh:552
#define NA_EDITED
Definition WM_types.hh:634
#define NC_GPENCIL
Definition WM_types.hh:412
#define ND_BONE_SELECT
Definition WM_types.hh:491
#define NC_OBJECT
Definition WM_types.hh:392
#define CHECK_PARENT(ebone)
#define EBONE_PREV_FLAG_GET(ebone)
#define EBONE_PREV_FLAG_SET(ebone, val)
#define STRUCT_SIZE_AND_OFFSET(_struct, _member)
#define BLI_assert_unreachable()
#define SET_FLAG_FROM_TEST(value, test, flag)
#define ELEM(...)
#define POINTER_OFFSET(v, ofs)
#define STREQ(a, b)
constexpr MutableSpan slice(const int64_t start, const int64_t size) const
Definition BLI_span.hh:579
bool contains(const Key &key) const
Definition BLI_set.hh:310
bool add(const Key &key)
Definition BLI_set.hh:248
int64_t size() const
Span< T > as_span() const
constexpr void copy_from(Span< T > values) const
#define INT_MAX
#define FLT_EPSILON
#define storage(slot, qualifiers)
ccl_device_inline dual1 len(const ccl_private dual< T > &a)
Definition math_dual.h:263
bool bone_is_visible(const bArmature *armature, const Bone *bone)
void base_activate(bContext *C, Base *base)
BMesh Iterators.
void WM_main_add_notifier(uint type, void *reference)
void ARMATURE_OT_select_linked(wmOperatorType *ot)
Vector< Base * > BKE_object_pose_base_array_get(const Main &bmain, const Scene *scene, ViewLayer *view_layer, View3D *v3d)
Definition object.cc:2640
BLI_assert(slot->slot_subtype.map==BMO_OP_SLOT_SUBTYPE_MAP_FLT)
MINLINE float len_squared_v3v3(const float a[3], const float b[3]) ATTR_WARN_UNUSED_RESULT
static float bone_length_squared_worldspace_get(Object *ob, EditBone *ebone)
static int selectbuffer_ret_hits_12(MutableSpan< GPUSelectResult >, const int hits12)
wmOperatorStatus WM_menu_invoke(bContext *C, wmOperator *op, const wmEvent *)
static void select_similar_bone_collection(bContext *C)
Base * ED_armature_base_and_ebone_from_select_buffer(const Span< Base * > bases, const uint select_id, EditBone **r_ebone)
int RNA_enum_get(PointerRNA *ptr, const char *name)
static void bone_direction_worldspace_get(Object *ob, EditBone *ebone, float *r_dir)
void view3d_gpu_select_cache_end()
static void select_similar_suffix(bContext *C)
void ARMATURE_OT_select_similar(wmOperatorType *ot)
@ RPT_WARNING
Definition BKE_report.hh:40
bool ED_armature_edit_select_pick(bContext *C, const int mval[2], const SelectPick_Params &params)
static void * ed_armature_pick_bone_from_selectbuffer_impl(const bool is_editmode, const Span< Base * > bases, const Span< GPUSelectResult > hit_results, bool findunsel, bool do_nearest, Base **r_base)
void ARMATURE_OT_select_more(wmOperatorType *ot)
ViewContext ED_view3d_viewcontext_init(bContext *C, Depsgraph *depsgraph)
static wmOperatorStatus armature_select_hierarchy_exec(bContext *C, wmOperator *op)
MINLINE void copy_v3_v3(float r[3], const float a[3])
unsigned int uint
Definition BKE_text.h:55
static int selectbuffer_ret_hits_5(MutableSpan< GPUSelectResult > hit_results, const int hits12, const int hits5)
static void select_similar_bone_color(bContext *C)
bool ED_armature_selectresult_is_bone(const GPUSelectResult &hit_result)
void ED_armature_ebone_selectflag_disable(EditBone *ebone, eBone_Flag flag)
void ED_armature_ebone_selectflag_enable(EditBone *ebone, eBone_Flag flag)
void BKE_object_update_select_id(Main *bmain)
Definition object.cc:5676
bool ED_armature_ebone_is_child_recursive(EditBone *ebone_parent, EditBone *ebone_child)
void ARMATURE_OT_shortest_path_pick(wmOperatorType *ot)
Bone * ED_armature_pick_bone(bContext *C, const int xy[2], bool findunsel, Base **r_base)
bool ED_armature_edit_deselect_all_visible_multi_ex(const Span< Base * > bases)
float angle_v3v3(const float a[3], const float b[3]) ATTR_WARN_UNUSED_RESULT
PropertyRNA * RNA_def_enum(StructOrFunctionRNA *cont_, const char *identifier, const EnumPropertyItem *items, const int default_value, const char *ui_name, const char *ui_description)
void ARMATURE_OT_select_hierarchy(wmOperatorType *ot)
void mul_v3_mat3_m4v3(float r[3], const float mat[4][4], const float vec[3])
void view3d_operator_needs_gpu(const bContext *C)
static void * ed_armature_pick_bone_impl(const bool is_editmode, bContext *C, const int xy[2], bool findunsel, Base **r_base)
Base * BKE_view_layer_active_base_get(ViewLayer *view_layer)
bool ED_operator_editarmature(bContext *C)
int gpu_select_buffer_depth_id_cmp(const void *sel_a_p, const void *sel_b_p)
bPoseChannel * ED_armature_pick_pchan_from_selectbuffer(Span< Base * > bases, const GPUSelectResult *hit_results, int hits, bool findunsel, bool do_nearest, Base **r_base)
static wmOperatorStatus armature_shortest_path_pick_invoke(bContext *C, wmOperator *op, const wmEvent *event)
static const EnumPropertyItem prop_similar_types[]
ViewLayer * CTX_data_view_layer(const bContext *C)
void WM_operator_properties_select_all(wmOperatorType *ot)
void view3d_gpu_select_cache_begin()
static void select_similar_data_pchan(bContext *C, const size_t bytes_size, const int offset)
eV3DSelectObjectFilter
Definition ED_view3d.hh:990
@ VIEW3D_SELECT_FILTER_NOP
Definition ED_view3d.hh:992
@ VIEW3D_SELECT_FILTER_OBJECT_MODE_LOCK_SAME_TYPE
Definition ED_view3d.hh:999
bool ED_armature_edit_select_op_from_tagged(bArmature *arm, const int sel_op)
EditBone * CTX_data_active_bone(const bContext *C)
static wmOperatorStatus armature_de_select_more_exec(bContext *C, wmOperator *)
static void select_similar_children(bContext *C)
unsigned short uint16_t
Definition BKE_text.h:80
static bool armature_select_linked_pick_poll(bContext *C)
void mul_m4_v3(const float M[4][4], float r[3])
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 void select_similar_siblings(bContext *C)
unsigned int uint32_t
Definition BKE_text.h:81
EditBone * ED_armature_ebone_find_shared_parent(EditBone *ebone_child[], const uint ebone_child_tot)
int BLI_findindex(const ListBase *listbase, const void *vlink) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1)
Definition listbase.cc:593
EditBone * ED_armature_pick_ebone(bContext *C, const int xy[2], bool findunsel, Base **r_base)
static void select_similar_length(bContext *C, const float thresh)
EditBone * ED_armature_ebone_get_mirrored(const ListBaseT< EditBone > *edbo, EditBone *ebo)
bPoseChannel * ED_armature_pick_pchan(bContext *C, const int xy[2], bool findunsel, Base **r_base)
static wmOperatorStatus armature_select_mirror_exec(bContext *C, wmOperator *op)
bool ED_armature_edit_select_pick_bone(bContext *C, Base *basact, EditBone *ebone, const eBone_Flag selmask, const SelectPick_Params &params)
int ED_select_op_action_deselected(eSelectOp sel_op, bool is_select, bool is_inside)
Vector< GPUSelectResult, 2500 > GPUSelectStorage
Definition GPU_select.hh:47
void ED_armature_ebone_selectflag_set(EditBone *ebone, eBone_Flag flag)
void DEG_id_tag_update(ID *id, unsigned int flags)
void BKE_report(ReportList *reports, eReportType type, const char *message)
Definition report.cc:162
BMesh const char void * data
void ED_armature_edit_sync_selection(ListBaseT< EditBone > *edbo)
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
Object * CTX_data_edit_object(const bContext *C)
void ARMATURE_OT_select_less(wmOperatorType *ot)
void ARMATURE_OT_select_all(wmOperatorType *ot)
bool BKE_view_layer_synced_ensure(const Main &bmain, const Scene *scene, ViewLayer *view_layer)
bool ED_operator_view3d_active(bContext *C)
static wmOperatorStatus armature_de_select_all_exec(bContext *C, wmOperator *op)
bool RNA_boolean_get(PointerRNA *ptr, const char *name)
void void BLI_string_split_prefix(const char *string, size_t string_maxlen, char *r_pre, char *r_body) ATTR_NONNULL(1
static wmOperatorStatus armature_select_similar_exec(bContext *C, wmOperator *op)
void WM_event_add_notifier(const bContext *C, uint type, void *reference)
static wmOperatorStatus armature_de_select_less_exec(bContext *C, wmOperator *)
int view3d_gpu_select_with_id_filter(const ViewContext *vc, GPUSelectBuffer *buffer, const rcti *input, eV3DSelectMode select_mode, eV3DSelectObjectFilter select_filter, uint select_id)
static void armature_select_more_less(Object *ob, bool more)
static wmOperatorStatus armature_select_linked_pick_invoke(bContext *C, wmOperator *op, const wmEvent *event)
bool BKE_object_is_in_editmode(const Object *ob)
Definition object.cc:1898
static EditBone * get_nearest_editbonepoint(ViewContext *vc, bool findunsel, bool use_cycle, Base **r_base, eBone_Flag *r_selmask)
bool ED_armature_edit_deselect_all_visible(Object *obedit)
MINLINE float normalize_v3(float n[3])
void ARMATURE_OT_select_mirror(wmOperatorType *ot)
int ED_armature_ebone_selectflag_get(const EditBone *ebone)
void ARMATURE_OT_select_linked_pick(wmOperatorType *ot)
MINLINE void sub_v3_v3v3(float r[3], const float a[3], const float b[3])
Main * CTX_data_main(const bContext *C)
static bool armature_shortest_path_select(bArmature *arm, EditBone *ebone_parent, EditBone *ebone_child, bool use_parent, bool is_test)
EditBone * ED_armature_pick_ebone_from_selectbuffer(Span< Base * > bases, const GPUSelectResult *hit_results, int hits, bool findunsel, bool do_nearest, Base **r_base)
static bool armature_edit_select_op_apply(bArmature *arm, EditBone *ebone, const eSelectOp sel_op, int is_ignore_flag, int is_inside_flag)
ATTR_WARN_UNUSED_RESULT const BMVert * v2
Base * ED_armature_base_and_bone_from_select_buffer(const Span< Base * > bases, const uint select_id, Bone **r_bone)
static void is_ancestor(EditBone *bone, EditBone *ancestor)
static void select_similar_direction(bContext *C, const float thresh)
void BLI_string_split_suffix(const char *string, size_t string_maxlen, char *r_body, char *r_suf) ATTR_NONNULL(1
@ ID_RECALC_SELECT
Definition DNA_ID.h:1101
@ ID_RECALC_SYNC_TO_EVAL
Definition DNA_ID.h:1118
@ SIMEDBONE_CHILDREN_IMMEDIATE
Vector< Object * > BKE_view_layer_array_from_objects_in_edit_mode_unique_data(const Main &bmain, const Scene *scene, ViewLayer *view_layer, const View3D *v3d)
Bone * ED_armature_pick_bone_from_selectbuffer(Span< Base * > bases, const GPUSelectResult *hit_results, int hits, bool findunsel, bool do_nearest, Base **r_base)
void ED_outliner_select_sync_from_edit_bone_tag(bContext *C)
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)
Scene * CTX_data_scene(const bContext *C)
static wmOperatorStatus armature_select_linked_exec(bContext *C, wmOperator *op)
bool WM_cursor_test_motion_and_update(const int mval[2])
@ OPTYPE_REGISTER
Definition WM_types.hh:188
@ OPTYPE_UNDO
Definition WM_types.hh:190
PropertyRNA * RNA_def_boolean(StructOrFunctionRNA *cont_, const char *identifier, const bool default_value, const char *ui_name, const char *ui_description)
bool ED_armature_edit_deselect_all_multi_ex(const Span< Base * > bases)
Vector< Base * > BKE_view_layer_array_from_bases_in_edit_mode(const Main &bmain, const Scene *scene, ViewLayer *view_layer, const View3D *v3d)
void BLI_rcti_init_pt_radius(struct rcti *rect, const int xy[2], int size)
Definition rct.cc:480
static void armature_select_more(bArmature *arm, EditBone *ebone)
static void armature_select_less(bArmature *, EditBone *ebone)
PropertyRNA * RNA_def_float(StructOrFunctionRNA *cont_, const char *identifier, const float default_value, const float hardmin, const float hardmax, const char *ui_name, const char *ui_description, const float softmin, const float softmax)
Object * ED_armature_object_and_ebone_from_select_buffer(const Span< Object * > objects, const uint select_id, EditBone **r_ebone)
void ED_armature_ebone_select_set(EditBone *ebone, bool select)
float RNA_float_get(PointerRNA *ptr, const char *name)
bPoseChannel * BKE_pose_channel_find_name(const bPose *pose, const char *name)
static void select_similar_prefix(bContext *C)
static bool armature_select_linked_impl(Object *ob, const bool select, const bool all_forks)
View3D * CTX_wm_view3d(const bContext *C)
static void select_similar_children_immediate(bContext *C)
bool ED_armature_edit_deselect_all(Object *obedit)
bool ED_armature_edit_deselect_all_visible_multi(bContext *C)
struct Object * object
union blender::EditBone::@252003325204232231327014100071366025164067232113 temp
ListBaseT< BoneCollectionReference > bone_collections
GPUSelectStorage storage
Definition GPU_select.hh:49
bke::ObjectRuntime * runtime
struct bPose * pose
ViewLayer * view_layer
Definition ED_view3d.hh:80
ListBaseT< EditBone > * edbo
struct EditBone * act_edbone
ListBaseT< bPoseChannel > chanbase
wmOperatorStatus(*) exec(bContext *C, wmOperator *op) ATTR_WARN_UNUSED_RESULT
Definition WM_types.hh:1125
const char * description
Definition WM_types.hh:1115
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
struct ReportList * reports