Blender V5.3
pose_slide.cc
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2009 Blender Authors, Joshua Leung.
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
30
31#include "MEM_guardedalloc.h"
32
33#include "BLI_array.hh"
34#include "BLI_listbase.hh"
36#include "BLI_string.hh"
37
38#include "BLT_translation.hh"
39
40#include "DNA_anim_types.h"
41#include "DNA_object_types.h"
42#include "DNA_scene_types.h"
43
44#include "BKE_fcurve.hh"
45#include "BKE_nla.hh"
46
47#include "BKE_context.hh"
48#include "BKE_layer.hh"
49#include "BKE_object.hh"
50#include "BKE_report.hh"
51#include "BKE_scene.hh"
52#include "BKE_unit.hh"
53
54#include "RNA_access.hh"
55#include "RNA_define.hh"
56#include "RNA_prototypes.hh"
57
58#include "WM_api.hh"
59#include "WM_types.hh"
60
61#include "UI_interface.hh"
62
64#include "ED_keyframes_edit.hh"
66#include "ED_markers.hh"
67#include "ED_numinput.hh"
68#include "ED_screen.hh"
69#include "ED_util.hh"
70
71#include "ANIM_fcurve.hh"
72#include "ANIM_rna.hh"
73
74#include "armature_intern.hh"
75
76namespace blender {
77
79{
81 if (!obact) {
82 return false;
83 }
85 if (mode == CTX_MODE_OBJECT) {
86 return true;
87 }
88
89 if (!(obact->mode & OB_MODE_EDIT)) {
90 Object *obpose = BKE_object_pose_armature_get(obact);
91 if (obpose != nullptr) {
92 if ((obact == obpose) || (obact->mode & OB_MODE_ALL_WEIGHT_PAINT)) {
93 return true;
94 }
95 }
96 }
97
98 return false;
99}
100
101/* **************************************************** */
102/* A) Push & Relax, Breakdowner */
103
115
118 PS_TFM_ALL = 0, /* All transforms and properties */
119
120 PS_TFM_LOC, /* Loc/Rot/Scale */
123
124 PS_TFM_BBONE_SHAPE, /* Bendy Bones */
125
126 PS_TFM_PROPS, /* Custom Properties */
127};
128
141
151
153 ListBaseT<SlideSubject> slide_subjects;
156
159
164
167
168 /* Store overlay settings when invoking the operator. Bones will be temporarily hidden. */
170
178
180
183
185};
186
189 {PS_TFM_ALL,
190 "ALL",
191 0,
192 "All Properties",
193 "All properties, including transforms, bendy bone shape, and custom properties"},
194 {PS_TFM_LOC, "LOC", 0, "Location", "Location only"},
195 {PS_TFM_ROT, "ROT", 0, "Rotation", "Rotation only"},
196 /* NOTE: `SIZE` identifier is only used for compatibility, should be `SCALE`. */
197 {PS_TFM_SCALE, "SIZE", 0, "Scale", "Scale only"},
198 {PS_TFM_BBONE_SHAPE, "BBONE", 0, "Bendy Bone", "Bendy Bone shape properties"},
199 {PS_TFM_PROPS, "CUSTOM", 0, "Custom Properties", "Custom properties"},
200 {0, nullptr, 0, nullptr, nullptr},
201};
202
203/* Property enum for AxisMutable. */
205 {ed::AXIS_MUTABLE_ALL, "FREE", 0, "Free", "All axes are affected"},
206 {ed::AXIS_MUTABLE_X, "X", 0, "X", "Only X-axis transforms are affected"},
207 {ed::AXIS_MUTABLE_Y, "Y", 0, "Y", "Only Y-axis transforms are affected"},
208 {ed::AXIS_MUTABLE_Z, "Z", 0, "Z", "Only Z-axis transforms are affected"},
209 {0, nullptr, 0, nullptr, nullptr},
210};
211
212/* ------------------------------------ */
213
218 const StringRef path)
219{
220 Vector<FCurve *> fcurves;
221 for (FCurve *fcurve : input_fcurves) {
222 if (fcurve->rna_path() != path) {
223 continue;
224 }
225 fcurves.append(fcurve);
226 }
227 return fcurves;
228}
229
232{
233 tPoseSlideOp *pso = MEM_new<tPoseSlideOp>(__func__);
234 op->customdata = pso;
235
236 /* Get info from context. */
237 pso->scene = CTX_data_scene(C);
238 pso->area = CTX_wm_area(C); /* Only really needed when doing modal(). */
239 pso->region = CTX_wm_region(C); /* Only really needed when doing modal(). */
240
241 pso->current_frame = pso->scene->r.cfra;
242 pso->mode = mode;
243
244 /* Set range info from property values - these may get overridden for the invoke(). */
245 pso->prev_frame = RNA_int_get(op->ptr, "prev_frame");
246 pso->next_frame = RNA_int_get(op->ptr, "next_frame");
247
248 /* Get the set of properties/axes that can be operated on. */
249 pso->channels = ePoseSlide_Channels(RNA_enum_get(op->ptr, "channels"));
250 pso->axis_mutability = ed::AxisMutable(RNA_enum_get(op->ptr, "axis_lock"));
251
252 pso->slider = ED_slider_create(C);
253 ED_slider_factor_set(pso->slider, RNA_float_get(op->ptr, "factor"));
254
255 /* For each Pose-Channel which gets affected, get the F-Curves for that channel
256 * and set the relevant transform flags. */
258 Set<ID *> unique_ids;
259 for (const SlideSubject &tflink : pso->slide_subjects) {
260 unique_ids.add(tflink.ptr.owner_id);
261 }
262 pso->ob_data_array.reinitialize(unique_ids.size());
263 int i = 0;
264 for (ID *id : unique_ids) {
265 ObjectFrameRange *range_data = &pso->ob_data_array[i];
266 i++;
267 BLI_assert(GS(id->name) == ID_OB);
268 range_data->object = id_cast<Object *>(id);
270 /* Apply NLA mapping corrections so the frame look-ups work. */
273 }
274
275 /* Do basic initialize of RB-BST used for finding keyframes, but leave the filling of it up
276 * to the caller of this (usually only invoke() will do it, to make things more efficient). */
277 pso->keylist = ED_keylist_create();
278
279 /* Initialize numeric input. */
280 initNumInput(&pso->num);
281 pso->num.idx_max = 0; /* One axis. */
282 pso->num.unit_type[0] = B_UNIT_NONE; /* Percentages don't have any units. */
283
284 if (pso->area && (pso->area->spacetype == SPACE_VIEW3D)) {
285 /* Save current bone visibility. */
286 View3D *v3d = static_cast<View3D *>(pso->area->spacedata.first_);
287 pso->overlay_flag = v3d->overlay.flag;
288 }
289
290 /* Return status is whether we've got all the data we were requested to get. */
291 return 1;
292}
293
298{
299 tPoseSlideOp *pso = static_cast<tPoseSlideOp *>(op->customdata);
300
302
303 /* Hide Bone Overlay. */
304 if (pso->area && (pso->area->spacetype == SPACE_VIEW3D)) {
305 View3D *v3d = static_cast<View3D *>(pso->area->spacedata.first_);
306 v3d->overlay.flag = pso->overlay_flag;
307 }
308
309 /* Free the temp pchan links and their data. */
311
312 /* Free RB-BST for keyframes (if it contained data). */
314
315 /* Free data itself. */
316 MEM_delete(pso);
317
318 /* Cleanup. */
319 op->customdata = nullptr;
320}
321
322/* ------------------------------------ */
323
328{
329 /* Wrapper around the generic version, allowing us to add some custom stuff later still. */
330 for (SlideSubject &slide_subject : pso->slide_subjects) {
331 slide_subjects_refresh(C, slide_subject);
332 }
333}
334
339 const ID *id,
340 float *prev_frame,
341 float *next_frame)
342{
343 for (const ObjectFrameRange &object_range : pso->ob_data_array) {
344 if (&object_range.object->id == id) {
345 *prev_frame = object_range.prev_frame;
346 *next_frame = object_range.next_frame;
347 return true;
348 }
349 }
350 *prev_frame = *next_frame = 0.0f;
351 return false;
352}
353
354/* Apply linear blending to the values of the given `prop_type`. */
356 SlideSubject &slide_subject,
358{
359
360 const float factor = ED_slider_factor_get(pso.slider);
361 ed::AnimTransformable *transformable = slide_subject.transformable;
362 Array<float> prev_values = transformable->get_property(prop_type);
363 Array<float> next_values = prev_values;
364
365 {
366 const std::string path = transformable->rna_path_to_property(prop_type);
367 const Vector<FCurve *> fcurves = fcurves_filtered_by_path(slide_subject.fcurves, path);
368 float prev_frame, next_frame;
369 pose_frame_range_from_id_get(&pso, transformable->owner_id(), &prev_frame, &next_frame);
370 for (const FCurve *fcurve : fcurves) {
371 prev_values[fcurve->array_index] = evaluate_fcurve(fcurve, prev_frame);
372 next_values[fcurve->array_index] = evaluate_fcurve(fcurve, next_frame);
373 }
374 }
375
376 /* Encodes a percentage value of where the current frame is between prev_- and next_frame. At 0
377 * it is at prev_frame. */
378 const float current_frame_factor = (pso.current_frame - pso.prev_frame) /
379 float(pso.next_frame - pso.prev_frame);
380 /* Note christoph: After looking at POSESLIDE_PUSH and _RELAX for a long time I finally realized
381 * what they do. They take the linear interpolation of the values based on the current frame and
382 * blend the current pose towards or away from it. The usefulness of this is likely limited and
383 * the naming could be better. Also this could be combined into a single slider. */
384 Array<float> current_frame_breakdown = ed::property_interpolated(
385 prev_values, next_values, current_frame_factor);
386
387 const ed::AxisMutable axis_flag = ed::AxisMutable(pso.axis_mutability);
388
389 switch (pso.mode) {
390
391 case POSESLIDE_PUSH: {
392 /* Slide the pose away from the breakdown pose in the timeline */
393 transformable->blend_property_to(prop_type, current_frame_breakdown, -factor, axis_flag);
394 break;
395 }
396 case POSESLIDE_RELAX: {
397 /* Slide the pose towards the breakdown pose in the timeline */
398 transformable->blend_property_to(prop_type, current_frame_breakdown, factor, axis_flag);
399 break;
400 }
401 case POSESLIDE_BREAKDOWN: /* Make the current pose slide around between the endpoints. */
402 {
403 /* Perform simple linear interpolation. */
404 Array<float> breakdown = ed::property_interpolated(prev_values, next_values, factor);
405 transformable->set_property(prop_type, breakdown, axis_flag);
406 break;
407 }
408 case POSESLIDE_BLEND: /* Blend the current pose with the previous (<50%) or next key (>50%). */
409 {
410 /* Convert factor to absolute 0-1 range which is needed for `blend_property_to`. */
411 const float blend_factor = fabs((factor - 0.5f) * 2);
412
413 if (factor < 0.5) {
414 /* Blend to previous key. */
415 transformable->blend_property_to(prop_type, prev_values, blend_factor, axis_flag);
416 }
417 else {
418 /* Blend to next key. */
419 transformable->blend_property_to(prop_type, next_values, blend_factor, axis_flag);
420 }
421
422 break;
423 }
424 /* Those are handled in pose_slide_rest_pose_apply. */
426 break;
427 }
428 }
429}
430
432 SlideSubject &slide_subject,
433 const Span<PropertySnapshot> snapshots)
434{
435 for (const PropertySnapshot &snapshot : snapshots) {
436 std::optional<std::string> path = RNA_path_from_ID_to_property(&slide_subject.ptr,
437 snapshot.property);
438 if (!path) {
440 continue;
441 }
442 const float factor = ED_slider_factor_get(pso.slider);
443 Array<float> base_values = snapshot.values;
444 Array<float> next_frame_values = base_values;
445 Array<float> prev_frame_values = base_values;
446 {
447 float prev_frame, next_frame;
448 const bool success = pose_frame_range_from_id_get(
449 &pso, slide_subject.ptr.owner_id, &prev_frame, &next_frame);
450 /* All `SlideSubject`s should have a frame range. */
451 BLI_assert(success);
452 UNUSED_VARS_NDEBUG(success);
453 const Vector<FCurve *> fcurves = fcurves_filtered_by_path(slide_subject.fcurves,
454 path.value());
455 if (fcurves.size() == 0) {
456 /* Property is not animated. */
457 continue;
458 }
459 for (const FCurve *fcurve : fcurves) {
460 prev_frame_values[fcurve->array_index] = evaluate_fcurve(fcurve, prev_frame);
461 next_frame_values[fcurve->array_index] = evaluate_fcurve(fcurve, next_frame);
462 }
463 }
464
465 Array<float> values;
466 switch (pso.mode) {
467 case POSESLIDE_PUSH:
468 case POSESLIDE_RELAX: {
469 /* See comment in `pose_slide_apply_linear` for the meaning of those values
470 * and push/relax. */
471 const float current_frame_factor = (pso.current_frame - pso.prev_frame) /
472 float(pso.next_frame - pso.prev_frame);
473 const Array<float> current_frame_breakdown = ed::property_interpolated(
474 prev_frame_values, next_frame_values, current_frame_factor);
475 const float factor_sign = pso.mode == POSESLIDE_RELAX ? 1 : -1;
477 base_values, current_frame_breakdown, factor * factor_sign);
478 break;
479 }
480
482 values = ed::property_interpolated(prev_frame_values, next_frame_values, factor);
483 break;
484
485 case POSESLIDE_BLEND: {
486 const float blend_factor = fabsf((factor - 0.5f) * 2);
487 if (factor < 0.5) {
488 values = ed::property_interpolated(base_values, prev_frame_values, blend_factor);
489 }
490 else {
491 values = ed::property_interpolated(base_values, next_frame_values, blend_factor);
492 }
493 break;
494 }
496 /* Those are handled in pose_slide_rest_pose_apply. */
498 values = base_values;
499 break;
500 }
501 animrig::rna_property_set_as_float(slide_subject.ptr, *snapshot.property, values);
502 }
503}
504
508static void pose_slide_apply_quat(tPoseSlideOp *pso, SlideSubject *slide_subject)
509{
510 ed::AnimTransformable *transformable = slide_subject->transformable;
511 float prev_frame, next_frame;
512
513 if (!pose_frame_range_from_id_get(pso, transformable->owner_id(), &prev_frame, &next_frame)) {
514 BLI_assert_msg(0, "Invalid slide_subject data");
515 return;
516 }
517
518 const std::string path = transformable->rna_path_to_property(
520
521 const float current_frame = float(pso->current_frame);
522 const float factor = ED_slider_factor_get(pso->slider);
523
524 /* By using `get_rotation()` we use the current values as default in case they are not animated.
525 * Due to using spherical interpolation, the not-animated values may be modified which may not be
526 * expected by the user. Ideally this throws a warning. */
527 ed::Rotation rot_prev_frame = transformable->get_rotation();
528 ed::Rotation rot_next_frame = rot_prev_frame;
529 Vector<FCurve *> quaternion_fcurves = fcurves_filtered_by_path(slide_subject->fcurves, path);
530 for (const FCurve *fcurve : quaternion_fcurves) {
531 rot_prev_frame.values[fcurve->array_index] = evaluate_fcurve(fcurve, prev_frame);
532 rot_next_frame.values[fcurve->array_index] = evaluate_fcurve(fcurve, next_frame);
533 }
534 normalize_qt(rot_prev_frame.values.data());
535 normalize_qt(rot_next_frame.values.data());
536
537 switch (pso->mode) {
538 case POSESLIDE_PUSH:
539 case POSESLIDE_RELAX: {
540 /* Compute breakdown based on actual frame range. */
541 const float interp_factor = (current_frame - pso->prev_frame) /
542 float(pso->next_frame - pso->prev_frame);
544 rot_prev_frame, rot_next_frame, interp_factor);
545
546 if (pso->mode == POSESLIDE_PUSH) {
547 transformable->blend_rotation_to(breakdown, -factor, ed::AXIS_MUTABLE_ALL);
548 }
549 else {
551 transformable->blend_rotation_to(breakdown, factor, ed::AXIS_MUTABLE_ALL);
552 }
553 break;
554 }
555
557 transformable->set_rotation(rot_prev_frame);
558 transformable->blend_rotation_to(rot_next_frame, factor, ed::AXIS_MUTABLE_ALL);
559 break;
560
561 case POSESLIDE_BLEND: {
562 const float blend_factor = fabs((factor - 0.5f) * 2);
563 if (factor < 0.5) {
564 transformable->blend_rotation_to(rot_prev_frame, blend_factor, ed::AXIS_MUTABLE_ALL);
565 }
566 else {
567 transformable->blend_rotation_to(rot_next_frame, blend_factor, ed::AXIS_MUTABLE_ALL);
568 }
569 break;
570 }
571
574 break;
575 }
576}
577
582{
583 const ed::AxisMutable axis_flag = ed::AxisMutable(pso->axis_mutability);
584 const float slider_factor = ED_slider_factor_get(pso->slider);
585 /* For each link, handle each set of transforms. */
586 for (SlideSubject &slide_subject : pso->slide_subjects) {
587 /* Valid transforms for each #bPoseChannel should have been noted already.
588 * - Sliding the pose should be a straightforward exercise for location+rotation,
589 * but rotations get more complicated since we may want to use quaternion blending
590 * for quaternions instead.
591 */
592 ed::AnimTransformable *transformable = slide_subject.transformable;
593
594 if (ELEM(pso->channels, PS_TFM_ALL, PS_TFM_LOC) &&
595 (slide_subject.transform_flag & ACT_TRANS_LOC))
596 {
597 transformable->blend_property_to(
598 ed::AnimTransformable::PropertyType::LOCATION, 0.0f, slider_factor, axis_flag);
599 }
600
601 if (ELEM(pso->channels, PS_TFM_ALL, PS_TFM_SCALE) &&
602 (slide_subject.transform_flag & ACT_TRANS_SCALE))
603 {
604 transformable->blend_property_to(
605 ed::AnimTransformable::PropertyType::SCALE, 1.0f, slider_factor, axis_flag);
606 }
607
608 if (ELEM(pso->channels, PS_TFM_ALL, PS_TFM_ROT) &&
609 (slide_subject.transform_flag & ACT_TRANS_ROT))
610 {
611 transformable->blend_rotation_to(
612 ed::identity_rotation(transformable->get_rotation_mode()), slider_factor, axis_flag);
613 }
614
616 (slide_subject.transform_flag & ACT_TRANS_BBONE))
617 {
618 /* TODO: Not implemented. */
619 }
620
621 if (ELEM(pso->channels, PS_TFM_ALL, PS_TFM_PROPS)) {
622 /* TODO: Not implemented. */
623 }
624 }
625
626 /* Depsgraph updates + redraws. */
627 pose_slide_refresh(C, pso);
628}
629
634{
635 /* Sanitize the frame ranges. */
636 if (pso->prev_frame == pso->next_frame) {
637 /* Move out one step either side. */
638 pso->prev_frame--;
639 pso->next_frame++;
640
641 for (ObjectFrameRange &object_range : pso->ob_data_array) {
642 AnimData *adt = object_range.object->adt;
643 /* Apply NLA mapping corrections so the frame look-ups work. */
644 object_range.prev_frame = BKE_nla_tweakedit_remap(
646 object_range.next_frame = BKE_nla_tweakedit_remap(
648 }
649 }
650
651 /* For each link, handle each set of transforms. */
652 for (SlideSubject &slide_subject : pso->slide_subjects) {
653 ed::AnimTransformable *transformable = slide_subject.transformable;
654
655 if (ELEM(pso->channels, PS_TFM_ALL, PS_TFM_LOC) &&
656 (slide_subject.transform_flag & ACT_TRANS_LOC))
657 {
658 /* Calculate these for the 'location' vector, and use location curves. */
660 }
661
662 if (ELEM(pso->channels, PS_TFM_ALL, PS_TFM_SCALE) &&
663 (slide_subject.transform_flag & ACT_TRANS_SCALE))
664 {
665 /* Calculate these for the 'scale' vector, and use scale curves. */
667 }
668
669 if (ELEM(pso->channels, PS_TFM_ALL, PS_TFM_ROT) &&
670 (slide_subject.transform_flag & ACT_TRANS_ROT))
671 {
672 /* Everything depends on the rotation mode. */
673 const eRotationModes rot_mode = transformable->get_rotation_mode();
674 if (rot_mode > 0) {
677 }
678 else if (rot_mode == ROT_MODE_AXISANGLE) {
679 /* TODO: need to figure out how to do this! */
680 }
681 else {
682 /* Quaternions - use quaternion blending. */
683 pose_slide_apply_quat(pso, &slide_subject);
684 }
685 }
686
688 (slide_subject.transform_flag & ACT_TRANS_BBONE))
689 {
691 *pso, slide_subject, slide_subject.additional_properties);
692 }
693
694 if (ELEM(pso->channels, PS_TFM_ALL, PS_TFM_PROPS)) {
695 pose_slide_apply_property_snapshots(*pso, slide_subject, slide_subject.properties);
696 pose_slide_apply_property_snapshots(*pso, slide_subject, slide_subject.system_properties);
697 }
698 }
699
700 /* Depsgraph updates + redraws. */
701 pose_slide_refresh(C, pso);
702}
703
708{
709 /* Wrapper around the generic call. */
711}
712
717{
718 /* Wrapper around the generic call, so that custom stuff can be added later. */
720}
721
722/* ------------------------------------ */
723
730{
731 const char *mode_st;
732 switch (pso->mode) {
733 case POSESLIDE_PUSH:
734 mode_st = IFACE_("Push Pose");
735 break;
736 case POSESLIDE_RELAX:
737 mode_st = IFACE_("Relax Pose");
738 break;
740 mode_st = IFACE_("Breakdown");
741 break;
742 case POSESLIDE_BLEND:
743 mode_st = IFACE_("Blend to Neighbor");
744 break;
745 default:
746 /* Unknown. */
747 mode_st = IFACE_("Sliding-Tool");
748 break;
749 }
750
752
753 WorkspaceStatus status(C);
754
755 status.item(IFACE_("Confirm"), ICON_MOUSE_LMB);
756 status.item(IFACE_("Cancel"), ICON_EVENT_ESC);
757 status.item(IFACE_("Adjust"), ICON_MOUSE_MOVE);
758
759 status.item_bool("", pso->channels == PS_TFM_LOC, ICON_EVENT_G);
760 status.item_bool("", pso->channels == PS_TFM_ROT, ICON_EVENT_R);
761 status.item_bool("", pso->channels == PS_TFM_SCALE, ICON_EVENT_S);
762 status.item_bool("", pso->channels == PS_TFM_BBONE_SHAPE, ICON_EVENT_B);
763 status.item_bool("", pso->channels == PS_TFM_PROPS, ICON_EVENT_C);
764
765 switch (pso->channels) {
766 case PS_TFM_LOC:
767 status.item("Location Only", ICON_NONE);
768 break;
769 case PS_TFM_ROT:
770 status.item("Rotation Only", ICON_NONE);
771 break;
772 case PS_TFM_SCALE:
773 status.item("Scale Only", ICON_NONE);
774 break;
776 status.item("Bendy Bones Only", ICON_NONE);
777 break;
778 case PS_TFM_PROPS:
779 status.item("Custom Properties Only", ICON_NONE);
780 break;
781 default:
782 status.item("Transform limits", ICON_NONE);
783 break;
784 }
785
787 status.item_bool("", pso->axis_mutability & ed::AXIS_MUTABLE_X, ICON_EVENT_X);
788 status.item_bool("", pso->axis_mutability & ed::AXIS_MUTABLE_Y, ICON_EVENT_Y);
789 status.item_bool("", pso->axis_mutability & ed::AXIS_MUTABLE_Z, ICON_EVENT_Z);
790 status.item(pso->axis_mutability == ed::AXIS_MUTABLE_ALL ? IFACE_("All Axes") :
791 IFACE_("Single Axis"),
792 ICON_NONE);
793 }
794
795 if (hasNumInput(&pso->num)) {
796 Scene *scene = pso->scene;
797 char str_offs[NUM_STR_REP_LEN];
798
799 outputNumInput(&pso->num, str_offs, scene->unit);
800
801 status.item(str_offs, ICON_NONE);
802 }
803 else if (pso->area && (pso->area->spacetype == SPACE_VIEW3D)) {
804 ED_slider_status_get(pso->slider, status);
805 View3D *v3d = static_cast<View3D *>(pso->area->spacedata.first_);
806 status.item_bool(
807 IFACE_("Bone Visibility"), !(v3d->overlay.flag & V3D_OVERLAY_HIDE_BONES), ICON_EVENT_H);
808 }
809}
810
815{
816 wmWindow *win = CTX_wm_window(C);
817
818 tPoseSlideOp *pso = static_cast<tPoseSlideOp *>(op->customdata);
819
820 ED_slider_init(pso->slider, event);
821
822 /* For each link, add all its keyframes to the search tree. */
823 for (SlideSubject &slide_subject : pso->slide_subjects) {
824 /* Do this for each F-Curve. */
825 for (FCurve *fcu : slide_subject.fcurves) {
826 AnimData *adt = BKE_animdata_from_id(slide_subject.transformable->owner_id());
827 fcurve_to_keylist(adt, fcu, pso->keylist, 0, {-FLT_MAX, FLT_MAX}, adt != nullptr);
828 }
829 }
830
831 /* Cancel if no keyframes found. */
833 if (ED_keylist_is_empty(pso->keylist)) {
834 BKE_report(op->reports, RPT_ERROR, "No keyframes to slide between");
835 pose_slide_exit(C, op);
836 return OPERATOR_CANCELLED;
837 }
838
839 float current_frame = float(pso->current_frame);
840
841 /* Firstly, check if the current frame is a keyframe. */
842 const ActKeyColumn *ak = ED_keylist_find_exact(pso->keylist, current_frame);
843
844 if (ak == nullptr) {
845 /* Current frame is not a keyframe, so search. */
846 const ActKeyColumn *pk = ED_keylist_find_prev(pso->keylist, current_frame);
847 const ActKeyColumn *nk = ED_keylist_find_next(pso->keylist, current_frame);
848
849 /* New set the frames. */
850 /* Previous frame. */
851 pso->prev_frame = (pk) ? (pk->cfra) : (pso->current_frame - 1);
852 RNA_int_set(op->ptr, "prev_frame", pso->prev_frame);
853 /* Next frame. */
854 pso->next_frame = (nk) ? (nk->cfra) : (pso->current_frame + 1);
855 RNA_int_set(op->ptr, "next_frame", pso->next_frame);
856 }
857 else {
858 /* Current frame itself is a keyframe, so just take keyframes on either side. */
859 /* Previous frame. */
860 pso->prev_frame = (ak->prev) ? (ak->prev->cfra) : (pso->current_frame - 1);
861 RNA_int_set(op->ptr, "prev_frame", pso->prev_frame);
862 /* Next frame. */
863 pso->next_frame = (ak->next) ? (ak->next->cfra) : (pso->current_frame + 1);
864 RNA_int_set(op->ptr, "next_frame", pso->next_frame);
865 }
866
867 /* Apply NLA mapping corrections so the frame look-ups work. */
868 for (ObjectFrameRange &object_range : pso->ob_data_array) {
869 AnimData *adt = object_range.object->adt;
872 }
873
874 /* Initial apply for operator. */
875 /* TODO: need to calculate factor for initial round too. */
876 if (!ELEM(pso->mode, POSESLIDE_BLEND_REST)) {
877 pose_slide_apply(C, pso);
878 }
879 else {
881 }
882
883 /* Depsgraph updates + redraws. */
884 pose_slide_refresh(C, pso);
885
886 /* Set cursor to indicate modal. */
888
889 /* Header print. */
891
892 /* Add a modal handler for this operator. */
894
896}
897
902 tPoseSlideOp *pso,
903 ePoseSlide_Channels channel)
904{
905 /* Turn channel on or off? */
906 if (pso->channels == channel) {
907 /* Already limiting to transform only, so pressing this again turns it off */
908 pso->channels = PS_TFM_ALL;
909 }
910 else {
911 /* Only this set of channels */
912 pso->channels = channel;
913 }
914 RNA_enum_set(op->ptr, "channels", pso->channels);
915
916 /* Reset axis limits too for good measure */
918 RNA_enum_set(op->ptr, "axis_lock", pso->axis_mutability);
919}
920
925 tPoseSlideOp *pso,
926 const ed::AxisMutable axis)
927{
928 /* Axis can only be set when a transform is set - it doesn't make sense otherwise */
931 RNA_enum_set(op->ptr, "axis_lock", pso->axis_mutability);
932 return false;
933 }
934
935 /* Turn on or off? */
936 if (pso->axis_mutability == axis) {
937 /* Already limiting on this axis, so turn off */
939 }
940 else {
941 /* Only this axis */
942 pso->axis_mutability = axis;
943 }
944 RNA_enum_set(op->ptr, "axis_lock", pso->axis_mutability);
945
946 /* Setting changed, so pose update is needed */
947 return true;
948}
949
954{
955 tPoseSlideOp *pso = static_cast<tPoseSlideOp *>(op->customdata);
956 wmWindow *win = CTX_wm_window(C);
957 bool do_pose_update = ED_slider_modal(pso->slider, event);
958
959 switch (event->type) {
960 case LEFTMOUSE: /* Confirm. */
961 case EVT_RETKEY:
962 case EVT_PADENTER: {
963 if (event->val == KM_PRESS) {
964 /* Return to normal cursor and header status. */
965 ED_workspace_status_text(C, nullptr);
967
968 /* Depsgraph updates + redraws. Redraw needed to remove UI. */
969 pose_slide_refresh(C, pso);
970
971 /* Insert keyframes as required. */
973 pose_slide_exit(C, op);
974
975 /* Done! */
976 return OPERATOR_FINISHED;
977 }
978 break;
979 }
980
981 case EVT_ESCKEY: /* Cancel. */
982 case RIGHTMOUSE: {
983 if (event->val == KM_PRESS) {
984 /* Return to normal cursor and header status. */
985 ED_workspace_status_text(C, nullptr);
987
988 /* Reset transforms back to original state. */
989 pose_slide_reset(pso);
990
991 /* Depsgraph updates + redraws. */
992 pose_slide_refresh(C, pso);
993
994 /* Clean up temp data. */
995 pose_slide_exit(C, op);
996
997 /* Canceled! */
998 return OPERATOR_CANCELLED;
999 }
1000 break;
1001 }
1002
1003 /* Factor Change... */
1004 case MOUSEMOVE: {
1005 /* `ED_slider_modal` already set `do_pose_update`. */
1006 /* Reset numInput so the cursor movement can take over again. This allows to type in a number
1007 * and then continue sliding around from there. */
1008 initNumInput(&pso->num);
1009 break;
1010 }
1011 default: {
1012 if ((event->val == KM_PRESS) && handleNumInput(C, &pso->num, event)) {
1013 float value;
1014
1015 /* Grab percentage from numeric input, and store this new value for redo
1016 * NOTE: users see ints, while internally we use a 0-1 float
1017 */
1018 value = ED_slider_factor_get(pso->slider) * 100.0f;
1019 applyNumInput(&pso->num, &value);
1020
1021 float factor = value / 100;
1022 ED_slider_factor_set(pso->slider, factor);
1023 RNA_float_set(op->ptr, "factor", ED_slider_factor_get(pso->slider));
1024
1025 /* Update pose to reflect the new values (see below) */
1026 do_pose_update = true;
1027 break;
1028 }
1029 if (event->val == KM_PRESS) {
1030 switch (event->type) {
1031 /* Transform Channel Limits. */
1032 /* XXX: Replace these hard-coded hotkeys with a modal-map that can be customized. */
1033 case EVT_GKEY: /* Location */
1034 {
1036 do_pose_update = true;
1037 break;
1038 }
1039 case EVT_RKEY: /* Rotation */
1040 {
1042 do_pose_update = true;
1043 break;
1044 }
1045 case EVT_SKEY: /* Scale */
1046 {
1048 do_pose_update = true;
1049 break;
1050 }
1051 case EVT_BKEY: /* Bendy Bones */
1052 {
1054 do_pose_update = true;
1055 break;
1056 }
1057 case EVT_CKEY: /* Custom Properties */
1058 {
1060 do_pose_update = true;
1061 break;
1062 }
1063
1064 /* Axis Locks */
1065 /* XXX: Hardcoded... */
1066 case EVT_XKEY: {
1068 do_pose_update = true;
1069 }
1070 break;
1071 }
1072 case EVT_YKEY: {
1074 do_pose_update = true;
1075 }
1076 break;
1077 }
1078 case EVT_ZKEY: {
1080 do_pose_update = true;
1081 }
1082 break;
1083 }
1084
1085 /* Toggle Bone visibility. */
1086 case EVT_HKEY: {
1087 if (pso->area && (pso->area->spacetype == SPACE_VIEW3D)) {
1088 View3D *v3d = static_cast<View3D *>(pso->area->spacedata.first_);
1091 }
1092 break;
1093 }
1094
1095 default: /* Some other unhandled key... */
1096 break;
1097 }
1098 }
1099 else {
1100 /* Unhandled event - maybe it was some view manipulation? */
1101 /* Allow to pass through. */
1103 }
1104 }
1105 }
1106
1107 /* Perform pose updates - in response to some user action
1108 * (e.g. pressing a key or moving the mouse). */
1109 if (do_pose_update) {
1110 RNA_float_set(op->ptr, "factor", ED_slider_factor_get(pso->slider));
1111
1112 /* Update percentage indicator in header. */
1114
1115 /* Reset transforms (to avoid accumulation errors). */
1116 pose_slide_reset(pso);
1117
1118 /* Apply. */
1119 if (!ELEM(pso->mode, POSESLIDE_BLEND_REST)) {
1120 pose_slide_apply(C, pso);
1121 }
1122 else {
1124 }
1125 }
1126
1127 /* Still running. */
1129}
1130
1135{
1136 /* Cleanup and done. */
1137 pose_slide_exit(C, op);
1138}
1139
1144{
1145 /* Settings should have been set up ok for applying, so just apply! */
1146 if (!ELEM(pso->mode, POSESLIDE_BLEND_REST)) {
1147 pose_slide_apply(C, pso);
1148 }
1149 else {
1151 }
1152
1153 /* Insert keyframes if needed. */
1155
1156 /* Cleanup and done. */
1157 pose_slide_exit(C, op);
1158
1159 return OPERATOR_FINISHED;
1160}
1161
1166{
1167 PropertyRNA *prop;
1168
1169 prop = RNA_def_float_factor(ot->srna,
1170 "factor",
1171 0.5f,
1172 0.0f,
1173 1.0f,
1174 "Factor",
1175 "Weighting factor for which keyframe is favored more",
1176 0.0,
1177 1.0);
1179
1180 prop = RNA_def_int(ot->srna,
1181 "prev_frame",
1182 0,
1183 MINAFRAME,
1184 MAXFRAME,
1185 "Previous Keyframe",
1186 "Frame number of keyframe immediately before the current frame",
1187 0,
1188 50);
1190
1191 prop = RNA_def_int(ot->srna,
1192 "next_frame",
1193 0,
1194 MINAFRAME,
1195 MAXFRAME,
1196 "Next Keyframe",
1197 "Frame number of keyframe immediately after the current frame",
1198 0,
1199 50);
1201
1202 prop = RNA_def_enum(ot->srna,
1203 "channels",
1205 PS_TFM_ALL,
1206 "Channels",
1207 "Set of properties that are affected");
1209 prop = RNA_def_enum(ot->srna,
1210 "axis_lock",
1213 "Axis Lock",
1214 "Transform axis to restrict effects to");
1216}
1217
1218/* ------------------------------------ */
1219
1224{
1225 /* Initialize data. */
1226 if (pose_slide_init(C, op, POSESLIDE_PUSH) == 0) {
1227 pose_slide_exit(C, op);
1228 return OPERATOR_CANCELLED;
1229 }
1230
1231 /* Do common setup work. */
1232 return pose_slide_invoke_common(C, op, event);
1233}
1234
1239{
1240 tPoseSlideOp *pso;
1241
1242 /* Initialize data (from RNA-props). */
1243 if (pose_slide_init(C, op, POSESLIDE_PUSH) == 0) {
1244 pose_slide_exit(C, op);
1245 return OPERATOR_CANCELLED;
1246 }
1247
1248 pso = static_cast<tPoseSlideOp *>(op->customdata);
1249
1250 /* Do common exec work. */
1251 return pose_slide_exec_common(C, op, pso);
1252}
1253
1255{
1256 /* identifiers */
1257 ot->name = "Push Pose from Breakdown";
1258 ot->idname = "POSE_OT_push";
1259 ot->description = "Exaggerate the current pose in regards to the breakdown pose";
1260
1261 /* callbacks */
1264 ot->modal = pose_slide_modal;
1266 ot->poll = pose_slide_poll;
1267
1268 /* flags */
1270
1271 /* Properties */
1273}
1274
1275/* ........................ */
1276
1281{
1282 /* Initialize data. */
1283 if (pose_slide_init(C, op, POSESLIDE_RELAX) == 0) {
1284 pose_slide_exit(C, op);
1285 return OPERATOR_CANCELLED;
1286 }
1287
1288 /* Do common setup work. */
1289 return pose_slide_invoke_common(C, op, event);
1290}
1291
1296{
1297 tPoseSlideOp *pso;
1298
1299 /* Initialize data (from RNA-props). */
1300 if (pose_slide_init(C, op, POSESLIDE_RELAX) == 0) {
1301 pose_slide_exit(C, op);
1302 return OPERATOR_CANCELLED;
1303 }
1304
1305 pso = static_cast<tPoseSlideOp *>(op->customdata);
1306
1307 /* Do common exec work. */
1308 return pose_slide_exec_common(C, op, pso);
1309}
1310
1312{
1313 /* identifiers */
1314 ot->name = "Relax Pose to Breakdown";
1315 ot->idname = "POSE_OT_relax";
1316 ot->description = "Make the current pose more similar to its breakdown pose";
1317
1318 /* callbacks */
1321 ot->modal = pose_slide_modal;
1323 ot->poll = pose_slide_poll;
1324
1325 /* flags */
1327
1328 /* Properties */
1330}
1331
1332/* ........................ */
1337 wmOperator *op,
1338 const wmEvent *event)
1339{
1340 /* Initialize data. */
1341 if (pose_slide_init(C, op, POSESLIDE_BLEND_REST) == 0) {
1342 pose_slide_exit(C, op);
1343 return OPERATOR_CANCELLED;
1344 }
1345
1346 tPoseSlideOp *pso = static_cast<tPoseSlideOp *>(op->customdata);
1349
1350 /* do common setup work */
1351 return pose_slide_invoke_common(C, op, event);
1352}
1353
1358{
1359 tPoseSlideOp *pso;
1360
1361 /* Initialize data (from RNA-props). */
1362 if (pose_slide_init(C, op, POSESLIDE_BLEND_REST) == 0) {
1363 pose_slide_exit(C, op);
1364 return OPERATOR_CANCELLED;
1365 }
1366
1367 pso = static_cast<tPoseSlideOp *>(op->customdata);
1368
1369 /* Do common exec work. */
1370 return pose_slide_exec_common(C, op, pso);
1371}
1372
1374{
1375 /* identifiers */
1376 ot->name = "Blend Pose with Rest Pose";
1377 ot->idname = "POSE_OT_blend_with_rest";
1378 ot->description = "Make the current pose more similar to, or further away from, the rest pose";
1379
1380 /* callbacks */
1383 ot->modal = pose_slide_modal;
1385 ot->poll = pose_slide_poll;
1386
1387 /* flags */
1389
1390 /* Properties */
1392}
1393
1394/* ........................ */
1395
1400 wmOperator *op,
1401 const wmEvent *event)
1402{
1403 /* Initialize data. */
1404 if (pose_slide_init(C, op, POSESLIDE_BREAKDOWN) == 0) {
1405 pose_slide_exit(C, op);
1406 return OPERATOR_CANCELLED;
1407 }
1408
1409 /* Do common setup work. */
1410 return pose_slide_invoke_common(C, op, event);
1411}
1412
1417{
1418 tPoseSlideOp *pso;
1419
1420 /* Initialize data (from RNA-props). */
1421 if (pose_slide_init(C, op, POSESLIDE_BREAKDOWN) == 0) {
1422 pose_slide_exit(C, op);
1423 return OPERATOR_CANCELLED;
1424 }
1425
1426 pso = static_cast<tPoseSlideOp *>(op->customdata);
1427
1428 /* Do common exec work. */
1429 return pose_slide_exec_common(C, op, pso);
1430}
1431
1433{
1434 /* identifiers */
1435 ot->name = "Pose Breakdowner";
1436 ot->idname = "POSE_OT_breakdown";
1437 ot->description = "Create a suitable breakdown pose on the current frame";
1438
1439 /* callbacks */
1442 ot->modal = pose_slide_modal;
1444 ot->poll = pose_slide_poll;
1445
1446 /* flags */
1448
1449 /* Properties */
1451}
1452
1453/* ........................ */
1455 wmOperator *op,
1456 const wmEvent *event)
1457{
1458 /* Initialize data. */
1459 if (pose_slide_init(C, op, POSESLIDE_BLEND) == 0) {
1460 pose_slide_exit(C, op);
1461 return OPERATOR_CANCELLED;
1462 }
1463
1464 /* Do common setup work. */
1465 return pose_slide_invoke_common(C, op, event);
1466}
1467
1469{
1470 tPoseSlideOp *pso;
1471
1472 /* Initialize data (from RNA-props). */
1473 if (pose_slide_init(C, op, POSESLIDE_BLEND) == 0) {
1474 pose_slide_exit(C, op);
1475 return OPERATOR_CANCELLED;
1476 }
1477
1478 pso = static_cast<tPoseSlideOp *>(op->customdata);
1479
1480 /* Do common exec work. */
1481 return pose_slide_exec_common(C, op, pso);
1482}
1483
1485{
1486 /* Identifiers. */
1487 ot->name = "Blend to Neighbor";
1488 ot->idname = "POSE_OT_blend_to_neighbor";
1489 ot->description = "Blend from current position to previous or next keyframe";
1490
1491 /* Callbacks. */
1494 ot->modal = pose_slide_modal;
1496 ot->poll = pose_slide_poll;
1497
1498 /* Flags. */
1500
1501 /* Properties. */
1503}
1504
1505/* **************************************************** */
1506/* B) Pose Propagate */
1507
1508/* "termination conditions" - i.e. when we stop */
1524
1525/* --------------------------------- */
1526
1529 float frame;
1530};
1531
1532static void propagate_curve_values(ListBaseT<SlideSubject> *slide_subjects,
1533 const float source_frame,
1534 ListBaseT<FrameLink> *target_frames)
1535{
1536 using namespace blender::animrig;
1537 const KeyframeSettings settings = get_keyframe_settings(true);
1538 for (SlideSubject &slide_subject : *slide_subjects) {
1539 for (FCurve *fcu : slide_subject.fcurves) {
1540 if (!fcu->bezt) {
1541 continue;
1542 }
1543 const float current_fcu_value = evaluate_fcurve(fcu, source_frame);
1544 for (FrameLink &target_frame : *target_frames) {
1546 fcu, {target_frame.frame, current_fcu_value}, settings, INSERTKEY_NOFLAGS);
1547 }
1548 }
1549 }
1550}
1551
1552static float find_next_key(const ListBaseT<SlideSubject> *slide_subjects, const float start_frame)
1553{
1554 float target_frame = FLT_MAX;
1555 for (const SlideSubject &slide_subject : *slide_subjects) {
1556 for (const FCurve *fcu : slide_subject.fcurves) {
1557 if (!fcu->bezt) {
1558 continue;
1559 }
1560 bool replace;
1561 int current_frame_index = BKE_fcurve_bezt_binarysearch_index(
1562 fcu->bezt, start_frame, fcu->totvert, &replace);
1563 if (replace) {
1564 current_frame_index += 1;
1565 }
1566 const int bezt_index = min_ii(current_frame_index, fcu->totvert - 1);
1567 target_frame = min_ff(target_frame, fcu->bezt[bezt_index].vec[1][0]);
1568 }
1569 }
1570
1571 return target_frame;
1572}
1573
1574static float find_last_key(const ListBaseT<SlideSubject> *slide_subjects)
1575{
1576 float target_frame = FLT_MIN;
1577 for (const SlideSubject &slide_subject : *slide_subjects) {
1578 for (const FCurve *fcu : slide_subject.fcurves) {
1579 if (!fcu->bezt) {
1580 continue;
1581 }
1582 target_frame = max_ff(target_frame, fcu->bezt[fcu->totvert - 1].vec[1][0]);
1583 }
1584 }
1585
1586 return target_frame;
1587}
1588
1589static void get_selected_marker_positions(Scene *scene, ListBaseT<FrameLink> *target_frames)
1590{
1591 ListBaseT<CfraElem> selected_markers = {nullptr, nullptr};
1592 ED_markers_make_cfra_list(&scene->markers, &selected_markers, true);
1593 for (const CfraElem &marker : selected_markers) {
1594 FrameLink *link = MEM_new_zeroed<FrameLink>("Marker Key Link");
1595 link->frame = marker.cfra;
1596 BLI_addtail(target_frames, link);
1597 }
1598 selected_markers.free_no_destruct();
1599}
1600
1601static void get_keyed_frames_in_range(const ListBaseT<SlideSubject> *slide_subjects,
1602 const float start_frame,
1603 const float end_frame,
1604 ListBaseT<FrameLink> *target_frames)
1605{
1606 AnimKeylist *keylist = ED_keylist_create();
1607 for (const SlideSubject &slide_subject : *slide_subjects) {
1608 for (FCurve *fcu : slide_subject.fcurves) {
1609 fcurve_to_keylist(nullptr, fcu, keylist, 0, {start_frame, end_frame}, false);
1610 }
1611 }
1612 for (const ActKeyColumn &column : *ED_keylist_listbase(keylist)) {
1613 if (column.cfra <= start_frame) {
1614 continue;
1615 }
1616 if (column.cfra > end_frame) {
1617 break;
1618 }
1619 FrameLink *link = MEM_new_zeroed<FrameLink>("Marker Key Link");
1620 link->frame = column.cfra;
1621 BLI_addtail(target_frames, link);
1622 }
1623 ED_keylist_free(keylist);
1624}
1625
1626static void get_selected_frames(const ListBaseT<SlideSubject> *slide_subjects,
1627 ListBaseT<FrameLink> *target_frames)
1628{
1629 AnimKeylist *keylist = ED_keylist_create();
1630 for (const SlideSubject &slide_subject : *slide_subjects) {
1631 for (FCurve *fcu : slide_subject.fcurves) {
1632 fcurve_to_keylist(nullptr, fcu, keylist, 0, {-FLT_MAX, FLT_MAX}, false);
1633 }
1634 }
1635 for (ActKeyColumn &column : *ED_keylist_listbase(keylist)) {
1636 if (!column.sel) {
1637 continue;
1638 }
1639 FrameLink *link = MEM_new_zeroed<FrameLink>("Marker Key Link");
1640 link->frame = column.cfra;
1641 BLI_addtail(target_frames, link);
1642 }
1643 ED_keylist_free(keylist);
1644}
1645
1646/* --------------------------------- */
1647
1649{
1650 Scene *scene = CTX_data_scene(C);
1651 ListBaseT<SlideSubject> slide_subjects = {nullptr, nullptr};
1652
1653 const int mode = RNA_enum_get(op->ptr, "mode");
1654
1655 /* Isolate F-Curves related to the selected bones. */
1656 slide_subjects_get(C, &slide_subjects);
1657
1658 if (slide_subjects.is_empty()) {
1659 /* There is a change the reason the list is empty is
1660 * that there is no valid object to propagate poses for.
1661 * This is very unlikely though, so we focus on the most likely issue. */
1662 BKE_report(op->reports, RPT_ERROR, "No keyframed poses to propagate to");
1663 return OPERATOR_CANCELLED;
1664 }
1665
1666 const float end_frame = RNA_float_get(op->ptr, "end_frame");
1667 const float current_frame = BKE_scene_frame_get(scene);
1668
1669 ListBaseT<FrameLink> target_frames = {nullptr, nullptr};
1670
1671 switch (mode) {
1673 float target_frame = find_next_key(&slide_subjects, current_frame);
1674 FrameLink *link = MEM_new_zeroed<FrameLink>("Next Key Link");
1675 link->frame = target_frame;
1676 BLI_addtail(&target_frames, link);
1677 propagate_curve_values(&slide_subjects, current_frame, &target_frames);
1678 break;
1679 }
1680
1682 float target_frame = find_last_key(&slide_subjects);
1683 FrameLink *link = MEM_new_zeroed<FrameLink>("Last Key Link");
1684 link->frame = target_frame;
1685 BLI_addtail(&target_frames, link);
1686 propagate_curve_values(&slide_subjects, current_frame, &target_frames);
1687 break;
1688 }
1689
1691 get_selected_marker_positions(scene, &target_frames);
1692 propagate_curve_values(&slide_subjects, current_frame, &target_frames);
1693 break;
1694 }
1695
1697 get_keyed_frames_in_range(&slide_subjects, current_frame, FLT_MAX, &target_frames);
1698 propagate_curve_values(&slide_subjects, current_frame, &target_frames);
1699 break;
1700 }
1702 get_keyed_frames_in_range(&slide_subjects, current_frame, end_frame, &target_frames);
1703 propagate_curve_values(&slide_subjects, current_frame, &target_frames);
1704 break;
1705 }
1707 get_selected_frames(&slide_subjects, &target_frames);
1708 propagate_curve_values(&slide_subjects, current_frame, &target_frames);
1709 break;
1710 }
1711 }
1712
1713 target_frames.free_no_destruct();
1714
1715 for (SlideSubject &slide_subject : slide_subjects) {
1716 slide_subjects_refresh(C, slide_subject);
1717 }
1718
1719 /* Free temp data. */
1720 slide_subjects_free(&slide_subjects);
1721
1722 return OPERATOR_FINISHED;
1723}
1724
1725/* --------------------------------- */
1726
1728{
1729 static const EnumPropertyItem terminate_items[] = {
1731 "NEXT_KEY",
1732 0,
1733 "To Next Keyframe",
1734 "Propagate pose to first keyframe following the current frame only"},
1736 "LAST_KEY",
1737 0,
1738 "To Last Keyframe",
1739 "Propagate pose to the last keyframe only (i.e. making action cyclic)"},
1741 "BEFORE_FRAME",
1742 0,
1743 "Before Frame",
1744 "Propagate pose to all keyframes between current frame and 'Frame' property"},
1746 "BEFORE_END",
1747 0,
1748 "Before Last Keyframe",
1749 "Propagate pose to all keyframes from current frame until no more are found"},
1751 "SELECTED_KEYS",
1752 0,
1753 "On Selected Keyframes",
1754 "Propagate pose to all selected keyframes"},
1756 "SELECTED_MARKERS",
1757 0,
1758 "On Selected Markers",
1759 "Propagate pose to all keyframes occurring on frames with Scene Markers after the current "
1760 "frame"},
1761 {0, nullptr, 0, nullptr, nullptr},
1762 };
1763
1764 /* identifiers */
1765 ot->name = "Propagate Pose";
1766 ot->idname = "POSE_OT_propagate";
1767 ot->description =
1768 "Copy selected aspects of the current pose to subsequent poses already keyframed";
1769
1770 /* callbacks */
1772 ot->poll = ED_operator_posemode; /* XXX: needs selected bones! */
1773
1774 /* flag */
1776
1777 /* properties */
1778 /* TODO: add "fade out" control for tapering off amount of propagation as time goes by? */
1779 ot->prop = RNA_def_enum(ot->srna,
1780 "mode",
1781 terminate_items,
1783 "Terminate Mode",
1784 "Method used to determine when to stop propagating pose to keyframes");
1785 RNA_def_float(ot->srna,
1786 "end_frame",
1787 250.0,
1788 FLT_MIN,
1789 FLT_MAX,
1790 "End Frame",
1791 "Frame to stop propagating frames to (for 'Before Frame' mode)",
1792 1.0,
1793 250.0);
1794}
1795
1796/* **************************************************** */
1797
1798} // namespace blender
Functions to modify FCurves.
Helper functions for animation to interact with the RNA system.
General operations, lookup, etc. for blender objects.
#define IFACE_(msgid)
#define OB_MODE_ALL_WEIGHT_PAINT
Object is a sort of wrapper for general info.
#define MINAFRAME
#define MAXFRAME
Defines an abstraction around various structs to modify their transform properties via a unified API ...
#define NUM_STR_REP_LEN
Read Blender memory allocation and freeing.
#define C
Definition RandGen.cpp:29
#define BLI_assert_unreachable()
#define UNUSED_VARS_NDEBUG(...)
#define ELEM(...)
#define BLI_assert_msg(a, msg)
const T * data() const
Definition BLI_array.hh:323
int64_t size() const
Definition BLI_set.hh:606
bool add(const Key &key)
Definition BLI_set.hh:248
int64_t size() const
void append(const T &value)
void item(std::string text, int icon1, int icon2=0)
Definition area.cc:1076
void item_bool(std::string text, bool inverted, int icon1, int icon2=0)
Definition area.cc:1097
void blend_property_to(PropertyType prop_type, Span< float > target, float factor, AxisMutable axis_flag)
void set_rotation(const Rotation &rotation)
std::string rna_path_to_property(PropertyType prop_type) const
void blend_rotation_to(const Rotation &target, float factor, AxisMutable axis_flag)
eRotationModes get_rotation_mode() const
TransformFloats get_property(PropertyType prop_type) const
void set_property(PropertyType prop_type, Span< float > values, AxisMutable axis_flag)
#define FLT_MAX
#define FLT_MIN
ccl_device_inline dual3 fabs(const ccl_private dual3 &a)
Definition math_dual.h:241
KeyframeSettings get_keyframe_settings(bool from_userprefs)
void rna_property_set_as_float(PointerRNA &ptr, PropertyRNA &prop, Span< float > values)
Definition anim_rna.cc:301
SingleKeyingResult insert_vert_fcurve(FCurve *fcu, const float2 position, const KeyframeSettings &settings, eInsertKeyFlags flag)
Main Key-framing API call.
Rotation identity_rotation(const eRotationModes mode)
Rotation rotation_interpolated(const Rotation &a, const Rotation &b, const float factor)
Array< float > property_interpolated(const Span< float > a, const Span< float > b, const float factor)
BMesh Iterators.
MINLINE float min_ff(float a, float b)
static void pose_slide_refresh(bContext *C, tPoseSlideOp *pso)
BLI_assert(slot->slot_subtype.map==BMO_OP_SLOT_SUBTYPE_MAP_FLT)
bool ED_slider_modal(tSlider *slider, const wmEvent *event)
Definition ed_draw.cc:492
ScrArea * CTX_wm_area(const bContext *C)
int RNA_enum_get(PointerRNA *ptr, const char *name)
static void pose_slide_autoKeyframe(bContext *C, tPoseSlideOp *pso)
static bool pose_slide_poll(bContext *C)
Definition pose_slide.cc:78
float BKE_nla_tweakedit_remap(AnimData *adt, float cframe, eNlaTime_ConvertModes mode)
static wmOperatorStatus pose_slide_breakdown_exec(bContext *C, wmOperator *op)
void ED_markers_make_cfra_list(ListBaseT< TimeMarker > *markers, ListBaseT< CfraElem > *lb, const bool only_selected)
bool handleNumInput(bContext *C, NumInput *n, const wmEvent *event)
Definition numinput.cc:344
void ED_slider_init(tSlider *slider, const wmEvent *event)
Definition ed_draw.cc:487
std::optional< std::string > RNA_path_from_ID_to_property(const PointerRNA *ptr, PropertyRNA *prop)
Definition rna_path.cc:1237
static wmOperatorStatus pose_slide_push_invoke(bContext *C, wmOperator *op, const wmEvent *event)
void slide_subjects_free(ListBaseT< SlideSubject > *slide_subjects)
static void get_keyed_frames_in_range(const ListBaseT< SlideSubject > *slide_subjects, const float start_frame, const float end_frame, ListBaseT< FrameLink > *target_frames)
void POSE_OT_relax(wmOperatorType *ot)
void ED_slider_factor_set(tSlider *slider, float factor)
Definition ed_draw.cc:607
void POSE_OT_blend_with_rest(wmOperatorType *ot)
float normalize_qt(float q[4])
void RNA_int_set(PointerRNA *ptr, const char *name, int value)
float ED_slider_factor_get(const tSlider *slider)
Definition ed_draw.cc:602
void WM_cursor_modal_set(wmWindow *win, int val)
@ NLATIME_CONVERT_UNMAP
Definition BKE_nla.hh:560
bool ED_operator_posemode(bContext *C)
const ActKeyColumn * ED_keylist_find_prev(const AnimKeylist *keylist, const float cfra)
PropertyRNA * RNA_def_enum(StructOrFunctionRNA *cont_, const char *identifier, const EnumPropertyItem *items, const int default_value, const char *ui_name, const char *ui_description)
ePoseSlide_Channels
@ PS_TFM_BBONE_SHAPE
int RNA_int_get(PointerRNA *ptr, const char *name)
bool hasNumInput(const NumInput *n)
Definition numinput.cc:188
wmWindow * CTX_wm_window(const bContext *C)
void RNA_enum_set(PointerRNA *ptr, const char *name, int value)
enum eContextObjectMode CTX_data_mode_enum(const bContext *C)
bool ED_keylist_is_empty(const AnimKeylist *keylist)
static void get_selected_marker_positions(Scene *scene, ListBaseT< FrameLink > *target_frames)
static wmOperatorStatus pose_slide_exec_common(bContext *C, wmOperator *op, tPoseSlideOp *pso)
void ED_region_tag_redraw(ARegion *region)
Definition area.cc:681
static void pose_slide_apply_property_snapshots(tPoseSlideOp &pso, SlideSubject &slide_subject, const Span< PropertySnapshot > snapshots)
const ActKeyColumn * ED_keylist_find_exact(const AnimKeylist *keylist, const float cfra)
const ActKeyColumn * ED_keylist_find_next(const AnimKeylist *keylist, const float cfra)
@ CTX_MODE_OBJECT
static void pose_slide_reset(tPoseSlideOp *pso)
static wmOperatorStatus pose_slide_blend_rest_invoke(bContext *C, wmOperator *op, const wmEvent *event)
void slide_subjects_reset(ListBaseT< SlideSubject > *slide_subjects)
void POSE_OT_breakdown(wmOperatorType *ot)
tSlider * ED_slider_create(bContext *C)
Definition ed_draw.cc:438
PropertyRNA * RNA_def_float_factor(StructOrFunctionRNA *cont_, const char *identifier, const float default_value, const float hardmin, const float hardmax, const char *ui_name, const char *ui_description, const float softmin, const float softmax)
static wmOperatorStatus pose_slide_modal(bContext *C, wmOperator *op, const wmEvent *event)
AnimData * BKE_animdata_from_id(const ID *id)
Definition anim_data.cc:93
static void pose_slide_rest_pose_apply(bContext *C, tPoseSlideOp *pso)
void fcurve_to_keylist(AnimData *adt, FCurve *fcu, AnimKeylist *keylist, const int saction_flag, float2 range, const bool use_nla_remapping)
static void pose_slide_apply(bContext *C, tPoseSlideOp *pso)
void * MEM_new_zeroed(size_t len, const char *str) ATTR_WARN_UNUSED_RESULT ATTR_ALLOC_SIZE(1) ATTR_NONNULL(2)
static wmOperatorStatus pose_slide_blend_rest_exec(bContext *C, wmOperator *op)
void slide_subjects_get(bContext *C, ListBaseT< SlideSubject > *r_transformable_list)
float BKE_scene_frame_get(const Scene *scene)
Definition scene.cc:2595
static wmOperatorStatus pose_slide_breakdown_invoke(bContext *C, wmOperator *op, const wmEvent *event)
void BKE_report(ReportList *reports, eReportType type, const char *message)
Definition report.cc:162
static wmOperatorStatus pose_slide_relax_invoke(bContext *C, wmOperator *op, const wmEvent *event)
Object * BKE_object_pose_armature_get(Object *ob)
Definition object.cc:2507
void slide_subjects_autokey(bContext *C, Scene *scene, const ListBaseT< SlideSubject > *slide_subjects)
void initNumInput(NumInput *n)
Definition numinput.cc:85
void POSE_OT_blend_to_neighbors(wmOperatorType *ot)
ePosePropagate_Termination
@ POSE_PROPAGATE_NEXT_KEY
@ POSE_PROPAGATE_BEFORE_END
@ POSE_PROPAGATE_SELECTED_KEYS
@ POSE_PROPAGATE_BEFORE_FRAME
@ POSE_PROPAGATE_LAST_KEY
@ POSE_PROPAGATE_SELECTED_MARKERS
static const EnumPropertyItem prop_channels_types[]
void WM_cursor_modal_restore(wmWindow *win)
void ED_keylist_prepare_for_direct_access(AnimKeylist *keylist)
AnimKeylist * ED_keylist_create()
static bool pose_frame_range_from_id_get(const tPoseSlideOp *pso, const ID *id, float *prev_frame, float *next_frame)
void RNA_float_set(PointerRNA *ptr, const char *name, float value)
bool applyNumInput(NumInput *n, float *vec)
Definition numinput.cc:207
void slide_subjects_refresh(bContext *C, const SlideSubject &slide_subject)
static void pose_slide_exit(bContext *C, wmOperator *op)
static wmOperatorStatus pose_slide_blend_to_neighbors_exec(bContext *C, wmOperator *op)
static void get_selected_frames(const ListBaseT< SlideSubject > *slide_subjects, ListBaseT< FrameLink > *target_frames)
static void pose_slide_apply_linear(tPoseSlideOp &pso, SlideSubject &slide_subject, const ed::AnimTransformable::PropertyType prop_type)
@ POSESLIDE_BLEND_REST
@ POSESLIDE_BLEND
@ POSESLIDE_RELAX
@ POSESLIDE_BREAKDOWN
@ POSESLIDE_PUSH
wmEventHandler_Op * WM_event_add_modal_handler(bContext *C, wmOperator *op)
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)
static bool pose_slide_toggle_axis_mutability(wmOperator *op, tPoseSlideOp *pso, const ed::AxisMutable axis)
void ED_slider_factor_bounds_set(tSlider *slider, float factor_bound_lower, float factor_bound_upper)
Definition ed_draw.cc:642
static wmOperatorStatus pose_slide_invoke_common(bContext *C, wmOperator *op, const wmEvent *event)
@ WM_CURSOR_EW_SCROLL
Definition wm_cursors.hh:56
void BLI_addtail(ListBase *listbase, void *vlink) ATTR_NONNULL(1)
Definition listbase.cc:118
static float find_next_key(const ListBaseT< SlideSubject > *slide_subjects, const float start_frame)
static void pose_slide_apply_quat(tPoseSlideOp *pso, SlideSubject *slide_subject)
MINLINE float max_ff(float a, float b)
static wmOperatorStatus pose_slide_relax_exec(bContext *C, wmOperator *op)
void outputNumInput(NumInput *n, char *str, const UnitSettings &unit_settings)
Definition numinput.cc:104
static wmOperatorStatus pose_slide_blend_to_neighbors_invoke(bContext *C, wmOperator *op, const wmEvent *event)
ID_Type GS(const char *name)
Definition DNA_ID.h:410
@ PROP_SKIP_SAVE
Definition RNA_types.hh:414
void ED_slider_status_get(const tSlider *slider, WorkspaceStatus &status)
Definition ed_draw.cc:573
static void pose_slide_draw_status(bContext *C, tPoseSlideOp *pso)
void ED_keylist_free(AnimKeylist *keylist)
Scene * CTX_data_scene(const bContext *C)
static wmOperatorStatus pose_propagate_exec(bContext *C, wmOperator *op)
int BKE_fcurve_bezt_binarysearch_index(const BezTriple array[], float frame, int arraylen, bool *r_replace)
@ OPTYPE_REGISTER
Definition WM_types.hh:188
@ OPTYPE_UNDO
Definition WM_types.hh:190
@ OPTYPE_BLOCKING
Definition WM_types.hh:192
@ OPTYPE_GRAB_CURSOR_X
Definition WM_types.hh:198
static Vector< FCurve * > fcurves_filtered_by_path(const Span< FCurve * > input_fcurves, const StringRef path)
static void pose_slide_cancel(bContext *C, wmOperator *op)
const ListBaseT< ActKeyColumn > * ED_keylist_listbase(const AnimKeylist *keylist)
@ B_UNIT_NONE
Definition BKE_unit.hh:165
void POSE_OT_push(wmOperatorType *ot)
static void pose_slide_opdef_properties(wmOperatorType *ot)
static float find_last_key(const ListBaseT< SlideSubject > *slide_subjects)
void ED_slider_property_label_set(tSlider *slider, const char *property_label)
Definition ed_draw.cc:665
MINLINE int min_ii(int a, int b)
PropertyRNA * RNA_def_float(StructOrFunctionRNA *cont_, const char *identifier, const float default_value, const float hardmin, const float hardmax, const char *ui_name, const char *ui_description, const float softmin, const float softmax)
Object * CTX_data_active_object(const bContext *C)
void POSE_OT_propagate(wmOperatorType *ot)
ARegion * CTX_wm_region(const bContext *C)
void ED_workspace_status_text(bContext *C, const char *str)
Definition area.cc:1153
static const EnumPropertyItem prop_axis_lock_types[]
float RNA_float_get(PointerRNA *ptr, const char *name)
static wmOperatorStatus pose_slide_push_exec(bContext *C, wmOperator *op)
void ED_slider_destroy(bContext *C, tSlider *slider)
Definition ed_draw.cc:589
static void propagate_curve_values(ListBaseT< SlideSubject > *slide_subjects, const float source_frame, ListBaseT< FrameLink > *target_frames)
float evaluate_fcurve(const FCurve *fcu, float evaltime)
static void pose_slide_toggle_channels_mode(wmOperator *op, tPoseSlideOp *pso, ePoseSlide_Channels channel)
static int pose_slide_init(bContext *C, wmOperator *op, ePoseSlide_Modes mode)
#define fabsf
KERNEL_FEATURE_LIGHT_PASSES KERNEL_FEATURE_PATH_GUIDING float
unsigned int totvert
int unit_type[NUM_MAX_ELEMENTS]
struct AnimData * adt
ListBaseT< TimeMarker > markers
struct UnitSettings unit
struct RenderData r
ListBaseT< SpaceLink > spacedata
eAction_TransformFlags transform_flag
Vector< PropertySnapshot > additional_properties
Vector< PropertySnapshot > system_properties
Vector< PropertySnapshot > properties
ed::AnimTransformable * transformable
Vector< FCurve * > fcurves
eView3DOverlay_Flag flag
View3DOverlay overlay
ListBaseT< SlideSubject > slide_subjects
AnimKeylist * keylist
ePoseSlide_Channels channels
ed::AxisMutable axis_mutability
ePoseSlide_Modes mode
Array< ObjectFrameRange > ob_data_array
eView3DOverlay_Flag overlay_flag
wmEventType type
Definition WM_types.hh:817
wmOperatorStatus(*) exec(bContext *C, wmOperator *op) ATTR_WARN_UNUSED_RESULT
Definition WM_types.hh:1125
const char * description
Definition WM_types.hh:1115
void(*) cancel(bContext *C, wmOperator *op)
Definition WM_types.hh:1149
bool(*) poll(bContext *C) ATTR_WARN_UNUSED_RESULT
Definition WM_types.hh:1165
wmOperatorStatus(*) invoke(bContext *C, wmOperator *op, const wmEvent *event) ATTR_WARN_UNUSED_RESULT
Definition WM_types.hh:1141
wmOperatorStatus(*) modal(bContext *C, wmOperator *op, const wmEvent *event) ATTR_WARN_UNUSED_RESULT
Definition WM_types.hh:1157
struct ReportList * reports