Blender V5.0
object_constraint.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
8
9#include <algorithm>
10#include <cstdio>
11#include <cstring>
12
13#include "MEM_guardedalloc.h"
14
15#include "BLI_dynstr.h"
16#include "BLI_listbase.h"
17#include "BLI_math_matrix.h"
18#include "BLI_math_vector.h"
19#include "BLI_string_utf8.h"
20#include "BLI_utildefines.h"
21
22#include "BLT_translation.hh"
23
24#include "DNA_anim_types.h"
25#include "DNA_armature_types.h"
27#include "DNA_curve_types.h"
28#include "DNA_object_types.h"
29#include "DNA_scene_types.h"
30#include "DNA_text_types.h"
31
32#include "BIK_api.h"
33#include "BKE_action.hh"
34#include "BKE_armature.hh"
35#include "BKE_constraint.h"
36#include "BKE_context.hh"
37#include "BKE_fcurve.hh"
38#include "BKE_layer.hh"
39#include "BKE_library.hh"
40#include "BKE_main.hh"
41#include "BKE_object.hh"
42#include "BKE_report.hh"
43#include "BKE_tracking.h"
44
45#include "DEG_depsgraph.hh"
48
49#ifdef WITH_PYTHON
50# include "BPY_extern.hh"
51#endif
52
53#include "WM_api.hh"
54#include "WM_types.hh"
55
56#include "RNA_access.hh"
57#include "RNA_define.hh"
58#include "RNA_enum_types.hh"
59#include "RNA_path.hh"
60#include "RNA_prototypes.hh"
61
62#include "ED_object.hh"
63#include "ED_screen.hh"
64
65#include "ANIM_action.hh"
66#include "ANIM_action_legacy.hh"
67#include "ANIM_animdata.hh"
68
69#include "UI_interface.hh"
71#include "UI_resources.hh"
72
73#include "object_intern.hh"
74
75namespace blender::ed::object {
76
77/* ------------------------------------------------------------------- */
80
82{
83 if (ob == nullptr) {
84 return nullptr;
85 }
86
87 if (ob->mode & OB_MODE_POSE) {
88 bPoseChannel *pchan;
89
91 if (pchan) {
92 return &pchan->constraints;
93 }
94 }
95 else {
96 return &ob->constraints;
97 }
98
99 return nullptr;
100}
101
103{
104 bPoseChannel *pose_bone = static_cast<bPoseChannel *>(CTX_data_pointer_get(C, "pose_bone").data);
105 if (pose_bone == nullptr) {
106 pose_bone = static_cast<bPoseChannel *>(CTX_data_pointer_get(C, "active_pose_bone").data);
107 if (pose_bone == nullptr) {
108 return nullptr;
109 }
110 }
111
112 return &pose_bone->constraints;
113}
114
116{
117 if (r_pchan) {
118 *r_pchan = nullptr;
119 }
120
121 if (ELEM(nullptr, ob, con)) {
122 return nullptr;
123 }
124
125 /* try object constraints first */
126 if (BLI_findindex(&ob->constraints, con) != -1) {
127 return &ob->constraints;
128 }
129
130 /* if armature, try pose bones too */
131 if (ob->pose) {
132 /* try each bone in order
133 * NOTE: it's not possible to directly look up the active bone yet, so this will have to do
134 */
135 LISTBASE_FOREACH (bPoseChannel *, pchan, &ob->pose->chanbase) {
136 if (BLI_findindex(&pchan->constraints, con) != -1) {
137
138 if (r_pchan) {
139 *r_pchan = pchan;
140 }
141
142 return &pchan->constraints;
143 }
144 }
145 }
146
147 /* done */
148 return nullptr;
149}
150
155
157
158/* ------------------------------------------------------------------- */
161
162/* helper function for add_constriant - sets the last target for the active constraint */
164 Object *target,
165 const char subtarget[],
166 int index)
167{
168 ListBase targets = {nullptr, nullptr};
170 int targets_num, i;
171
172 if (BKE_constraint_targets_get(con, &targets)) {
173 targets_num = BLI_listbase_count(&targets);
174
175 if (index < 0) {
176 if (abs(index) < targets_num) {
177 index = targets_num - abs(index);
178 }
179 else {
180 index = targets_num - 1;
181 }
182 }
183 else if (index >= targets_num) {
184 index = targets_num - 1;
185 }
186
187 for (ct = static_cast<bConstraintTarget *>(targets.first), i = 0; ct; ct = ct->next, i++) {
188 if (i == index) {
189 ct->tar = target;
190 STRNCPY_UTF8(ct->subtarget, subtarget);
191 break;
192 }
193 }
194
195 BKE_constraint_targets_flush(con, &targets, false);
196 }
197}
198
200
201/* ------------------------------------------------------------------- */
204
205static void test_constraint(
206 Main *bmain, Object *owner, bPoseChannel *pchan, bConstraint *con, int type)
207{
208 ListBase targets = {nullptr, nullptr};
209 bool check_targets = true;
210
211 /* clear disabled-flag first */
213
214 if (con->type == CONSTRAINT_TYPE_KINEMATIC) {
215 bKinematicConstraint *data = static_cast<bKinematicConstraint *>(con->data);
216
217 /* Bad: we need a separate set of checks here as pole-target is optional...
218 * otherwise pole-target must exist too or else the constraint is deemed invalid. */
219
220 /* default IK check ... */
221 if (BKE_object_exists_check(bmain, data->tar) == 0) {
222 data->tar = nullptr;
223 con->flag |= CONSTRAINT_DISABLE;
224 }
225 else if (data->tar == owner) {
227 con->flag |= CONSTRAINT_DISABLE;
228 }
229 }
230
231 if (data->poletar) {
232 if (BKE_object_exists_check(bmain, data->poletar) == 0) {
233 data->poletar = nullptr;
234 con->flag |= CONSTRAINT_DISABLE;
235 }
236 else if (data->poletar == owner) {
237 if (!BKE_armature_find_bone_name(BKE_armature_from_object(owner), data->polesubtarget)) {
238 con->flag |= CONSTRAINT_DISABLE;
239 }
240 }
241 }
242 /* ... can be overwritten here */
243 BIK_test_constraint(owner, con);
244 /* targets have already been checked for this */
245 check_targets = false;
246 }
247 else if (con->type == CONSTRAINT_TYPE_PIVOT) {
248 bPivotConstraint *data = static_cast<bPivotConstraint *>(con->data);
249
250 /* target doesn't have to exist, but if it is non-null, it must exist! */
251 if (data->tar && BKE_object_exists_check(bmain, data->tar) == 0) {
252 data->tar = nullptr;
253 con->flag |= CONSTRAINT_DISABLE;
254 }
255 else if (data->tar == owner) {
257 con->flag |= CONSTRAINT_DISABLE;
258 }
259 }
260
261 /* targets have already been checked for this */
262 check_targets = false;
263 }
264 else if (con->type == CONSTRAINT_TYPE_ACTION) {
265 bActionConstraint *data = static_cast<bActionConstraint *>(con->data);
266
267 /* validate action */
268 if (data->act == nullptr) {
269 /* must have action */
270 con->flag |= CONSTRAINT_DISABLE;
271 }
272 else {
274 if (!ELEM(data->act->idroot, ID_OB, 0)) {
275 /* Only object-rooted actions can be used. */
276 data->act = nullptr;
277 con->flag |= CONSTRAINT_DISABLE;
278 }
279 }
280 else {
281 /* The slot was assigned, so assume that it is suitable to animate the
282 * owner (only suitable slots appear in the drop-down). */
283 animrig::Action &action = data->act->wrap();
284 animrig::Slot *slot = action.slot_for_handle(data->action_slot_handle);
285 if (!slot) {
286 con->flag |= CONSTRAINT_DISABLE;
287 }
288 }
289 }
290
291 /* Skip target checking if we're not using it */
292 if (data->flag & ACTCON_USE_EVAL_TIME) {
293 check_targets = false;
294 }
295 }
296 else if (con->type == CONSTRAINT_TYPE_FOLLOWPATH) {
298
299 /* don't allow track/up axes to be the same */
300 if (data->upflag == data->trackflag) {
301 con->flag |= CONSTRAINT_DISABLE;
302 }
303 if (data->upflag + 3 == data->trackflag) {
304 con->flag |= CONSTRAINT_DISABLE;
305 }
306 }
307 else if (con->type == CONSTRAINT_TYPE_TRACKTO) {
308 bTrackToConstraint *data = static_cast<bTrackToConstraint *>(con->data);
309
310 /* don't allow track/up axes to be the same */
311 if (data->reserved2 == data->reserved1) {
312 con->flag |= CONSTRAINT_DISABLE;
313 }
314 if (data->reserved2 + 3 == data->reserved1) {
315 con->flag |= CONSTRAINT_DISABLE;
316 }
317 }
318 else if (con->type == CONSTRAINT_TYPE_LOCKTRACK) {
319 bLockTrackConstraint *data = static_cast<bLockTrackConstraint *>(con->data);
320
321 if (data->lockflag == data->trackflag) {
322 con->flag |= CONSTRAINT_DISABLE;
323 }
324 if (data->lockflag + 3 == data->trackflag) {
325 con->flag |= CONSTRAINT_DISABLE;
326 }
327 }
328 else if (con->type == CONSTRAINT_TYPE_SPLINEIK) {
329 bSplineIKConstraint *data = static_cast<bSplineIKConstraint *>(con->data);
330
331 /* if the number of points does not match the amount required by the chain length,
332 * free the points array and request a rebind...
333 */
334 if ((data->points == nullptr) || (data->numpoints != data->chainlen + 1)) {
335 MEM_SAFE_FREE(data->points);
336 data->numpoints = 0;
337
338 /* clear the bound flag, forcing a rebind next time this is evaluated */
340 }
341 }
342 else if (con->type == CONSTRAINT_TYPE_FOLLOWTRACK) {
344
345 if ((data->flag & CAMERASOLVER_ACTIVECLIP) == 0) {
346 if (data->clip != nullptr && data->track[0]) {
347 MovieTracking *tracking = &data->clip->tracking;
348 MovieTrackingObject *tracking_object;
349
350 if (data->object[0]) {
351 tracking_object = BKE_tracking_object_get_named(tracking, data->object);
352 }
353 else {
354 tracking_object = BKE_tracking_object_get_camera(tracking);
355 }
356
357 if (!tracking_object) {
358 con->flag |= CONSTRAINT_DISABLE;
359 }
360 else {
361 if (!BKE_tracking_object_find_track_with_name(tracking_object, data->track)) {
362 con->flag |= CONSTRAINT_DISABLE;
363 }
364 }
365 }
366 else {
367 con->flag |= CONSTRAINT_DISABLE;
368 }
369 }
370 }
371 else if (con->type == CONSTRAINT_TYPE_CAMERASOLVER) {
373
374 if ((data->flag & CAMERASOLVER_ACTIVECLIP) == 0 && (data->clip == nullptr)) {
375 con->flag |= CONSTRAINT_DISABLE;
376 }
377 }
378 else if (con->type == CONSTRAINT_TYPE_OBJECTSOLVER) {
380
381 if ((data->flag & CAMERASOLVER_ACTIVECLIP) == 0 && (data->clip == nullptr)) {
382 con->flag |= CONSTRAINT_DISABLE;
383 }
384 }
385 else if (con->type == CONSTRAINT_TYPE_TRANSFORM_CACHE) {
387
388 if ((data->cache_file == nullptr) || (data->object_path[0] == '\0')) {
389 con->flag |= CONSTRAINT_DISABLE;
390 }
391 }
392
393 /* Check targets for constraints */
394 if (check_targets && BKE_constraint_targets_get(con, &targets)) {
395 /* disable and clear constraints targets that are incorrect */
396 LISTBASE_FOREACH (bConstraintTarget *, ct, &targets) {
397 /* general validity checks (for those constraints that need this) */
398 if (BKE_object_exists_check(bmain, ct->tar) == 0) {
399 /* object doesn't exist, but constraint requires target */
400 ct->tar = nullptr;
401 con->flag |= CONSTRAINT_DISABLE;
402 }
403 else if (ct->tar == owner) {
404 if (type == CONSTRAINT_OBTYPE_BONE) {
405 if (!BKE_armature_find_bone_name(BKE_armature_from_object(owner), ct->subtarget)) {
406 /* bone must exist in armature... */
407 /* TODO: clear subtarget? */
408 con->flag |= CONSTRAINT_DISABLE;
409 }
410 else if (STREQ(pchan->name, ct->subtarget)) {
411 /* cannot target self */
412 ct->subtarget[0] = '\0';
413 con->flag |= CONSTRAINT_DISABLE;
414 }
415 }
416 else {
417 /* cannot use self as target */
418 ct->tar = nullptr;
419 con->flag |= CONSTRAINT_DISABLE;
420 }
421 }
422
423 /* target checks for specific constraints */
424 if (ELEM(con->type,
428 {
429 if (ct->tar) {
430 /* The object type check is only needed here in case we have a placeholder
431 * object assigned (because the library containing the curve is missing).
432 *
433 * In other cases it should be impossible to have a type mismatch.
434 */
435 if (ct->tar->type != OB_CURVES_LEGACY) {
436 con->flag |= CONSTRAINT_DISABLE;
437 }
438 else {
439 Curve *cu = static_cast<Curve *>(ct->tar->data);
440
441 /* auto-set 'Path' setting on curve so this works. */
442 cu->flag |= CU_PATH;
443 }
444 }
445 }
446 else if (con->type == CONSTRAINT_TYPE_ARMATURE) {
447 if (ct->tar) {
448 /* The object type check is only needed here in case we have a placeholder
449 * object assigned (because the library containing the armature is missing).
450 *
451 * In other cases it should be impossible to have a type mismatch.
452 */
453 if (ct->tar->type != OB_ARMATURE) {
454 con->flag |= CONSTRAINT_DISABLE;
455 }
456 else if (!BKE_armature_find_bone_name(BKE_armature_from_object(ct->tar), ct->subtarget))
457 {
458 /* bone must exist in armature... */
459 con->flag |= CONSTRAINT_DISABLE;
460 }
461 }
462 }
463 }
464
465 /* free any temporary targets */
466 BKE_constraint_targets_flush(con, &targets, false);
467 }
468 else if (check_targets) {
469 /* constraints with empty target list that actually require targets */
471 con->flag |= CONSTRAINT_DISABLE;
472 }
473 }
474}
475
476static int constraint_type_get(Object *owner, bPoseChannel *pchan)
477{
478 int type;
479 /* Check parents */
480 if (pchan) {
481 switch (owner->type) {
482 case OB_ARMATURE:
484 break;
485 default:
487 break;
488 }
489 }
490 else {
492 }
493 return type;
494}
495
496/* checks validity of object pointers, and NULLs,
497 * if Bone doesn't exist it sets the CONSTRAINT_DISABLE flag.
498 */
499static void test_constraints(Main *bmain, Object *ob, bPoseChannel *pchan)
500{
501 ListBase *conlist = nullptr;
502 int type;
503
504 if (ob == nullptr) {
505 return;
506 }
507
508 type = constraint_type_get(ob, pchan);
509
510 /* Get the constraint list for this object */
511 switch (type) {
513 conlist = &ob->constraints;
514 break;
516 conlist = &pchan->constraints;
517 break;
518 }
519
520 /* Check all constraints - is constraint valid? */
521 if (conlist) {
522 LISTBASE_FOREACH (bConstraint *, curcon, conlist) {
523 test_constraint(bmain, ob, pchan, curcon, type);
524 }
525 }
526}
527
529{
530 if (ob->constraints.first) {
531 test_constraints(bmain, ob, nullptr);
532 }
533
534 if (ob->type == OB_ARMATURE && ob->pose) {
535 LISTBASE_FOREACH (bPoseChannel *, pchan, &ob->pose->chanbase) {
536 if (pchan->constraints.first) {
537 test_constraints(bmain, ob, pchan);
538 }
539 }
540 }
541}
542
543static void object_test_constraint(Main *bmain, Object *ob, bConstraint *con)
544{
545 if (ob->type == OB_ARMATURE && ob->pose) {
546 if (BLI_findindex(&ob->constraints, con) != -1) {
547 test_constraint(bmain, ob, nullptr, con, CONSTRAINT_OBTYPE_OBJECT);
548 }
549 else {
550 LISTBASE_FOREACH (bPoseChannel *, pchan, &ob->pose->chanbase) {
551 if (BLI_findindex(&pchan->constraints, con) != -1) {
552 test_constraint(bmain, ob, pchan, con, CONSTRAINT_OBTYPE_BONE);
553 break;
554 }
555 }
556 }
557 }
558 else {
559 test_constraint(bmain, ob, nullptr, con, CONSTRAINT_OBTYPE_OBJECT);
560 }
561}
562
564
565/* ------------------------------------------------------------------- */
568
569#define EDIT_CONSTRAINT_OWNER_OBJECT 0
570#define EDIT_CONSTRAINT_OWNER_BONE 1
571
574 "OBJECT",
575 0,
576 "Object",
577 "Edit a constraint on the active object"},
578 {EDIT_CONSTRAINT_OWNER_BONE, "BONE", 0, "Bone", "Edit a constraint on the active bone"},
579 {0, nullptr, 0, nullptr, nullptr},
580};
581
583 StructRNA *rna_type,
584 const bool is_liboverride_allowed)
585{
586 PointerRNA ptr = CTX_data_pointer_get_type(C, "constraint", rna_type);
587 Object *ob = (ptr.owner_id) ? (Object *)ptr.owner_id : context_active_object(C);
588 bConstraint *con = static_cast<bConstraint *>(ptr.data);
589
591 return false;
592 }
593
594 if (ptr.owner_id != nullptr && !ID_IS_EDITABLE(ptr.owner_id)) {
595 CTX_wm_operator_poll_msg_set(C, "Cannot edit library data");
596 return false;
597 }
598
599 if (!is_liboverride_allowed && BKE_constraint_is_nonlocal_in_liboverride(ob, con)) {
601 C, "Cannot edit constraints coming from linked data in a library override");
602 return false;
603 }
604
605 return true;
606}
607
609{
610 return edit_constraint_poll_generic(C, &RNA_Constraint, false);
611}
612
613/* Used by operators performing actions allowed also on constraints from the overridden linked
614 * object (not only from added 'local' ones). */
616{
617 return edit_constraint_poll_generic(C, &RNA_Constraint, true);
618}
619
621{
622 PropertyRNA *prop;
623 prop = RNA_def_string(
624 ot->srna, "constraint", nullptr, MAX_NAME, "Constraint", "Name of the constraint to edit");
626 prop = RNA_def_enum(
627 ot->srna, "owner", constraint_owner_items, 0, "Owner", "The owner of this constraint");
629}
630
632{
634 ot->srna, "report", false, "Report", "Create a notification after the operation");
636}
637
639 wmOperator *op,
640 const wmEvent *event,
641 wmOperatorStatus *r_retval)
642{
643 PointerRNA ptr = CTX_data_pointer_get_type(C, "constraint", &RNA_Constraint);
644 Object *ob = (ptr.owner_id) ? (Object *)ptr.owner_id : context_active_object(C);
645 bConstraint *con;
646 ListBase *list;
647
648 if (RNA_struct_property_is_set(op->ptr, "constraint") &&
649 RNA_struct_property_is_set(op->ptr, "owner"))
650 {
651 return true;
652 }
653
654 if (ptr.data) {
655 con = static_cast<bConstraint *>(ptr.data);
656 RNA_string_set(op->ptr, "constraint", con->name);
657
658 list = constraint_list_from_constraint(ob, con, nullptr);
659
660 if (&ob->constraints == list) {
662 }
663 else {
665 }
666
667 return true;
668 }
669
670 /* Check the custom data of panels under the mouse for a modifier. */
671 if (event != nullptr) {
673
674 if (!(panel_ptr == nullptr || RNA_pointer_is_null(panel_ptr))) {
675 if (RNA_struct_is_a(panel_ptr->type, &RNA_Constraint)) {
676 con = static_cast<bConstraint *>(panel_ptr->data);
677 RNA_string_set(op->ptr, "constraint", con->name);
678 list = constraint_list_from_constraint(ob, con, nullptr);
679 RNA_enum_set(op->ptr,
680 "owner",
683
684 return true;
685 }
686
687 BLI_assert(r_retval != nullptr); /* We need the return value in this case. */
688 if (r_retval != nullptr) {
690 }
691 return false;
692 }
693 }
694
695 if (r_retval != nullptr) {
696 *r_retval = OPERATOR_CANCELLED;
697 }
698 return false;
699}
700
702{
703 char constraint_name[MAX_NAME];
704 int owner = RNA_enum_get(op->ptr, "owner");
705 bConstraint *con;
706 ListBase *list = nullptr;
707
708 RNA_string_get(op->ptr, "constraint", constraint_name);
709
710 if (owner == EDIT_CONSTRAINT_OWNER_BONE) {
711 list = pose_constraint_list(C);
712 if (!list) {
713 return nullptr;
714 }
715 }
716 else {
717 list = &ob->constraints;
718 }
719
720 con = BKE_constraints_find_name(list, constraint_name);
721#if 0
722 if (G.debug & G_DEBUG) {
723 printf("constraint found = %p, %s\n", (void *)con, (con) ? con->name : "<Not found>");
724 }
725#endif
726
727 if (con && (type != 0) && (con->type != type)) {
728 con = nullptr;
729 }
730
731 return con;
732}
733
735
736/* ------------------------------------------------------------------- */
741
743{
744 Main *bmain = CTX_data_main(C);
747 bStretchToConstraint *data = (con) ? (bStretchToConstraint *)con->data : nullptr;
748
749 /* despite 3 layers of checks, we may still not be able to find a constraint */
750 if (data == nullptr) {
751 return OPERATOR_CANCELLED;
752 }
753
754 /* just set original length to 0.0, which will cause a reset on next recalc */
755 data->orglength = 0.0f;
756 constraint_update(bmain, ob);
757
759 return OPERATOR_FINISHED;
760}
761
763 wmOperator *op,
764 const wmEvent * /*event*/)
765{
766 if (edit_constraint_invoke_properties(C, op, nullptr, nullptr)) {
767 return stretchto_reset_exec(C, op);
768 }
769 return OPERATOR_CANCELLED;
770}
771
773{
774 /* identifiers */
775 ot->name = "Reset Original Length";
776 ot->idname = "CONSTRAINT_OT_stretchto_reset";
777 ot->description = "Reset original length of bone for Stretch To Constraint";
778
779 /* callbacks */
780 ot->invoke = stretchto_reset_invoke;
781 ot->exec = stretchto_reset_exec;
783
784 /* flags */
786
787 /* properties */
789}
790
792
793/* ------------------------------------------------------------------- */
798
800{
801 Main *bmain = CTX_data_main(C);
804 bDistLimitConstraint *data = (con) ? (bDistLimitConstraint *)con->data : nullptr;
805
806 /* despite 3 layers of checks, we may still not be able to find a constraint */
807 if (data == nullptr) {
808 return OPERATOR_CANCELLED;
809 }
810
811 /* just set original length to 0.0, which will cause a reset on next recalc */
812 data->dist = 0.0f;
813 constraint_update(bmain, ob);
814
816 return OPERATOR_FINISHED;
817}
818
820 wmOperator *op,
821 const wmEvent * /*event*/)
822{
823 if (edit_constraint_invoke_properties(C, op, nullptr, nullptr)) {
824 return limitdistance_reset_exec(C, op);
825 }
826 return OPERATOR_CANCELLED;
827}
828
830{
831 /* identifiers */
832 ot->name = "Reset Distance";
833 ot->idname = "CONSTRAINT_OT_limitdistance_reset";
834 ot->description = "Reset limiting distance for Limit Distance Constraint";
835
836 /* callbacks */
840
841 /* flags */
843
844 /* properties */
846}
847
849
850/* ------------------------------------------------------------------- */
853
854/* Force evaluation so that the 'set inverse' flag is handled.
855 * No-op when the constraint is enabled, as in such cases the evaluation will happen anyway.
856 */
858{
859 if ((con->flag & (CONSTRAINT_DISABLE | CONSTRAINT_OFF)) == 0) {
860 return;
861 }
862
865
866 short flag_backup = con->flag;
869 con->flag = flag_backup;
870}
871
872/* ChildOf Constraint - set inverse callback */
874{
875 Main *bmain = CTX_data_main(C);
878 bChildOfConstraint *data = (con) ? (bChildOfConstraint *)con->data : nullptr;
879
880 /* despite 3 layers of checks, we may still not be able to find a constraint */
881 if (data == nullptr) {
882 printf("DEBUG: Child-Of Set Inverse - object = '%s'\n", (ob) ? ob->id.name + 2 : "<None>");
883 BKE_report(op->reports, RPT_ERROR, "Could not find constraint data for Child-Of Set Inverse");
884 return OPERATOR_CANCELLED;
885 }
886
887 /* Set a flag to request recalculation on next update. */
888 data->flag |= CHILDOF_SET_INVERSE;
889
890 /* Force constraint to run, it will perform the recalculation. */
892
893 constraint_update(bmain, ob);
895
896 return OPERATOR_FINISHED;
897}
898
900 wmOperator *op,
901 const wmEvent * /*event*/)
902{
903 if (edit_constraint_invoke_properties(C, op, nullptr, nullptr)) {
904 return childof_set_inverse_exec(C, op);
905 }
906 return OPERATOR_CANCELLED;
907}
908
910{
911 /* identifiers */
912 ot->name = "Set Inverse";
913 ot->idname = "CONSTRAINT_OT_childof_set_inverse";
914 ot->description = "Set inverse correction for Child Of constraint";
915
916 /* callbacks */
920
921 /* flags */
923
924 /* properties */
926}
927
928/* ChildOf Constraint - clear inverse callback */
930{
931 Main *bmain = CTX_data_main(C);
934 bChildOfConstraint *data = (con) ? (bChildOfConstraint *)con->data : nullptr;
935
936 if (data == nullptr) {
937 BKE_report(op->reports, RPT_ERROR, "Child Of constraint not found");
938 return OPERATOR_CANCELLED;
939 }
940
941 /* simply clear the matrix */
942 unit_m4(data->invmat);
943
944 constraint_update(bmain, ob);
946
947 return OPERATOR_FINISHED;
948}
949
951 wmOperator *op,
952 const wmEvent * /*event*/)
953{
954 if (edit_constraint_invoke_properties(C, op, nullptr, nullptr)) {
955 return childof_clear_inverse_exec(C, op);
956 }
957 return OPERATOR_CANCELLED;
958}
959
961{
963 return false;
964 }
965
966 PointerRNA ptr = CTX_data_pointer_get_type(C, "constraint", &RNA_Constraint);
967 bConstraint *con = static_cast<bConstraint *>(ptr.data);
968
969 /* Allow workflows with unset context's constraint.
970 * The constraint can also be provided as an operator's property. */
971 if (con == nullptr) {
972 return true;
973 }
974
975 if (con->type != CONSTRAINT_TYPE_CHILDOF) {
976 return false;
977 }
978
979 bChildOfConstraint *data = static_cast<bChildOfConstraint *>(con->data);
980
981 if (is_identity_m4(data->invmat)) {
982 CTX_wm_operator_poll_msg_set(C, "No inverse correction is set, so there is nothing to clear");
983 return false;
984 }
985 return true;
986}
987
989{
990 /* identifiers */
991 ot->name = "Clear Inverse";
992 ot->idname = "CONSTRAINT_OT_childof_clear_inverse";
993 ot->description = "Clear inverse correction for Child Of constraint";
994
995 /* callbacks */
999
1000 /* flags */
1001 ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
1002
1003 /* properties */
1005}
1006
1008
1009/* ------------------------------------------------------------------- */
1012
1014{
1015 Main *bmain = CTX_data_main(C);
1018 bFollowPathConstraint *data = (con) ? (bFollowPathConstraint *)con->data : nullptr;
1019
1020 bAction *act = nullptr;
1021 FCurve *fcu = nullptr;
1022 int sfra = RNA_int_get(op->ptr, "frame_start");
1023 int len = RNA_int_get(op->ptr, "length");
1024 float standardRange = 1.0;
1025
1026 /* nearly impossible sanity check */
1027 if (data == nullptr) {
1028 BKE_report(op->reports, RPT_ERROR, "Follow Path constraint not found");
1029 return OPERATOR_CANCELLED;
1030 }
1031
1032 /* add F-Curve as appropriate */
1033 if (data->tar) {
1034 Curve *cu = (Curve *)data->tar->data;
1035
1036 if (ELEM(nullptr, cu->adt, cu->adt->action) ||
1037 (animrig::fcurve_find_in_assigned_slot(*cu->adt, {"eval_time", 0}) == nullptr))
1038 {
1039 /* create F-Curve for path animation */
1040 act = animrig::id_action_ensure(bmain, &cu->id);
1041 PointerRNA id_ptr = RNA_id_pointer_create(&cu->id);
1042 fcu = animrig::action_fcurve_ensure_ex(bmain, act, nullptr, &id_ptr, {"eval_time", 0});
1043
1044 /* standard vertical range - 1:1 = 100 frames */
1045 standardRange = 100.0f;
1046 }
1047 else {
1048 /* path anim exists already - abort for now as this may well be what was intended */
1049 BKE_report(op->reports, RPT_WARNING, "Path is already animated");
1050 return OPERATOR_CANCELLED;
1051 }
1052 }
1053 else {
1054 /* animate constraint's "fixed offset" */
1055 PropertyRNA *prop;
1056
1057 /* get RNA pointer to constraint's "offset_factor" property - to build RNA path */
1058 PointerRNA ptr = RNA_pointer_create_discrete(&ob->id, &RNA_FollowPathConstraint, con);
1059 prop = RNA_struct_find_property(&ptr, "offset_factor");
1060
1061 const std::optional<std::string> path = RNA_path_from_ID_to_property(&ptr, prop);
1062 BLI_assert(path.has_value());
1063
1064 /* create F-Curve for constraint */
1065 act = animrig::id_action_ensure(bmain, &ob->id);
1066 PointerRNA id_ptr = RNA_id_pointer_create(&ob->id);
1067 fcu = animrig::action_fcurve_ensure_ex(bmain, act, nullptr, &id_ptr, {path->c_str(), 0});
1068
1069 /* standard vertical range - 0.0 to 1.0 */
1070 standardRange = 1.0f;
1071
1072 /* enable "Use Fixed Position" so that animating this has effect */
1073 data->followflag |= FOLLOWPATH_STATIC;
1074 }
1075
1076 /* setup dummy 'generator' modifier here to get 1-1 correspondence still working
1077 * and define basic slope of this curve based on the properties
1078 */
1079 if (!fcu->bezt && !fcu->fpt && !fcu->modifiers.first) {
1081 FMod_Generator *gen = static_cast<FMod_Generator *>(fcm->data);
1082
1083 /* Assume that we have the following equation:
1084 * y = Ax + B
1085 * 1 0 <-- coefficients array indices
1086 */
1087 float A = standardRange / float(len);
1088 float B = float(-sfra) * A;
1089
1090 gen->coefficients[1] = A;
1091 gen->coefficients[0] = B;
1092 }
1093
1094 /* updates... */
1096 return OPERATOR_FINISHED;
1097}
1098
1100 wmOperator *op,
1101 const wmEvent * /*event*/)
1102{
1103 /* hook up invoke properties for figuring out which constraint we're dealing with */
1104 if (edit_constraint_invoke_properties(C, op, nullptr, nullptr)) {
1105 return followpath_path_animate_exec(C, op);
1106 }
1107 return OPERATOR_CANCELLED;
1108}
1109
1111{
1112 /* identifiers */
1113 ot->name = "Auto Animate Path";
1114 ot->idname = "CONSTRAINT_OT_followpath_path_animate";
1115 ot->description =
1116 "Add default animation for path used by constraint if it isn't animated already";
1117
1118 /* callbacks */
1121 ot->poll = edit_constraint_poll;
1122
1123 /* flags */
1124 ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
1125
1126 /* props */
1128 RNA_def_int(ot->srna,
1129 "frame_start",
1130 1,
1131 MINAFRAME,
1132 MAXFRAME,
1133 "Start Frame",
1134 "First frame of path animation",
1135 MINAFRAME,
1136 MAXFRAME);
1137 RNA_def_int(ot->srna,
1138 "length",
1139 100,
1140 0,
1141 MAXFRAME,
1142 "Length",
1143 "Number of frames that path animation should take",
1144 0,
1145 MAXFRAME);
1146}
1147
1149
1150/* ------------------------------------------------------------------- */
1153
1155{
1156 Main *bmain = CTX_data_main(C);
1159 bObjectSolverConstraint *data = (con) ? (bObjectSolverConstraint *)con->data : nullptr;
1160
1161 /* despite 3 layers of checks, we may still not be able to find a constraint */
1162 if (data == nullptr) {
1163 printf("DEBUG: ObjectSolver Set Inverse - object = '%s'\n", (ob) ? ob->id.name + 2 : "<None>");
1164 BKE_report(
1165 op->reports, RPT_ERROR, "Could not find constraint data for ObjectSolver Set Inverse");
1166 return OPERATOR_CANCELLED;
1167 }
1168
1169 /* Set a flag to request recalculation on next update. */
1171
1172 /* Force constraint to run, it will perform the recalculation. */
1174
1175 constraint_update(bmain, ob);
1177
1178 return OPERATOR_FINISHED;
1179}
1180
1182 wmOperator *op,
1183 const wmEvent * /*event*/)
1184{
1185 if (edit_constraint_invoke_properties(C, op, nullptr, nullptr)) {
1186 return objectsolver_set_inverse_exec(C, op);
1187 }
1188 return OPERATOR_CANCELLED;
1189}
1190
1192{
1193 /* identifiers */
1194 ot->name = "Set Inverse";
1195 ot->idname = "CONSTRAINT_OT_objectsolver_set_inverse";
1196 ot->description = "Set inverse correction for Object Solver constraint";
1197
1198 /* callbacks */
1201 ot->poll = edit_constraint_poll;
1202
1203 /* flags */
1204 ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
1205
1206 /* properties */
1208}
1209
1211
1212/* ------------------------------------------------------------------- */
1215
1217{
1218 Main *bmain = CTX_data_main(C);
1221 bObjectSolverConstraint *data = (con) ? (bObjectSolverConstraint *)con->data : nullptr;
1222
1223 if (data == nullptr) {
1224 BKE_report(op->reports, RPT_ERROR, "Child Of constraint not found");
1225 return OPERATOR_CANCELLED;
1226 }
1227
1228 /* simply clear the matrix */
1229 unit_m4(data->invmat);
1230
1231 constraint_update(bmain, ob);
1233
1234 return OPERATOR_FINISHED;
1235}
1236
1238 wmOperator *op,
1239 const wmEvent * /*event*/)
1240{
1241 if (edit_constraint_invoke_properties(C, op, nullptr, nullptr)) {
1243 }
1244 return OPERATOR_CANCELLED;
1245}
1246
1248{
1249 if (!edit_constraint_poll(C)) {
1250 return false;
1251 }
1252
1253 PointerRNA ptr = CTX_data_pointer_get_type(C, "constraint", &RNA_Constraint);
1254 bConstraint *con = static_cast<bConstraint *>(ptr.data);
1255 if (con == nullptr) {
1256 return true;
1257 }
1258
1260
1261 if (is_identity_m4(data->invmat)) {
1262 CTX_wm_operator_poll_msg_set(C, "No inverse correction is set, so there is nothing to clear");
1263 return false;
1264 }
1265 return true;
1266}
1267
1269{
1270 /* identifiers */
1271 ot->name = "Clear Inverse";
1272 ot->idname = "CONSTRAINT_OT_objectsolver_clear_inverse";
1273 ot->description = "Clear inverse correction for Object Solver constraint";
1274
1275 /* callbacks */
1279
1280 /* flags */
1281 ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
1282
1283 /* properties */
1285}
1286
1288
1289/* ------------------------------------------------------------------- */
1292
1294{
1295 ListBase *lb = constraint_list_from_constraint(ob, con, nullptr);
1296
1297 /* lets be nice and escape if its active already */
1298 /* NOTE: this assumes that the stack doesn't have other active ones set... */
1299 if ((lb && con) && (con->flag & CONSTRAINT_ACTIVE)) {
1300 return;
1301 }
1302
1304}
1305
1307{
1308 if (ob->pose) {
1310 }
1311
1312 object_test_constraints(bmain, ob);
1313
1314 if (ob->type == OB_ARMATURE) {
1316 }
1317 else {
1319 }
1320}
1321
1322static void object_pose_tag_update(Main *bmain, Object *ob)
1323{
1324 BKE_pose_tag_recalc(bmain, ob->pose); /* Checks & sort pose channels. */
1325}
1326
1328{
1329 constraint_update(bmain, ob);
1330
1331 if (ob->pose) {
1332 object_pose_tag_update(bmain, ob);
1333 }
1335}
1336
1338{
1339 if (ob->pose) {
1341 }
1342
1343 if (con) {
1344 object_test_constraint(bmain, ob, con);
1345 }
1346
1347 if (ob->type == OB_ARMATURE) {
1349 }
1350 else {
1352 }
1353
1354 /* Do Copy-on-Write tag here too, otherwise constraint
1355 * influence/mute buttons in UI have no effect
1356 */
1358}
1359
1361{
1362 constraint_tag_update(bmain, ob, con);
1363
1364 if (ob->pose) {
1365 object_pose_tag_update(bmain, ob);
1366 }
1368}
1369
1370bool constraint_move_to_index(Object *ob, bConstraint *con, const int index)
1371{
1372 BLI_assert(con != nullptr);
1373 BLI_assert(index >= 0);
1374
1375 ListBase *conlist = constraint_list_from_constraint(ob, con, nullptr);
1376 int current_index = BLI_findindex(conlist, con);
1377 BLI_assert(current_index >= 0);
1378
1379 BLI_listbase_link_move(conlist, con, index - current_index);
1380
1382
1383 return true;
1384}
1385
1386void constraint_link(Main *bmain, Object *ob_dst, ListBase *dst, ListBase *src)
1387{
1389 BKE_constraints_copy(dst, src, true);
1390 LISTBASE_FOREACH (bConstraint *, con, dst) {
1391 constraint_dependency_tag_update(bmain, ob_dst, con);
1392 }
1394}
1395
1397{
1398 bConstraint *copy_con = BKE_constraint_copy_for_object(ob_dst, con);
1400
1401 constraint_dependency_tag_update(bmain, ob_dst, con);
1403}
1404
1406{
1407 bConstraint *copy_con = BKE_constraint_copy_for_pose(ob_dst, pchan, con);
1409
1410 constraint_dependency_tag_update(bmain, ob_dst, con);
1412}
1413
1415
1416/* ------------------------------------------------------------------- */
1419
1421{
1422 Main *bmain = CTX_data_main(C);
1424 bConstraint *con = edit_constraint_property_get(C, op, ob, 0);
1425
1426 if (con == nullptr) {
1427 return OPERATOR_CANCELLED;
1428 }
1429
1430 ListBase *lb = constraint_list_from_constraint(ob, con, nullptr);
1431
1432 /* Store name temporarily for report. */
1433 char name[MAX_NAME];
1434 STRNCPY_UTF8(name, con->name);
1435
1436 /* free the constraint */
1437 if (BKE_constraint_remove_ex(lb, ob, con)) {
1438 /* Needed to set the flags on pose-bones correctly. */
1439 constraint_update(bmain, ob);
1440
1441 /* relations */
1443
1444 /* notifiers */
1446
1447 if (RNA_boolean_get(op->ptr, "report")) {
1448 BKE_reportf(op->reports, RPT_INFO, "Removed constraint: %s", name);
1449 }
1450
1451 return OPERATOR_FINISHED;
1452 }
1453 /* couldn't remove due to some invalid data */
1454 return OPERATOR_CANCELLED;
1455}
1456
1458{
1459 wmOperatorStatus retval;
1460 if (!edit_constraint_invoke_properties(C, op, event, &retval)) {
1461 return OPERATOR_CANCELLED;
1462 }
1463 return constraint_delete_exec(C, op);
1464}
1465
1467{
1468 /* identifiers */
1469 ot->name = "Delete Constraint";
1470 ot->idname = "CONSTRAINT_OT_delete";
1471 ot->description = "Remove constraint from constraint stack";
1472
1473 /* callbacks */
1474 ot->invoke = constraint_delete_invoke;
1475 ot->exec = constraint_delete_exec;
1476 ot->poll = edit_constraint_poll;
1477
1478 /* flags */
1479 ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
1482}
1483
1485
1486/* ------------------------------------------------------------------- */
1489
1491{
1492 Scene *scene = CTX_data_scene(C);
1494 Main *bmain = CTX_data_main(C);
1496 bConstraint *con = edit_constraint_property_get(C, op, ob, 0);
1497
1498 if (con == nullptr) {
1499 return OPERATOR_CANCELLED;
1500 }
1501
1502 bPoseChannel *pchan;
1504
1505 /* Store name temporarily for report. */
1506 char name[MAX_NAME];
1507 STRNCPY_UTF8(name, con->name);
1508 const bool is_first_constraint = con != constraints->first;
1509
1510 /* Copy the constraint. */
1511 bool success;
1512 if (pchan) {
1514 depsgraph, scene, constraints, ob, con, pchan);
1515 }
1516 else {
1518 }
1519
1520 if (!success) {
1521 /* Couldn't remove due to some invalid data. */
1522 return OPERATOR_CANCELLED;
1523 }
1524
1525 /* Update for any children that may get moved. */
1527
1528 /* Needed to set the flags on pose-bones correctly. */
1529 constraint_update(bmain, ob);
1530
1533 if (pchan) {
1535 }
1536 else {
1538 }
1539
1540 if (RNA_boolean_get(op->ptr, "report")) {
1541 if (is_first_constraint) {
1542 BKE_report(op->reports,
1543 RPT_INFO,
1544 "Applied constraint was not first, result may not be as expected");
1545 }
1546 else {
1547 /* Only add this report if the operator didn't cause another one. The purpose here is
1548 * to alert that something happened, and the previous report will do that anyway. */
1549 BKE_reportf(op->reports, RPT_INFO, "Applied constraint: %s", name);
1550 }
1551 }
1552
1553 return OPERATOR_FINISHED;
1554}
1555
1557{
1558 wmOperatorStatus retval;
1559 if (!edit_constraint_invoke_properties(C, op, event, &retval)) {
1560 return OPERATOR_CANCELLED;
1561 }
1562 return constraint_apply_exec(C, op);
1563}
1564
1566{
1567 /* identifiers */
1568 ot->name = "Apply Constraint";
1569 ot->idname = "CONSTRAINT_OT_apply";
1570 ot->description = "Apply constraint and remove from the stack";
1571
1572 /* callbacks */
1573 ot->invoke = constraint_apply_invoke;
1574 ot->exec = constraint_apply_exec;
1575 ot->poll = edit_constraint_poll;
1576
1577 /* flags */
1578 ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
1581}
1582
1584
1585/* ------------------------------------------------------------------- */
1588
1590{
1591 Main *bmain = CTX_data_main(C);
1593 bConstraint *con = edit_constraint_property_get(C, op, ob, 0);
1594
1595 if (con == nullptr) {
1596 return OPERATOR_CANCELLED;
1597 }
1598
1599 bPoseChannel *pchan;
1601
1602 /* Store name temporarily for report. */
1603 char name[MAX_NAME];
1604 STRNCPY_UTF8(name, con->name);
1605
1606 /* Copy the constraint. */
1607 bConstraint *copy_con;
1608 if (pchan) {
1609 copy_con = BKE_constraint_copy_for_pose(ob, pchan, con);
1610 }
1611 else {
1612 copy_con = BKE_constraint_copy_for_object(ob, con);
1613 }
1614
1615 if (!copy_con) {
1616 /* Couldn't remove due to some invalid data. */
1617 return OPERATOR_CANCELLED;
1618 }
1620
1621 /* Move constraint to correct position. */
1622 const int new_index = BLI_findindex(constraints, con) + 1;
1623 const int current_index = BLI_findindex(constraints, copy_con);
1624 BLI_assert(new_index >= 0);
1625 BLI_assert(current_index >= 0);
1626 BLI_listbase_link_move(constraints, copy_con, new_index - current_index);
1627
1628 /* Needed to set the flags on pose-bones correctly. */
1629 constraint_update(bmain, ob);
1630
1633
1634 if (RNA_boolean_get(op->ptr, "report")) {
1635 BKE_reportf(op->reports, RPT_INFO, "Copied constraint: %s", name);
1636 }
1637
1638 return OPERATOR_FINISHED;
1639}
1640
1642{
1643 wmOperatorStatus retval;
1644 if (!edit_constraint_invoke_properties(C, op, event, &retval)) {
1645 return OPERATOR_CANCELLED;
1646 }
1647 return constraint_copy_exec(C, op);
1648}
1649
1651{
1652 /* identifiers */
1653 ot->name = "Duplicate Constraint";
1654 ot->idname = "CONSTRAINT_OT_copy";
1655 ot->description = "Duplicate constraint at the same position in the stack";
1656
1657 /* callbacks */
1658 ot->invoke = constraint_copy_invoke;
1659 ot->exec = constraint_copy_exec;
1660 ot->poll = edit_constraint_poll;
1661
1662 /* flags */
1663 ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
1666}
1667
1669
1670/* ------------------------------------------------------------------- */
1673
1675{
1676 Main *bmain = CTX_data_main(C);
1677 Object *obact = context_active_object(C);
1678 bConstraint *con = edit_constraint_property_get(C, op, obact, 0);
1679
1680 if (con == nullptr) {
1681 return OPERATOR_CANCELLED;
1682 }
1683
1684 bPoseChannel *pchan;
1685 constraint_list_from_constraint(obact, con, &pchan);
1686
1687 if (pchan) {
1688 /* Don't do anything if bone doesn't exist or doesn't have any constraints. */
1689 if (pchan->constraints.first == nullptr) {
1690 BKE_report(op->reports, RPT_ERROR, "No constraints for copying");
1691 return OPERATOR_CANCELLED;
1692 }
1693
1694 Object *prev_ob = nullptr;
1695
1696 /* Copy all constraints from active pose-bone to all selected pose-bones. */
1697 CTX_DATA_BEGIN_WITH_ID (C, bPoseChannel *, chan, selected_pose_bones, Object *, ob) {
1698 /* If we're not handling the object we're copying from, copy all constraints over. */
1699 if (pchan == chan) {
1700 continue;
1701 }
1702
1703 bConstraint *copy_con = BKE_constraint_copy_for_pose(ob, chan, con);
1705
1706 /* Update flags (need to add here, not just copy). */
1707 chan->constflag |= pchan->constflag;
1708
1709 if (prev_ob == ob) {
1710 continue;
1711 }
1712
1713 BKE_pose_tag_recalc(bmain, ob->pose);
1715 prev_ob = ob;
1716 }
1718 }
1719 else {
1720 /* Copy all constraints from active object to all selected objects. */
1721 CTX_DATA_BEGIN (C, Object *, ob, selected_editable_objects) {
1722 /* If we're not handling the object we're copying from, copy all constraints over. */
1723 if (obact == ob) {
1724 continue;
1725 }
1726
1727 bConstraint *copy_con = BKE_constraint_copy_for_object(ob, con);
1729
1731 }
1733 }
1734
1735 /* Force depsgraph to get recalculated since new relationships added. */
1737
1739
1740 return OPERATOR_FINISHED;
1741}
1742
1744 wmOperator *op,
1745 const wmEvent *event)
1746{
1747 wmOperatorStatus retval;
1748 if (!edit_constraint_invoke_properties(C, op, event, &retval)) {
1749 return retval;
1750 }
1752}
1753
1755{
1756 PointerRNA ptr = CTX_data_pointer_get_type(C, "constraint", &RNA_Constraint);
1757 Object *obact = (ptr.owner_id) ? (Object *)ptr.owner_id : context_active_object(C);
1758 bConstraint *con = static_cast<bConstraint *>(ptr.data);
1759 bPoseChannel *pchan;
1760 constraint_list_from_constraint(obact, con, &pchan);
1761
1762 if (pchan) {
1763 bool found = false;
1764 CTX_DATA_BEGIN_WITH_ID (C, bPoseChannel *, chan, selected_pose_bones, Object *, ob) {
1765 UNUSED_VARS(ob);
1766 if (pchan != chan) {
1769 found = true;
1770 break;
1771 }
1772 }
1774 if (found) {
1775 return true;
1776 }
1777
1778 CTX_wm_operator_poll_msg_set(C, "No other bones are selected");
1779 return false;
1780 }
1781
1782 if (!obact) {
1783 CTX_wm_operator_poll_msg_set(C, "No selected object to copy from");
1784 return false;
1785 }
1786
1787 bool found = false;
1788 CTX_DATA_BEGIN (C, Object *, ob, selected_objects) {
1789 if (ob != obact) {
1792 found = true;
1793 break;
1794 }
1795 }
1797 if (found) {
1798 return true;
1799 }
1800
1801 CTX_wm_operator_poll_msg_set(C, "No other objects are selected");
1802 return false;
1803}
1804
1806{
1807 /* identifiers */
1808 ot->name = "Copy Constraint To Selected";
1809 ot->idname = "CONSTRAINT_OT_copy_to_selected";
1810 ot->description = "Copy constraint to other selected objects/bones";
1811
1812 /* API callbacks. */
1816
1817 /* flags */
1818 ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
1820}
1821
1823
1824/* ------------------------------------------------------------------- */
1827
1829{
1831 bConstraint *con = edit_constraint_property_get(C, op, ob, 0);
1832
1833 if (con && con->next) {
1834 ListBase *conlist = constraint_list_from_constraint(ob, con, nullptr);
1835 bConstraint *nextCon = con->next;
1836
1837 /* insert the nominated constraint after the one that used to be after it */
1838 BLI_remlink(conlist, con);
1839 BLI_insertlinkafter(conlist, nextCon, con);
1840
1843
1844 return OPERATOR_FINISHED;
1845 }
1846
1847 return OPERATOR_CANCELLED;
1848}
1849
1851 wmOperator *op,
1852 const wmEvent *event)
1853{
1854 wmOperatorStatus retval;
1855 if (edit_constraint_invoke_properties(C, op, event, &retval)) {
1856 return constraint_move_down_exec(C, op);
1857 }
1858 return retval;
1859}
1860
1862{
1863 /* identifiers */
1864 ot->name = "Move Constraint Down";
1865 ot->idname = "CONSTRAINT_OT_move_down";
1866 ot->description = "Move constraint down in constraint stack";
1867
1868 /* callbacks */
1871 ot->poll = edit_constraint_poll;
1872
1873 /* flags */
1874 ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
1875
1876 /* properties */
1878}
1879
1881
1882/* ------------------------------------------------------------------- */
1885
1887{
1889 bConstraint *con = edit_constraint_property_get(C, op, ob, 0);
1890
1891 if (con && con->prev) {
1892 ListBase *conlist = constraint_list_from_constraint(ob, con, nullptr);
1893 bConstraint *prevCon = con->prev;
1894
1895 /* insert the nominated constraint before the one that used to be before it */
1896 BLI_remlink(conlist, con);
1897 BLI_insertlinkbefore(conlist, prevCon, con);
1898
1901
1902 return OPERATOR_FINISHED;
1903 }
1904
1905 return OPERATOR_CANCELLED;
1906}
1907
1909 wmOperator *op,
1910 const wmEvent *event)
1911{
1912 wmOperatorStatus retval;
1913 if (edit_constraint_invoke_properties(C, op, event, &retval)) {
1914 return constraint_move_up_exec(C, op);
1915 }
1916 return retval;
1917}
1918
1920{
1921 /* identifiers */
1922 ot->name = "Move Constraint Up";
1923 ot->idname = "CONSTRAINT_OT_move_up";
1924 ot->description = "Move constraint up in constraint stack";
1925
1926 /* callbacks */
1928 ot->invoke = constraint_move_up_invoke;
1929 ot->poll = edit_constraint_poll;
1930
1931 /* flags */
1932 ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
1934}
1935
1937
1938/* ------------------------------------------------------------------- */
1941
1943{
1945 bConstraint *con = edit_constraint_property_get(C, op, ob, 0);
1946
1947 int new_index = RNA_int_get(op->ptr, "index");
1948 new_index = std::max(new_index, 0);
1949
1950 if (con) {
1951 constraint_move_to_index(ob, con, new_index);
1952
1954
1955 return OPERATOR_FINISHED;
1956 }
1957
1958 return OPERATOR_CANCELLED;
1959}
1960
1962 wmOperator *op,
1963 const wmEvent *event)
1964{
1965 wmOperatorStatus retval;
1966 if (edit_constraint_invoke_properties(C, op, event, &retval)) {
1967 return constraint_move_to_index_exec(C, op);
1968 }
1969 return retval;
1970}
1971
1973{
1974 /* identifiers */
1975 ot->name = "Move Constraint to Index";
1976 ot->idname = "CONSTRAINT_OT_move_to_index";
1977 ot->description =
1978 "Change the constraint's position in the list so it evaluates after the set number of "
1979 "others";
1980
1981 /* callbacks */
1984 ot->poll = edit_constraint_poll;
1985
1986 /* flags */
1987 ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
1989 RNA_def_int(ot->srna,
1990 "index",
1991 0,
1992 0,
1993 INT_MAX,
1994 "Index",
1995 "The index to move the constraint to",
1996 0,
1997 INT_MAX);
1998}
1999
2001
2002/* ------------------------------------------------------------------- */
2005
2007{
2008 Main *bmain = CTX_data_main(C);
2009 Object *prev_ob = nullptr;
2010
2011 /* free constraints for all selected bones */
2012 CTX_DATA_BEGIN_WITH_ID (C, bPoseChannel *, pchan, selected_pose_bones, Object *, ob) {
2013 BKE_constraints_free(&pchan->constraints);
2014 pchan->constflag = 0;
2015
2016 if (prev_ob != ob) {
2019 prev_ob = ob;
2020 }
2021 }
2023
2024 /* force depsgraph to get recalculated since relationships removed */
2026
2027 /* NOTE: calling BIK_clear_data() isn't needed here. */
2028
2029 return OPERATOR_FINISHED;
2030}
2031
2033{
2034 /* identifiers */
2035 ot->name = "Clear Pose Constraints";
2036 ot->idname = "POSE_OT_constraints_clear";
2037 ot->description = "Clear all constraints from the selected bones";
2038
2039 /* callbacks */
2041 /* XXX: do we want to ensure there are selected bones too? */
2043}
2044
2046{
2047 Main *bmain = CTX_data_main(C);
2048
2049 /* do freeing */
2050 CTX_DATA_BEGIN (C, Object *, ob, selected_editable_objects) {
2051 BKE_constraints_free(&ob->constraints);
2053 }
2055
2056 /* force depsgraph to get recalculated since relationships removed */
2058
2059 /* do updates */
2061
2062 return OPERATOR_FINISHED;
2063}
2064
2066
2067/* ------------------------------------------------------------------- */
2070
2072{
2073 /* identifiers */
2074 ot->name = "Clear Object Constraints";
2075 ot->idname = "OBJECT_OT_constraints_clear";
2076 ot->description = "Clear all constraints from the selected objects";
2077
2078 /* callbacks */
2081}
2082
2084
2085/* ------------------------------------------------------------------- */
2088
2090{
2091 Main *bmain = CTX_data_main(C);
2093
2094 /* don't do anything if bone doesn't exist or doesn't have any constraints */
2095 if (ELEM(nullptr, pchan, pchan->constraints.first)) {
2096 BKE_report(op->reports, RPT_ERROR, "No active bone with constraints for copying");
2097 return OPERATOR_CANCELLED;
2098 }
2099
2100 Object *prev_ob = nullptr;
2101
2102 /* Copy all constraints from active pose-bone to all selected pose-bones. */
2103 CTX_DATA_BEGIN_WITH_ID (C, bPoseChannel *, chan, selected_pose_bones, Object *, ob) {
2104 /* if we're not handling the object we're copying from, copy all constraints over */
2105 if (pchan != chan) {
2106 BKE_constraints_copy(&chan->constraints, &pchan->constraints, true);
2107 /* update flags (need to add here, not just copy) */
2108 chan->constflag |= pchan->constflag;
2109
2110 if (prev_ob != ob) {
2111 BKE_pose_tag_recalc(bmain, ob->pose);
2113 prev_ob = ob;
2114 }
2115 }
2116 }
2118
2119 /* force depsgraph to get recalculated since new relationships added */
2121
2123
2124 return OPERATOR_FINISHED;
2125}
2126
2128{
2129 /* identifiers */
2130 ot->name = "Copy Constraints to Selected Bones";
2131 ot->idname = "POSE_OT_constraints_copy";
2132 ot->description = "Copy constraints to other selected bones";
2133
2134 /* API callbacks. */
2137
2138 /* flags */
2139 ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
2140}
2141
2143
2144/* ------------------------------------------------------------------- */
2147
2149{
2150 Main *bmain = CTX_data_main(C);
2151 Object *obact = context_active_object(C);
2152
2153 /* copy all constraints from active object to all selected objects */
2154 CTX_DATA_BEGIN (C, Object *, ob, selected_editable_objects) {
2155 /* if we're not handling the object we're copying from, copy all constraints over */
2156 if (obact != ob) {
2157 BKE_constraints_copy(&ob->constraints, &obact->constraints, true);
2159 }
2160 }
2162
2163 /* force depsgraph to get recalculated since new relationships added */
2165
2166 /* notifiers for updates */
2168
2169 return OPERATOR_FINISHED;
2170}
2171
2173{
2174 /* identifiers */
2175 ot->name = "Copy Constraints to Selected Objects";
2176 ot->idname = "OBJECT_OT_constraints_copy";
2177 ot->description = "Copy constraints to other selected objects";
2178
2179 /* API callbacks. */
2182
2183 /* flags */
2184 ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
2185}
2186
2188
2189/* ------------------------------------------------------------------- */
2192
2193/* get the Object and/or PoseChannel to use as target */
2195 bContext *C, int con_type, Object **tar_ob, bPoseChannel **tar_pchan, bool add)
2196{
2197 Object *obact = context_active_object(C);
2199 bool only_curve = false, only_mesh = false, only_ob = false;
2200 bool found = false;
2201
2202 /* clear tar_ob and tar_pchan fields before use
2203 * - assume for now that both always exist...
2204 */
2205 *tar_ob = nullptr;
2206 *tar_pchan = nullptr;
2207
2208 /* check if constraint type doesn't requires a target
2209 * - if so, no need to get any targets
2210 */
2211 switch (con_type) {
2212 /* no-target constraints --------------------------- */
2213 /* null constraint - shouldn't even be added! */
2215 /* limit constraints - no targets needed */
2220 return false;
2221
2222 /* restricted target-type constraints -------------- */
2223 /* NOTE: for these, we cannot try to add a target object if no valid ones are found,
2224 * since that doesn't work */
2225 /* curve-based constraints - set the only_curve and only_ob flags */
2229 only_curve = true;
2230 only_ob = true;
2231 add = false;
2232 break;
2233
2234 /* mesh only? */
2236 only_mesh = true;
2237 only_ob = true;
2238 add = false;
2239 break;
2240
2241 /* Armature only. */
2243 add = false;
2244 break;
2245 }
2246
2247 /* if the active Object is Armature, and we can search for bones, do so... */
2248 if ((obact->type == OB_ARMATURE) && (only_ob == false)) {
2249 /* search in list of selected Pose-Channels for target */
2250 CTX_DATA_BEGIN (C, bPoseChannel *, pchan, selected_pose_bones_from_active_object) {
2251 /* just use the first one that we encounter, as long as it is not the active one */
2252 if (pchan != pchanact) {
2253 *tar_ob = obact;
2254 *tar_pchan = pchan;
2255 found = true;
2256
2257 break;
2258 }
2259 }
2261 }
2262
2263 /* if not yet found, try selected Objects... */
2264 if (found == false) {
2265 /* search in selected objects context */
2266 CTX_DATA_BEGIN (C, Object *, ob, selected_objects) {
2267 /* just use the first object we encounter (that isn't the active object)
2268 * and which fulfills the criteria for the object-target that we've got
2269 */
2270 if (ob != obact) {
2271 /* for armatures in pose mode, look inside the armature for the active bone
2272 * so that we set up cross-armature constraints with less effort
2273 */
2274 if ((ob->type == OB_ARMATURE) && (ob->mode & OB_MODE_POSE) && (!only_curve && !only_mesh))
2275 {
2276
2277 /* Only use the object & bone if the bone is visible & selected
2278 * since we may have multiple objects in pose mode at once. */
2280 if (pchan != nullptr) {
2281 *tar_pchan = pchan;
2282 *tar_ob = ob;
2283 found = true;
2284 }
2285
2286 break;
2287 }
2288 if (((!only_curve) || (ob->type == OB_CURVES_LEGACY)) &&
2289 ((!only_mesh) || (ob->type == OB_MESH)))
2290 {
2291 /* set target */
2292 *tar_ob = ob;
2293 found = true;
2294
2295 /* perform some special operations on the target */
2296 if (only_curve) {
2297 /* Curve-Path option must be enabled for follow-path constraints to be able to work
2298 */
2299 Curve *cu = (Curve *)ob->data;
2300 cu->flag |= CU_PATH;
2301 }
2302
2303 break;
2304 }
2305 }
2306 }
2308 }
2309
2310 /* if still not found, add a new empty to act as a target (if allowed) */
2311 if ((found == false) && (add)) {
2312 Main *bmain = CTX_data_main(C);
2313 Scene *scene = CTX_data_scene(C);
2314 ViewLayer *view_layer = CTX_data_view_layer(C);
2315 BKE_view_layer_synced_ensure(scene, view_layer);
2316 Base *base = BKE_view_layer_active_base_get(view_layer);
2317 Object *obt;
2318
2319 /* add new target object */
2320 obt = BKE_object_add(bmain, scene, view_layer, OB_EMPTY, nullptr);
2321
2322 /* transform cent to global coords for loc */
2323 if (pchanact) {
2324 /* Since by default, IK targets the tip of the last bone,
2325 * use the tip of the active PoseChannel if adding a target for an IK Constraint. */
2326 if (con_type == CONSTRAINT_TYPE_KINEMATIC) {
2327 mul_v3_m4v3(obt->loc, obact->object_to_world().ptr(), pchanact->pose_tail);
2328 }
2329 else {
2330 mul_v3_m4v3(obt->loc, obact->object_to_world().ptr(), pchanact->pose_head);
2331 }
2332 }
2333 else {
2334 copy_v3_v3(obt->loc, obact->object_to_world().location());
2335 }
2336
2337 /* restore, BKE_object_add sets active */
2338 view_layer->basact = base;
2339 base_select(base, BA_SELECT);
2340
2341 /* make our new target the new object */
2342 *tar_ob = obt;
2343 found = true;
2344 }
2345
2346 /* return whether there's any target */
2347 return found;
2348}
2349
2350/* used by add constraint operators to add the constraint required */
2352 bContext *C, wmOperator *op, Object *ob, ListBase *list, int type, const bool setTarget)
2353{
2354 Main *bmain = CTX_data_main(C);
2355 bPoseChannel *pchan;
2356 bConstraint *con;
2357
2358 if (list == &ob->constraints) {
2359 pchan = nullptr;
2360 }
2361 else {
2363
2364 /* ensure not to confuse object/pose adding */
2365 if (pchan == nullptr) {
2366 BKE_report(op->reports, RPT_ERROR, "No active pose bone to add a constraint to");
2367 return OPERATOR_CANCELLED;
2368 }
2369 }
2370 /* check if constraint to be added is valid for the given constraints stack */
2371 if (type == CONSTRAINT_TYPE_NULL) {
2372 return OPERATOR_CANCELLED;
2373 }
2374
2375 /* Create a new constraint of the type required,
2376 * and add it to the active/given constraints list. */
2377 if (pchan) {
2378 con = BKE_constraint_add_for_pose(ob, pchan, nullptr, type);
2379 }
2380 else {
2381 con = BKE_constraint_add_for_object(ob, nullptr, type);
2382 }
2383
2384 /* get the first selected object/bone, and make that the target
2385 * - apart from the buttons-window add buttons, we shouldn't add in this way
2386 */
2387 if (setTarget) {
2388 Object *tar_ob = nullptr;
2389 bPoseChannel *tar_pchan = nullptr;
2390
2391 /* get the target objects, adding them as need be */
2392 if (get_new_constraint_target(C, type, &tar_ob, &tar_pchan, true)) {
2393
2394 /* Armature constraints don't have a target by default, add one. */
2395 if (type == CONSTRAINT_TYPE_ARMATURE) {
2396 bArmatureConstraint *acon = static_cast<bArmatureConstraint *>(con->data);
2397 bConstraintTarget *ct = MEM_callocN<bConstraintTarget>("Constraint Target");
2398
2399 ct->weight = 1.0f;
2400 BLI_addtail(&acon->targets, ct);
2401
2402 constraint_dependency_tag_update(bmain, ob, con);
2403 }
2404
2405 /* Method of setting target depends on the type of target we've got - by default,
2406 * just set the first target (distinction here is only for multiple-targeted constraints).
2407 */
2408 if (tar_pchan) {
2409 set_constraint_nth_target(con, tar_ob, tar_pchan->name, 0);
2410 }
2411 else {
2412 set_constraint_nth_target(con, tar_ob, "", 0);
2413 }
2414 }
2415 }
2416
2417 /* make sure all settings are valid - similar to above checks, but sometimes can be wrong */
2418 object_test_constraints(bmain, ob);
2419
2420 if (pchan) {
2422 }
2423
2424 /* force depsgraph to get recalculated since new relationships added */
2426
2427 if ((ob->type == OB_ARMATURE) && (pchan)) {
2428 BKE_pose_tag_recalc(bmain, ob->pose); /* sort pose channels */
2430 }
2431 else {
2433 }
2434
2435 /* notifiers for updates */
2437
2438 return OPERATOR_FINISHED;
2439}
2440
2441/* ------------------ */
2442
2443/* dummy operator callback */
2445{
2447 int type = RNA_enum_get(op->ptr, "type");
2448 short with_targets = 0;
2449
2450 if (!ob) {
2451 BKE_report(op->reports, RPT_ERROR, "No active object to add constraint to");
2452 return OPERATOR_CANCELLED;
2453 }
2454
2455 /* hack: set constraint targets from selected objects in context is allowed when
2456 * operator name included 'with_targets', since the menu doesn't allow multiple properties
2457 */
2458 if (strstr(op->idname, "with_targets")) {
2459 with_targets = 1;
2460 }
2461
2462 return constraint_add_exec(C, op, ob, &ob->constraints, type, with_targets);
2463}
2464
2465/* dummy operator callback */
2467{
2469 int type = RNA_enum_get(op->ptr, "type");
2470 short with_targets = 0;
2471
2472 if (!ob) {
2473 BKE_report(op->reports, RPT_ERROR, "No active object to add constraint to");
2474 return OPERATOR_CANCELLED;
2475 }
2476
2477 /* hack: set constraint targets from selected objects in context is allowed when
2478 * operator name included 'with_targets', since the menu doesn't allow multiple properties
2479 */
2480 if (strstr(op->idname, "with_targets")) {
2481 with_targets = 1;
2482 }
2483
2484 return constraint_add_exec(C, op, ob, constraint_active_list(ob), type, with_targets);
2485}
2486
2487/* ------------------ */
2488
2489/* Filters constraints that are only compatible with bones */
2491 PointerRNA * /*ptr*/,
2492 PropertyRNA * /*prop*/,
2493 bool *r_free)
2494{
2496 EnumPropertyItem *object_constraint_items = nullptr;
2497 int totitem = 0;
2498
2499 while (item->identifier) {
2501 RNA_enum_item_add(&object_constraint_items, &totitem, item);
2502 }
2503 item++;
2504 }
2505
2506 RNA_enum_item_end(&object_constraint_items, &totitem);
2507 *r_free = true;
2508
2509 return object_constraint_items;
2510}
2511
2513{
2514 PropertyRNA *prop;
2515
2516 /* identifiers */
2517 ot->name = "Add Constraint";
2518 ot->description = "Add a constraint to the active object";
2519 ot->idname = "OBJECT_OT_constraint_add";
2520
2521 /* API callbacks. */
2522 ot->invoke = WM_menu_invoke;
2525
2526 /* flags */
2527 ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
2528
2529 /* properties */
2530 prop = RNA_def_enum(ot->srna, "type", rna_enum_dummy_NULL_items, 0, "Type", "");
2532 ot->prop = prop;
2533}
2534
2536
2537/* ------------------------------------------------------------------- */
2540
2542{
2543 PropertyRNA *prop;
2544
2545 /* identifiers */
2546 ot->name = "Add Constraint (with Targets)";
2547 ot->description =
2548 "Add a constraint to the active object, with target (where applicable) set to the "
2549 "selected objects/bones";
2550 ot->idname = "OBJECT_OT_constraint_add_with_targets";
2551
2552 /* API callbacks. */
2553 ot->invoke = WM_menu_invoke;
2556
2557 /* flags */
2558 ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
2559
2560 /* properties */
2561 prop = RNA_def_enum(ot->srna, "type", rna_enum_dummy_NULL_items, 0, "Type", "");
2563 ot->prop = prop;
2564}
2565
2567{
2568 /* identifiers */
2569 ot->name = "Add Constraint";
2570 ot->description = "Add a constraint to the active bone";
2571 ot->idname = "POSE_OT_constraint_add";
2572
2573 /* API callbacks. */
2574 ot->invoke = WM_menu_invoke;
2577
2578 /* flags */
2579 ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
2580
2581 /* properties */
2582 ot->prop = RNA_def_enum(ot->srna, "type", rna_enum_constraint_type_items, 0, "Type", "");
2583}
2584
2586{
2587 /* identifiers */
2588 ot->name = "Add Constraint (with Targets)";
2589 ot->description =
2590 "Add a constraint to the active bone, with target (where applicable) set to the selected "
2591 "Objects/Bones";
2592 ot->idname = "POSE_OT_constraint_add_with_targets";
2593
2594 /* API callbacks. */
2595 ot->invoke = WM_menu_invoke;
2598
2599 /* flags */
2600 ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
2601
2602 /* properties */
2603 ot->prop = RNA_def_enum(ot->srna, "type", rna_enum_constraint_type_items, 0, "Type", "");
2604}
2605
2607
2608/* ------------------------------------------------------------------- */
2613
2614/* TODO: should these be here, or back in `editors/armature/poseobject.c` again? */
2615
2616/* present menu with options + validation for targets to use */
2618{
2621 bConstraint *con = nullptr;
2622
2623 uiPopupMenu *pup;
2624 uiLayout *layout;
2625 Object *tar_ob = nullptr;
2626 bPoseChannel *tar_pchan = nullptr;
2627
2628 /* must have active bone */
2629 if (ELEM(nullptr, ob, pchan)) {
2630 BKE_report(op->reports, RPT_ERROR, "Must have an active bone to add IK constraint to");
2631 return OPERATOR_CANCELLED;
2632 }
2633
2634 /* bone must not have any constraints already */
2635 for (con = static_cast<bConstraint *>(pchan->constraints.first); con; con = con->next) {
2636 if (con->type == CONSTRAINT_TYPE_KINEMATIC) {
2637 break;
2638 }
2639 }
2640 if (con) {
2641 BKE_report(op->reports, RPT_ERROR, "Bone already has an IK constraint");
2642 return OPERATOR_CANCELLED;
2643 }
2644
2645 /* prepare popup menu to choose targeting options */
2646 pup = UI_popup_menu_begin(C, IFACE_("Add IK"), ICON_NONE);
2647 layout = UI_popup_menu_layout(pup);
2648
2649 /* the type of targets we'll set determines the menu entries to show... */
2650 if (get_new_constraint_target(C, CONSTRAINT_TYPE_KINEMATIC, &tar_ob, &tar_pchan, false)) {
2651 /* bone target, or object target?
2652 * - the only thing that matters is that we want a target...
2653 */
2654 if (tar_pchan) {
2655 PointerRNA op_ptr = layout->op("POSE_OT_ik_add", IFACE_("Target Selected Bone"), ICON_NONE);
2656 RNA_boolean_set(&op_ptr, "with_targets", true);
2657 }
2658 else {
2659 PointerRNA op_ptr = layout->op(
2660 "POSE_OT_ik_add", IFACE_("Target Selected Object"), ICON_NONE);
2661 RNA_boolean_set(&op_ptr, "with_targets", true);
2662 }
2663 }
2664 else {
2665 /* we have a choice of adding to a new empty, or not setting any target (targetless IK) */
2666 PointerRNA op_ptr = layout->op("POSE_OT_ik_add", IFACE_("Target New Empty Object"), ICON_NONE);
2667 RNA_boolean_set(&op_ptr, "with_targets", true);
2668 op_ptr = layout->op("POSE_OT_ik_add", IFACE_("Without Target"), ICON_NONE);
2669 RNA_boolean_set(&op_ptr, "with_targets", false);
2670 }
2671
2672 /* finish building the menu, and process it (should result in calling self again) */
2673 UI_popup_menu_end(C, pup);
2674
2675 return OPERATOR_INTERFACE;
2676}
2677
2678/* call constraint_add_exec() to add the IK constraint */
2680{
2682 const bool with_targets = RNA_boolean_get(op->ptr, "with_targets");
2683
2684 /* add the constraint - all necessary checks should have
2685 * been done by the invoke() callback already... */
2686 return constraint_add_exec(
2687 C, op, ob, constraint_active_list(ob), CONSTRAINT_TYPE_KINEMATIC, with_targets);
2688}
2689
2691{
2692 /* identifiers */
2693 ot->name = "Add IK to Bone";
2694 ot->description =
2695 "Add an IK Constraint to the active Bone. The target can be a selected bone or object";
2696 ot->idname = "POSE_OT_ik_add";
2697
2698 /* API callbacks. */
2699 ot->invoke = pose_ik_add_invoke;
2700 ot->exec = pose_ik_add_exec;
2702
2703 /* flags */
2704 ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
2705
2706 /* properties */
2707 RNA_def_boolean(ot->srna,
2708 "with_targets",
2709 true,
2710 "With Targets",
2711 "Assign IK Constraint with targets derived from the select bones/objects");
2712}
2713
2715
2716/* ------------------------------------------------------------------- */
2721
2723{
2724 Object *prev_ob = nullptr;
2725
2726 /* only remove IK Constraints */
2727 CTX_DATA_BEGIN_WITH_ID (C, bPoseChannel *, pchan, selected_pose_bones, Object *, ob) {
2728 bConstraint *con, *next;
2729
2730 /* TODO: should we be checking if these constraints were local
2731 * before we try and remove them? */
2732 for (con = static_cast<bConstraint *>(pchan->constraints.first); con; con = next) {
2733 next = con->next;
2734 if (con->type == CONSTRAINT_TYPE_KINEMATIC) {
2735 BKE_constraint_remove_ex(&pchan->constraints, ob, con);
2736 }
2737 }
2738 pchan->constflag &= ~(PCHAN_HAS_IK | PCHAN_HAS_NO_TARGET);
2739
2740 if (prev_ob != ob) {
2741 prev_ob = ob;
2742
2743 /* Refresh depsgraph. */
2745
2746 /* NOTE: notifier might evolve. */
2748 }
2749 }
2751
2752 return OPERATOR_FINISHED;
2753}
2754
2756{
2757 /* identifiers */
2758 ot->name = "Remove IK";
2759 ot->description = "Remove all IK Constraints from selected bones";
2760 ot->idname = "POSE_OT_ik_clear";
2761
2762 /* API callbacks. */
2763 ot->exec = pose_ik_clear_exec;
2765
2766 /* flags */
2767 ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
2768}
2769
2771
2772} // namespace blender::ed::object
Functions and classes to work with Actions.
Functions for backward compatibility with the legacy Action API.
Functions to work with AnimData.
void BIK_test_constraint(struct Object *ob, struct bConstraint *cons)
Blender kernel action and pose functionality.
void BKE_pose_tag_recalc(Main *bmain, bPose *pose) ATTR_NONNULL(1
void BKE_pose_update_constraint_flags(bPose *pose) ATTR_NONNULL(1)
bPoseChannel * BKE_pose_channel_active_or_first_selected(Object *ob) ATTR_WARN_UNUSED_RESULT
bPoseChannel * BKE_pose_channel_active_if_bonecoll_visible(Object *ob) ATTR_WARN_UNUSED_RESULT
void BKE_pose_tag_update_constraint_flags(bPose *pose) ATTR_NONNULL(1)
bArmature * BKE_armature_from_object(Object *ob)
Bone * BKE_armature_find_bone_name(bArmature *arm, const char *name)
struct bConstraint * BKE_constraints_find_name(struct ListBase *list, const char *name)
void BKE_constraints_free(struct ListBase *list)
void BKE_constraint_targets_flush(struct bConstraint *con, struct ListBase *targets, bool no_copy)
int BKE_constraint_targets_get(struct bConstraint *con, struct ListBase *r_targets)
void BKE_constraints_copy(struct ListBase *dst, const struct ListBase *src, bool do_extern)
bool BKE_constraint_remove_ex(ListBase *list, struct Object *ob, struct bConstraint *con)
struct bConstraint * BKE_constraint_copy_for_pose(struct Object *ob, struct bPoseChannel *pchan, struct bConstraint *src)
struct bConstraint * BKE_constraint_add_for_object(struct Object *ob, const char *name, short type)
bool BKE_constraint_apply_and_remove_for_pose(struct Depsgraph *depsgraph, struct Scene *scene, ListBase *constraints, struct Object *ob, struct bConstraint *con, struct bPoseChannel *pchan)
bool BKE_constraint_is_nonlocal_in_liboverride(const struct Object *ob, const struct bConstraint *con)
struct bConstraint * BKE_constraint_add_for_pose(struct Object *ob, struct bPoseChannel *pchan, const char *name, short type)
bool BKE_constraint_apply_and_remove_for_object(struct Depsgraph *depsgraph, struct Scene *scene, ListBase *constraints, struct Object *ob, struct bConstraint *con)
struct bConstraint * BKE_constraint_copy_for_object(struct Object *ob, struct bConstraint *src)
struct bConstraint * BKE_constraints_active_get(struct ListBase *list)
void BKE_constraints_active_set(ListBase *list, struct bConstraint *con)
#define CTX_DATA_BEGIN_WITH_ID(C, Type, instance, member, Type_id, instance_id)
PointerRNA CTX_data_pointer_get(const bContext *C, const char *member)
bPoseChannel * CTX_data_active_pose_bone(const bContext *C)
#define CTX_DATA_BEGIN(C, Type, instance, member)
PointerRNA CTX_data_pointer_get_type(const bContext *C, const char *member, StructRNA *type)
void CTX_wm_operator_poll_msg_set(bContext *C, const char *msg)
Depsgraph * CTX_data_ensure_evaluated_depsgraph(const bContext *C)
Object * CTX_data_active_object(const bContext *C)
Scene * CTX_data_scene(const bContext *C)
Main * CTX_data_main(const bContext *C)
#define CTX_DATA_END
ViewLayer * CTX_data_view_layer(const bContext *C)
FModifier * add_fmodifier(ListBase *modifiers, int type, FCurve *owner_fcu)
@ G_DEBUG
void BKE_view_layer_synced_ensure(const Scene *scene, ViewLayer *view_layer)
Base * BKE_view_layer_active_base_get(ViewLayer *view_layer)
General operations, lookup, etc. for blender objects.
bool BKE_object_exists_check(Main *bmain, const Object *obtest)
Object * BKE_object_add(Main *bmain, Scene *scene, ViewLayer *view_layer, int type, const char *name) ATTR_NONNULL(1
void BKE_object_eval_constraints(Depsgraph *depsgraph, Scene *scene, Object *ob)
Object * BKE_object_pose_armature_get(Object *ob)
void BKE_reportf(ReportList *reports, eReportType type, const char *format,...) ATTR_PRINTF_FORMAT(3
@ RPT_INFO
Definition BKE_report.hh:35
@ RPT_ERROR
Definition BKE_report.hh:39
@ RPT_WARNING
Definition BKE_report.hh:38
void BKE_report(ReportList *reports, eReportType type, const char *message)
Definition report.cc:153
struct MovieTrackingObject * BKE_tracking_object_get_camera(const struct MovieTracking *tracking)
struct MovieTrackingObject * BKE_tracking_object_get_named(struct MovieTracking *tracking, const char *name)
Definition tracking.cc:1966
struct MovieTrackingTrack * BKE_tracking_object_find_track_with_name(struct MovieTrackingObject *tracking_object, const char *name)
Definition tracking.cc:1993
#define BLI_assert(a)
Definition BLI_assert.h:46
A dynamically sized string ADT.
int BLI_findindex(const ListBase *listbase, const void *vlink) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1)
Definition listbase.cc:586
#define LISTBASE_FOREACH(type, var, list)
void BLI_addtail(ListBase *listbase, void *vlink) ATTR_NONNULL(1)
Definition listbase.cc:111
void BLI_insertlinkafter(ListBase *listbase, void *vprevlink, void *vnewlink) ATTR_NONNULL(1)
Definition listbase.cc:332
void BLI_remlink(ListBase *listbase, void *vlink) ATTR_NONNULL(1)
Definition listbase.cc:131
void void void bool BLI_listbase_link_move(ListBase *listbase, void *vlink, int step) ATTR_NONNULL()
Definition listbase.cc:436
int BLI_listbase_count(const ListBase *listbase) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1)
Definition listbase.cc:524
void BLI_insertlinkbefore(ListBase *listbase, void *vnextlink, void *vnewlink) ATTR_NONNULL(1)
Definition listbase.cc:371
bool is_identity_m4(const float m[4][4])
void mul_v3_m4v3(float r[3], const float mat[4][4], const float vec[3])
void unit_m4(float m[4][4])
MINLINE void copy_v3_v3(float r[3], const float a[3])
#define STRNCPY_UTF8(dst, src)
#define UNUSED_VARS(...)
#define ELEM(...)
#define STREQ(a, b)
#define IFACE_(msgid)
void DEG_id_tag_update(ID *id, unsigned int flags)
void DEG_relations_tag_update(Main *bmain)
Scene * DEG_get_evaluated_scene(const Depsgraph *graph)
@ ID_RECALC_TRANSFORM
Definition DNA_ID.h:1054
@ ID_RECALC_SYNC_TO_EVAL
Definition DNA_ID.h:1118
@ ID_RECALC_GEOMETRY
Definition DNA_ID.h:1074
#define ID_IS_EDITABLE(_id)
Definition DNA_ID.h:705
@ ID_OB
@ PCHAN_HAS_NO_TARGET
@ PCHAN_HAS_IK
@ FMODIFIER_TYPE_GENERATOR
@ CONSTRAINT_OFF
@ CONSTRAINT_OVERRIDE_LIBRARY_LOCAL
@ CONSTRAINT_ACTIVE
@ CONSTRAINT_DISABLE
@ CONSTRAINT_TYPE_TRACKTO
@ CONSTRAINT_TYPE_PIVOT
@ CONSTRAINT_TYPE_CHILDOF
@ CONSTRAINT_TYPE_FOLLOWTRACK
@ CONSTRAINT_TYPE_OBJECTSOLVER
@ CONSTRAINT_TYPE_ARMATURE
@ CONSTRAINT_TYPE_SHRINKWRAP
@ CONSTRAINT_TYPE_ROTLIMIT
@ CONSTRAINT_TYPE_CAMERASOLVER
@ CONSTRAINT_TYPE_SPLINEIK
@ CONSTRAINT_TYPE_KINEMATIC
@ CONSTRAINT_TYPE_NULL
@ CONSTRAINT_TYPE_DISTLIMIT
@ CONSTRAINT_TYPE_LOCLIMIT
@ CONSTRAINT_TYPE_CLAMPTO
@ CONSTRAINT_TYPE_LOCKTRACK
@ CONSTRAINT_TYPE_SIZELIMIT
@ CONSTRAINT_TYPE_ACTION
@ CONSTRAINT_TYPE_FOLLOWPATH
@ CONSTRAINT_TYPE_STRETCHTO
@ CONSTRAINT_TYPE_SAMEVOL
@ CONSTRAINT_TYPE_TRANSFORM_CACHE
@ CONSTRAINT_OBTYPE_OBJECT
@ CONSTRAINT_OBTYPE_BONE
@ CAMERASOLVER_ACTIVECLIP
@ ACTCON_USE_EVAL_TIME
@ FOLLOWPATH_STATIC
@ CONSTRAINT_SPLINEIK_BOUND
@ OBJECTSOLVER_SET_INVERSE
@ CHILDOF_SET_INVERSE
@ CU_PATH
#define MAX_NAME
Definition DNA_defs.h:50
@ OB_MODE_POSE
Object is a sort of wrapper for general info.
@ OB_EMPTY
@ OB_ARMATURE
@ OB_MESH
@ OB_CURVES_LEGACY
#define MINAFRAME
#define MAXFRAME
@ OPERATOR_CANCELLED
@ OPERATOR_INTERFACE
@ OPERATOR_FINISHED
@ OPERATOR_PASS_THROUGH
bool ED_operator_object_active_local_editable(bContext *C)
bool ED_operator_object_active_editable(bContext *C)
bool ED_operator_posemode_exclusive(bContext *C)
bool ED_operator_object_active_local_editable_posemode_exclusive(bContext *C)
bool ED_operator_object_active_editable_ex(bContext *C, const Object *ob)
Read Guarded memory(de)allocation.
#define MEM_SAFE_FREE(v)
@ PROP_SKIP_SAVE
Definition RNA_types.hh:344
@ PROP_HIDDEN
Definition RNA_types.hh:338
#define C
Definition RandGen.cpp:29
void UI_popup_menu_end(bContext *C, uiPopupMenu *pup)
uiPopupMenu * UI_popup_menu_begin(bContext *C, const char *title, int icon) ATTR_NONNULL()
uiLayout * UI_popup_menu_layout(uiPopupMenu *pup)
PointerRNA * UI_region_panel_custom_data_under_cursor(const bContext *C, const wmEvent *event)
#define NA_ADDED
Definition WM_types.hh:586
@ OPTYPE_UNDO
Definition WM_types.hh:182
@ OPTYPE_REGISTER
Definition WM_types.hh:180
#define ND_POSE
Definition WM_types.hh:458
#define ND_CONSTRAINT
Definition WM_types.hh:464
#define NA_REMOVED
Definition WM_types.hh:587
#define ND_TRANSFORM
Definition WM_types.hh:456
#define NC_OBJECT
Definition WM_types.hh:379
BMesh const char void * data
#define A
BPy_StructRNA * depsgraph
btSequentialImpulseConstraintSolverMt int btPersistentManifold int btTypedConstraint ** constraints
Slot * slot_for_handle(slot_handle_t handle)
nullptr float
#define printf(...)
#define abs
void * MEM_callocN(size_t len, const char *str)
Definition mallocn.cc:118
static ulong * next
#define B
#define G(x, y, z)
static void add(blender::Map< std::string, std::string > &messages, Message &msg)
Definition msgfmt.cc:222
bool action_treat_as_legacy(const bAction &action)
bAction * id_action_ensure(Main *bmain, ID *id)
Definition animdata.cc:195
FCurve * action_fcurve_ensure_ex(Main *bmain, bAction *act, const char group[], PointerRNA *ptr, const FCurveDescriptor &fcurve_descriptor)
FCurve * fcurve_find_in_assigned_slot(AnimData &adt, const FCurveDescriptor &fcurve_descriptor)
static int constraint_type_get(Object *owner, bPoseChannel *pchan)
void object_test_constraints(Main *bmain, Object *ob)
static wmOperatorStatus objectsolver_set_inverse_exec(bContext *C, wmOperator *op)
static bool edit_constraint_poll(bContext *C)
bConstraint * constraint_active_get(Object *ob)
void constraint_link(Main *bmain, Object *ob_dst, ListBase *dst, ListBase *src)
static wmOperatorStatus constraint_move_up_invoke(bContext *C, wmOperator *op, const wmEvent *event)
static wmOperatorStatus followpath_path_animate_exec(bContext *C, wmOperator *op)
static wmOperatorStatus constraint_move_down_invoke(bContext *C, wmOperator *op, const wmEvent *event)
static bool edit_constraint_poll_generic(bContext *C, StructRNA *rna_type, const bool is_liboverride_allowed)
void constraint_copy_for_object(Main *bmain, Object *ob_dst, bConstraint *con)
static void object_pose_tag_update(Main *bmain, Object *ob)
static wmOperatorStatus constraint_copy_invoke(bContext *C, wmOperator *op, const wmEvent *event)
void CONSTRAINT_OT_move_down(wmOperatorType *ot)
static void edit_constraint_report_property(wmOperatorType *ot)
static void object_test_constraint(Main *bmain, Object *ob, bConstraint *con)
void constraint_active_set(Object *ob, bConstraint *con)
static bool objectsolver_clear_inverse_poll(bContext *C)
static wmOperatorStatus constraint_delete_exec(bContext *C, wmOperator *op)
static wmOperatorStatus childof_set_inverse_invoke(bContext *C, wmOperator *op, const wmEvent *)
void constraint_copy_for_pose(Main *bmain, Object *ob_dst, bPoseChannel *pchan, bConstraint *con)
static wmOperatorStatus constraint_apply_exec(bContext *C, wmOperator *op)
static void test_constraints(Main *bmain, Object *ob, bPoseChannel *pchan)
static wmOperatorStatus constraint_copy_to_selected_invoke(bContext *C, wmOperator *op, const wmEvent *event)
void constraint_dependency_tag_update(Main *bmain, Object *ob, bConstraint *con)
static bool edit_constraint_liboverride_allowed_poll(bContext *C)
static wmOperatorStatus constraint_add_exec(bContext *C, wmOperator *op, Object *ob, ListBase *list, int type, const bool setTarget)
void constraint_update(Main *bmain, Object *ob)
static bConstraint * edit_constraint_property_get(bContext *C, wmOperator *op, Object *ob, int type)
static wmOperatorStatus childof_clear_inverse_invoke(bContext *C, wmOperator *op, const wmEvent *)
static const EnumPropertyItem * object_constraint_add_itemf(bContext *, PointerRNA *, PropertyRNA *, bool *r_free)
static wmOperatorStatus object_constraint_add_exec(bContext *C, wmOperator *op)
static wmOperatorStatus constraint_copy_exec(bContext *C, wmOperator *op)
void OBJECT_OT_constraint_add_with_targets(wmOperatorType *ot)
void CONSTRAINT_OT_objectsolver_set_inverse(wmOperatorType *ot)
static bool constraint_copy_to_selected_poll(bContext *C)
static void force_evaluation_if_constraint_disabled(bContext *C, Object *ob, bConstraint *con)
static wmOperatorStatus stretchto_reset_exec(bContext *C, wmOperator *op)
void base_select(Base *base, eObjectSelect_Mode mode)
ListBase * pose_constraint_list(const bContext *C)
static wmOperatorStatus constraint_copy_to_selected_exec(bContext *C, wmOperator *op)
void CONSTRAINT_OT_limitdistance_reset(wmOperatorType *ot)
static wmOperatorStatus pose_ik_clear_exec(bContext *C, wmOperator *)
static wmOperatorStatus objectsolver_clear_inverse_invoke(bContext *C, wmOperator *op, const wmEvent *)
static bool get_new_constraint_target(bContext *C, int con_type, Object **tar_ob, bPoseChannel **tar_pchan, bool add)
static wmOperatorStatus constraint_move_up_exec(bContext *C, wmOperator *op)
static wmOperatorStatus pose_ik_add_invoke(bContext *C, wmOperator *op, const wmEvent *)
static wmOperatorStatus limitdistance_reset_exec(bContext *C, wmOperator *op)
static wmOperatorStatus constraint_move_down_exec(bContext *C, wmOperator *op)
void CONSTRAINT_OT_copy(wmOperatorType *ot)
void CONSTRAINT_OT_apply(wmOperatorType *ot)
void constraint_tag_update(Main *bmain, Object *ob, bConstraint *con)
static wmOperatorStatus objectsolver_set_inverse_invoke(bContext *C, wmOperator *op, const wmEvent *)
void CONSTRAINT_OT_move_up(wmOperatorType *ot)
ListBase * constraint_active_list(Object *ob)
void POSE_OT_constraints_copy(wmOperatorType *ot)
static wmOperatorStatus childof_clear_inverse_exec(bContext *C, wmOperator *op)
static wmOperatorStatus object_constraint_copy_exec(bContext *C, wmOperator *)
static wmOperatorStatus objectsolver_clear_inverse_exec(bContext *C, wmOperator *op)
static wmOperatorStatus childof_set_inverse_exec(bContext *C, wmOperator *op)
static wmOperatorStatus limitdistance_reset_invoke(bContext *C, wmOperator *op, const wmEvent *)
static wmOperatorStatus constraint_apply_invoke(bContext *C, wmOperator *op, const wmEvent *event)
Object * context_active_object(const bContext *C)
static wmOperatorStatus constraint_delete_invoke(bContext *C, wmOperator *op, const wmEvent *event)
static wmOperatorStatus constraint_move_to_index_invoke(bContext *C, wmOperator *op, const wmEvent *event)
static wmOperatorStatus followpath_path_animate_invoke(bContext *C, wmOperator *op, const wmEvent *)
void POSE_OT_ik_add(wmOperatorType *ot)
void POSE_OT_ik_clear(wmOperatorType *ot)
void POSE_OT_constraint_add(wmOperatorType *ot)
void constraint_dependency_update(Main *bmain, Object *ob)
static wmOperatorStatus constraint_move_to_index_exec(bContext *C, wmOperator *op)
void CONSTRAINT_OT_delete(wmOperatorType *ot)
bool constraint_move_to_index(Object *ob, bConstraint *con, int index)
static wmOperatorStatus stretchto_reset_invoke(bContext *C, wmOperator *op, const wmEvent *)
void CONSTRAINT_OT_stretchto_reset(wmOperatorType *ot)
void OBJECT_OT_constraint_add(wmOperatorType *ot)
static wmOperatorStatus pose_constraints_clear_exec(bContext *C, wmOperator *)
void CONSTRAINT_OT_move_to_index(wmOperatorType *ot)
void OBJECT_OT_constraints_copy(wmOperatorType *ot)
static void test_constraint(Main *bmain, Object *owner, bPoseChannel *pchan, bConstraint *con, int type)
static wmOperatorStatus pose_constraint_add_exec(bContext *C, wmOperator *op)
void OBJECT_OT_constraints_clear(wmOperatorType *ot)
static void edit_constraint_properties(wmOperatorType *ot)
static wmOperatorStatus pose_constraint_copy_exec(bContext *C, wmOperator *op)
static void set_constraint_nth_target(bConstraint *con, Object *target, const char subtarget[], int index)
static wmOperatorStatus pose_ik_add_exec(bContext *C, wmOperator *op)
void CONSTRAINT_OT_objectsolver_clear_inverse(wmOperatorType *ot)
static bool childof_clear_inverse_poll(bContext *C)
void CONSTRAINT_OT_childof_clear_inverse(wmOperatorType *ot)
void CONSTRAINT_OT_followpath_path_animate(wmOperatorType *ot)
static const EnumPropertyItem constraint_owner_items[]
void CONSTRAINT_OT_childof_set_inverse(wmOperatorType *ot)
void POSE_OT_constraint_add_with_targets(wmOperatorType *ot)
static wmOperatorStatus object_constraints_clear_exec(bContext *C, wmOperator *)
void CONSTRAINT_OT_copy_to_selected(wmOperatorType *ot)
void POSE_OT_constraints_clear(wmOperatorType *ot)
static bool edit_constraint_invoke_properties(bContext *C, wmOperator *op, const wmEvent *event, wmOperatorStatus *r_retval)
ListBase * constraint_list_from_constraint(Object *ob, bConstraint *con, bPoseChannel **r_pchan)
#define EDIT_CONSTRAINT_OWNER_BONE
#define EDIT_CONSTRAINT_OWNER_OBJECT
const char * name
bool RNA_struct_is_a(const StructRNA *type, const StructRNA *srna)
void RNA_string_set(PointerRNA *ptr, const char *name, const char *value)
PropertyRNA * RNA_struct_find_property(PointerRNA *ptr, const char *identifier)
void RNA_boolean_set(PointerRNA *ptr, const char *name, bool value)
int RNA_int_get(PointerRNA *ptr, const char *name)
std::string RNA_string_get(PointerRNA *ptr, const char *name)
bool RNA_pointer_is_null(const PointerRNA *ptr)
bool RNA_struct_property_is_set(PointerRNA *ptr, const char *identifier)
bool RNA_boolean_get(PointerRNA *ptr, const char *name)
void RNA_enum_set(PointerRNA *ptr, const char *name, int value)
PointerRNA RNA_pointer_create_discrete(ID *id, StructRNA *type, void *data)
int RNA_enum_get(PointerRNA *ptr, const char *name)
PointerRNA RNA_id_pointer_create(ID *id)
const EnumPropertyItem rna_enum_constraint_type_items[]
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)
void RNA_enum_item_end(EnumPropertyItem **items, int *totitem)
void RNA_enum_item_add(EnumPropertyItem **items, int *totitem, const EnumPropertyItem *item)
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)
void RNA_def_enum_funcs(PropertyRNA *prop, EnumPropertyItemFunc itemfunc)
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)
std::optional< std::string > RNA_path_from_ID_to_property(const PointerRNA *ptr, PropertyRNA *prop)
Definition rna_path.cc:1173
const EnumPropertyItem rna_enum_dummy_NULL_items[]
Definition rna_rna.cc:26
bAction * action
struct AnimData * adt
const char * identifier
Definition RNA_types.hh:657
FPoint * fpt
BezTriple * bezt
ListBase modifiers
Definition DNA_ID.h:414
char name[258]
Definition DNA_ID.h:432
void * first
ListBase constraints
struct bPose * pose
float loc[3]
StructRNA * type
Definition RNA_types.hh:52
void * data
Definition RNA_types.hh:53
struct Base * basact
struct bConstraintTarget * next
struct bConstraint * prev
struct bConstraint * next
ListBase chanbase
PointerRNA op(wmOperatorType *ot, std::optional< blender::StringRef > name, int icon, blender::wm::OpCallContext context, eUI_Item_Flag flag)
struct ReportList * reports
struct PointerRNA * ptr
i
Definition text_draw.cc:230
uint len
void WM_main_add_notifier(uint type, void *reference)
void WM_event_add_notifier(const bContext *C, uint type, void *reference)
PointerRNA * ptr
Definition wm_files.cc:4238
wmOperatorType * ot
Definition wm_files.cc:4237
wmOperatorStatus WM_menu_invoke(bContext *C, wmOperator *op, const wmEvent *)