Blender V4.5
armature_add.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_anim_types.h"
11#include "DNA_armature_types.h"
13#include "DNA_object_types.h"
14#include "DNA_scene_types.h"
15
16#include "MEM_guardedalloc.h"
17
18#include "BLI_listbase.h"
19#include "BLI_map.hh"
20#include "BLI_math_matrix.h"
21#include "BLI_math_rotation.h"
22#include "BLI_math_vector.h"
23#include "BLI_string.h"
24#include "BLI_string_utils.hh"
25
26#include "BLT_translation.hh"
27
28#include "BKE_action.hh"
29#include "BKE_armature.hh"
30#include "BKE_constraint.h"
31#include "BKE_context.hh"
32#include "BKE_fcurve.hh"
33#include "BKE_idprop.hh"
34#include "BKE_layer.hh"
35#include "BKE_lib_id.hh"
36#include "BKE_object_types.hh"
37#include "BKE_report.hh"
38
39#include "ANIM_action.hh"
40
41#include "RNA_access.hh"
42#include "RNA_define.hh"
43
44#include "WM_api.hh"
45#include "WM_types.hh"
46
47#include "ED_armature.hh"
48#include "ED_outliner.hh"
49#include "ED_screen.hh"
50#include "ED_view3d.hh"
51
52#include "ANIM_armature.hh"
54
55#include "DEG_depsgraph.hh"
56
57#include "armature_intern.hh"
58
59using blender::Vector;
60
61/* *************** Adding stuff in editmode *************** */
62
64{
65 EditBone *bone = MEM_callocN<EditBone>("eBone");
66
67 STRNCPY(bone->name, name);
68 ED_armature_ebone_unique_name(arm->edbo, bone->name, nullptr);
69
70 BLI_addtail(arm->edbo, bone);
71
72 bone->flag |= BONE_TIPSEL;
74 bone->weight = 1.0f;
75 bone->dist = 0.25f;
76 bone->xwidth = 0.1f;
77 bone->zwidth = 0.1f;
78 bone->rad_head = 0.10f;
79 bone->rad_tail = 0.05f;
80 bone->segments = 1;
81
82 /* Bendy-Bone parameters */
83 bone->roll1 = 0.0f;
84 bone->roll2 = 0.0f;
85 bone->curve_in_x = 0.0f;
86 bone->curve_in_z = 0.0f;
87 bone->curve_out_x = 0.0f;
88 bone->curve_out_z = 0.0f;
89 bone->ease1 = 1.0f;
90 bone->ease2 = 1.0f;
91
92 /* Prevent custom bone colors from having alpha zero.
93 * Part of the fix for issue #115434. */
94 bone->color.custom.solid[3] = 255;
95 bone->color.custom.select[3] = 255;
96 bone->color.custom.active[3] = 255;
97
98 copy_v3_fl(bone->scale_in, 1.0f);
99 copy_v3_fl(bone->scale_out, 1.0f);
100
101 return bone;
102}
103
105 const float length,
106 const bool view_aligned)
107{
108 bArmature *arm = static_cast<bArmature *>(obedit_arm->data);
109 EditBone *bone;
110
112
113 /* Create a bone */
114 bone = ED_armature_ebone_add(arm, DATA_("Bone"));
115
116 arm->act_edbone = bone;
117
118 zero_v3(bone->head);
119 zero_v3(bone->tail);
120
121 bone->tail[view_aligned ? 1 : 2] = length;
122
123 if (arm->runtime.active_collection) {
125 }
126
127 return bone;
128}
129
139{
140 bArmature *arm;
141 EditBone *ebone, *newbone, *flipbone;
142 float mat[3][3], imat[3][3];
143 int a, to_root = 0;
144 Object *obedit;
145 Scene *scene;
146
147 scene = CTX_data_scene(C);
148 obedit = CTX_data_edit_object(C);
149 arm = static_cast<bArmature *>(obedit->data);
150
151 /* find the active or selected bone */
152 for (ebone = static_cast<EditBone *>(arm->edbo->first); ebone; ebone = ebone->next) {
154 continue;
155 }
156 if (ebone->flag & BONE_TIPSEL || arm->act_edbone == ebone) {
157 break;
158 }
159 }
160
161 if (ebone == nullptr) {
162 for (ebone = static_cast<EditBone *>(arm->edbo->first); ebone; ebone = ebone->next) {
164 continue;
165 }
166 if (ebone->flag & BONE_ROOTSEL || arm->act_edbone == ebone) {
167 break;
168 }
169 }
170 if (ebone == nullptr) {
171 return OPERATOR_CANCELLED;
172 }
173
174 to_root = 1;
175 }
176
178
179 /* we re-use code for mirror editing... */
180 flipbone = nullptr;
181 if (arm->flag & ARM_MIRROR_EDIT) {
182 flipbone = ED_armature_ebone_get_mirrored(arm->edbo, ebone);
183 }
184
185 for (a = 0; a < 2; a++) {
186 if (a == 1) {
187 if (flipbone == nullptr) {
188 break;
189 }
190 std::swap(flipbone, ebone);
191 }
192
193 newbone = ED_armature_ebone_add(arm, ebone->name);
194 arm->act_edbone = newbone;
195
196 if (to_root) {
197 copy_v3_v3(newbone->head, ebone->head);
198 newbone->rad_head = ebone->rad_tail;
199 newbone->parent = ebone->parent;
200 }
201 else {
202 copy_v3_v3(newbone->head, ebone->tail);
203 newbone->rad_head = ebone->rad_tail;
204 newbone->parent = ebone;
205 newbone->flag |= BONE_CONNECTED;
206 }
207
208 const View3DCursor *curs = &scene->cursor;
209 copy_v3_v3(newbone->tail, curs->location);
210 sub_v3_v3v3(newbone->tail, newbone->tail, obedit->object_to_world().location());
211
212 if (a == 1) {
213 newbone->tail[0] = -newbone->tail[0];
214 }
215
216 copy_m3_m4(mat, obedit->object_to_world().ptr());
217 invert_m3_m3(imat, mat);
218 mul_m3_v3(imat, newbone->tail);
219
220 newbone->length = len_v3v3(newbone->head, newbone->tail);
221 newbone->rad_tail = newbone->length * 0.05f;
222 newbone->dist = newbone->length * 0.25f;
223 }
224
226
230
231 return OPERATOR_FINISHED;
232}
233
235 wmOperator *op,
236 const wmEvent *event)
237{
238 /* TODO: most of this code is copied from set3dcursor_invoke,
239 * it would be better to reuse code in set3dcursor_invoke */
240
241 /* temporarily change 3d cursor position */
242 Scene *scene;
243 ARegion *region;
244 View3D *v3d;
245 float tvec[3], oldcurs[3], mval_f[2];
246
247 scene = CTX_data_scene(C);
248 region = CTX_wm_region(C);
249 v3d = CTX_wm_view3d(C);
250
251 View3DCursor *cursor = &scene->cursor;
252
253 copy_v3_v3(oldcurs, cursor->location);
254
255 copy_v2fl_v2i(mval_f, event->mval);
256 ED_view3d_win_to_3d(v3d, region, cursor->location, mval_f, tvec);
257 copy_v3_v3(cursor->location, tvec);
258
259 /* extrude to the where new cursor is and store the operation result */
261
262 /* restore previous 3d cursor position */
263 copy_v3_v3(cursor->location, oldcurs);
264
265 /* Support dragging to move after extrude, see: #114282. */
266 if (retval & OPERATOR_FINISHED) {
267 retval |= OPERATOR_PASS_THROUGH;
268 }
270}
271
273{
274 /* identifiers */
275 ot->name = "Extrude to Cursor";
276 ot->idname = "ARMATURE_OT_click_extrude";
277 ot->description = "Create a new bone going from the last selected joint to the mouse position";
278
279 /* API callbacks. */
283
284 /* flags */
286
287 /* props */
288}
289
290EditBone *add_points_bone(Object *obedit, float head[3], float tail[3])
291{
292 EditBone *ebo;
293
294 ebo = ED_armature_ebone_add(static_cast<bArmature *>(obedit->data), DATA_("Bone"));
295
296 copy_v3_v3(ebo->head, head);
297 copy_v3_v3(ebo->tail, tail);
298
299 return ebo;
300}
301
302static void pre_edit_bone_duplicate(ListBase *editbones)
303{
304 /* clear temp */
306}
307
313 const bPose *pose,
315 bPoseChannel *pchan_src)
316{
317 bPoseChannel *pchan_dst = nullptr;
318 const char *name_src = pchan_src->name;
319 const blender::StringRefNull name_dst = name_map.lookup_default(name_src, "");
320 if (!name_dst.is_empty()) {
321 pchan_dst = BKE_pose_channel_find_name(pose, name_dst.c_str());
322 }
323
324 if (pchan_dst == nullptr) {
325 pchan_dst = pchan_src;
326 }
327
328 return pchan_dst;
329}
330
331static void pose_edit_bone_duplicate(ListBase *editbones, Object *ob)
332{
333 if (ob->pose == nullptr) {
334 return;
335 }
336
339
341
342 LISTBASE_FOREACH (EditBone *, ebone_src, editbones) {
343 EditBone *ebone_dst = ebone_src->temp.ebone;
344 if (!ebone_dst) {
345 ebone_dst = ED_armature_ebone_get_mirrored(editbones, ebone_src);
346 }
347
348 if (ebone_dst) {
349 name_map.add_as(ebone_src->name, ebone_dst->name);
350 }
351 }
352
353 LISTBASE_FOREACH (EditBone *, ebone_src, editbones) {
354 EditBone *ebone_dst = ebone_src->temp.ebone;
355 if (!ebone_dst) {
356 continue;
357 }
358
359 bPoseChannel *pchan_src = BKE_pose_channel_find_name(ob->pose, ebone_src->name);
360 if (!pchan_src) {
361 continue;
362 }
363
364 bPoseChannel *pchan_dst = BKE_pose_channel_find_name(ob->pose, ebone_dst->name);
365 if (!pchan_dst) {
366 continue;
367 }
368
369 if (pchan_src->custom_tx) {
370 pchan_dst->custom_tx = pchan_duplicate_map(ob->pose, name_map, pchan_src->custom_tx);
371 }
372 if (pchan_src->bbone_prev) {
373 pchan_dst->bbone_prev = pchan_duplicate_map(ob->pose, name_map, pchan_src->bbone_prev);
374 }
375 if (pchan_src->bbone_next) {
376 pchan_dst->bbone_next = pchan_duplicate_map(ob->pose, name_map, pchan_src->bbone_next);
377 }
378 }
379}
380
382 Object *ob,
383 const bool lookup_mirror_subtarget)
384{
385 /* If an edit bone has been duplicated, lets update its constraints if the
386 * subtarget they point to has also been duplicated.
387 */
388 bPoseChannel *pchan = BKE_pose_channel_ensure(ob->pose, dup_bone->name);
389
390 if (!pchan) {
391 return;
392 }
393
394 EditBone *oldtarget, *newtarget;
395 ListBase *conlist = &pchan->constraints;
396 char name_flipped[MAX_ID_NAME - 2];
397 LISTBASE_FOREACH (bConstraint *, curcon, conlist) {
398 /* does this constraint have a subtarget in
399 * this armature?
400 */
401 ListBase targets = {nullptr, nullptr};
402
403 if (!BKE_constraint_targets_get(curcon, &targets)) {
404 continue;
405 }
406 LISTBASE_FOREACH (bConstraintTarget *, ct, &targets) {
407 if (!ct->tar || !ct->subtarget[0]) {
408 continue;
409 }
410 Object *target_ob = ct->tar;
411 if (target_ob->type != OB_ARMATURE || !target_ob->data) {
412 /* Can only mirror armature. */
413 continue;
414 }
415 bArmature *target_armature = static_cast<bArmature *>(target_ob->data);
416 /* Was the subtarget bone duplicated too? If
417 * so, update the constraint to point at the
418 * duplicate of the old subtarget.
419 */
420
421 /* TODO: support updating sub-targets for multi-object edit mode.
422 * This requires all objects bones to be duplicated before this runs. */
423 oldtarget = (ob == target_ob) ?
424 ED_armature_ebone_find_name(target_armature->edbo, ct->subtarget) :
425 nullptr;
426 if (oldtarget && oldtarget->temp.ebone) {
427 newtarget = oldtarget->temp.ebone;
428 STRNCPY(ct->subtarget, newtarget->name);
429 }
430 else if (lookup_mirror_subtarget) {
431 BLI_string_flip_side_name(name_flipped, ct->subtarget, false, sizeof(name_flipped));
432 if (bPoseChannel *flipped_bone = BKE_pose_channel_find_name(ct->tar->pose, name_flipped)) {
433 STRNCPY(ct->subtarget, flipped_bone->name);
434 }
435 }
436 }
437 BKE_constraint_targets_flush(curcon, &targets, false);
438 }
439}
440
442 EditBone *dup_bone, EditBone *orig_bone, Object *ob, bPoseChannel *pchan, bConstraint *curcon)
443{
444 bActionConstraint *act_con = static_cast<bActionConstraint *>(curcon->data);
445
446 float mat[4][4];
447
448 bConstraintOb cob{};
449 cob.depsgraph = nullptr;
450 cob.scene = nullptr;
451 cob.ob = ob;
452 cob.pchan = pchan;
454
455 unit_m4(mat);
456 bPoseChannel *target_pchan = BKE_pose_channel_find_name(ob->pose, act_con->subtarget);
458 ob, target_pchan, &cob, mat, curcon->tarspace, CONSTRAINT_SPACE_LOCAL, false);
459
460 float max_axis_val = 0;
461 int max_axis = 0;
462 /* Which axis represents X now. IE, which axis defines the mirror plane. */
463 for (int i = 0; i < 3; i++) {
464 float cur_val = fabsf(mat[0][i]);
465 if (cur_val > max_axis_val) {
466 max_axis = i;
467 max_axis_val = cur_val;
468 }
469 }
470
471 /* data->type is mapped as follows for backwards compatibility:
472 * 00,01,02 - rotation (it used to be like this)
473 * 10,11,12 - scaling
474 * 20,21,22 - location
475 */
476 /* Mirror the target range */
477 if (act_con->type < 10 && act_con->type != max_axis) {
478 /* Y or Z rotation */
479 act_con->min = -act_con->min;
480 act_con->max = -act_con->max;
481 }
482 else if (act_con->type == max_axis + 10) {
483 /* X scaling */
484 }
485 else if (act_con->type == max_axis + 20) {
486 /* X location */
487 float imat[4][4];
488
489 invert_m4_m4(imat, mat);
490
491 float min_vec[3], max_vec[3];
492
493 zero_v3(min_vec);
494 zero_v3(max_vec);
495
496 min_vec[0] = act_con->min;
497 max_vec[0] = act_con->max;
498
499 /* convert values into local object space */
500 mul_m4_v3(mat, min_vec);
501 mul_m4_v3(mat, max_vec);
502
503 min_vec[0] *= -1;
504 max_vec[0] *= -1;
505
506 /* convert back to the settings space */
507 mul_m4_v3(imat, min_vec);
508 mul_m4_v3(imat, max_vec);
509
510 act_con->min = min_vec[0];
511 act_con->max = max_vec[0];
512 }
513
514 /* See if there is any channels that uses this bone */
515 bAction *act = (bAction *)act_con->act;
516 if (act) {
517 blender::animrig::Action &action = act->wrap();
519 action, act_con->action_slot_handle);
520
521 /* Create a copy and mirror the animation */
522 auto bone_name_filter = [&](const FCurve &fcurve) -> bool {
524 fcurve, "pose.bones[", orig_bone->name);
525 };
527 act, act_con->action_slot_handle, bone_name_filter);
528 for (const FCurve *old_curve : fcurves) {
529 FCurve *new_curve = BKE_fcurve_copy(old_curve);
530 char *old_path = new_curve->rna_path;
531
532 new_curve->rna_path = BLI_string_replaceN(old_path, orig_bone->name, dup_bone->name);
533 MEM_freeN(old_path);
534
535 /* FIXME: deal with the case where this F-Curve already exists. */
536
537 /* Flip the animation */
538 int i;
539 BezTriple *bezt;
540 for (i = 0, bezt = new_curve->bezt; i < new_curve->totvert; i++, bezt++) {
541 const size_t slength = strlen(new_curve->rna_path);
542 bool flip = false;
543 if (BLI_strn_endswith(new_curve->rna_path, "location", slength) &&
544 new_curve->array_index == 0)
545 {
546 flip = true;
547 }
548 else if (BLI_strn_endswith(new_curve->rna_path, "rotation_quaternion", slength) &&
549 ELEM(new_curve->array_index, 2, 3))
550 {
551 flip = true;
552 }
553 else if (BLI_strn_endswith(new_curve->rna_path, "rotation_euler", slength) &&
554 ELEM(new_curve->array_index, 1, 2))
555 {
556 flip = true;
557 }
558 else if (BLI_strn_endswith(new_curve->rna_path, "rotation_axis_angle", slength) &&
559 ELEM(new_curve->array_index, 2, 3))
560 {
561 flip = true;
562 }
563
564 if (flip) {
565 bezt->vec[0][1] *= -1;
566 bezt->vec[1][1] *= -1;
567 bezt->vec[2][1] *= -1;
568 }
569 }
570
571 if (action.is_action_legacy()) {
572 /* Make sure that a action group name for the new bone exists */
573 bActionGroup *agrp = BKE_action_group_find_name(act, dup_bone->name);
574 if (agrp == nullptr) {
575 agrp = action_groups_add_new(act, dup_bone->name);
576 }
577 BLI_assert(agrp != nullptr);
578 action_groups_add_channel(act, agrp, new_curve);
579 continue;
580 }
581
582 BLI_assert_msg(cbag, "If there are F-Curves for this slot, there should be a channelbag");
583 bActionGroup &agrp = cbag->channel_group_ensure(dup_bone->name);
584 cbag->fcurve_append(*new_curve);
585 cbag->fcurve_assign_to_channel_group(*new_curve, agrp);
586 }
587 }
588
589 /* Make depsgraph aware of our changes. */
591}
592
594{
595 /* IK constraint */
596 bKinematicConstraint *ik = static_cast<bKinematicConstraint *>(curcon->data);
597 ik->poleangle = -M_PI - ik->poleangle;
598 /* Wrap the angle to the +/-180.0f range (default soft limit of the input boxes). */
600}
601
603 bPoseChannel *pchan,
604 bConstraint *curcon)
605{
606 /* This code assumes that bRotLimitConstraint and bLocLimitConstraint have the same fields in
607 * the same memory locations. */
608 bRotLimitConstraint *limit = static_cast<bRotLimitConstraint *>(curcon->data);
609 float local_mat[4][4], imat[4][4];
610
611 float min_vec[3], max_vec[3];
612
613 min_vec[0] = limit->xmin;
614 min_vec[1] = limit->ymin;
615 min_vec[2] = limit->zmin;
616
617 max_vec[0] = limit->xmax;
618 max_vec[1] = limit->ymax;
619 max_vec[2] = limit->zmax;
620
621 unit_m4(local_mat);
622
623 bConstraintOb cob{};
624 cob.depsgraph = nullptr;
625 cob.scene = nullptr;
626 cob.ob = ob;
627 cob.pchan = pchan;
629
631 ob, pchan, &cob, local_mat, curcon->ownspace, CONSTRAINT_SPACE_LOCAL, false);
632
633 if (curcon->type == CONSTRAINT_TYPE_ROTLIMIT) {
634 /* Zero out any location translation */
635 local_mat[3][0] = local_mat[3][1] = local_mat[3][2] = 0;
636 }
637
638 invert_m4_m4(imat, local_mat);
639 /* convert values into local object space */
640 mul_m4_v3(local_mat, min_vec);
641 mul_m4_v3(local_mat, max_vec);
642
643 if (curcon->type == CONSTRAINT_TYPE_ROTLIMIT) {
644 float min_copy[3];
645
646 copy_v3_v3(min_copy, min_vec);
647
648 min_vec[1] = max_vec[1] * -1;
649 min_vec[2] = max_vec[2] * -1;
650
651 max_vec[1] = min_copy[1] * -1;
652 max_vec[2] = min_copy[2] * -1;
653 }
654 else {
655 float min_x_copy = min_vec[0];
656
657 min_vec[0] = max_vec[0] * -1;
658 max_vec[0] = min_x_copy * -1;
659
660 /* Also flip the enabled axis check-boxes accordingly. */
661 const bool use_max_x = (limit->flag & LIMIT_XMAX);
662 const bool use_min_x = (limit->flag & LIMIT_XMIN);
663 limit->flag |= use_max_x ? LIMIT_XMIN : 0;
664 limit->flag &= (use_max_x && !use_min_x) ? ~LIMIT_XMAX : limit->flag;
665 limit->flag |= use_min_x ? LIMIT_XMAX : 0;
666 limit->flag &= (use_min_x && !use_max_x) ? ~LIMIT_XMIN : limit->flag;
667 }
668
669 /* convert back to the settings space */
670 mul_m4_v3(imat, min_vec);
671 mul_m4_v3(imat, max_vec);
672
673 limit->xmin = min_vec[0];
674 limit->ymin = min_vec[1];
675 limit->zmin = min_vec[2];
676
677 limit->xmax = max_vec[0];
678 limit->ymax = max_vec[1];
679 limit->zmax = max_vec[2];
680}
681
683 bPoseChannel *pchan,
684 bConstraint *curcon)
685{
686 bTransformConstraint *trans = static_cast<bTransformConstraint *>(curcon->data);
687
688 float target_mat[4][4], own_mat[4][4], imat[4][4];
689
690 bConstraintOb cob{};
691 cob.depsgraph = nullptr;
692 cob.scene = nullptr;
693 cob.ob = ob;
694 cob.pchan = pchan;
696
697 unit_m4(own_mat);
699 ob, pchan, &cob, own_mat, curcon->ownspace, CONSTRAINT_SPACE_LOCAL, false);
700
701 /* ###Source map mirroring### */
702 float old_min, old_max;
703
704 /* Source location */
705 invert_m4_m4(imat, own_mat);
706
707 /* convert values into local object space */
708 mul_m4_v3(own_mat, trans->from_min);
709 mul_m4_v3(own_mat, trans->from_max);
710
711 old_min = trans->from_min[0];
712 old_max = trans->from_max[0];
713
714 trans->from_min[0] = -old_max;
715 trans->from_max[0] = -old_min;
716
717 /* convert back to the settings space */
718 mul_m4_v3(imat, trans->from_min);
719 mul_m4_v3(imat, trans->from_max);
720
721 /* Source rotation */
722
723 /* Zero out any location translation */
724 own_mat[3][0] = own_mat[3][1] = own_mat[3][2] = 0;
725
726 invert_m4_m4(imat, own_mat);
727
728 /* convert values into local object space */
729 mul_m4_v3(own_mat, trans->from_min_rot);
730 mul_m4_v3(own_mat, trans->from_max_rot);
731
732 old_min = trans->from_min_rot[1];
733 old_max = trans->from_max_rot[1];
734
735 trans->from_min_rot[1] = old_max * -1;
736 trans->from_max_rot[1] = old_min * -1;
737
738 old_min = trans->from_min_rot[2];
739 old_max = trans->from_max_rot[2];
740
741 trans->from_min_rot[2] = old_max * -1;
742 trans->from_max_rot[2] = old_min * -1;
743
744 /* convert back to the settings space */
745 mul_m4_v3(imat, trans->from_min_rot);
746 mul_m4_v3(imat, trans->from_max_rot);
747
748 /* Source scale does not require any mirroring */
749
750 /* ###Destination map mirroring### */
751 float temp_vec[3];
752 float imat_rot[4][4];
753
754 bPoseChannel *target_pchan = BKE_pose_channel_find_name(ob->pose, trans->subtarget);
755 unit_m4(target_mat);
757 ob, target_pchan, &cob, target_mat, curcon->tarspace, CONSTRAINT_SPACE_LOCAL, false);
758
759 invert_m4_m4(imat, target_mat);
760 /* convert values into local object space */
761 mul_m4_v3(target_mat, trans->to_min);
762 mul_m4_v3(target_mat, trans->to_max);
763 mul_m4_v3(target_mat, trans->to_min_scale);
764 mul_m4_v3(target_mat, trans->to_max_scale);
765
766 /* Zero out any location translation */
767 target_mat[3][0] = target_mat[3][1] = target_mat[3][2] = 0;
768 invert_m4_m4(imat_rot, target_mat);
769
770 mul_m4_v3(target_mat, trans->to_min_rot);
771 mul_m4_v3(target_mat, trans->to_max_rot);
772
773 /* TODO(sebpa): This does not support euler order, but doing so will make this way more complex.
774 * For now we have decided to not support all corner cases and advanced setups. */
775
776 /* Helper variables to denote the axis in trans->map */
777 const char X = 0;
778 const char Y = 1;
779 const char Z = 2;
780
781 switch (trans->to) {
782 case TRANS_SCALE:
783 copy_v3_v3(temp_vec, trans->to_max_scale);
784
785 for (int i = 0; i < 3; i++) {
786 if ((trans->from == TRANS_LOCATION && trans->map[i] == X) ||
787 (trans->from == TRANS_ROTATION && trans->map[i] != X))
788 {
789 /* X Loc to X/Y/Z Scale: Min/Max Flipped */
790 /* Y Rot to X/Y/Z Scale: Min/Max Flipped */
791 /* Z Rot to X/Y/Z Scale: Min/Max Flipped */
792 trans->to_max_scale[i] = trans->to_min_scale[i];
793 trans->to_min_scale[i] = temp_vec[i];
794 }
795 }
796 break;
797 case TRANS_LOCATION:
798 /* Invert the X location */
799 trans->to_min[0] *= -1;
800 trans->to_max[0] *= -1;
801
802 copy_v3_v3(temp_vec, trans->to_max);
803
804 for (int i = 0; i < 3; i++) {
805 if ((trans->from == TRANS_LOCATION && trans->map[i] == X) ||
806 (trans->from == TRANS_ROTATION && trans->map[i] != X))
807 {
808 /* X Loc to X/Y/Z Loc: Min/Max Flipped (and Inverted)
809 * Y Rot to X/Y/Z Loc: Min/Max Flipped
810 * Z Rot to X/Y/Z Loc: Min/Max Flipped */
811 trans->to_max[i] = trans->to_min[i];
812 trans->to_min[i] = temp_vec[i];
813 }
814 }
815 break;
816 case TRANS_ROTATION:
817 /* Invert the Z rotation */
818 trans->to_min_rot[2] *= -1;
819 trans->to_max_rot[2] *= -1;
820
821 if ((trans->from == TRANS_LOCATION && trans->map[1] != X) ||
822 (trans->from == TRANS_ROTATION && trans->map[1] != Y) || trans->from == TRANS_SCALE)
823 {
824 /* Invert the Y rotation */
825 trans->to_min_rot[1] *= -1;
826 trans->to_max_rot[1] *= -1;
827 }
828
829 copy_v3_v3(temp_vec, trans->to_max_rot);
830
831 for (int i = 0; i < 3; i++) {
832 if ((trans->from == TRANS_LOCATION && trans->map[i] == X && i != 1) ||
833 (trans->from == TRANS_ROTATION && trans->map[i] == Y && i != 1) ||
834 (trans->from == TRANS_ROTATION && trans->map[i] == Z))
835 {
836 /* X Loc to X/Z Rot: Flipped
837 * Y Rot to X/Z Rot: Flipped
838 * Z Rot to X/Y/Z rot: Flipped */
839 trans->to_max_rot[i] = trans->to_min_rot[i];
840 trans->to_min_rot[i] = temp_vec[i];
841 }
842 }
843
844 if (trans->from == TRANS_ROTATION && trans->map[1] == Y) {
845 /* Y Rot to Y Rot: Flip and invert */
846 trans->to_max_rot[1] = -trans->to_min_rot[1];
847 trans->to_min_rot[1] = -temp_vec[1];
848 }
849
850 break;
851 }
852 /* convert back to the settings space */
853 mul_m4_v3(imat, trans->to_min);
854 mul_m4_v3(imat, trans->to_max);
855 mul_m4_v3(imat_rot, trans->to_min_rot);
856 mul_m4_v3(imat_rot, trans->to_max_rot);
857 mul_m4_v3(imat, trans->to_min_scale);
858 mul_m4_v3(imat, trans->to_max_scale);
859}
860
861static void track_axis_x_swap(int &value)
862{
863 /* Swap track axis X <> -X. */
864 if (value == TRACK_X) {
865 value = TRACK_nX;
866 }
867 else if (value == TRACK_nX) {
868 value = TRACK_X;
869 }
870}
871
872static void track_axis_x_swap(char &value)
873{
874 /* Swap track axis X <> -X. */
875 if (value == TRACK_X) {
876 value = TRACK_nX;
877 }
878 else if (value == TRACK_nX) {
879 value = TRACK_X;
880 }
881}
882
884{
885 bTrackToConstraint *data = static_cast<bTrackToConstraint *>(curcon->data);
886 track_axis_x_swap(data->reserved1);
887}
888
890{
891 bLockTrackConstraint *data = static_cast<bLockTrackConstraint *>(curcon->data);
892 track_axis_x_swap(data->trackflag);
893}
894
896{
897 bDampTrackConstraint *data = static_cast<bDampTrackConstraint *>(curcon->data);
898 track_axis_x_swap(data->trackflag);
899}
900
906
908 EditBone *orig_bone,
909 Object *ob)
910{
911 /* If an edit bone has been duplicated, lets update its constraints if the
912 * subtarget they point to has also been duplicated.
913 */
914 bPoseChannel *pchan;
915 ListBase *conlist;
916
917 if ((pchan = BKE_pose_channel_ensure(ob->pose, dup_bone->name)) == nullptr ||
918 (conlist = &pchan->constraints) == nullptr)
919 {
920 return;
921 }
922
923 LISTBASE_FOREACH (bConstraint *, curcon, conlist) {
924 switch (curcon->type) {
926 update_duplicate_action_constraint_settings(dup_bone, orig_bone, ob, pchan, curcon);
927 break;
930 break;
934 break;
937 break;
940 break;
943 break;
946 break;
949 break;
950 }
951 }
952}
953
955{
956 if (ob->pose == nullptr) {
957 return;
958 }
959 bPoseChannel *pchan;
960 pchan = BKE_pose_channel_ensure(ob->pose, dup_bone->name);
961
962 if (pchan->custom != nullptr) {
963 Main *bmain = CTX_data_main(C);
964 char name_flip[MAX_ID_NAME - 2];
965
966 /* Invert the X location */
967 pchan->custom_translation[0] *= -1;
968 /* Invert the Y rotation */
969 pchan->custom_rotation_euler[1] *= -1;
970 /* Invert the Z rotation */
971 pchan->custom_rotation_euler[2] *= -1;
972
973 /* Skip the first two chars in the object name as those are used to store object type */
974 BLI_string_flip_side_name(name_flip, pchan->custom->id.name + 2, false, sizeof(name_flip));
975 Object *shape_ob = reinterpret_cast<Object *>(BKE_libblock_find_name(bmain, ID_OB, name_flip));
976
977 /* If name_flip doesn't exist, BKE_libblock_find_name() returns pchan->custom (best match) */
978 shape_ob = shape_ob == pchan->custom ? nullptr : shape_ob;
979
980 if (shape_ob != nullptr) {
981 /* A flipped shape object exists, use it! */
982 pchan->custom = shape_ob;
983 }
984 else {
985 /* Flip shape */
986 pchan->custom_scale_xyz[0] *= -1;
987 }
988 }
989}
990
991/* Properties should be added on a case by case basis whenever needed to avoid mirroring things
992 * that shouldn't be mirrored. */
993static void mirror_pose_bone(Object &ob, EditBone &ebone)
994{
995 bPoseChannel *pose_bone = BKE_pose_channel_find_name(ob.pose, ebone.name);
996 BLI_assert(pose_bone);
997 float limit_min = pose_bone->limitmin[2];
998 pose_bone->limitmin[2] = -pose_bone->limitmax[2];
999 pose_bone->limitmax[2] = -limit_min;
1000}
1001
1003 EditBone &source_bone,
1004 EditBone &target_bone)
1005{
1006 BLI_assert_msg(armature.edbo != nullptr, "Expecting the armature to be in edit mode");
1007 char name_flip[64];
1008 /* Avoiding modification of the ListBase in the iteration. */
1009 blender::Vector<BoneCollection *> unassign_collections;
1010 blender::Vector<BoneCollection *> assign_collections;
1011
1012 /* Find all collections from source_bone that can be flipped. */
1013 LISTBASE_FOREACH (BoneCollectionReference *, collection_reference, &source_bone.bone_collections)
1014 {
1015 BoneCollection *collection = collection_reference->bcoll;
1016 BLI_string_flip_side_name(name_flip, collection->name, false, sizeof(name_flip));
1017 if (STREQ(name_flip, collection->name)) {
1018 /* Name flipping failed. */
1019 continue;
1020 }
1021 BoneCollection *flipped_collection = ANIM_armature_bonecoll_get_by_name(&armature, name_flip);
1022 if (!flipped_collection) {
1023 const int bcoll_index = blender::animrig::armature_bonecoll_find_index(&armature,
1024 collection);
1025 const int parent_index = blender::animrig::armature_bonecoll_find_parent_index(&armature,
1026 bcoll_index);
1027 flipped_collection = ANIM_armature_bonecoll_new(&armature, name_flip, parent_index);
1028 }
1029 BLI_assert(flipped_collection != nullptr);
1030 unassign_collections.append(collection);
1031 assign_collections.append(flipped_collection);
1032 }
1033
1034 /* The target_bone might not be in unassign_collections anymore, or might already be in
1035 * assign_collections. The assign functions will just do nothing in those cases. */
1036 for (BoneCollection *collection : unassign_collections) {
1037 ANIM_armature_bonecoll_unassign_editbone(collection, &target_bone);
1038 }
1039
1040 for (BoneCollection *collection : assign_collections) {
1041 ANIM_armature_bonecoll_assign_editbone(collection, &target_bone);
1042 }
1043}
1044
1045static void copy_pchan(EditBone *src_bone, EditBone *dst_bone, Object *src_ob, Object *dst_ob)
1046{
1047 /* copy the ID property */
1048 if (src_bone->prop) {
1049 dst_bone->prop = IDP_CopyProperty(src_bone->prop);
1050 }
1051 if (src_bone->system_properties) {
1053 }
1054
1055 /* Lets duplicate the list of constraints that the
1056 * current bone has.
1057 */
1058 if (src_ob->pose) {
1059 bPoseChannel *chanold, *channew;
1060
1061 chanold = BKE_pose_channel_ensure(src_ob->pose, src_bone->name);
1062 if (chanold) {
1063 /* WARNING: this creates a new pose-channel, but there will not be an attached bone
1064 * yet as the new bones created here are still 'EditBones' not 'Bones'.
1065 */
1066 channew = BKE_pose_channel_ensure(dst_ob->pose, dst_bone->name);
1067
1068 if (channew) {
1069 BKE_pose_channel_copy_data(channew, chanold);
1070 }
1071 }
1072 }
1073}
1074
1075void ED_armature_ebone_copy(EditBone *dest, const EditBone *source)
1076{
1077 memcpy(dest, source, sizeof(*dest));
1079}
1080
1082 EditBone *cur_bone, const char *name, ListBase *editbones, Object *src_ob, Object *dst_ob)
1083{
1084 EditBone *e_bone = MEM_mallocN<EditBone>("addup_editbone");
1085
1086 /* Copy data from old bone to new bone */
1087 ED_armature_ebone_copy(e_bone, cur_bone);
1088
1089 cur_bone->temp.ebone = e_bone;
1090 e_bone->temp.ebone = cur_bone;
1091
1092 if (name != nullptr) {
1093 STRNCPY(e_bone->name, name);
1094 }
1095
1096 ED_armature_ebone_unique_name(editbones, e_bone->name, nullptr);
1097 BLI_addtail(editbones, e_bone);
1098
1099 copy_pchan(cur_bone, e_bone, src_ob, dst_ob);
1100
1101 return e_bone;
1102}
1103
1104EditBone *duplicateEditBone(EditBone *cur_bone, const char *name, ListBase *editbones, Object *ob)
1105{
1106 return duplicateEditBoneObjects(cur_bone, name, editbones, ob, ob);
1107}
1108
1110{
1111 const Scene *scene = CTX_data_scene(C);
1112 ViewLayer *view_layer = CTX_data_view_layer(C);
1113 const bool do_flip_names = RNA_boolean_get(op->ptr, "do_flip_names");
1114
1115 /* cancel if nothing selected */
1116 if (CTX_DATA_COUNT(C, selected_bones) == 0) {
1117 return OPERATOR_CANCELLED;
1118 }
1119
1121 scene, view_layer, CTX_wm_view3d(C));
1122 for (Object *ob : objects) {
1123 EditBone *ebone_iter;
1124 /* The beginning of the duplicated bones in the edbo list */
1125 EditBone *ebone_first_dupe = nullptr;
1126
1127 bArmature *arm = static_cast<bArmature *>(ob->data);
1128
1129 ED_armature_edit_sync_selection(arm->edbo); /* XXX why is this needed? */
1130
1132
1133 /* Select mirrored bones */
1134 if (arm->flag & ARM_MIRROR_EDIT) {
1135 LISTBASE_FOREACH (EditBone *, ebone_iter, arm->edbo) {
1136 if (blender::animrig::bone_is_visible_editbone(arm, ebone_iter) &&
1137 (ebone_iter->flag & BONE_SELECTED))
1138 {
1139 EditBone *ebone;
1140
1141 ebone = ED_armature_ebone_get_mirrored(arm->edbo, ebone_iter);
1142 if (ebone) {
1143 ebone->flag |= BONE_SELECTED;
1144 }
1145 }
1146 }
1147 }
1148
1149 /* Find the selected bones and duplicate them as needed */
1150 for (ebone_iter = static_cast<EditBone *>(arm->edbo->first);
1151 ebone_iter && ebone_iter != ebone_first_dupe;
1152 ebone_iter = ebone_iter->next)
1153 {
1154 if (blender::animrig::bone_is_visible_editbone(arm, ebone_iter) &&
1155 (ebone_iter->flag & BONE_SELECTED))
1156 {
1157 EditBone *ebone;
1158 char new_bone_name_buff[MAXBONENAME];
1159 const char *new_bone_name = ebone_iter->name;
1160
1161 if (do_flip_names) {
1163 new_bone_name_buff, ebone_iter->name, false, sizeof(new_bone_name_buff));
1164
1165 /* Only use flipped name if not yet in use. Otherwise we'd get again inconsistent
1166 * namings (different numbers), better keep default behavior in this case. */
1167 if (ED_armature_ebone_find_name(arm->edbo, new_bone_name_buff) == nullptr) {
1168 new_bone_name = new_bone_name_buff;
1169 }
1170 }
1171
1172 ebone = duplicateEditBone(ebone_iter, new_bone_name, arm->edbo, ob);
1173
1174 if (!ebone_first_dupe) {
1175 ebone_first_dupe = ebone;
1176 }
1177 }
1178 }
1179
1180 /* Run though the list and fix the pointers */
1181 for (ebone_iter = static_cast<EditBone *>(arm->edbo->first);
1182 ebone_iter && ebone_iter != ebone_first_dupe;
1183 ebone_iter = ebone_iter->next)
1184 {
1185 if (blender::animrig::bone_is_visible_editbone(arm, ebone_iter) &&
1186 (ebone_iter->flag & BONE_SELECTED))
1187 {
1188 EditBone *ebone = ebone_iter->temp.ebone;
1189
1190 if (!ebone_iter->parent) {
1191 /* If this bone has no parent,
1192 * Set the duplicate->parent to nullptr
1193 */
1194 ebone->parent = nullptr;
1195 }
1196 else if (ebone_iter->parent->temp.ebone) {
1197 /* If this bone has a parent that was duplicated,
1198 * Set the duplicate->parent to the cur_bone->parent->temp
1199 */
1200 ebone->parent = ebone_iter->parent->temp.ebone;
1201 }
1202 else {
1203 /* If this bone has a parent that IS not selected,
1204 * Set the duplicate->parent to the cur_bone->parent
1205 */
1206 ebone->parent = ebone_iter->parent;
1207 ebone->flag &= ~BONE_CONNECTED;
1208 }
1209
1210 /* Update custom handle links. */
1211 if (ebone_iter->bbone_prev && ebone_iter->bbone_prev->temp.ebone) {
1212 ebone->bbone_prev = ebone_iter->bbone_prev->temp.ebone;
1213 }
1214 if (ebone_iter->bbone_next && ebone_iter->bbone_next->temp.ebone) {
1215 ebone->bbone_next = ebone_iter->bbone_next->temp.ebone;
1216 }
1217
1218 /* Lets try to fix any constraint sub-targets that might have been duplicated. */
1219 update_duplicate_subtarget(ebone, ob, false);
1220 }
1221 }
1222
1223 /* correct the active bone */
1224 if (arm->act_edbone && arm->act_edbone->temp.ebone) {
1225 arm->act_edbone = arm->act_edbone->temp.ebone;
1226 }
1227
1228 /* Deselect the old bones and select the new ones */
1229 for (ebone_iter = static_cast<EditBone *>(arm->edbo->first);
1230 ebone_iter && ebone_iter != ebone_first_dupe;
1231 ebone_iter = ebone_iter->next)
1232 {
1233 if (blender::animrig::bone_is_visible_editbone(arm, ebone_iter)) {
1234 ebone_iter->flag &= ~(BONE_SELECTED | BONE_TIPSEL | BONE_ROOTSEL);
1235 }
1236 }
1237
1239
1242 }
1243
1245
1246 return OPERATOR_FINISHED;
1247}
1248
1250{
1251 /* identifiers */
1252 ot->name = "Duplicate Selected Bone(s)";
1253 ot->idname = "ARMATURE_OT_duplicate";
1254 ot->description = "Make copies of the selected bones within the same armature";
1255
1256 /* API callbacks. */
1259
1260 /* flags */
1261 ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
1262
1264 ot->srna,
1265 "do_flip_names",
1266 false,
1267 "Flip Names",
1268 "Try to flip names of the bones, if possible, instead of adding a number extension");
1269}
1270
1271/* Get the duplicated or existing mirrored copy of the bone. */
1273{
1274 if (bone == nullptr) {
1275 return nullptr;
1276 }
1277 if (bone->temp.ebone != nullptr) {
1278 return bone->temp.ebone;
1279 }
1280
1281 EditBone *mirror = ED_armature_ebone_get_mirrored(arm->edbo, bone);
1282 return (mirror != nullptr) ? mirror : bone;
1283}
1284
1290{
1291 const Scene *scene = CTX_data_scene(C);
1292 ViewLayer *view_layer = CTX_data_view_layer(C);
1293 const int direction = RNA_enum_get(op->ptr, "direction");
1294 const bool copy_bone_colors = RNA_boolean_get(op->ptr, "copy_bone_colors");
1295 const int axis = 0;
1296
1297 /* cancel if nothing selected */
1298 if (CTX_DATA_COUNT(C, selected_bones) == 0) {
1299 return OPERATOR_CANCELLED;
1300 }
1301
1303 scene, view_layer, CTX_wm_view3d(C));
1304 for (Object *obedit : objects) {
1305 EditBone *ebone_iter;
1306 /* The beginning of the duplicated mirrored bones in the edbo list */
1307 EditBone *ebone_first_dupe = nullptr;
1308
1309 bArmature *arm = static_cast<bArmature *>(obedit->data);
1310
1311 ED_armature_edit_sync_selection(arm->edbo); /* XXX why is this needed? */
1312
1314
1315 /* Deselect ebones depending on input axis and direction.
1316 * A symmetrizable selection contains selected ebones of the input direction
1317 * and unique selected bones with an unique flippable name.
1318 *
1319 * Storing temp pointers to mirrored unselected ebones. */
1320 LISTBASE_FOREACH (EditBone *, ebone_iter, arm->edbo) {
1321 if (!(blender::animrig::bone_is_visible_editbone(arm, ebone_iter) &&
1322 (ebone_iter->flag & BONE_SELECTED)))
1323 {
1324 /* Skipping invisible selected bones. */
1325 continue;
1326 }
1327
1328 char name_flip[MAXBONENAME];
1329 if (ebone_iter == nullptr) {
1330 continue;
1331 }
1332
1333 BLI_string_flip_side_name(name_flip, ebone_iter->name, false, sizeof(name_flip));
1334
1335 if (STREQ(name_flip, ebone_iter->name)) {
1336 /* Skipping ebones without flippable as they don't have the potential to be mirrored. */
1337 ebone_iter->flag &= ~(BONE_SELECTED | BONE_TIPSEL | BONE_ROOTSEL);
1338 continue;
1339 }
1340
1341 EditBone *ebone = ED_armature_ebone_find_name(arm->edbo, name_flip);
1342
1343 if (!ebone) {
1344 /* The ebone_iter is unique and mirror-able. */
1345 continue;
1346 }
1347
1348 if (ebone->flag & BONE_SELECTED) {
1349 /* The mirrored ebone and the ebone_iter are selected.
1350 * Deselect based on the input direction and axis. */
1351 float axis_delta;
1352
1353 axis_delta = ebone->head[axis] - ebone_iter->head[axis];
1354 if (axis_delta == 0.0f) {
1355 /* The ebone heads are overlapping. */
1356 axis_delta = ebone->tail[axis] - ebone_iter->tail[axis];
1357
1358 if (axis_delta == 0.0f) {
1359 /* Both mirrored bones point to each other and overlap exactly.
1360 * In this case there's no well defined solution, so de-select both and skip. */
1361 ebone->flag &= ~(BONE_SELECTED | BONE_TIPSEL | BONE_ROOTSEL);
1362 ebone_iter->flag &= ~(BONE_SELECTED | BONE_TIPSEL | BONE_ROOTSEL);
1363 continue;
1364 }
1365 }
1366
1367 /* Deselect depending on direction. */
1368 if (((axis_delta < 0.0f) ? -1 : 1) == direction) {
1369 /* Don't store temp ptr if the iter_bone gets deselected.
1370 * In this case, the ebone.temp should point to the ebone_iter. */
1371 ebone_iter->flag &= ~(BONE_SELECTED | BONE_TIPSEL | BONE_ROOTSEL);
1372 continue;
1373 }
1374
1375 ebone->flag &= ~(BONE_SELECTED | BONE_TIPSEL | BONE_ROOTSEL);
1376 }
1377
1378 /* Set temp pointer to mirrored ebones */
1379 ebone_iter->temp.ebone = ebone;
1380 }
1381
1382 /* Find the selected bones and duplicate them as needed, with mirrored name. */
1383 for (ebone_iter = static_cast<EditBone *>(arm->edbo->first);
1384 ebone_iter && ebone_iter != ebone_first_dupe;
1385 ebone_iter = ebone_iter->next)
1386 {
1387 if (blender::animrig::bone_is_visible_editbone(arm, ebone_iter) &&
1388 (ebone_iter->flag & BONE_SELECTED))
1389 {
1390 if (ebone_iter->temp.ebone != nullptr) {
1391 /* This will be set if the mirror bone already exists (no need to make a new one)
1392 * but we do need to make sure that the 'pchan' settings (constraints etc)
1393 * is synchronized. */
1394 bPoseChannel *pchan;
1395 /* Make sure we clean up the old data before overwriting it */
1396 pchan = BKE_pose_channel_ensure(obedit->pose, ebone_iter->temp.ebone->name);
1397 BKE_pose_channel_free(pchan);
1398 /* Sync pchan data */
1399 copy_pchan(ebone_iter, ebone_iter->temp.ebone, obedit, obedit);
1400 /* Sync scale mode */
1401 ebone_iter->temp.ebone->inherit_scale_mode = ebone_iter->inherit_scale_mode;
1402 continue;
1403 }
1404
1405 char name_flip[MAXBONENAME];
1406
1407 BLI_string_flip_side_name(name_flip, ebone_iter->name, false, sizeof(name_flip));
1408
1409 /* mirrored bones must have a side-suffix */
1410 if (!STREQ(name_flip, ebone_iter->name)) {
1411 EditBone *ebone;
1412
1413 ebone = duplicateEditBone(ebone_iter, name_flip, arm->edbo, obedit);
1414
1415 if (!ebone_first_dupe) {
1416 ebone_first_dupe = ebone;
1417 }
1418 }
1419 }
1420 }
1421
1422 /* Run through the list and fix the pointers. */
1423 for (ebone_iter = static_cast<EditBone *>(arm->edbo->first);
1424 ebone_iter && ebone_iter != ebone_first_dupe;
1425 ebone_iter = ebone_iter->next)
1426 {
1427 if (ebone_iter->temp.ebone) {
1428 /* copy all flags except for ... */
1429 const int flag_copy = (~0) & ~(BONE_SELECTED | BONE_ROOTSEL | BONE_TIPSEL);
1430
1431 EditBone *ebone = ebone_iter->temp.ebone;
1432
1433 /* Copy flags in case bone is pre-existing data. */
1434 ebone->flag = (ebone->flag & ~flag_copy) | (ebone_iter->flag & flag_copy);
1435
1436 /* Copy Viewport Display. */
1437 ebone->drawtype = ebone_iter->drawtype;
1438 if (copy_bone_colors) {
1439 ebone->color.palette_index = ebone_iter->color.palette_index;
1440 copy_v4_v4_uchar(ebone->color.custom.active, ebone_iter->color.custom.active);
1441 copy_v4_v4_uchar(ebone->color.custom.select, ebone_iter->color.custom.select);
1442 copy_v4_v4_uchar(ebone->color.custom.solid, ebone_iter->color.custom.solid);
1443 ebone->color.custom.flag = ebone_iter->color.custom.flag;
1444 }
1445
1446 if (ebone_iter->parent == nullptr) {
1447 /* If this bone has no parent,
1448 * Set the duplicate->parent to nullptr
1449 */
1450 ebone->parent = nullptr;
1451 ebone->flag &= ~BONE_CONNECTED;
1452 }
1453 else {
1454 /* the parent may have been duplicated, if not lookup the mirror parent */
1455 EditBone *ebone_parent = get_symmetrized_bone(arm, ebone_iter->parent);
1456
1457 if (ebone_parent == ebone_iter->parent) {
1458 /* If the mirror lookup failed, (but the current bone has a parent)
1459 * then we can assume the parent has no L/R but is a center bone.
1460 * So just use the same parent for both.
1461 */
1462
1463 if (ebone->head[axis] != 0.0f) {
1464 /* The mirrored bone doesn't start on the mirror axis, so assume that this one
1465 * should not be connected to the old parent */
1466 ebone->flag &= ~BONE_CONNECTED;
1467 }
1468 }
1469
1470 ebone->parent = ebone_parent;
1471 }
1472
1473 /* Update custom handle links. */
1474 ebone->bbone_prev = get_symmetrized_bone(arm, ebone_iter->bbone_prev);
1475 ebone->bbone_next = get_symmetrized_bone(arm, ebone_iter->bbone_next);
1476
1477 /* Sync bbone handle types */
1478 ebone->bbone_prev_type = ebone_iter->bbone_prev_type;
1479 ebone->bbone_next_type = ebone_iter->bbone_next_type;
1480
1481 ebone->bbone_mapping_mode = ebone_iter->bbone_mapping_mode;
1482 ebone->bbone_flag = ebone_iter->bbone_flag;
1483 ebone->bbone_prev_flag = ebone_iter->bbone_prev_flag;
1484 ebone->bbone_next_flag = ebone_iter->bbone_next_flag;
1485
1486 /* Lets try to fix any constraint sub-targets that might have been duplicated. */
1487 update_duplicate_subtarget(ebone, obedit, true);
1488 /* Try to update constraint options so that they are mirrored as well
1489 * (need to supply bone_iter as well in case we are working with existing bones) */
1490 update_duplicate_constraint_settings(ebone, ebone_iter, obedit);
1491 /* Mirror bone shapes if possible */
1492 update_duplicate_custom_bone_shapes(C, ebone, obedit);
1493 /* Mirror any settings on the pose bone. */
1494 mirror_pose_bone(*obedit, *ebone);
1495 mirror_bone_collection_assignments(*arm, *ebone_iter, *ebone);
1496 }
1497 }
1498
1500
1501 /* Selected bones now have their 'temp' pointer set,
1502 * so we don't need this anymore */
1503
1504 /* Deselect the old bones and select the new ones */
1505 for (ebone_iter = static_cast<EditBone *>(arm->edbo->first);
1506 ebone_iter && ebone_iter != ebone_first_dupe;
1507 ebone_iter = ebone_iter->next)
1508 {
1509 if (blender::animrig::bone_is_visible_editbone(arm, ebone_iter)) {
1510 ebone_iter->flag &= ~(BONE_SELECTED | BONE_TIPSEL | BONE_ROOTSEL);
1511 }
1512 }
1513
1514 /* New bones will be selected, but some of the bones may already exist */
1515 for (ebone_iter = static_cast<EditBone *>(arm->edbo->first);
1516 ebone_iter && ebone_iter != ebone_first_dupe;
1517 ebone_iter = ebone_iter->next)
1518 {
1519 EditBone *ebone = ebone_iter->temp.ebone;
1520 if (ebone && EBONE_SELECTABLE(arm, ebone)) {
1521 ED_armature_ebone_select_set(ebone, true);
1522 }
1523 }
1524
1525 /* correct the active bone */
1526 if (arm->act_edbone && arm->act_edbone->temp.ebone) {
1527 arm->act_edbone = arm->act_edbone->temp.ebone;
1528 }
1529
1530 pose_edit_bone_duplicate(arm->edbo, obedit);
1531
1533 DEG_id_tag_update(&obedit->id, ID_RECALC_SELECT);
1534 }
1535
1536 return OPERATOR_FINISHED;
1537}
1538
1540{
1541 /* NOTE: following conventions from #MESH_OT_symmetrize */
1542
1543 /* subset of 'rna_enum_symmetrize_direction_items' */
1544 static const EnumPropertyItem arm_symmetrize_direction_items[] = {
1545 {-1, "NEGATIVE_X", 0, "-X to +X", ""},
1546 {+1, "POSITIVE_X", 0, "+X to -X", ""},
1547 {0, nullptr, 0, nullptr, nullptr},
1548 };
1549
1550 /* identifiers */
1551 ot->name = "Symmetrize";
1552 ot->idname = "ARMATURE_OT_symmetrize";
1553 ot->description = "Enforce symmetry, make copies of the selection or use existing";
1554
1555 /* API callbacks. */
1558
1559 /* flags */
1560 ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
1561
1562 ot->prop = RNA_def_enum(ot->srna,
1563 "direction",
1564 arm_symmetrize_direction_items,
1565 -1,
1566 "Direction",
1567 "Which sides to copy from and to (when both are selected)");
1568 ot->prop = RNA_def_boolean(
1569 ot->srna, "copy_bone_colors", false, "Bone Colors", "Copy colors to existing bones");
1570}
1571
1572/* ------------------------------------------ */
1573
1574/* previously extrude_armature */
1575/* context; editmode armature */
1576/* if forked && mirror-edit: makes two bones with flipped names */
1578{
1579 const Scene *scene = CTX_data_scene(C);
1580 ViewLayer *view_layer = CTX_data_view_layer(C);
1581 const bool forked = RNA_boolean_get(op->ptr, "forked");
1582 bool changed_multi = false;
1584 scene, view_layer, CTX_wm_view3d(C));
1585
1586 enum ExtrudePoint {
1587 SKIP_EXTRUDE,
1588 TIP_EXTRUDE,
1589 ROOT_EXTRUDE,
1590 };
1591
1592 for (Object *ob : objects) {
1593 bArmature *arm = static_cast<bArmature *>(ob->data);
1594 bool forked_iter = forked;
1595
1596 EditBone *newbone = nullptr, *ebone, *flipbone, *first = nullptr;
1597 int a, totbone = 0;
1598 ExtrudePoint do_extrude;
1599
1600 /* since we allow root extrude too, we have to make sure selection is OK */
1601 LISTBASE_FOREACH (EditBone *, ebone, arm->edbo) {
1603 if (ebone->flag & BONE_ROOTSEL) {
1604 if (ebone->parent && (ebone->flag & BONE_CONNECTED)) {
1605 if (ebone->parent->flag & BONE_TIPSEL) {
1606 ebone->flag &= ~BONE_ROOTSEL;
1607 }
1608 }
1609 }
1610 }
1611 }
1612
1613 /* Duplicate the necessary bones */
1614 for (ebone = static_cast<EditBone *>(arm->edbo->first); ((ebone) && (ebone != first));
1615 ebone = ebone->next)
1616 {
1618 continue;
1619 }
1620 /* We extrude per definition the tip. */
1621 do_extrude = SKIP_EXTRUDE;
1622 if (ebone->flag & (BONE_TIPSEL | BONE_SELECTED)) {
1623 do_extrude = TIP_EXTRUDE;
1624 }
1625 else if (ebone->flag & BONE_ROOTSEL) {
1626 /* but, a bone with parent deselected we do the root... */
1627 if (ebone->parent && (ebone->parent->flag & BONE_TIPSEL)) {
1628 /* pass */
1629 }
1630 else {
1631 do_extrude = ROOT_EXTRUDE;
1632 }
1633 }
1634
1635 if (do_extrude) {
1636 /* we re-use code for mirror editing... */
1637 flipbone = nullptr;
1638 if (arm->flag & ARM_MIRROR_EDIT) {
1639 flipbone = ED_armature_ebone_get_mirrored(arm->edbo, ebone);
1640 if (flipbone) {
1641 forked_iter = false; /* we extrude 2 different bones */
1642 if (flipbone->flag & (BONE_TIPSEL | BONE_ROOTSEL | BONE_SELECTED)) {
1643 /* don't want this bone to be selected... */
1644 flipbone->flag &= ~(BONE_TIPSEL | BONE_SELECTED | BONE_ROOTSEL);
1645 }
1646 }
1647 if ((flipbone == nullptr) && (forked_iter)) {
1648 flipbone = ebone;
1649 }
1650 }
1651
1652 for (a = 0; a < 2; a++) {
1653 if (a == 1) {
1654 if (flipbone == nullptr) {
1655 break;
1656 }
1657 std::swap(flipbone, ebone);
1658 }
1659
1660 totbone++;
1661 newbone = MEM_callocN<EditBone>("extrudebone");
1662
1663 if (do_extrude == TIP_EXTRUDE) {
1664 copy_v3_v3(newbone->head, ebone->tail);
1665 copy_v3_v3(newbone->tail, newbone->head);
1666 newbone->parent = ebone;
1667
1668 /* copies it, in case mirrored bone */
1669 newbone->flag = ebone->flag & (BONE_TIPSEL | BONE_RELATIVE_PARENTING);
1670
1671 if (newbone->parent) {
1672 newbone->flag |= BONE_CONNECTED;
1673 }
1674 }
1675 else if (do_extrude == ROOT_EXTRUDE) {
1676 copy_v3_v3(newbone->head, ebone->head);
1677 copy_v3_v3(newbone->tail, ebone->head);
1678 newbone->parent = ebone->parent;
1679
1680 newbone->flag = BONE_TIPSEL;
1681
1682 if (newbone->parent && (ebone->flag & BONE_CONNECTED)) {
1683 newbone->flag |= BONE_CONNECTED;
1684 }
1685 }
1686
1687 newbone->color = ebone->color;
1688 newbone->drawtype = ebone->drawtype;
1689
1690 newbone->weight = ebone->weight;
1691 newbone->dist = ebone->dist;
1692 newbone->xwidth = ebone->xwidth;
1693 newbone->zwidth = ebone->zwidth;
1694 newbone->rad_head = ebone->rad_tail; /* don't copy entire bone. */
1695 newbone->rad_tail = ebone->rad_tail;
1696 newbone->segments = 1;
1697 newbone->layer = ebone->layer;
1698
1699 /* Bendy-Bone parameters */
1700 newbone->roll1 = ebone->roll1;
1701 newbone->roll2 = ebone->roll2;
1702 newbone->curve_in_x = ebone->curve_in_x;
1703 newbone->curve_in_z = ebone->curve_in_z;
1704 newbone->curve_out_x = ebone->curve_out_x;
1705 newbone->curve_out_z = ebone->curve_out_z;
1706 newbone->ease1 = ebone->ease1;
1707 newbone->ease2 = ebone->ease2;
1708
1709 copy_v3_v3(newbone->scale_in, ebone->scale_in);
1710 copy_v3_v3(newbone->scale_out, ebone->scale_out);
1711
1712 STRNCPY(newbone->name, ebone->name);
1713
1714 if (flipbone && forked_iter) { /* only set if mirror edit */
1715 if (strlen(newbone->name) < (MAXBONENAME - 2)) {
1716 BLI_strncat(newbone->name, (a == 0) ? "_L" : "_R", sizeof(newbone->name));
1717 }
1718 }
1719 ED_armature_ebone_unique_name(arm->edbo, newbone->name, nullptr);
1720
1721 /* Copy bone collection membership. */
1722 BLI_duplicatelist(&newbone->bone_collections, &ebone->bone_collections);
1723
1724 /* Add the new bone to the list */
1725 BLI_addtail(arm->edbo, newbone);
1726 if (!first) {
1727 first = newbone;
1728 }
1729
1730 /* restore ebone if we were flipping */
1731 if (a == 1 && flipbone) {
1732 std::swap(flipbone, ebone);
1733 }
1734 }
1735 }
1736
1737 /* Deselect the old bone */
1738 ebone->flag &= ~(BONE_TIPSEL | BONE_SELECTED | BONE_ROOTSEL);
1739 }
1740 /* if only one bone, make this one active */
1741 if (totbone == 1 && first) {
1742 arm->act_edbone = first;
1743 }
1744 else {
1745 arm->act_edbone = newbone;
1746 }
1747
1748 if (totbone == 0) {
1749 continue;
1750 }
1751
1752 changed_multi = true;
1753
1754 /* Transform the endpoints */
1756
1759 }
1760
1761 if (!changed_multi) {
1762 return OPERATOR_CANCELLED;
1763 }
1764
1766
1767 return OPERATOR_FINISHED;
1768}
1769
1771{
1772 /* identifiers */
1773 ot->name = "Extrude";
1774 ot->idname = "ARMATURE_OT_extrude";
1775 ot->description = "Create new bones from the selected joints";
1776
1777 /* API callbacks. */
1778 ot->exec = armature_extrude_exec;
1780
1781 /* flags */
1782 ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
1783
1784 /* props */
1785 RNA_def_boolean(ot->srna, "forked", false, "Forked", "");
1786}
1787
1788/* ********************** Bone Add *************************************/
1789
1790/* Op makes a new bone and returns it with its tip selected. */
1791
1793{
1795 Object *obedit = CTX_data_edit_object(C);
1796 EditBone *bone;
1797 float obmat[3][3], curs[3], viewmat[3][3], totmat[3][3], imat[3][3];
1798 char name[MAXBONENAME];
1799
1800 RNA_string_get(op->ptr, "name", name);
1801
1802 copy_v3_v3(curs, CTX_data_scene(C)->cursor.location);
1803
1804 /* Get inverse point for head and orientation for tail */
1805 invert_m4_m4(obedit->runtime->world_to_object.ptr(), obedit->object_to_world().ptr());
1806 mul_m4_v3(obedit->world_to_object().ptr(), curs);
1807
1808 if (rv3d && (U.flag & USER_ADD_VIEWALIGNED)) {
1809 copy_m3_m4(obmat, rv3d->viewmat);
1810 }
1811 else {
1812 unit_m3(obmat);
1813 }
1814
1815 copy_m3_m4(viewmat, obedit->object_to_world().ptr());
1816 mul_m3_m3m3(totmat, obmat, viewmat);
1817 invert_m3_m3(imat, totmat);
1818
1820
1821 /* Create a bone. */
1822 bone = ED_armature_ebone_add(static_cast<bArmature *>(obedit->data), name);
1823 ANIM_armature_bonecoll_assign_active(static_cast<bArmature *>(obedit->data), bone);
1824
1825 bArmature *arm = static_cast<bArmature *>(obedit->data);
1826 if (!ANIM_bonecoll_is_visible_editbone(arm, bone)) {
1827 const BoneCollectionReference *bcoll_ref = static_cast<const BoneCollectionReference *>(
1828 bone->bone_collections.first);
1829 BLI_assert_msg(bcoll_ref,
1830 "Bone that is not visible due to its bone collections MUST be assigned to at "
1831 "least one of them.");
1832 BKE_reportf(op->reports,
1834 "Bone was added to a hidden collection '%s'",
1835 bcoll_ref->bcoll->name);
1836 }
1837
1838 copy_v3_v3(bone->head, curs);
1839
1840 if (rv3d && (U.flag & USER_ADD_VIEWALIGNED)) {
1841 add_v3_v3v3(bone->tail, bone->head, imat[1]); /* bone with unit length 1 */
1842 }
1843 else {
1844 add_v3_v3v3(bone->tail, bone->head, imat[2]); /* bone with unit length 1, pointing up Z */
1845 }
1846
1847 /* NOTE: notifier might evolve. */
1851
1852 return OPERATOR_FINISHED;
1853}
1854
1856{
1857 /* identifiers */
1858 ot->name = "Add Bone";
1859 ot->idname = "ARMATURE_OT_bone_primitive_add";
1860 ot->description = "Add a new bone located at the 3D cursor";
1861
1862 /* API callbacks. */
1865
1866 /* flags */
1867 ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
1868
1869 RNA_def_string(ot->srna, "name", nullptr, MAXBONENAME, "Name", "Name of the newly created bone");
1870}
1871
1872/* ********************** Subdivide *******************************/
1873
1874/* Subdivide Operators:
1875 * This group of operators all use the same 'exec' callback, but they are called
1876 * through several different operators - a combined menu (which just calls the exec in the
1877 * appropriate ways), and two separate ones.
1878 */
1879
1881{
1882 Object *obedit = CTX_data_edit_object(C);
1883 EditBone *newbone;
1884 int cuts, i;
1885
1886 /* there may not be a number_cuts property defined (for 'simple' subdivide) */
1887 cuts = RNA_int_get(op->ptr, "number_cuts");
1888
1889 /* loop over all editable bones */
1890 CTX_DATA_BEGIN_WITH_ID (C, EditBone *, ebone, selected_editable_bones, bArmature *, arm) {
1891 /* Keep track of the last bone in the editbone list. The newly created ones
1892 * will be appended after this one. */
1893 EditBone *last_bone_before_cutting = static_cast<EditBone *>(arm->edbo->last);
1894 BLI_assert_msg(last_bone_before_cutting,
1895 "If there is no bone before subdividing, which bone is being subdivided here?");
1896
1897 for (i = cuts + 1; i > 1; i--) {
1898 /* compute cut ratio first */
1899 float cutratio = 1.0f / float(i);
1900 float cutratioI = 1.0f - cutratio;
1901
1902 float val1[3];
1903 float val2[3];
1904 float val3[3];
1905
1906 newbone = MEM_mallocN<EditBone>("ebone subdiv");
1907 *newbone = *ebone;
1908 BLI_addtail(arm->edbo, newbone);
1909
1910 /* calculate location of newbone->head */
1911 copy_v3_v3(val1, ebone->head);
1912 copy_v3_v3(val2, ebone->tail);
1913 copy_v3_v3(val3, newbone->head);
1914
1915 val3[0] = val1[0] * cutratio + val2[0] * cutratioI;
1916 val3[1] = val1[1] * cutratio + val2[1] * cutratioI;
1917 val3[2] = val1[2] * cutratio + val2[2] * cutratioI;
1918
1919 copy_v3_v3(newbone->head, val3);
1920 copy_v3_v3(newbone->tail, ebone->tail);
1921 copy_v3_v3(ebone->tail, newbone->head);
1922
1923 newbone->rad_head = ((ebone->rad_head * cutratio) + (ebone->rad_tail * cutratioI));
1924 ebone->rad_tail = newbone->rad_head;
1925
1926 newbone->flag |= BONE_CONNECTED;
1927 newbone->prop = nullptr;
1928 newbone->system_properties = nullptr;
1929
1930 /* correct parent bones */
1931 LISTBASE_FOREACH (EditBone *, tbone, arm->edbo) {
1932 if (tbone->parent == ebone) {
1933 tbone->parent = newbone;
1934 }
1935 }
1936 newbone->parent = ebone;
1937
1938 /* Copy bone collection membership. */
1939 BLI_duplicatelist(&newbone->bone_collections, &ebone->bone_collections);
1940 }
1941
1942 /* Ensure the bones are uniquely named, in the right order to ensure "Bone" is subdivided into
1943 * "Bone", "Bone.001", "Bone.002", etc. This has to be in the opposite order as the cuts in the
1944 * code above.
1945 *
1946 * The code above cuts into fractions (for cuts=3 it cuts into 1/4, then 1/3, then 1/2), which
1947 * means that it MUST be run in that order. Since the loop below also must run in the order it
1948 * is now in, and that's the opposite order of the loop above, they cannot be combined.
1949 *
1950 * If the code above were refactored, it could just calculate the final bone length and create
1951 * (N-1) bones of that length, which can then be done in any order. Then the code below can be
1952 * integrated into the code above.
1953 */
1954 ListBase new_bones;
1955 new_bones.first = last_bone_before_cutting->next;
1956 new_bones.last = static_cast<EditBone *>(arm->edbo->last);
1957 LISTBASE_FOREACH_BACKWARD (EditBone *, newbone, &new_bones) {
1958 ED_armature_ebone_unique_name(arm->edbo, newbone->name, newbone);
1959 }
1960 }
1962
1963 /* NOTE: notifier might evolve. */
1967
1968 return OPERATOR_FINISHED;
1969}
1970
1972{
1973 PropertyRNA *prop;
1974
1975 /* identifiers */
1976 ot->name = "Subdivide";
1977 ot->idname = "ARMATURE_OT_subdivide";
1978 ot->description = "Break selected bones into chains of smaller bones";
1979
1980 /* API callbacks. */
1983
1984 /* flags */
1985 ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
1986
1987 /* Properties */
1988 prop = RNA_def_int(ot->srna, "number_cuts", 1, 1, 1000, "Number of Cuts", "", 1, 10);
1989 /* Avoid re-using last var because it can cause
1990 * _very_ high poly meshes and annoy users (or worse crash) */
1992}
Functions and classes to work with Actions.
Functions to deal with Armatures.
C++ functions to deal with Armature collections (i.e. the successor of bone layers).
bool ANIM_bonecoll_is_visible_editbone(const bArmature *armature, const EditBone *ebone)
bool ANIM_armature_bonecoll_unassign_editbone(BoneCollection *bcoll, EditBone *ebone)
void ANIM_armature_bonecoll_assign_active(const bArmature *armature, EditBone *ebone)
BoneCollection * ANIM_armature_bonecoll_new(bArmature *armature, const char *name, int parent_index=-1)
BoneCollection * ANIM_armature_bonecoll_get_by_name(bArmature *armature, const char *name) ATTR_WARN_UNUSED_RESULT
bool ANIM_armature_bonecoll_assign_editbone(BoneCollection *bcoll, EditBone *ebone)
Blender kernel action and pose functionality.
void BKE_pose_channel_copy_data(bPoseChannel *pchan, const bPoseChannel *pchan_from)
void BKE_pose_channels_hash_free(bPose *pose) ATTR_NONNULL(1)
void action_groups_add_channel(bAction *act, bActionGroup *agrp, FCurve *fcurve)
void BKE_pose_channels_hash_ensure(bPose *pose) ATTR_NONNULL(1)
bPoseChannel * BKE_pose_channel_find_name(const bPose *pose, const char *name)
void BKE_pose_channel_free(bPoseChannel *pchan) ATTR_NONNULL(1)
bPoseChannel * BKE_pose_channel_ensure(bPose *pose, const char *name) ATTR_NONNULL(2)
bActionGroup * action_groups_add_new(bAction *act, const char name[])
bActionGroup * BKE_action_group_find_name(bAction *act, const char name[])
void BKE_constraint_targets_flush(struct bConstraint *con, struct ListBase *targets, bool no_copy)
void BKE_constraint_mat_convertspace(struct Object *ob, struct bPoseChannel *pchan, struct bConstraintOb *cob, float mat[4][4], short from, short to, bool keep_scale)
int BKE_constraint_targets_get(struct bConstraint *con, struct ListBase *r_targets)
void BKE_constraint_custom_object_space_init(struct bConstraintOb *cob, struct bConstraint *con)
#define CTX_DATA_BEGIN_WITH_ID(C, Type, instance, member, Type_id, instance_id)
#define CTX_DATA_COUNT(C, member)
Scene * CTX_data_scene(const bContext *C)
Object * CTX_data_edit_object(const bContext *C)
Main * CTX_data_main(const bContext *C)
RegionView3D * CTX_wm_region_view3d(const bContext *C)
ARegion * CTX_wm_region(const bContext *C)
#define CTX_DATA_END
View3D * CTX_wm_view3d(const bContext *C)
ViewLayer * CTX_data_view_layer(const bContext *C)
FCurve * BKE_fcurve_copy(const FCurve *fcu)
IDProperty * IDP_CopyProperty(const IDProperty *prop) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL()
Definition idprop.cc:873
blender::Vector< Object * > BKE_view_layer_array_from_objects_in_edit_mode_unique_data(const Scene *scene, ViewLayer *view_layer, const View3D *v3d)
ID * BKE_libblock_find_name(Main *bmain, short type, const char *name, const std::optional< Library * > lib=std::nullopt) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL()
Definition lib_id.cc:1679
void BKE_reportf(ReportList *reports, eReportType type, const char *format,...) ATTR_PRINTF_FORMAT(3
#define BLI_assert(a)
Definition BLI_assert.h:46
#define BLI_assert_msg(a, msg)
Definition BLI_assert.h:53
#define LISTBASE_FOREACH(type, var, list)
#define LISTBASE_FOREACH_BACKWARD(type, var, list)
void BLI_addtail(ListBase *listbase, void *vlink) ATTR_NONNULL(1)
Definition listbase.cc:111
void void void void void void BLI_duplicatelist(ListBase *dst, const ListBase *src) ATTR_NONNULL(1
#define M_PI
void mul_m3_v3(const float M[3][3], float r[3])
void unit_m3(float m[3][3])
void copy_m3_m4(float m1[3][3], const float m2[4][4])
bool invert_m3_m3(float inverse[3][3], const float mat[3][3])
void mul_m4_v3(const float M[4][4], float r[3])
bool invert_m4_m4(float inverse[4][4], const float mat[4][4])
void mul_m3_m3m3(float R[3][3], const float A[3][3], const float B[3][3])
void unit_m4(float m[4][4])
float angle_wrap_rad(float angle)
MINLINE void copy_v2fl_v2i(float r[2], const int a[2])
MINLINE float len_v3v3(const float a[3], const float b[3]) ATTR_WARN_UNUSED_RESULT
MINLINE void sub_v3_v3v3(float r[3], const float a[3], const float b[3])
MINLINE void copy_v4_v4_uchar(unsigned char r[4], const unsigned char a[4])
MINLINE void copy_v3_v3(float r[3], const float a[3])
MINLINE void add_v3_v3v3(float r[3], const float a[3], const float b[3])
MINLINE void copy_v3_fl(float r[3], float f)
MINLINE void zero_v3(float r[3])
int bool bool bool BLI_strn_endswith(const char *__restrict str, const char *__restrict end, size_t str_len) ATTR_NONNULL(1
char char size_t char * BLI_strncat(char *__restrict dst, const char *__restrict src, size_t dst_maxncpy) ATTR_NONNULL(1
char * STRNCPY(char(&dst)[N], const char *src)
Definition BLI_string.h:688
size_t BLI_string_flip_side_name(char *name_dst, const char *name_src, bool strip_number, size_t name_dst_maxncpy) ATTR_NONNULL(1
char * BLI_string_replaceN(const char *__restrict str, const char *__restrict substr_old, const char *__restrict substr_new) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1
#define ELEM(...)
#define STREQ(a, b)
#define DATA_(msgid)
void DEG_id_tag_update(ID *id, unsigned int flags)
@ ID_RECALC_SELECT
Definition DNA_ID.h:1009
@ ID_RECALC_ANIMATION_NO_FLUSH
Definition DNA_ID.h:1084
@ ID_OB
#define MAXBONENAME
@ BONE_ROOTSEL
@ BONE_SELECTED
@ BONE_TIPSEL
@ BONE_CONNECTED
@ BONE_RELATIVE_PARENTING
@ ARM_MIRROR_EDIT
@ ARM_DRAW_TYPE_ARMATURE_DEFINED
@ CONSTRAINT_TYPE_TRACKTO
@ CONSTRAINT_TYPE_TRANSFORM
@ CONSTRAINT_TYPE_SHRINKWRAP
@ CONSTRAINT_TYPE_ROTLIMIT
@ CONSTRAINT_TYPE_KINEMATIC
@ CONSTRAINT_TYPE_LOCLIMIT
@ CONSTRAINT_TYPE_LOCKTRACK
@ CONSTRAINT_TYPE_ACTION
@ CONSTRAINT_TYPE_DAMPTRACK
@ CONSTRAINT_SPACE_LOCAL
@ TRANS_ROTATION
@ TRANS_LOCATION
Object is a sort of wrapper for general info.
@ OB_ARMATURE
@ USER_ADD_VIEWALIGNED
@ OPERATOR_CANCELLED
@ OPERATOR_FINISHED
@ OPERATOR_PASS_THROUGH
#define EBONE_SELECTABLE(arm, ebone)
void ED_outliner_select_sync_from_edit_bone_tag(bContext *C)
bool ED_operator_editarmature(bContext *C)
void ED_view3d_win_to_3d(const View3D *v3d, const ARegion *region, const float depth_pt[3], const float mval[2], float r_out[3])
#define X
#define Z
#define Y
Read Guarded memory(de)allocation.
@ PROP_SKIP_SAVE
Definition RNA_types.hh:330
#define C
Definition RandGen.cpp:29
#define ND_BONE_SELECT
Definition WM_types.hh:457
#define NC_OBJECT
Definition WM_types.hh:376
@ OPTYPE_DEPENDS_ON_CURSOR
Definition WM_types.hh:218
@ OPTYPE_UNDO
Definition WM_types.hh:182
@ OPTYPE_REGISTER
Definition WM_types.hh:180
EditBone * ED_armature_ebone_add(bArmature *arm, const char *name)
void ARMATURE_OT_subdivide(wmOperatorType *ot)
EditBone * ED_armature_ebone_add_primitive(Object *obedit_arm, const float length, const bool view_aligned)
static void update_duplicate_constraint_settings(EditBone *dup_bone, EditBone *orig_bone, Object *ob)
EditBone * duplicateEditBone(EditBone *cur_bone, const char *name, ListBase *editbones, Object *ob)
static void track_axis_x_swap(int &value)
static void update_duplicate_action_constraint_settings(EditBone *dup_bone, EditBone *orig_bone, Object *ob, bPoseChannel *pchan, bConstraint *curcon)
static wmOperatorStatus armature_subdivide_exec(bContext *C, wmOperator *op)
static wmOperatorStatus armature_click_extrude_invoke(bContext *C, wmOperator *op, const wmEvent *event)
static wmOperatorStatus armature_duplicate_selected_exec(bContext *C, wmOperator *op)
static void update_duplicate_transform_constraint_settings(Object *ob, bPoseChannel *pchan, bConstraint *curcon)
static void update_duplicate_kinematics_constraint_settings(bConstraint *curcon)
static EditBone * get_symmetrized_bone(bArmature *arm, EditBone *bone)
void ED_armature_ebone_copy(EditBone *dest, const EditBone *source)
void ARMATURE_OT_click_extrude(wmOperatorType *ot)
static wmOperatorStatus armature_click_extrude_exec(bContext *C, wmOperator *)
static wmOperatorStatus armature_bone_primitive_add_exec(bContext *C, wmOperator *op)
static void mirror_bone_collection_assignments(bArmature &armature, EditBone &source_bone, EditBone &target_bone)
static void update_duplicate_subtarget(EditBone *dup_bone, Object *ob, const bool lookup_mirror_subtarget)
static wmOperatorStatus armature_extrude_exec(bContext *C, wmOperator *op)
static void update_duplicate_constraint_shrinkwrap_settings(bConstraint *curcon)
static void update_duplicate_constraint_damp_track_settings(bConstraint *curcon)
void ARMATURE_OT_duplicate(wmOperatorType *ot)
void ARMATURE_OT_symmetrize(wmOperatorType *ot)
void ARMATURE_OT_extrude(wmOperatorType *ot)
static void pre_edit_bone_duplicate(ListBase *editbones)
static void mirror_pose_bone(Object &ob, EditBone &ebone)
static bPoseChannel * pchan_duplicate_map(const bPose *pose, const blender::Map< blender::StringRefNull, blender::StringRefNull > &name_map, bPoseChannel *pchan_src)
void ARMATURE_OT_bone_primitive_add(wmOperatorType *ot)
static void pose_edit_bone_duplicate(ListBase *editbones, Object *ob)
static void update_duplicate_constraint_lock_track_settings(bConstraint *curcon)
static void update_duplicate_custom_bone_shapes(bContext *C, EditBone *dup_bone, Object *ob)
static wmOperatorStatus armature_symmetrize_exec(bContext *C, wmOperator *op)
static void update_duplicate_constraint_track_to_settings(bConstraint *curcon)
static void update_duplicate_loc_rot_constraint_settings(Object *ob, bPoseChannel *pchan, bConstraint *curcon)
static void copy_pchan(EditBone *src_bone, EditBone *dst_bone, Object *src_ob, Object *dst_ob)
EditBone * add_points_bone(Object *obedit, float head[3], float tail[3])
EditBone * duplicateEditBoneObjects(EditBone *cur_bone, const char *name, ListBase *editbones, Object *src_ob, Object *dst_ob)
void ED_armature_ebone_unique_name(ListBase *ebones, char *name, EditBone *bone)
bool ED_armature_edit_deselect_all(Object *obedit)
void ED_armature_edit_transform_mirror_update(Object *obedit)
EditBone * ED_armature_ebone_find_name(const ListBase *edbo, const char *name)
void ED_armature_ebone_listbase_temp_clear(ListBase *lb)
void ED_armature_edit_sync_selection(ListBase *edbo)
void ED_armature_ebone_select_set(EditBone *ebone, bool select)
EditBone * ED_armature_ebone_get_mirrored(const ListBase *edbo, EditBone *ebo)
#define U
BMesh const char void * data
Value lookup_default(const Key &key, const Value &default_value) const
Definition BLI_map.hh:570
bool add_as(ForwardKey &&key, ForwardValue &&...value)
Definition BLI_map.hh:312
constexpr bool is_empty() const
constexpr const char * c_str() const
void append(const T &value)
bool fcurve_assign_to_channel_group(FCurve &fcurve, bActionGroup &to_group)
bActionGroup & channel_group_ensure(StringRefNull name)
#define fabsf(x)
float length(VecOp< float, D >) RET
#define MAX_ID_NAME
void * MEM_mallocN(size_t len, const char *str)
Definition mallocn.cc:128
void * MEM_callocN(size_t len, const char *str)
Definition mallocn.cc:118
void MEM_freeN(void *vmemh)
Definition mallocn.cc:113
bool fcurve_matches_collection_path(const FCurve &fcurve, StringRefNull collection_rna_path, StringRefNull data_name)
bool bone_is_visible_editbone(const bArmature *armature, const EditBone *ebone)
Vector< FCurve * > fcurves_in_action_slot_filtered(bAction *act, slot_handle_t slot_handle, FunctionRef< bool(const FCurve &fcurve)> predicate)
const animrig::Channelbag * channelbag_for_action_slot(const Action &action, slot_handle_t slot_handle)
int armature_bonecoll_find_index(const bArmature *armature, const ::BoneCollection *bcoll)
int armature_bonecoll_find_parent_index(const bArmature *armature, int bcoll_index)
void RNA_string_get(PointerRNA *ptr, const char *name, char *value)
int RNA_int_get(PointerRNA *ptr, const char *name)
bool RNA_boolean_get(PointerRNA *ptr, const char *name)
int RNA_enum_get(PointerRNA *ptr, const char *name)
PropertyRNA * RNA_def_string(StructOrFunctionRNA *cont_, const char *identifier, const char *default_value, const int maxlen, const char *ui_name, const char *ui_description)
PropertyRNA * RNA_def_enum(StructOrFunctionRNA *cont_, const char *identifier, const EnumPropertyItem *items, const int default_value, const char *ui_name, const char *ui_description)
PropertyRNA * RNA_def_boolean(StructOrFunctionRNA *cont_, const char *identifier, const bool default_value, const char *ui_name, const char *ui_description)
void RNA_def_property_flag(PropertyRNA *prop, PropertyFlag flag)
PropertyRNA * RNA_def_int(StructOrFunctionRNA *cont_, const char *identifier, const int default_value, const int hardmin, const int hardmax, const char *ui_name, const char *ui_description, const int softmin, const int softmax)
float vec[3][3]
struct BoneCollection * bcoll
ThemeWireColor custom
float curve_out_z
float scale_in[3]
char name[64]
short bbone_prev_flag
float ease2
float weight
float roll1
::BoneColor color
short segments
float tail[3]
IDProperty * prop
char bbone_prev_type
EditBone * parent
float roll2
ListBase bone_collections
float curve_in_x
float zwidth
union EditBone::@313026223344046157307162027212134045115206003172 temp
short bbone_next_flag
float curve_in_z
float length
float xwidth
EditBone * next
EditBone * bbone_prev
char bbone_next_type
IDProperty * system_properties
float rad_tail
EditBone * bbone_next
EditBone * ebone
float ease1
eBone_BBoneMappingMode bbone_mapping_mode
float rad_head
float scale_out[3]
char inherit_scale_mode
float curve_out_x
float head[3]
char * rna_path
BezTriple * bezt
int array_index
char name[66]
Definition DNA_ID.h:415
void * last
void * first
struct bPose * pose
ObjectRuntimeHandle * runtime
float viewmat[4][4]
View3DCursor cursor
unsigned char select[4]
unsigned char solid[4]
unsigned char active[4]
struct BoneCollection * active_collection
struct EditBone * act_edbone
ListBase * edbo
struct bArmature_Runtime runtime
struct bPoseChannel * pchan
struct Scene * scene
struct Object * ob
struct Depsgraph * depsgraph
float custom_scale_xyz[3]
float custom_rotation_euler[3]
struct bPoseChannel * custom_tx
struct bPoseChannel * bbone_next
struct Object * custom
float custom_translation[3]
struct bPoseChannel * bbone_prev
int mval[2]
Definition WM_types.hh:760
struct ReportList * reports
struct PointerRNA * ptr
i
Definition text_draw.cc:230
void WM_event_add_notifier(const bContext *C, uint type, void *reference)
wmOperatorType * ot
Definition wm_files.cc:4226
wmOperatorStatus WM_operator_flag_only_pass_through_on_press(wmOperatorStatus retval, const wmEvent *event)