Blender V5.3
armature_edit.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 "MEM_guardedalloc.h"
15
16#include "BLT_translation.hh"
17
18#include "BLI_listbase.hh"
19#include "BLI_math_matrix_c.hh"
21#include "BLI_math_vector_c.hh"
22
23#include "BKE_action.hh"
24#include "BKE_armature.hh"
25#include "BKE_context.hh"
26#include "BKE_global.hh"
27#include "BKE_layer.hh"
28#include "BKE_main.hh"
29#include "BKE_object.hh"
30#include "BKE_object_types.hh"
31#include "BKE_report.hh"
32
33#include "RNA_access.hh"
34#include "RNA_define.hh"
35#include "RNA_prototypes.hh"
36
37#include "UI_interface_icons.hh"
38
39#include "WM_api.hh"
40#include "WM_types.hh"
41
42#include "ED_armature.hh"
43#include "ED_object.hh"
44#include "ED_outliner.hh"
45#include "ED_screen.hh"
46#include "ED_view3d.hh"
47
48#include "ANIM_armature.hh"
49
50#include "DEG_depsgraph.hh"
51
52#include "armature_intern.hh"
53
54namespace blender {
55
56/* -------------------------------------------------------------------- */
59
61{
62 bArmature *armature = static_cast<bArmature *>(
63 CTX_data_pointer_get_type(C, "armature", RNA_Armature).data);
64
65 if (armature == nullptr) {
67 if (object && object->type == OB_ARMATURE) {
68 armature = id_cast<bArmature *>(object->data);
69 }
70 }
71
72 return armature;
73}
74
75/* NOTE: these functions are exported to the Object module to be called from the tools there */
76
77void ED_armature_edit_transform(bArmature *arm, const float mat[4][4], const bool do_props)
78{
79 float scale = mat4_to_scale(mat); /* store the scale of the matrix here to use on envelopes */
80 float mat3[3][3];
81
82 copy_m3_m4(mat3, mat);
83 normalize_m3(mat3);
84 /* Do the rotations */
85 for (EditBone &ebone : *arm->edbo) {
86 float tmat[3][3];
87
88 /* find the current bone's roll matrix */
89 ED_armature_ebone_to_mat3(&ebone, tmat);
90
91 /* transform the roll matrix */
92 mul_m3_m3m3(tmat, mat3, tmat);
93
94 /* transform the bone */
95 mul_m4_v3(mat, ebone.head);
96 mul_m4_v3(mat, ebone.tail);
97
98 /* apply the transformed roll back */
99 mat3_to_vec_roll(tmat, nullptr, &ebone.roll);
100
101 if (do_props) {
102 ebone.rad_head *= scale;
103 ebone.rad_tail *= scale;
104 ebone.dist *= scale;
105
106 /* we could be smarter and scale by the matrix along the x & z axis */
107 ebone.xwidth *= scale;
108 ebone.zwidth *= scale;
109 }
110 }
111}
112
113void ED_armature_transform(bArmature *arm, const float mat[4][4], const bool do_props)
114{
115 if (arm->edbo) {
116 ED_armature_edit_transform(arm, mat, do_props);
117 }
118 else {
119 BKE_armature_transform(arm, mat, do_props);
120 }
121}
122
124 Main *bmain, Object *ob, const float cursor[3], int centermode, int around)
125{
126 const bool is_editmode = BKE_object_is_in_editmode(ob);
127 bArmature *arm = id_cast<bArmature *>(ob->data);
128 float cent[3];
129
130 /* Put the armature into edit-mode. */
131 if (is_editmode == false) {
133 }
134
135 /* Find the center-point. */
136 if (centermode == 2) {
137 copy_v3_v3(cent, cursor);
138 invert_m4_m4(ob->runtime->world_to_object.ptr(), ob->object_to_world().ptr());
139 mul_m4_v3(ob->world_to_object().ptr(), cent);
140 }
141 else {
142 if (around == V3D_AROUND_CENTER_BOUNDS) {
143 float min[3], max[3];
145 for (EditBone &ebone : *arm->edbo) {
146 minmax_v3v3_v3(min, max, ebone.head);
147 minmax_v3v3_v3(min, max, ebone.tail);
148 }
149 mid_v3_v3v3(cent, min, max);
150 }
151 else { /* #V3D_AROUND_CENTER_MEDIAN. */
152 int total = 0;
153 zero_v3(cent);
154 for (EditBone &ebone : *arm->edbo) {
155 total += 2;
156 add_v3_v3(cent, ebone.head);
157 add_v3_v3(cent, ebone.tail);
158 }
159 if (total) {
160 mul_v3_fl(cent, 1.0f / float(total));
161 }
162 }
163 }
164
165 /* Do the adjustments */
166 for (EditBone &ebone : *arm->edbo) {
167 sub_v3_v3(ebone.head, cent);
168 sub_v3_v3(ebone.tail, cent);
169 }
170
171 /* Turn the list into an armature */
172 if (is_editmode == false) {
173 ED_armature_from_edit(bmain, arm);
175 }
176
177 /* Adjust object location for new center-point. */
178 if (centermode && (is_editmode == false)) {
179 mul_mat3_m4_v3(ob->object_to_world().ptr(), cent); /* omit translation part */
180 add_v3_v3(ob->loc, cent);
181 }
182}
183
185
186/* -------------------------------------------------------------------- */
189
191 const float align_axis[3],
192 const bool axis_only)
193{
194 float mat[3][3], nor[3];
195 float vec[3], align_axis_proj[3], roll = 0.0f;
196
197 BLI_ASSERT_UNIT_V3(align_axis);
198
199 sub_v3_v3v3(nor, bone->tail, bone->head);
200
201 /* If tail == head or the bone is aligned with the axis... */
202 if (normalize_v3(nor) <= FLT_EPSILON ||
203 (fabsf(dot_v3v3(align_axis, nor)) >= (1.0f - FLT_EPSILON)))
204 {
205 return roll;
206 }
207
208 vec_roll_to_mat3_normalized(nor, 0.0f, mat);
209
210 /* project the new_up_axis along the normal */
211 project_v3_v3v3_normalized(vec, align_axis, nor);
212 sub_v3_v3v3(align_axis_proj, align_axis, vec);
213
214 if (axis_only) {
215 if (angle_v3v3(align_axis_proj, mat[2]) > float(M_PI_2)) {
216 negate_v3(align_axis_proj);
217 }
218 }
219
220 roll = angle_v3v3(align_axis_proj, mat[2]);
221
222 cross_v3_v3v3(vec, mat[2], align_axis_proj);
223
224 if (dot_v3v3(vec, nor) < 0.0f) {
225 return -roll;
226 }
227 return roll;
228}
229
230/* NOTE: ranges arithmetic is used below. */
253
255 RNA_ENUM_ITEM_HEADING(N_("Positive"), nullptr),
256 {CALC_ROLL_TAN_POS_X, "POS_X", 0, "Local +X Tangent", ""},
257 {CALC_ROLL_TAN_POS_Z, "POS_Z", 0, "Local +Z Tangent", ""},
258
259 {CALC_ROLL_POS_X, "GLOBAL_POS_X", 0, "Global +X Axis", ""},
260 {CALC_ROLL_POS_Y, "GLOBAL_POS_Y", 0, "Global +Y Axis", ""},
261 {CALC_ROLL_POS_Z, "GLOBAL_POS_Z", 0, "Global +Z Axis", ""},
262
263 RNA_ENUM_ITEM_HEADING(N_("Negative"), nullptr),
264 {CALC_ROLL_TAN_NEG_X, "NEG_X", 0, "Local -X Tangent", ""},
265 {CALC_ROLL_TAN_NEG_Z, "NEG_Z", 0, "Local -Z Tangent", ""},
266
267 {CALC_ROLL_NEG_X, "GLOBAL_NEG_X", 0, "Global -X Axis", ""},
268 {CALC_ROLL_NEG_Y, "GLOBAL_NEG_Y", 0, "Global -Y Axis", ""},
269 {CALC_ROLL_NEG_Z, "GLOBAL_NEG_Z", 0, "Global -Z Axis", ""},
270
271 RNA_ENUM_ITEM_HEADING(N_("Other"), nullptr),
272 {CALC_ROLL_ACTIVE, "ACTIVE", 0, "Active Bone", ""},
273 {CALC_ROLL_VIEW, "VIEW", 0, "View Axis", ""},
274 {CALC_ROLL_CURSOR, "CURSOR", 0, "Cursor", ""},
275 {0, nullptr, 0, nullptr, nullptr},
276};
277
279{
280 const Main *bmain = CTX_data_main(C);
281 const Scene *scene = CTX_data_scene(C);
282 ViewLayer *view_layer = CTX_data_view_layer(C);
283 Object *ob_active = CTX_data_edit_object(C);
284
285 eCalcRollTypes type = eCalcRollTypes(RNA_enum_get(op->ptr, "type"));
286 const bool axis_only = RNA_boolean_get(op->ptr, "axis_only");
287 /* axis_flip when matching the active bone never makes sense */
288 bool axis_flip = ((type >= CALC_ROLL_ACTIVE) ? RNA_boolean_get(op->ptr, "axis_flip") :
289 (type >= CALC_ROLL_TAN_NEG_X) ? true :
290 false);
291
293 *bmain, scene, view_layer, CTX_wm_view3d(C));
294 for (Object *ob : objects) {
295 bArmature *arm = id_cast<bArmature *>(ob->data);
296 bool changed = false;
297
298 float imat[3][3];
299 EditBone *ebone;
300
301 if ((type >= CALC_ROLL_NEG_X) && (type <= CALC_ROLL_TAN_NEG_Z)) {
302 type = eCalcRollTypes(int(type) - (CALC_ROLL_ACTIVE - CALC_ROLL_NEG_X));
303 axis_flip = true;
304 }
305
306 copy_m3_m4(imat, ob->object_to_world().ptr());
307 invert_m3(imat);
308
309 if (type == CALC_ROLL_CURSOR) { /* Cursor */
310 float cursor_local[3];
311 const View3DCursor *cursor = &scene->cursor;
312
313 invert_m4_m4(ob->runtime->world_to_object.ptr(), ob->object_to_world().ptr());
314 copy_v3_v3(cursor_local, cursor->location);
315 mul_m4_v3(ob->world_to_object().ptr(), cursor_local);
316
317 /* cursor */
318 for (EditBone &ebone : *arm->edbo) {
319 if (animrig::bone_is_visible(arm, &ebone) && EBONE_EDITABLE(&ebone)) {
320 float cursor_rel[3];
321 sub_v3_v3v3(cursor_rel, cursor_local, ebone.head);
322 if (axis_flip) {
323 negate_v3(cursor_rel);
324 }
325 if (normalize_v3(cursor_rel) != 0.0f) {
326 ebone.roll = ED_armature_ebone_roll_to_vector(&ebone, cursor_rel, axis_only);
327 changed = true;
328 }
329 }
330 }
331 }
333 for (EditBone &ebone : *arm->edbo) {
334 if (ebone.parent) {
335 bool is_edit = (animrig::bone_is_visible(arm, &ebone) && EBONE_EDITABLE(&ebone));
336 bool is_edit_parent = (animrig::bone_is_visible(arm, ebone.parent) &&
337 EBONE_EDITABLE(ebone.parent));
338
339 if (is_edit || is_edit_parent) {
340 EditBone *ebone_other = ebone.parent;
341 float dir_a[3];
342 float dir_b[3];
343 float vec[3];
344 bool is_vec_zero;
345
346 sub_v3_v3v3(dir_a, ebone.tail, ebone.head);
347 normalize_v3(dir_a);
348
349 /* find the first bone in the chain with a different direction */
350 do {
351 sub_v3_v3v3(dir_b, ebone_other->head, ebone_other->tail);
352 normalize_v3(dir_b);
353
354 if (type == CALC_ROLL_TAN_POS_Z) {
355 cross_v3_v3v3(vec, dir_a, dir_b);
356 }
357 else {
358 add_v3_v3v3(vec, dir_a, dir_b);
359 }
360 } while ((is_vec_zero = (normalize_v3(vec) < 0.00001f)) &&
361 (ebone_other = ebone_other->parent));
362
363 if (!is_vec_zero) {
364 if (axis_flip) {
365 negate_v3(vec);
366 }
367
368 if (is_edit) {
369 ebone.roll = ED_armature_ebone_roll_to_vector(&ebone, vec, axis_only);
370 changed = true;
371 }
372
373 /* parentless bones use cross product with child */
374 if (is_edit_parent) {
375 if (ebone.parent->parent == nullptr) {
377 ebone.parent, vec, axis_only);
378 changed = true;
379 }
380 }
381 }
382 }
383 }
384 }
385 }
386 else {
387 float vec[3] = {0.0f, 0.0f, 0.0f};
388 if (type == CALC_ROLL_VIEW) { /* View */
390 if (rv3d == nullptr) {
391 BKE_report(op->reports, RPT_ERROR, "No region view3d available");
392 return OPERATOR_CANCELLED;
393 }
394
395 copy_v3_v3(vec, rv3d->viewinv[2]);
396 mul_m3_v3(imat, vec);
397 }
398 else if (type == CALC_ROLL_ACTIVE) {
399 float mat[3][3];
400 bArmature *arm_active = id_cast<bArmature *>(ob_active->data);
401 ebone = static_cast<EditBone *>(arm_active->act_edbone);
402 if (ebone == nullptr) {
403 BKE_report(op->reports, RPT_ERROR, "No active bone set");
404 return OPERATOR_CANCELLED;
405 }
406
407 ED_armature_ebone_to_mat3(ebone, mat);
408 copy_v3_v3(vec, mat[2]);
409 }
410 else if (type < 6) { /* NOTE: always true, check to quiet GCC12.2 `-Warray-bounds`. */
411 /* Axis */
412 if (type < 3) {
413 vec[type] = 1.0f;
414 }
415 else {
416 vec[type - 2] = -1.0f;
417 }
418 mul_m3_v3(imat, vec);
419 normalize_v3(vec);
420 }
421 else {
422 /* The previous block should handle all remaining cases. */
424 }
425
426 if (axis_flip) {
427 negate_v3(vec);
428 }
429
430 for (EditBone &ebone : *arm->edbo) {
431 if (animrig::bone_is_visible(arm, &ebone) && EBONE_EDITABLE(&ebone)) {
432 /* roll func is a callback which assumes that all is well */
433 ebone.roll = ED_armature_ebone_roll_to_vector(&ebone, vec, axis_only);
434 changed = true;
435 }
436 }
437 }
438
439 if (arm->flag & ARM_MIRROR_EDIT) {
440 for (EditBone &ebone : *arm->edbo) {
441 if ((animrig::bone_is_visible(arm, &ebone) && EBONE_EDITABLE(&ebone)) == 0) {
442 EditBone *ebone_mirr = ED_armature_ebone_get_mirrored(arm->edbo, &ebone);
443 if (ebone_mirr &&
444 (animrig::bone_is_visible(arm, ebone_mirr) && EBONE_EDITABLE(ebone_mirr)))
445 {
446 ebone.roll = -ebone_mirr->roll;
447 }
448 }
449 }
450 }
451
452 if (changed) {
453 /* NOTE: notifier might evolve. */
456 }
457 }
458
459 return OPERATOR_FINISHED;
460}
461
463{
464 /* identifiers */
465 ot->name = "Recalculate Roll";
466 ot->idname = "ARMATURE_OT_calculate_roll";
467 ot->description = "Automatically fix alignment of select bones' axes";
468
469 /* API callbacks. */
473
474 /* flags */
476
477 /* properties */
478 ot->prop = RNA_def_enum(ot->srna, "type", prop_calc_roll_types, CALC_ROLL_TAN_POS_X, "Type", "");
479 RNA_def_boolean(ot->srna, "axis_flip", false, "Flip Axis", "Negate the alignment axis");
481 "axis_only",
482 false,
483 "Shortest Rotation",
484 "Ignore the axis direction, use the shortest rotation to align");
485}
486
488{
489 const Main *bmain = CTX_data_main(C);
490 const Scene *scene = CTX_data_scene(C);
491 ViewLayer *view_layer = CTX_data_view_layer(C);
492 const float roll = RNA_float_get(op->ptr, "roll");
493
495 *bmain, scene, view_layer, CTX_wm_view3d(C));
496 for (Object *ob : objects) {
497 bArmature *arm = id_cast<bArmature *>(ob->data);
498 bool changed = false;
499
500 for (EditBone &ebone : *arm->edbo) {
501 if (animrig::bone_is_visible(arm, &ebone) && EBONE_EDITABLE(&ebone)) {
502 /* Roll func is a callback which assumes that all is well. */
503 ebone.roll = roll;
504 changed = true;
505 }
506 }
507
508 if (arm->flag & ARM_MIRROR_EDIT) {
509 for (EditBone &ebone : *arm->edbo) {
510 if ((animrig::bone_is_visible(arm, &ebone) && EBONE_EDITABLE(&ebone)) == 0) {
511 EditBone *ebone_mirr = ED_armature_ebone_get_mirrored(arm->edbo, &ebone);
512 if (ebone_mirr &&
513 (animrig::bone_is_visible(arm, ebone_mirr) && EBONE_EDITABLE(ebone_mirr)))
514 {
515 ebone.roll = -ebone_mirr->roll;
516 changed = true;
517 }
518 }
519 }
520 }
521
522 if (changed) {
523 /* NOTE: notifier might evolve. */
526 }
527 }
528
529 return OPERATOR_FINISHED;
530}
531
533{
534 /* identifiers */
535 ot->name = "Clear Roll";
536 ot->idname = "ARMATURE_OT_roll_clear";
537 ot->description = "Clear roll for selected bones";
538
539 /* API callbacks. */
542
543 /* flags */
545
547 "roll",
548 0,
549 nullptr,
550 DEG2RADF(-360.0f),
551 DEG2RADF(360.0f),
552 "Roll",
553 "",
554 DEG2RADF(-360.0f),
555 DEG2RADF(360.0f));
556}
557
559
560/* -------------------------------------------------------------------- */
563
564/* temporary data-structure for merge/fill bones */
567
568 EditBone *head_owner; /* EditBone which uses this point as a 'head' point */
569 EditBone *tail_owner; /* EditBone which uses this point as a 'tail' point */
570
571 float vec[3]; /* the actual location of the point in local/EditMode space */
572};
573
574/* find chain-tips (i.e. bones without children) */
575static void chains_find_tips(ListBaseT<EditBone> *edbo, ListBaseT<LinkData> *list)
576{
577 EditBone *ebo;
578 LinkData *ld;
579
580 /* NOTE: this is potentially very slow ... there's got to be a better way. */
581 for (EditBone &curBone : *edbo) {
582 short stop = 0;
583
584 /* is this bone contained within any existing chain? (skip if so) */
585 for (LinkData &ld : *list) {
586 for (ebo = static_cast<EditBone *>(ld.data); ebo; ebo = ebo->parent) {
587 if (ebo == &curBone) {
588 stop = 1;
589 break;
590 }
591 }
592
593 if (stop) {
594 break;
595 }
596 }
597 /* skip current bone if it is part of an existing chain */
598 if (stop) {
599 continue;
600 }
601
602 /* is any existing chain part of the chain formed by this bone? */
603 stop = 0;
604 for (ebo = curBone.parent; ebo; ebo = ebo->parent) {
605 for (LinkData &ld : *list) {
606 if (ld.data == ebo) {
607 ld.data = &curBone;
608 stop = 1;
609 break;
610 }
611 }
612
613 if (stop) {
614 break;
615 }
616 }
617 /* current bone has already been added to a chain? */
618 if (stop) {
619 continue;
620 }
621
622 /* add current bone to a new chain */
623 ld = MEM_new_zeroed<LinkData>("BoneChain");
624 ld->data = &curBone;
625 BLI_addtail(list, ld);
626 }
627}
628
630
631/* -------------------------------------------------------------------- */
634
635static void fill_add_joint(EditBone *ebo, short eb_tail, ListBaseT<EditBonePoint> *points)
636{
637 EditBonePoint *ebp;
638 float vec[3];
639 short found = 0;
640
641 if (eb_tail) {
642 copy_v3_v3(vec, ebo->tail);
643 }
644 else {
645 copy_v3_v3(vec, ebo->head);
646 }
647
648 for (EditBonePoint &ebp : *points) {
649 if (equals_v3v3(ebp.vec, vec)) {
650 if (eb_tail) {
651 if ((ebp.head_owner) && (ebp.head_owner->parent == ebo)) {
652 /* so this bone's tail owner is this bone */
653 ebp.tail_owner = ebo;
654 found = 1;
655 break;
656 }
657 }
658 else {
659 if ((ebp.tail_owner) && (ebo->parent == ebp.tail_owner)) {
660 /* so this bone's head owner is this bone */
661 ebp.head_owner = ebo;
662 found = 1;
663 break;
664 }
665 }
666 }
667 }
668
669 /* allocate a new point if no existing point was related */
670 if (found == 0) {
671 ebp = MEM_new_zeroed<EditBonePoint>("EditBonePoint");
672
673 if (eb_tail) {
674 copy_v3_v3(ebp->vec, ebo->tail);
675 ebp->tail_owner = ebo;
676 }
677 else {
678 copy_v3_v3(ebp->vec, ebo->head);
679 ebp->head_owner = ebo;
680 }
681
682 BLI_addtail(points, ebp);
683 }
684}
685
686/* bone adding between selected joints */
688{
689 Scene *scene = CTX_data_scene(C);
690 View3D *v3d = CTX_wm_view3d(C);
691 ListBaseT<EditBonePoint> points = {nullptr, nullptr};
692 EditBone *newbone = nullptr;
693 int count;
694 bool mixed_object_error = false;
695
696 /* loop over all bones, and only consider if visible */
697 bArmature *arm = nullptr;
698 CTX_DATA_BEGIN_WITH_ID (C, EditBone *, ebone, visible_bones, bArmature *, arm_iter) {
699 bool check = false;
700 if (!(ebone->flag & BONE_CONNECTED) && (ebone->flag & BONE_ROOTSEL)) {
701 fill_add_joint(ebone, 0, &points);
702 check = true;
703 }
704 if (ebone->flag & BONE_TIPSEL) {
705 fill_add_joint(ebone, 1, &points);
706 check = true;
707 }
708
709 if (check) {
710 if (arm && (arm != arm_iter)) {
711 mixed_object_error = true;
712 }
713 arm = arm_iter;
714 }
715 }
717
718 /* the number of joints determines how we fill:
719 * 1) between joint and cursor (joint=head, cursor=tail)
720 * 2) between the two joints (order is dependent on active-bone/hierarchy)
721 * 3+) error (a smarter method involving finding chains needs to be worked out)
722 */
723 count = points.count();
724
725 if (count == 0) {
726 BKE_report(op->reports, RPT_ERROR, "No joints selected");
727 return OPERATOR_CANCELLED;
728 }
729
730 if (mixed_object_error) {
731 BKE_report(op->reports, RPT_ERROR, "Bones for different objects selected");
732 points.free_no_destruct();
733 return OPERATOR_CANCELLED;
734 }
735
736 Object *obedit = nullptr;
737 {
738 const Main *bmain = CTX_data_main(C);
739 ViewLayer *view_layer = CTX_data_view_layer(C);
740 FOREACH_OBJECT_IN_EDIT_MODE_BEGIN (bmain, scene, view_layer, v3d, ob_iter) {
741 if (ob_iter->data == id_cast<const ID *>(arm)) {
742 obedit = ob_iter;
743 }
744 }
746 }
747 BLI_assert(obedit != nullptr);
748
749 if (count == 1) {
750 EditBonePoint *ebp;
751 float curs[3];
752
753 /* Get Points - selected joint */
754 ebp = points.first();
755
756 /* Get points - cursor (tail) */
757 invert_m4_m4(obedit->runtime->world_to_object.ptr(), obedit->object_to_world().ptr());
758 mul_v3_m4v3(curs, obedit->world_to_object().ptr(), scene->cursor.location);
759
760 /* Create a bone */
761 newbone = add_points_bone(obedit, ebp->vec, curs);
762
763 /* Copy bone collection membership. */
764 if (ebp->head_owner) {
766 }
767 else {
769 }
770 }
771 else if (count == 2) {
772 EditBonePoint *ebp_a, *ebp_b;
773 float head[3], tail[3];
774 short headtail = 0;
775
776 /* check that the points don't belong to the same bone */
777 ebp_a = points.first();
778 ebp_b = ebp_a->next;
779
780 if (((ebp_a->head_owner == ebp_b->tail_owner) && (ebp_a->head_owner != nullptr)) ||
781 ((ebp_a->tail_owner == ebp_b->head_owner) && (ebp_a->tail_owner != nullptr)))
782 {
783 BKE_report(op->reports, RPT_ERROR, "Same bone selected...");
784 points.free_no_destruct();
785 return OPERATOR_CANCELLED;
786 }
787
788 /* find which one should be the 'head' */
789 if ((ebp_a->head_owner && ebp_b->head_owner) || (ebp_a->tail_owner && ebp_b->tail_owner)) {
790 /* use active, nice predictable */
791 if (arm->act_edbone && ELEM(arm->act_edbone, ebp_a->head_owner, ebp_a->tail_owner)) {
792 headtail = 1;
793 }
794 else if (arm->act_edbone && ELEM(arm->act_edbone, ebp_b->head_owner, ebp_b->tail_owner)) {
795 headtail = 2;
796 }
797 else {
798 /* rule: whichever one is closer to 3d-cursor */
799 float curs[3];
800 float dist_sq_a, dist_sq_b;
801
802 /* get cursor location */
803 invert_m4_m4(obedit->runtime->world_to_object.ptr(), obedit->object_to_world().ptr());
804 mul_v3_m4v3(curs, obedit->world_to_object().ptr(), scene->cursor.location);
805
806 /* get distances */
807 dist_sq_a = len_squared_v3v3(ebp_a->vec, curs);
808 dist_sq_b = len_squared_v3v3(ebp_b->vec, curs);
809
810 /* compare distances - closer one therefore acts as direction for bone to go */
811 headtail = (dist_sq_a < dist_sq_b) ? 2 : 1;
812 }
813 }
814 else if (ebp_a->head_owner) {
815 headtail = 1;
816 }
817 else if (ebp_b->head_owner) {
818 headtail = 2;
819 }
820
821 /* assign head/tail combinations */
822 if (headtail == 2) {
823 copy_v3_v3(head, ebp_a->vec);
824 copy_v3_v3(tail, ebp_b->vec);
825 }
826 else if (headtail == 1) {
827 copy_v3_v3(head, ebp_b->vec);
828 copy_v3_v3(tail, ebp_a->vec);
829 }
830
831 /* add new bone and parent it to the appropriate end */
832 if (headtail) {
833 newbone = add_points_bone(obedit, head, tail);
834
835 /* do parenting (will need to set connected flag too) */
836 if (headtail == 2) {
837 /* ebp tail or head - tail gets priority */
838 if (ebp_a->tail_owner) {
839 newbone->parent = ebp_a->tail_owner;
840 }
841 else {
842 newbone->parent = ebp_a->head_owner;
843 }
844 }
845 else {
846 /* ebp_b tail or head - tail gets priority */
847 if (ebp_b->tail_owner) {
848 newbone->parent = ebp_b->tail_owner;
849 }
850 else {
851 newbone->parent = ebp_b->head_owner;
852 }
853 }
854
855 /* don't set for bone connecting two head points of bones */
856 if (ebp_a->tail_owner || ebp_b->tail_owner) {
857 newbone->flag |= BONE_CONNECTED;
858 }
859
860 /* Copy bone collection membership. */
861 if (ebp_a->head_owner) {
863 }
864 else {
866 }
867 if (ebp_b->head_owner) {
869 }
870 else {
872 }
873 }
874 }
875 else {
876 BKE_reportf(op->reports, RPT_ERROR, "Too many points selected: %d", count);
877 points.free_no_destruct();
878 return OPERATOR_CANCELLED;
879 }
880
881 if (newbone) {
883 arm->act_edbone = newbone;
884 newbone->flag |= BONE_TIPSEL;
885 }
886
887 /* updates */
890
891 /* free points */
892 points.free_no_destruct();
893
894 return OPERATOR_FINISHED;
895}
896
898{
899 /* identifiers */
900 ot->name = "Fill Between Joints";
901 ot->idname = "ARMATURE_OT_fill";
902 ot->description = "Add bone between selected joint(s) and/or 3D cursor";
903
904 /* callbacks */
907
908 /* flags */
910}
911
913
914/* -------------------------------------------------------------------- */
921
922/* helper to clear BONE_TRANSFORM flags */
924{
925 for (EditBone &ebone : *arm->edbo) {
926 ebone.flag &= ~BONE_TRANSFORM;
927 }
928}
929
931{
932 const Main *bmain = CTX_data_main(C);
933 const Scene *scene = CTX_data_scene(C);
934 ViewLayer *view_layer = CTX_data_view_layer(C);
936 *bmain, scene, view_layer, CTX_wm_view3d(C));
937
938 for (Object *ob : objects) {
939 bArmature *arm = id_cast<bArmature *>(ob->data);
940
941 ListBaseT<LinkData> chains = {nullptr, nullptr};
942
943 /* get chains of bones (ends on chains) */
944 chains_find_tips(arm->edbo, &chains);
945 if (chains.is_empty()) {
946 continue;
947 }
948
949 /* ensure that mirror bones will also be operated on */
951
952 /* Clear BONE_TRANSFORM flags
953 * - Used to prevent duplicate/canceling operations from occurring #34123.
954 * - #BONE_DONE cannot be used here as that's already used for mirroring.
955 */
957
958 /* loop over chains, only considering selected and visible bones */
959 for (LinkData &chain : chains) {
960 EditBone *ebo, *child = nullptr, *parent = nullptr;
961
962 /* loop over bones in chain */
963 for (ebo = static_cast<EditBone *>(chain.data); ebo; ebo = parent) {
964 /* parent is this bone's original parent
965 * - we store this, as the next bone that is checked is this one
966 * but the value of ebo->parent may change here...
967 */
968 parent = ebo->parent;
969
970 /* skip bone if already handled, see #34123. */
971 if ((ebo->flag & BONE_TRANSFORM) == 0) {
972 /* only if selected and editable */
973 if (animrig::bone_is_visible(arm, ebo) && EBONE_EDITABLE(ebo)) {
974 /* swap head and tail coordinates */
975 swap_v3_v3(ebo->head, ebo->tail);
976
977 /* do parent swapping:
978 * - use 'child' as new parent
979 * - connected flag is only set if points are coincidental
980 */
981 ebo->parent = child;
982 if ((child) && equals_v3v3(ebo->head, child->tail)) {
983 ebo->flag |= BONE_CONNECTED;
984 }
985 else {
986 ebo->flag &= ~BONE_CONNECTED;
987 }
988
989 /* get next bones
990 * - child will become the new parent of next bone
991 */
992 child = ebo;
993 }
994 else {
995 /* not swapping this bone, however, if its 'parent' got swapped, unparent us from it
996 * as it will be facing in opposite direction
997 */
998 if ((parent) && (animrig::bone_is_visible(arm, parent) && EBONE_EDITABLE(parent))) {
999 ebo->parent = nullptr;
1000 ebo->flag &= ~BONE_CONNECTED;
1001 }
1002
1003 /* get next bones
1004 * - child will become new parent of next bone (not swapping occurred,
1005 * so set to nullptr to prevent infinite-loop)
1006 */
1007 child = nullptr;
1008 }
1009
1010 /* tag as done (to prevent double-swaps) */
1011 ebo->flag |= BONE_TRANSFORM;
1012 }
1013 }
1014 }
1015
1016 /* free chains */
1017 chains.free_no_destruct();
1018
1019 /* clear temp flags */
1022
1023 /* NOTE: notifier might evolve. */
1026 }
1027
1028 return OPERATOR_FINISHED;
1029}
1030
1032{
1033 /* identifiers */
1034 ot->name = "Switch Direction";
1035 ot->idname = "ARMATURE_OT_switch_direction";
1036 ot->description = "Change the direction that a chain of bones points in (head and tail swap)";
1037
1038 /* API callbacks. */
1041
1042 /* flags */
1044}
1045
1047
1048/* -------------------------------------------------------------------- */
1051
1052/* Helper to fix a ebone position if its parent has moved due to alignment. */
1053static void fix_connected_bone(EditBone *ebone)
1054{
1055 float diff[3];
1056
1057 if (!(ebone->parent) || !(ebone->flag & BONE_CONNECTED) ||
1058 equals_v3v3(ebone->parent->tail, ebone->head))
1059 {
1060 return;
1061 }
1062
1063 /* if the parent has moved we translate child's head and tail accordingly */
1064 sub_v3_v3v3(diff, ebone->parent->tail, ebone->head);
1065 add_v3_v3(ebone->head, diff);
1066 add_v3_v3(ebone->tail, diff);
1067}
1068
1069/* helper to recursively find chains of connected bones starting at ebone and fix their position */
1070static void fix_editbone_connected_children(ListBaseT<EditBone> *edbo, EditBone *ebone)
1071{
1072 for (EditBone &selbone : *edbo) {
1073 if ((selbone.parent) && (selbone.parent == ebone) && (selbone.flag & BONE_CONNECTED)) {
1074 fix_connected_bone(&selbone);
1075 fix_editbone_connected_children(edbo, &selbone);
1076 }
1077 }
1078}
1079
1080static void bone_align_to_bone(ListBaseT<EditBone> *edbo, EditBone *selbone, EditBone *actbone)
1081{
1082 float selboneaxis[3], actboneaxis[3], length;
1083
1084 sub_v3_v3v3(actboneaxis, actbone->tail, actbone->head);
1085 normalize_v3(actboneaxis);
1086
1087 sub_v3_v3v3(selboneaxis, selbone->tail, selbone->head);
1088 length = len_v3(selboneaxis);
1089
1090 mul_v3_fl(actboneaxis, length);
1091 add_v3_v3v3(selbone->tail, selbone->head, actboneaxis);
1092 selbone->roll = actbone->roll;
1093
1094 /* If the bone being aligned has connected descendants they must be moved
1095 * according to their parent new position, otherwise they would be left
1096 * in an inconsistent state: connected but away from the parent. */
1097 fix_editbone_connected_children(edbo, selbone);
1098}
1099
1101{
1103 bArmature *arm = id_cast<bArmature *>(ob->data);
1104 EditBone *actbone = CTX_data_active_bone(C);
1105 EditBone *actmirb = nullptr;
1106 int num_selected_bones;
1107
1108 /* there must be an active bone */
1109 if (actbone == nullptr) {
1110 BKE_report(op->reports, RPT_ERROR, "Operation requires an active bone");
1111 return OPERATOR_CANCELLED;
1112 }
1113
1114 if (arm->flag & ARM_MIRROR_EDIT) {
1115 /* For X-Axis Mirror Editing option, we may need a mirror copy of actbone
1116 * - if there's a mirrored copy of selbone, try to find a mirrored copy of actbone
1117 * (i.e. selbone="child.L" and actbone="parent.L", find "child.R" and "parent.R").
1118 * This is useful for arm-chains, for example parenting lower arm to upper arm
1119 * - if there's no mirrored copy of actbone (i.e. actbone = "parent.C" or "parent")
1120 * then just use actbone. Useful when doing upper arm to spine.
1121 */
1122 actmirb = ED_armature_ebone_get_mirrored(arm->edbo, actbone);
1123 if (actmirb == nullptr) {
1124 actmirb = actbone;
1125 }
1126 }
1127
1128 /* if there is only 1 selected bone, we assume that it is the active bone,
1129 * since a user will need to have clicked on a bone (thus selecting it) to make it active
1130 */
1131 num_selected_bones = CTX_DATA_COUNT(C, selected_editable_bones);
1132 if (num_selected_bones <= 1) {
1133 /* When only the active bone is selected, and it has a parent,
1134 * align it to the parent, as that is the only possible outcome.
1135 */
1136 if (actbone->parent) {
1137 bone_align_to_bone(arm->edbo, actbone, actbone->parent);
1138
1139 if ((arm->flag & ARM_MIRROR_EDIT) && (actmirb->parent)) {
1140 bone_align_to_bone(arm->edbo, actmirb, actmirb->parent);
1141 }
1142
1143 BKE_reportf(op->reports, RPT_INFO, "Aligned bone '%s' to parent", actbone->name);
1144 }
1145 }
1146 else {
1147 /* Align 'selected' bones to the active one
1148 * - the context iterator contains both selected bones and their mirrored copies,
1149 * so we assume that unselected bones are mirrored copies of some selected bone
1150 * - since the active one (and/or its mirror) will also be selected, we also need
1151 * to check that we are not trying to operate on them, since such an operation
1152 * would cause errors
1153 */
1154
1155 /* align selected bones to the active one */
1156 CTX_DATA_BEGIN (C, EditBone *, ebone, selected_editable_bones) {
1157 if (ELEM(ebone, actbone, actmirb) == 0) {
1158 if (ebone->flag & BONE_SELECTED) {
1159 bone_align_to_bone(arm->edbo, ebone, actbone);
1160 }
1161 else if ((arm->flag & ARM_MIRROR_EDIT)) {
1162 /* Need to check for the mirror mode, because when editing multiple armatures with
1163 * differing mirror settings `actmirb` can be a nullptr. See #146242. */
1164 bone_align_to_bone(arm->edbo, ebone, actmirb);
1165 }
1166 }
1167 }
1169
1171 op->reports, RPT_INFO, "%d bones aligned to bone '%s'", num_selected_bones, actbone->name);
1172 }
1173
1174 /* NOTE: notifier might evolve. */
1177
1178 return OPERATOR_FINISHED;
1179}
1180
1182{
1183 /* identifiers */
1184 ot->name = "Align Bones";
1185 ot->idname = "ARMATURE_OT_align";
1186 ot->description = "Align selected bones to the active bone (or to their parent)";
1187
1188 /* API callbacks. */
1191
1192 /* flags */
1194}
1195
1197
1198/* -------------------------------------------------------------------- */
1201
1203{
1204 const Main *bmain = CTX_data_main(C);
1205 const Scene *scene = CTX_data_scene(C);
1206 ViewLayer *view_layer = CTX_data_view_layer(C);
1207
1209 *bmain, scene, view_layer, CTX_wm_view3d(C));
1210 for (Object *ob : objects) {
1211 bArmature *arm = id_cast<bArmature *>(ob->data);
1212
1213 for (EditBone &bone : *arm->edbo) {
1214 if (bone.parent && (bone.flag & BONE_SELECTED) != (bone.parent->flag & BONE_SELECTED)) {
1215 bone.parent = nullptr;
1216 bone.flag &= ~BONE_CONNECTED;
1217 }
1218 }
1219 for (EditBone &bone : *arm->edbo) {
1220 ED_armature_ebone_select_set(&bone, (bone.flag & BONE_SELECTED) != 0);
1221 }
1222
1225 }
1226
1227 return OPERATOR_FINISHED;
1228}
1229
1231{
1232 /* identifiers */
1233 ot->name = "Split";
1234 ot->idname = "ARMATURE_OT_split";
1235 ot->description = "Split off selected bones from connected unselected bones";
1236
1237 /* API callbacks. */
1240
1241 /* flags */
1243}
1244
1246
1247/* -------------------------------------------------------------------- */
1250
1251static bool armature_delete_ebone_cb(const char *bone_name, void *arm_p)
1252{
1253 bArmature *arm = static_cast<bArmature *>(arm_p);
1254 EditBone *ebone;
1255
1256 ebone = ED_armature_ebone_find_name(arm->edbo, bone_name);
1257 return (ebone && animrig::bone_is_selected(arm, ebone));
1258}
1259
1260/* previously delete_armature */
1261/* only editmode! */
1263{
1264 EditBone *curBone, *ebone_next;
1265 bool changed_multi = false;
1266
1267 /* cancel if nothing selected */
1268 if (CTX_DATA_COUNT(C, selected_bones) == 0) {
1269 return OPERATOR_CANCELLED;
1270 }
1271
1272 const Main *bmain = CTX_data_main(C);
1273 const Scene *scene = CTX_data_scene(C);
1274 ViewLayer *view_layer = CTX_data_view_layer(C);
1276 *bmain, scene, view_layer, CTX_wm_view3d(C));
1277 for (Object *obedit : objects) {
1278 bArmature *arm = id_cast<bArmature *>(obedit->data);
1279 bool changed = false;
1280
1282
1284
1285 for (curBone = arm->edbo->first(); curBone; curBone = ebone_next) {
1286 ebone_next = curBone->next;
1287 if (animrig::bone_is_selected(arm, curBone)) {
1288 if (curBone == arm->act_edbone) {
1289 arm->act_edbone = nullptr;
1290 }
1291 ED_armature_ebone_remove(arm, curBone);
1292 changed = true;
1293 }
1294 }
1295
1296 if (changed) {
1297 changed_multi = true;
1298
1300 BKE_pose_tag_recalc(CTX_data_main(C), obedit->pose);
1304 }
1305 }
1306
1307 if (!changed_multi) {
1308 return OPERATOR_CANCELLED;
1309 }
1310
1311 return OPERATOR_FINISHED;
1312}
1313
1315 wmOperator *op,
1316 const wmEvent * /*event*/)
1317{
1318 if (RNA_boolean_get(op->ptr, "confirm")) {
1320 op,
1321 IFACE_("Delete selected bones?"),
1322 nullptr,
1323 IFACE_("Delete"),
1325 false);
1326 }
1327 return armature_delete_selected_exec(C, op);
1328}
1329
1331{
1332 /* identifiers */
1333 ot->name = "Delete Selected Bone(s)";
1334 ot->idname = "ARMATURE_OT_delete";
1335 ot->description = "Remove selected bones from the armature";
1336
1337 /* API callbacks. */
1341
1342 /* flags */
1345}
1346
1347static bool armature_dissolve_ebone_cb(const char *bone_name, void *arm_p)
1348{
1349 bArmature *arm = static_cast<bArmature *>(arm_p);
1350 EditBone *ebone;
1351
1352 ebone = ED_armature_ebone_find_name(arm->edbo, bone_name);
1353 return (ebone && (ebone->flag & BONE_DONE));
1354}
1355
1357{
1358 const Main *bmain = CTX_data_main(C);
1359 const Scene *scene = CTX_data_scene(C);
1360 ViewLayer *view_layer = CTX_data_view_layer(C);
1361 EditBone *ebone, *ebone_next;
1362 bool changed_multi = false;
1363
1365 *bmain, scene, view_layer, CTX_wm_view3d(C));
1366 for (Object *obedit : objects) {
1367 bArmature *arm = id_cast<bArmature *>(obedit->data);
1368 bool changed = false;
1369
1370 /* store for mirror */
1371 Map<EditBone *, eBone_Flag> ebone_flag_orig;
1372 int ebone_num = 0;
1373
1374 for (EditBone &ebone : *arm->edbo) {
1375 ebone.temp.p = nullptr;
1376 ebone.flag &= ~BONE_DONE;
1377 ebone_num++;
1378 }
1379
1380 if (arm->flag & ARM_MIRROR_EDIT) {
1381 ebone_flag_orig.reserve(ebone_num);
1382 for (EditBone &ebone : *arm->edbo) {
1383 ebone_flag_orig.add(&ebone, ebone.flag);
1384 }
1385
1387
1388 for (const auto &item : ebone_flag_orig.items()) {
1389 ebone = item.key;
1390 eBone_Flag &flag = item.value;
1391 flag = ebone->flag & ~flag;
1392 }
1393 }
1394
1395 for (EditBone &ebone : *arm->edbo) {
1396 if (ebone.parent && ebone.flag & BONE_CONNECTED) {
1397 if (ebone.parent->temp.ebone == ebone.parent) {
1398 /* ignore */
1399 }
1400 else if (ebone.parent->temp.ebone) {
1401 /* set ignored */
1402 ebone.parent->temp.ebone = ebone.parent;
1403 }
1404 else {
1405 /* set child */
1406 ebone.parent->temp.ebone = &ebone;
1407 }
1408 }
1409 }
1410
1411 /* cleanup multiple used bones */
1412 for (EditBone &ebone : *arm->edbo) {
1413 if (ebone.temp.ebone == &ebone) {
1414 ebone.temp.ebone = nullptr;
1415 }
1416 }
1417
1418 for (EditBone &ebone : *arm->edbo) {
1419 /* break connections for unseen bones */
1420 if ((animrig::bone_is_visible(arm, &ebone) &&
1422 {
1423 ebone.temp.ebone = nullptr;
1424 }
1425
1426 if ((animrig::bone_is_visible(arm, &ebone) &&
1428 {
1429 if (ebone.parent && (ebone.flag & BONE_CONNECTED)) {
1430 ebone.parent->temp.ebone = nullptr;
1431 }
1432 }
1433 }
1434
1435 for (EditBone &ebone : *arm->edbo) {
1436
1437 if (ebone.parent && (ebone.parent->temp.ebone == &ebone)) {
1438 ebone.flag |= BONE_DONE;
1439 }
1440 }
1441
1443
1444 for (ebone = arm->edbo->first(); ebone; ebone = ebone_next) {
1445 ebone_next = ebone->next;
1446
1447 if (ebone->flag & BONE_DONE) {
1448 copy_v3_v3(ebone->parent->tail, ebone->tail);
1449 ebone->parent->rad_tail = ebone->rad_tail;
1451
1452 ED_armature_ebone_remove_ex(arm, ebone, false);
1453 changed = true;
1454 }
1455 }
1456
1457 if (changed) {
1458 for (EditBone &ebone : *arm->edbo) {
1459 if (ebone.parent && ebone.parent->temp.ebone && (ebone.flag & BONE_CONNECTED)) {
1460 ebone.rad_head = ebone.parent->rad_tail;
1461 }
1462 }
1463
1464 if (arm->flag & ARM_MIRROR_EDIT) {
1465 for (EditBone &ebone : *arm->edbo) {
1466 if (const eBone_Flag *flag_p = ebone_flag_orig.lookup_ptr(&ebone)) {
1467 ebone.flag &= ~*flag_p;
1468 }
1469 }
1470 }
1471 }
1472
1473 if (changed) {
1474 changed_multi = true;
1479 }
1480 }
1481
1482 if (!changed_multi) {
1483 return OPERATOR_CANCELLED;
1484 }
1485
1486 return OPERATOR_FINISHED;
1487}
1488
1490{
1491 /* identifiers */
1492 ot->name = "Dissolve Selected Bone(s)";
1493 ot->idname = "ARMATURE_OT_dissolve";
1494 ot->description = "Dissolve selected bones from the armature";
1495
1496 /* API callbacks. */
1499
1500 /* flags */
1502}
1503
1505
1506/* -------------------------------------------------------------------- */
1509
1511{
1512 const Main *bmain = CTX_data_main(C);
1513 const Scene *scene = CTX_data_scene(C);
1514 ViewLayer *view_layer = CTX_data_view_layer(C);
1515 const int invert = RNA_boolean_get(op->ptr, "unselected") ? BONE_SELECTED : 0;
1516
1517 /* cancel if nothing selected */
1518 if (CTX_DATA_COUNT(C, selected_bones) == 0) {
1519 return OPERATOR_CANCELLED;
1520 }
1521
1523 *bmain, scene, view_layer, CTX_wm_view3d(C));
1524 for (Object *obedit : objects) {
1525 bArmature *arm = id_cast<bArmature *>(obedit->data);
1526 bool changed = false;
1527
1528 for (EditBone &ebone : *arm->edbo) {
1529 if (animrig::bone_is_visible(arm, &ebone)) {
1530 if ((ebone.flag & BONE_SELECTED) != invert) {
1532 ebone.flag |= BONE_HIDDEN_A;
1533 changed = true;
1534 }
1535 }
1536 }
1537
1538 if (!changed) {
1539 continue;
1540 }
1542
1545 }
1546 return OPERATOR_FINISHED;
1547}
1548
1550{
1551 /* identifiers */
1552 ot->name = "Hide Selected";
1553 ot->idname = "ARMATURE_OT_hide";
1554 ot->description = "Tag selected bones to not be visible in Edit Mode";
1555
1556 /* API callbacks. */
1559
1560 /* flags */
1562
1563 /* props */
1565 ot->srna, "unselected", false, "Unselected", "Hide unselected rather than selected");
1566}
1567
1569
1570/* -------------------------------------------------------------------- */
1573
1575{
1576 const Main *bmain = CTX_data_main(C);
1577 const Scene *scene = CTX_data_scene(C);
1578 ViewLayer *view_layer = CTX_data_view_layer(C);
1579 const bool select = RNA_boolean_get(op->ptr, "select");
1581 *bmain, scene, view_layer, CTX_wm_view3d(C));
1582 for (Object *obedit : objects) {
1583 bArmature *arm = id_cast<bArmature *>(obedit->data);
1584 bool changed = false;
1585
1586 for (EditBone &ebone : *arm->edbo) {
1587 if (ANIM_bonecoll_is_visible_editbone(arm, &ebone)) {
1588 if (ebone.flag & BONE_HIDDEN_A) {
1589 if (!(ebone.flag & BONE_UNSELECTABLE)) {
1591 }
1592 ebone.flag &= ~BONE_HIDDEN_A;
1593 changed = true;
1594 }
1595 }
1596 }
1597
1598 if (changed) {
1600
1603 }
1604 }
1605 return OPERATOR_FINISHED;
1606}
1607
1609{
1610 /* identifiers */
1611 ot->name = "Reveal Hidden";
1612 ot->idname = "ARMATURE_OT_reveal";
1613 ot->description = "Reveal all bones hidden in Edit Mode";
1614
1615 /* API callbacks. */
1618
1619 /* flags */
1621
1622 RNA_def_boolean(ot->srna, "select", true, "Select", "");
1623}
1624
1626
1627} // namespace blender
Functions to deal with Armatures.
Blender kernel action and pose functionality.
#define CTX_DATA_BEGIN_WITH_ID(C, Type, instance, member, Type_id, instance_id)
#define CTX_DATA_BEGIN(C, Type, instance, member)
#define CTX_DATA_COUNT(C, member)
#define CTX_DATA_END
#define FOREACH_OBJECT_IN_EDIT_MODE_END
Definition BKE_layer.hh:488
#define FOREACH_OBJECT_IN_EDIT_MODE_BEGIN(_bmain, _scene, _view_layer, _v3d, _instance)
Definition BKE_layer.hh:484
General operations, lookup, etc. for blender objects.
#define BLI_ASSERT_UNIT_V3(v)
#define DEG2RADF(_deg)
#define M_PI_2
#define IFACE_(msgid)
Object is a sort of wrapper for general info.
#define EBONE_EDITABLE(ebone)
Read Blender memory allocation and freeing.
#define RNA_ENUM_ITEM_HEADING(name, description)
Definition RNA_types.hh:759
#define C
Definition RandGen.cpp:29
#define ND_ARMATURE_STRUCTURE
Definition WM_types.hh:501
#define ND_BONE_SELECT
Definition WM_types.hh:491
#define NC_OBJECT
Definition WM_types.hh:392
#define INIT_MINMAX(min, max)
#define BLI_assert_unreachable()
#define SET_FLAG_FROM_TEST(value, test, flag)
#define ELEM(...)
btScalar max
const Value * lookup_ptr(const Key &key) const
Definition BLI_map.hh:508
bool add(const Key &key, const Value &value)
Definition BLI_map.hh:295
void reserve(int64_t n)
Definition BLI_map.hh:1028
ItemIterator items() const &
Definition BLI_map.hh:902
IMETHOD Vector diff(const Vector &a, const Vector &b, double dt)
Definition frames.inl:1166
#define FLT_EPSILON
float length(VecOp< float, D >) RET
float2x2 invert(float2x2 mat)
float3x3 scale(float3x3 mat, float2 scale)
bool bone_is_visible(const bArmature *armature, const Bone *bone)
bool bone_is_selected(const bArmature *armature, const Bone *bone)
Object * context_active_object(const bContext *C)
BMesh Iterators.
void ARMATURE_OT_hide(wmOperatorType *ot)
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
void mul_m3_v3(const float M[3][3], float r[3])
wmOperatorStatus WM_menu_invoke(bContext *C, wmOperator *op, const wmEvent *)
void ARMATURE_OT_dissolve(wmOperatorType *ot)
void ARMATURE_OT_split(wmOperatorType *ot)
int RNA_enum_get(PointerRNA *ptr, const char *name)
void BKE_pose_tag_recalc(Main *bmain, bPose *pose) ATTR_NONNULL(1
MINLINE void copy_v3_v3(float r[3], const float a[3])
static void fix_editbone_connected_children(ListBaseT< EditBone > *edbo, EditBone *ebone)
void ED_armature_origin_set(Main *bmain, Object *ob, const float cursor[3], int centermode, int around)
void ED_armature_to_edit(bArmature *arm)
void ED_armature_from_edit(Main *bmain, bArmature *arm)
void copy_m3_m4(float m1[3][3], const float m2[4][4])
void mat3_to_vec_roll(const float mat[3][3], float r_vec[3], float *r_roll)
void minmax_v3v3_v3(float min[3], float max[3], const float vec[3])
MINLINE void add_v3_v3v3(float r[3], const float a[3], const float b[3])
static wmOperatorStatus armature_roll_clear_exec(bContext *C, wmOperator *op)
static wmOperatorStatus armature_split_exec(bContext *C, wmOperator *)
float mat4_to_scale(const float mat[4][4])
void mul_v3_m4v3(float r[3], const float mat[4][4], const float vec[3])
static bool armature_delete_ebone_cb(const char *bone_name, void *arm_p)
void project_v3_v3v3_normalized(float out[3], const float p[3], const float v_proj[3])
void normalize_m3(float R[3][3]) ATTR_NONNULL()
float angle_v3v3(const float a[3], const float b[3]) ATTR_WARN_UNUSED_RESULT
bool invert_m4_m4(float inverse[4][4], const float mat[4][4])
void ARMATURE_OT_calculate_roll(wmOperatorType *ot)
@ V3D_AROUND_CENTER_BOUNDS
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_tag_unselect(bArmature *arm)
bool ED_operator_editarmature(bContext *C)
void ED_armature_ebone_remove_ex(bArmature *arm, EditBone *exBone, bool clear_connected)
static wmOperatorStatus armature_switch_direction_exec(bContext *C, wmOperator *)
void ED_armature_edit_transform(bArmature *arm, const float mat[4][4], const bool do_props)
ViewLayer * CTX_data_view_layer(const bContext *C)
static void fix_connected_bone(EditBone *ebone)
MINLINE void mul_v3_fl(float r[3], float f)
EditBone * CTX_data_active_bone(const bContext *C)
MINLINE void sub_v3_v3(float r[3], const float a[3])
void mul_m4_v3(const float M[4][4], float r[3])
void ARMATURE_OT_fill(wmOperatorType *ot)
MINLINE bool equals_v3v3(const float v1[3], const float v2[3]) ATTR_WARN_UNUSED_RESULT
void WM_operator_properties_confirm_or_exec(wmOperatorType *ot)
EditBone * ED_armature_ebone_get_mirrored(const ListBaseT< EditBone > *edbo, EditBone *ebo)
void armature_tag_select_mirrored(bArmature *arm)
void * MEM_new_zeroed(size_t len, const char *str) ATTR_WARN_UNUSED_RESULT ATTR_ALLOC_SIZE(1) ATTR_NONNULL(2)
static wmOperatorStatus armature_calc_roll_exec(bContext *C, wmOperator *op)
void ED_armature_ebone_to_mat3(EditBone *ebone, float r_mat[3][3])
static void fill_add_joint(EditBone *ebo, short eb_tail, ListBaseT< EditBonePoint > *points)
MINLINE void cross_v3_v3v3(float r[3], const float a[3], const float b[3])
void DEG_id_tag_update(ID *id, unsigned int flags)
MINLINE void swap_v3_v3(float a[3], float b[3])
void BKE_report(ReportList *reports, eReportType type, const char *message)
Definition report.cc:162
void ED_armature_edit_sync_selection(ListBaseT< EditBone > *edbo)
Object * CTX_data_edit_object(const bContext *C)
bool ANIM_bonecoll_is_visible_editbone(const bArmature *armature, const EditBone *ebone)
bArmature * ED_armature_context(const bContext *C)
void ARMATURE_OT_reveal(wmOperatorType *ot)
static void armature_clear_swap_done_flags(bArmature *arm)
void ARMATURE_OT_roll_clear(wmOperatorType *ot)
static const EnumPropertyItem prop_calc_roll_types[]
MINLINE void negate_v3(float r[3])
void ED_armature_transform(bArmature *arm, const float mat[4][4], const bool do_props)
void BKE_pose_channels_remove(Object *ob, bool(*filter_fn)(const char *bone_name, void *user_data), void *user_data) ATTR_NONNULL(1
RegionView3D * CTX_wm_region_view3d(const bContext *C)
void ED_armature_edit_free(bArmature *arm)
MINLINE float len_v3(const float a[3]) ATTR_WARN_UNUSED_RESULT
bool RNA_boolean_get(PointerRNA *ptr, const char *name)
wmOperatorStatus WM_operator_confirm_ex(bContext *C, wmOperator *op, const char *title, const char *message, const char *confirm_text, ui::AlertIcon icon, bool cancel_default)
MINLINE void zero_v3(float r[3])
void ARMATURE_OT_align(wmOperatorType *ot)
void WM_event_add_notifier(const bContext *C, uint type, void *reference)
void mul_mat3_m4_v3(const float mat[4][4], float r[3])
bool invert_m3(float mat[3][3])
bool BKE_object_is_in_editmode(const Object *ob)
Definition object.cc:1898
static void chains_find_tips(ListBaseT< EditBone > *edbo, ListBaseT< LinkData > *list)
static wmOperatorStatus armature_dissolve_selected_exec(bContext *C, wmOperator *)
MINLINE float normalize_v3(float n[3])
void ED_armature_ebone_remove(bArmature *arm, EditBone *exBone)
MINLINE void add_v3_v3(float r[3], const float a[3])
int ED_armature_ebone_selectflag_get(const EditBone *ebone)
MINLINE void sub_v3_v3v3(float r[3], const float a[3], const float b[3])
void mid_v3_v3v3(float r[3], const float a[3], const float b[3])
void BKE_reportf(ReportList *reports, eReportType type, const char *format,...) ATTR_PRINTF_FORMAT(3
Definition report.cc:191
static void bone_align_to_bone(ListBaseT< EditBone > *edbo, EditBone *selbone, EditBone *actbone)
void BLI_addtail(ListBase *listbase, void *vlink) ATTR_NONNULL(1)
Definition listbase.cc:118
Main * CTX_data_main(const bContext *C)
void ANIM_armature_bonecoll_assign_from_other_editbone(EditBone *dst, EditBone *src)
void armature_select_mirrored(bArmature *arm)
PropertyRNA * RNA_def_float_rotation(StructOrFunctionRNA *cont_, const char *identifier, const int len, const float *default_value, const float hardmin, const float hardmax, const char *ui_name, const char *ui_description, const float softmin, const float softmax)
void armature_select_mirrored_ex(bArmature *arm, eBone_Flag flag)
void ARMATURE_OT_switch_direction(wmOperatorType *ot)
static wmOperatorStatus armature_hide_exec(bContext *C, wmOperator *op)
@ ID_RECALC_SELECT
Definition DNA_ID.h:1101
@ ID_RECALC_SYNC_TO_EVAL
Definition DNA_ID.h:1118
void ARMATURE_OT_delete(wmOperatorType *ot)
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)
void ED_outliner_select_sync_from_edit_bone_tag(bContext *C)
EditBone * add_points_bone(Object *obedit, float head[3], float tail[3])
Scene * CTX_data_scene(const bContext *C)
void vec_roll_to_mat3_normalized(const float nor[3], float roll, float r_mat[3][3])
@ OPTYPE_REGISTER
Definition WM_types.hh:188
@ OPTYPE_UNDO
Definition WM_types.hh:190
void mul_m3_m3m3(float R[3][3], const float A[3][3], const float B[3][3])
float ED_armature_ebone_roll_to_vector(const EditBone *bone, const float align_axis[3], const bool axis_only)
static bool armature_dissolve_ebone_cb(const char *bone_name, void *arm_p)
PropertyRNA * RNA_def_boolean(StructOrFunctionRNA *cont_, const char *identifier, const bool default_value, const char *ui_name, const char *ui_description)
@ CALC_ROLL_TAN_POS_X
@ CALC_ROLL_TAN_POS_Z
@ CALC_ROLL_TAN_NEG_X
@ CALC_ROLL_TAN_NEG_Z
static wmOperatorStatus armature_delete_selected_exec(bContext *C, wmOperator *)
MINLINE float dot_v3v3(const float a[3], const float b[3]) ATTR_WARN_UNUSED_RESULT
static wmOperatorStatus armature_delete_selected_invoke(bContext *C, wmOperator *op, const wmEvent *)
void ED_armature_ebone_select_set(EditBone *ebone, bool select)
static wmOperatorStatus armature_align_bones_exec(bContext *C, wmOperator *op)
float RNA_float_get(PointerRNA *ptr, const char *name)
PointerRNA CTX_data_pointer_get_type(const bContext *C, const char *member, StructRNA *type)
View3D * CTX_wm_view3d(const bContext *C)
void BKE_armature_transform(bArmature *arm, const float mat[4][4], bool do_props)
static wmOperatorStatus armature_fill_bones_exec(bContext *C, wmOperator *op)
EditBone * ED_armature_ebone_find_name(const ListBaseT< EditBone > *edbo, const char *name)
static wmOperatorStatus armature_reveal_exec(bContext *C, wmOperator *op)
bool ED_armature_edit_deselect_all(Object *obedit)
#define fabsf
#define min(a, b)
Definition sort.cc:38
union blender::EditBone::@252003325204232231327014100071366025164067232113 temp
const c_style_mat & ptr() const
bke::ObjectRuntime * runtime
View3DCursor cursor
ListBaseT< EditBone > * edbo
struct EditBone * act_edbone
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
#define N_(msgid)