Blender  V2.93
keyframing.c
Go to the documentation of this file.
1 /*
2  * This program is free software; you can redistribute it and/or
3  * modify it under the terms of the GNU General Public License
4  * as published by the Free Software Foundation; either version 2
5  * of the License, or (at your option) any later version.
6  *
7  * This program is distributed in the hope that it will be useful,
8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10  * GNU General Public License for more details.
11  *
12  * You should have received a copy of the GNU General Public License
13  * along with this program; if not, write to the Free Software Foundation,
14  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
15  *
16  * The Original Code is Copyright (C) 2009 Blender Foundation, Joshua Leung
17  * All rights reserved.
18  */
19 
24 #include <float.h>
25 #include <math.h>
26 #include <stddef.h>
27 #include <stdio.h>
28 #include <string.h>
29 
30 #include "MEM_guardedalloc.h"
31 
32 #include "BLI_blenlib.h"
33 #include "BLI_math.h"
34 #include "BLI_utildefines.h"
35 
36 #include "BLT_translation.h"
37 
38 #include "DNA_anim_types.h"
39 #include "DNA_armature_types.h"
40 #include "DNA_constraint_types.h"
41 #include "DNA_key_types.h"
42 #include "DNA_material_types.h"
43 #include "DNA_object_types.h"
44 #include "DNA_rigidbody_types.h"
45 #include "DNA_scene_types.h"
46 
47 #include "BKE_action.h"
48 #include "BKE_anim_data.h"
49 #include "BKE_animsys.h"
50 #include "BKE_armature.h"
51 #include "BKE_context.h"
52 #include "BKE_fcurve.h"
53 #include "BKE_fcurve_driver.h"
54 #include "BKE_global.h"
55 #include "BKE_idtype.h"
56 #include "BKE_key.h"
57 #include "BKE_main.h"
58 #include "BKE_material.h"
59 #include "BKE_nla.h"
60 #include "BKE_report.h"
61 
62 #include "DEG_depsgraph.h"
63 #include "DEG_depsgraph_build.h"
64 #include "DEG_depsgraph_query.h"
65 
66 #include "ED_anim_api.h"
67 #include "ED_keyframes_edit.h"
68 #include "ED_keyframing.h"
69 #include "ED_object.h"
70 #include "ED_screen.h"
71 
72 #include "UI_interface.h"
73 #include "UI_resources.h"
74 
75 #include "WM_api.h"
76 #include "WM_types.h"
77 
78 #include "RNA_access.h"
79 #include "RNA_define.h"
80 #include "RNA_enum_types.h"
81 
82 #include "anim_intern.h"
83 
85  PropertyRNA *prop,
86  Scene *scene);
87 
88 /* ************************************************** */
89 /* Keyframing Setting Wrangling */
90 
91 /* Get the active settings for keyframing settings from context (specifically the given scene) */
92 eInsertKeyFlags ANIM_get_keyframing_flags(Scene *scene, const bool use_autokey_mode)
93 {
95 
96  /* standard flags */
97  {
98  /* visual keying */
99  if (IS_AUTOKEY_FLAG(scene, AUTOMATKEY)) {
100  flag |= INSERTKEY_MATRIX;
101  }
102 
103  /* only needed */
104  if (IS_AUTOKEY_FLAG(scene, INSERTNEEDED)) {
105  flag |= INSERTKEY_NEEDED;
106  }
107 
108  /* default F-Curve color mode - RGB from XYZ indices */
109  if (IS_AUTOKEY_FLAG(scene, XYZ2RGB)) {
110  flag |= INSERTKEY_XYZ2RGB;
111  }
112  }
113 
114  /* only if including settings from the autokeying mode... */
115  if (use_autokey_mode) {
116  /* keyframing mode - only replace existing keyframes */
117  if (IS_AUTOKEY_MODE(scene, EDITKEYS)) {
118  flag |= INSERTKEY_REPLACE;
119  }
120 
121  /* cycle-aware keyframe insertion - preserve cycle period and flow */
122  if (IS_AUTOKEY_FLAG(scene, CYCLEAWARE)) {
123  flag |= INSERTKEY_CYCLE_AWARE;
124  }
125  }
126 
127  return flag;
128 }
129 
130 /* ******************************************* */
131 /* Animation Data Validation */
132 
133 /* Get (or add relevant data to be able to do so) the Active Action for the given
134  * Animation Data block, given an ID block where the Animation Data should reside.
135  */
137 {
138  AnimData *adt;
139 
140  /* init animdata if none available yet */
141  adt = BKE_animdata_from_id(id);
142  if (adt == NULL) {
143  adt = BKE_animdata_add_id(id);
144  }
145  if (adt == NULL) {
146  /* if still none (as not allowed to add, or ID doesn't have animdata for some reason) */
147  printf("ERROR: Couldn't add AnimData (ID = %s)\n", (id) ? (id->name) : "<None>");
148  return NULL;
149  }
150 
151  /* init action if none available yet */
152  /* TODO: need some wizardry to handle NLA stuff correct */
153  if (adt->action == NULL) {
154  /* init action name from name of ID block */
155  char actname[sizeof(id->name) - 2];
156  BLI_snprintf(actname, sizeof(actname), "%sAction", id->name + 2);
157 
158  /* create action */
159  adt->action = BKE_action_add(bmain, actname);
160 
161  /* set ID-type from ID-block that this is going to be assigned to
162  * so that users can't accidentally break actions by assigning them
163  * to the wrong places
164  */
166 
167  /* Tag depsgraph to be rebuilt to include time dependency. */
169  }
170 
172 
173  /* return the action */
174  return adt->action;
175 }
176 
181 FCurve *ED_action_fcurve_find(struct bAction *act, const char rna_path[], const int array_index)
182 {
183  /* Sanity checks. */
184  if (ELEM(NULL, act, rna_path)) {
185  return NULL;
186  }
187  return BKE_fcurve_find(&act->curves, rna_path, array_index);
188 }
189 
195  struct bAction *act,
196  const char group[],
197  struct PointerRNA *ptr,
198  const char rna_path[],
199  const int array_index)
200 {
201  bActionGroup *agrp;
202  FCurve *fcu;
203 
204  /* Sanity checks. */
205  if (ELEM(NULL, act, rna_path)) {
206  return NULL;
207  }
208 
209  /* try to find f-curve matching for this setting
210  * - add if not found and allowed to add one
211  * TODO: add auto-grouping support? how this works will need to be resolved
212  */
213  fcu = BKE_fcurve_find(&act->curves, rna_path, array_index);
214 
215  if (fcu == NULL) {
216  /* use default settings to make a F-Curve */
217  fcu = BKE_fcurve_create();
218 
220  fcu->auto_smoothing = U.auto_smoothing_new;
221  if (BLI_listbase_is_empty(&act->curves)) {
222  fcu->flag |= FCURVE_ACTIVE; /* first one added active */
223  }
224 
225  /* store path - make copy, and store that */
226  fcu->rna_path = BLI_strdup(rna_path);
227  fcu->array_index = array_index;
228 
229  /* if a group name has been provided, try to add or find a group, then add F-Curve to it */
230  if (group) {
231  /* try to find group */
232  agrp = BKE_action_group_find_name(act, group);
233 
234  /* no matching groups, so add one */
235  if (agrp == NULL) {
236  agrp = action_groups_add_new(act, group);
237 
238  /* sync bone group colors if applicable */
239  if (ptr && (ptr->type == &RNA_PoseBone)) {
240  Object *ob = (Object *)ptr->owner_id;
241  bPoseChannel *pchan = ptr->data;
242  bPose *pose = ob->pose;
243  bActionGroup *grp;
244 
245  /* find bone group (if present), and use the color from that */
246  grp = (bActionGroup *)BLI_findlink(&pose->agroups, (pchan->agrp_index - 1));
247  if (grp) {
248  agrp->customCol = grp->customCol;
249  action_group_colors_sync(agrp, grp);
250  }
251  }
252  }
253 
254  /* add F-Curve to group */
255  action_groups_add_channel(act, agrp, fcu);
256  }
257  else {
258  /* just add F-Curve to end of Action's list */
259  BLI_addtail(&act->curves, fcu);
260  }
261 
262  /* New f-curve was added, meaning it's possible that it affects
263  * dependency graph component which wasn't previously animated.
264  */
266  }
267 
268  /* return the F-Curve */
269  return fcu;
270 }
271 
272 /* Helper for update_autoflags_fcurve() */
274 {
275  /* set additional flags for the F-Curve (i.e. only integer values) */
277  switch (RNA_property_type(prop)) {
278  case PROP_FLOAT:
279  /* do nothing */
280  break;
281  case PROP_INT:
282  /* do integer (only 'whole' numbers) interpolation between all points */
283  fcu->flag |= FCURVE_INT_VALUES;
284  break;
285  default:
286  /* do 'discrete' (i.e. enum, boolean values which cannot take any intermediate
287  * values at all) interpolation between all points
288  * - however, we must also ensure that evaluated values are only integers still
289  */
291  break;
292  }
293 }
294 
295 /* Update integer/discrete flags of the FCurve (used when creating/inserting keyframes,
296  * but also through RNA when editing an ID prop, see T37103).
297  */
299 {
300  PointerRNA tmp_ptr;
301  PropertyRNA *prop;
302  int old_flag = fcu->flag;
303 
304  if ((ptr->owner_id == NULL) && (ptr->data == NULL)) {
305  BKE_report(reports, RPT_ERROR, "No RNA pointer available to retrieve values for this fcurve");
306  return;
307  }
308 
309  /* try to get property we should be affecting */
310  if (RNA_path_resolve_property(ptr, fcu->rna_path, &tmp_ptr, &prop) == false) {
311  /* property not found... */
312  const char *idname = (ptr->owner_id) ? ptr->owner_id->name : TIP_("<No ID pointer>");
313 
314  BKE_reportf(reports,
315  RPT_ERROR,
316  "Could not update flags for this fcurve, as RNA path is invalid for the given ID "
317  "(ID = %s, path = %s)",
318  idname,
319  fcu->rna_path);
320  return;
321  }
322 
323  /* update F-Curve flags */
325 
326  if (old_flag != fcu->flag) {
327  /* Same as if keyframes had been changed */
329  }
330 }
331 
332 /* ************************************************** */
333 /* KEYFRAME INSERTION */
334 
335 /* Move the point where a key is about to be inserted to be inside the main cycle range.
336  * Returns the type of the cycle if it is enabled and valid.
337  */
338 static eFCU_Cycle_Type remap_cyclic_keyframe_location(FCurve *fcu, float *px, float *py)
339 {
340  if (fcu->totvert < 2 || !fcu->bezt) {
341  return FCU_CYCLE_NONE;
342  }
343 
345 
346  if (type == FCU_CYCLE_NONE) {
347  return FCU_CYCLE_NONE;
348  }
349 
350  BezTriple *first = &fcu->bezt[0], *last = &fcu->bezt[fcu->totvert - 1];
351  float start = first->vec[1][0], end = last->vec[1][0];
352 
353  if (start >= end) {
354  return FCU_CYCLE_NONE;
355  }
356 
357  if (*px < start || *px > end) {
358  float period = end - start;
359  float step = floorf((*px - start) / period);
360  *px -= step * period;
361 
362  if (type == FCU_CYCLE_OFFSET) {
363  /* Nasty check to handle the case when the modes are different better. */
364  FMod_Cycles *data = ((FModifier *)fcu->modifiers.first)->data;
365  short mode = (step >= 0) ? data->after_mode : data->before_mode;
366 
368  *py -= step * (last->vec[1][1] - first->vec[1][1]);
369  }
370  }
371  }
372 
373  return type;
374 }
375 
376 /* -------------- BezTriple Insertion -------------------- */
377 
378 /* Change the Y position of a keyframe to match the input, adjusting handles. */
379 static void replace_bezt_keyframe_ypos(BezTriple *dst, const BezTriple *bezt)
380 {
381  /* just change the values when replacing, so as to not overwrite handles */
382  float dy = bezt->vec[1][1] - dst->vec[1][1];
383 
384  /* just apply delta value change to the handle values */
385  dst->vec[0][1] += dy;
386  dst->vec[1][1] += dy;
387  dst->vec[2][1] += dy;
388 
389  dst->f1 = bezt->f1;
390  dst->f2 = bezt->f2;
391  dst->f3 = bezt->f3;
392 
393  /* TODO: perform some other operations? */
394 }
395 
396 /* This function adds a given BezTriple to an F-Curve. It will allocate
397  * memory for the array if needed, and will insert the BezTriple into a
398  * suitable place in chronological order.
399  *
400  * NOTE: any recalculate of the F-Curve that needs to be done will need to
401  * be done by the caller.
402  */
404 {
405  int i = 0;
406 
407  /* are there already keyframes? */
408  if (fcu->bezt) {
409  bool replace;
410  i = BKE_fcurve_bezt_binarysearch_index(fcu->bezt, bezt->vec[1][0], fcu->totvert, &replace);
411 
412  /* replace an existing keyframe? */
413  if (replace) {
414  /* sanity check: 'i' may in rare cases exceed arraylen */
415  if ((i >= 0) && (i < fcu->totvert)) {
416  if (flag & INSERTKEY_OVERWRITE_FULL) {
417  fcu->bezt[i] = *bezt;
418  }
419  else {
420  replace_bezt_keyframe_ypos(&fcu->bezt[i], bezt);
421  }
422 
423  if (flag & INSERTKEY_CYCLE_AWARE) {
424  /* If replacing an end point of a cyclic curve without offset,
425  * modify the other end too. */
426  if ((i == 0 || i == fcu->totvert - 1) &&
428  replace_bezt_keyframe_ypos(&fcu->bezt[i == 0 ? fcu->totvert - 1 : 0], bezt);
429  }
430  }
431  }
432  }
433  /* Keyframing modes allow not replacing the keyframe. */
434  else if ((flag & INSERTKEY_REPLACE) == 0) {
435  /* insert new - if we're not restricted to replacing keyframes only */
436  BezTriple *newb = MEM_callocN((fcu->totvert + 1) * sizeof(BezTriple), "beztriple");
437 
438  /* Add the beztriples that should occur before the beztriple to be pasted
439  * (originally in fcu). */
440  if (i > 0) {
441  memcpy(newb, fcu->bezt, i * sizeof(BezTriple));
442  }
443 
444  /* add beztriple to paste at index i */
445  *(newb + i) = *bezt;
446 
447  /* add the beztriples that occur after the beztriple to be pasted (originally in fcu) */
448  if (i < fcu->totvert) {
449  memcpy(newb + i + 1, fcu->bezt + i, (fcu->totvert - i) * sizeof(BezTriple));
450  }
451 
452  /* replace (+ free) old with new, only if necessary to do so */
453  MEM_freeN(fcu->bezt);
454  fcu->bezt = newb;
455 
456  fcu->totvert++;
457  }
458  else {
459  return -1;
460  }
461  }
462  /* no keyframes already, but can only add if...
463  * 1) keyframing modes say that keyframes can only be replaced, so adding new ones won't know
464  * 2) there are no samples on the curve
465  * NOTE: maybe we may want to allow this later when doing samples -> bezt conversions,
466  * but for now, having both is asking for trouble
467  */
468  else if ((flag & INSERTKEY_REPLACE) == 0 && (fcu->fpt == NULL)) {
469  /* create new keyframes array */
470  fcu->bezt = MEM_callocN(sizeof(BezTriple), "beztriple");
471  *(fcu->bezt) = *bezt;
472  fcu->totvert = 1;
473  }
474  /* cannot add anything */
475  else {
476  /* return error code -1 to prevent any misunderstandings */
477  return -1;
478  }
479 
480  /* we need to return the index, so that some tools which do post-processing can
481  * detect where we added the BezTriple in the array
482  */
483  return i;
484 }
485 
496 static void subdivide_nonauto_handles(const FCurve *fcu,
497  BezTriple *bezt,
498  BezTriple *prev,
499  BezTriple *next)
500 {
501  if (prev->ipo != BEZT_IPO_BEZ || bezt->ipo != BEZT_IPO_BEZ) {
502  return;
503  }
504 
505  /* Don't change Vector handles, or completely auto regions. */
506  const bool bezt_auto = BEZT_IS_AUTOH(bezt) || (bezt->h1 == HD_VECT && bezt->h2 == HD_VECT);
507  const bool prev_auto = BEZT_IS_AUTOH(prev) || (prev->h2 == HD_VECT);
508  const bool next_auto = BEZT_IS_AUTOH(next) || (next->h1 == HD_VECT);
509  if (bezt_auto && prev_auto && next_auto) {
510  return;
511  }
512 
513  /* Subdivide the curve. */
514  float delta;
515  if (!BKE_fcurve_bezt_subdivide_handles(bezt, prev, next, &delta)) {
516  return;
517  }
518 
519  /* Decide when to force auto to manual. */
520  if (!BEZT_IS_AUTOH(bezt)) {
521  return;
522  }
523  if ((prev_auto || next_auto) && fcu->auto_smoothing == FCURVE_SMOOTH_CONT_ACCEL) {
524  const float hx = bezt->vec[1][0] - bezt->vec[0][0];
525  const float dx = bezt->vec[1][0] - prev->vec[1][0];
526 
527  /* This mode always uses 1/3 of key distance for handle x size. */
528  const bool auto_works_well = fabsf(hx - dx / 3.0f) < 0.001f;
529  if (auto_works_well) {
530  return;
531  }
532  }
533 
534  /* Turn off auto mode. */
535  bezt->h1 = bezt->h2 = HD_ALIGN;
536 }
537 
548  FCurve *fcu, float x, float y, eBezTriple_KeyframeType keyframe_type, eInsertKeyFlags flag)
549 {
550  BezTriple beztr = {{{0}}};
551  uint oldTot = fcu->totvert;
552  int a;
553 
554  /* set all three points, for nicer start position
555  * NOTE: +/- 1 on vec.x for left and right handles is so that 'free' handles work ok...
556  */
557  beztr.vec[0][0] = x - 1.0f;
558  beztr.vec[0][1] = y;
559  beztr.vec[1][0] = x;
560  beztr.vec[1][1] = y;
561  beztr.vec[2][0] = x + 1.0f;
562  beztr.vec[2][1] = y;
563  beztr.f1 = beztr.f2 = beztr.f3 = SELECT;
564 
565  /* set default handle types and interpolation mode */
566  if (flag & INSERTKEY_NO_USERPREF) {
567  /* for Py-API, we want scripts to have predictable behavior,
568  * hence the option to not depend on the userpref defaults
569  */
570  beztr.h1 = beztr.h2 = HD_AUTO_ANIM;
571  beztr.ipo = BEZT_IPO_BEZ;
572  }
573  else {
574  /* for UI usage - defaults should come from the userprefs and/or toolsettings */
575  beztr.h1 = beztr.h2 = U.keyhandles_new; /* use default handle type here */
576 
577  /* use default interpolation mode, with exceptions for int/discrete values */
578  beztr.ipo = U.ipo_new;
579  }
580 
581  /* interpolation type used is constrained by the type of values the curve can take */
582  if (fcu->flag & FCURVE_DISCRETE_VALUES) {
583  beztr.ipo = BEZT_IPO_CONST;
584  }
585  else if ((beztr.ipo == BEZT_IPO_BEZ) && (fcu->flag & FCURVE_INT_VALUES)) {
586  beztr.ipo = BEZT_IPO_LIN;
587  }
588 
589  /* set keyframe type value (supplied), which should come from the scene settings in most cases */
590  BEZKEYTYPE(&beztr) = keyframe_type;
591 
592  /* set default values for "easing" interpolation mode settings
593  * NOTE: Even if these modes aren't currently used, if users switch
594  * to these later, we want these to work in a sane way out of
595  * the box.
596  */
597 
598  /* "back" easing - this value used to be used when overshoot=0, but that
599  * introduced discontinuities in how the param worked. */
600  beztr.back = 1.70158f;
601 
602  /* "elastic" easing - values here were hand-optimized for a default duration of
603  * ~10 frames (typical mograph motion length) */
604  beztr.amplitude = 0.8f;
605  beztr.period = 4.1f;
606 
607  /* add temp beztriple to keyframes */
608  a = insert_bezt_fcurve(fcu, &beztr, flag);
610 
611  /* what if 'a' is a negative index?
612  * for now, just exit to prevent any segfaults
613  */
614  if (a < 0) {
615  return -1;
616  }
617 
618  /* Set handle-type and interpolation. */
619  if ((fcu->totvert > 2) && (flag & INSERTKEY_REPLACE) == 0) {
620  BezTriple *bezt = (fcu->bezt + a);
621 
622  /* Set interpolation from previous (if available),
623  * but only if we didn't just replace some keyframe:
624  * - Replacement is indicated by no-change in number of verts.
625  * - When replacing, the user may have specified some interpolation that should be kept.
626  */
627  if (fcu->totvert > oldTot) {
628  if (a > 0) {
629  bezt->ipo = (bezt - 1)->ipo;
630  }
631  else if (a < fcu->totvert - 1) {
632  bezt->ipo = (bezt + 1)->ipo;
633  }
634 
635  if (0 < a && a < (fcu->totvert - 1) && (flag & INSERTKEY_OVERWRITE_FULL) == 0) {
636  subdivide_nonauto_handles(fcu, bezt, bezt - 1, bezt + 1);
637  }
638  }
639  }
640 
641  /* don't recalculate handles if fast is set
642  * - this is a hack to make importers faster
643  * - we may calculate twice (due to auto-handle needing to be calculated twice)
644  */
645  if ((flag & INSERTKEY_FAST) == 0) {
646  calchandles_fcurve(fcu);
647  }
648 
649  /* return the index at which the keyframe was added */
650  return a;
651 }
652 
653 /* -------------- 'Smarter' Keyframing Functions -------------------- */
654 /* return codes for new_key_needed */
655 enum {
660 } /*eKeyNeededStatus*/;
661 
662 /* This helper function determines whether a new keyframe is needed */
663 /* Cases where keyframes should not be added:
664  * 1. Keyframe to be added between two keyframes with similar values
665  * 2. Keyframe to be added on frame where two keyframes are already situated
666  * 3. Keyframe lies at point that intersects the linear line between two keyframes
667  */
668 static short new_key_needed(FCurve *fcu, float cFrame, float nValue)
669 {
670  /* safety checking */
671  if (fcu == NULL) {
672  return KEYNEEDED_JUSTADD;
673  }
674  int totCount = fcu->totvert;
675  if (totCount == 0) {
676  return KEYNEEDED_JUSTADD;
677  }
678 
679  /* loop through checking if any are the same */
680  BezTriple *bezt = fcu->bezt;
681  BezTriple *prev = NULL;
682  for (int i = 0; i < totCount; i++) {
683  float prevPosi = 0.0f, prevVal = 0.0f;
684  float beztPosi = 0.0f, beztVal = 0.0f;
685 
686  /* get current time+value */
687  beztPosi = bezt->vec[1][0];
688  beztVal = bezt->vec[1][1];
689 
690  if (prev) {
691  /* there is a keyframe before the one currently being examined */
692 
693  /* get previous time+value */
694  prevPosi = prev->vec[1][0];
695  prevVal = prev->vec[1][1];
696 
697  /* keyframe to be added at point where there are already two similar points? */
698  if (IS_EQF(prevPosi, cFrame) && IS_EQF(beztPosi, cFrame) && IS_EQF(beztPosi, prevPosi)) {
699  return KEYNEEDED_DONTADD;
700  }
701 
702  /* keyframe between prev+current points ? */
703  if ((prevPosi <= cFrame) && (cFrame <= beztPosi)) {
704  /* is the value of keyframe to be added the same as keyframes on either side ? */
705  if (IS_EQF(prevVal, nValue) && IS_EQF(beztVal, nValue) && IS_EQF(prevVal, beztVal)) {
706  return KEYNEEDED_DONTADD;
707  }
708 
709  float realVal;
710 
711  /* get real value of curve at that point */
712  realVal = evaluate_fcurve(fcu, cFrame);
713 
714  /* compare whether it's the same as proposed */
715  if (IS_EQF(realVal, nValue)) {
716  return KEYNEEDED_DONTADD;
717  }
718  return KEYNEEDED_JUSTADD;
719  }
720 
721  /* new keyframe before prev beztriple? */
722  if (cFrame < prevPosi) {
723  /* A new keyframe will be added. However, whether the previous beztriple
724  * stays around or not depends on whether the values of previous/current
725  * beztriples and new keyframe are the same.
726  */
727  if (IS_EQF(prevVal, nValue) && IS_EQF(beztVal, nValue) && IS_EQF(prevVal, beztVal)) {
728  return KEYNEEDED_DELNEXT;
729  }
730 
731  return KEYNEEDED_JUSTADD;
732  }
733  }
734  else {
735  /* just add a keyframe if there's only one keyframe
736  * and the new one occurs before the existing one does.
737  */
738  if ((cFrame < beztPosi) && (totCount == 1)) {
739  return KEYNEEDED_JUSTADD;
740  }
741  }
742 
743  /* continue. frame to do not yet passed (or other conditions not met) */
744  if (i < (totCount - 1)) {
745  prev = bezt;
746  bezt++;
747  }
748  else {
749  break;
750  }
751  }
752 
753  /* Frame in which to add a new-keyframe occurs after all other keys
754  * -> If there are at least two existing keyframes, then if the values of the
755  * last two keyframes and the new-keyframe match, the last existing keyframe
756  * gets deleted as it is no longer required.
757  * -> Otherwise, a keyframe is just added. 1.0 is added so that fake-2nd-to-last
758  * keyframe is not equal to last keyframe.
759  */
760  bezt = (fcu->bezt + (fcu->totvert - 1));
761  float valA = bezt->vec[1][1];
762  float valB;
763  if (prev) {
764  valB = prev->vec[1][1];
765  }
766  else {
767  valB = bezt->vec[1][1] + 1.0f;
768  }
769 
770  if (IS_EQF(valA, nValue) && IS_EQF(valA, valB)) {
771  return KEYNEEDED_DELPREV;
772  }
773 
774  return KEYNEEDED_JUSTADD;
775 }
776 
777 /* ------------------ RNA Data-Access Functions ------------------ */
778 
779 /* Try to read value using RNA-properties obtained already */
781  PointerRNA *ptr, PropertyRNA *prop, float *buffer, int buffer_size, int *r_count)
782 {
783  BLI_assert(buffer_size >= 1);
784 
785  float *values = buffer;
786 
787  if (RNA_property_array_check(prop)) {
788  int length = *r_count = RNA_property_array_length(ptr, prop);
789  bool *tmp_bool;
790  int *tmp_int;
791 
792  if (length > buffer_size) {
793  values = MEM_malloc_arrayN(sizeof(float), length, __func__);
794  }
795 
796  switch (RNA_property_type(prop)) {
797  case PROP_BOOLEAN:
798  tmp_bool = MEM_malloc_arrayN(sizeof(*tmp_bool), length, __func__);
799  RNA_property_boolean_get_array(ptr, prop, tmp_bool);
800  for (int i = 0; i < length; i++) {
801  values[i] = (float)tmp_bool[i];
802  }
803  MEM_freeN(tmp_bool);
804  break;
805  case PROP_INT:
806  tmp_int = MEM_malloc_arrayN(sizeof(*tmp_int), length, __func__);
807  RNA_property_int_get_array(ptr, prop, tmp_int);
808  for (int i = 0; i < length; i++) {
809  values[i] = (float)tmp_int[i];
810  }
811  MEM_freeN(tmp_int);
812  break;
813  case PROP_FLOAT:
814  RNA_property_float_get_array(ptr, prop, values);
815  break;
816  default:
817  memset(values, 0, sizeof(float) * length);
818  }
819  }
820  else {
821  *r_count = 1;
822 
823  switch (RNA_property_type(prop)) {
824  case PROP_BOOLEAN:
825  *values = (float)RNA_property_boolean_get(ptr, prop);
826  break;
827  case PROP_INT:
828  *values = (float)RNA_property_int_get(ptr, prop);
829  break;
830  case PROP_FLOAT:
831  *values = RNA_property_float_get(ptr, prop);
832  break;
833  case PROP_ENUM:
834  *values = (float)RNA_property_enum_get(ptr, prop);
835  break;
836  default:
837  *values = 0.0f;
838  }
839  }
840 
841  return values;
842 }
843 
844 /* ------------------ 'Visual' Keyframing Functions ------------------ */
845 
846 /* internal status codes for visualkey_can_use */
847 enum {
852 };
853 
854 /* This helper function determines if visual-keyframing should be used when
855  * inserting keyframes for the given channel. As visual-keyframing only works
856  * on Object and Pose-Channel blocks, this should only get called for those
857  * blocktypes, when using "standard" keying but 'Visual Keying' option in Auto-Keying
858  * settings is on.
859  */
861 {
862  bConstraint *con = NULL;
863  short searchtype = VISUALKEY_NONE;
864  bool has_rigidbody = false;
865  bool has_parent = false;
866  const char *identifier = NULL;
867 
868  /* validate data */
869  if (ELEM(NULL, ptr, ptr->data, prop)) {
870  return false;
871  }
872 
873  /* get first constraint and determine type of keyframe constraints to check for
874  * - constraints can be on either Objects or PoseChannels, so we only check if the
875  * ptr->type is RNA_Object or RNA_PoseBone, which are the RNA wrapping-info for
876  * those structs, allowing us to identify the owner of the data
877  */
878  if (ptr->type == &RNA_Object) {
879  /* Object */
880  Object *ob = ptr->data;
881  RigidBodyOb *rbo = ob->rigidbody_object;
882 
883  con = ob->constraints.first;
884  identifier = RNA_property_identifier(prop);
885  has_parent = (ob->parent != NULL);
886 
887  /* active rigidbody objects only, as only those are affected by sim */
888  has_rigidbody = ((rbo) && (rbo->type == RBO_TYPE_ACTIVE));
889  }
890  else if (ptr->type == &RNA_PoseBone) {
891  /* Pose Channel */
892  bPoseChannel *pchan = ptr->data;
893 
894  con = pchan->constraints.first;
895  identifier = RNA_property_identifier(prop);
896  has_parent = (pchan->parent != NULL);
897  }
898 
899  /* check if any data to search using */
900  if (ELEM(NULL, con, identifier) && (has_parent == false) && (has_rigidbody == false)) {
901  return false;
902  }
903 
904  /* location or rotation identifiers only... */
905  if (identifier == NULL) {
906  printf("%s failed: NULL identifier\n", __func__);
907  return false;
908  }
909 
910  if (strstr(identifier, "location")) {
911  searchtype = VISUALKEY_LOC;
912  }
913  else if (strstr(identifier, "rotation")) {
914  searchtype = VISUALKEY_ROT;
915  }
916  else if (strstr(identifier, "scale")) {
917  searchtype = VISUALKEY_SCA;
918  }
919  else {
920  printf("%s failed: identifier - '%s'\n", __func__, identifier);
921  return false;
922  }
923 
924  /* only search if a searchtype and initial constraint are available */
925  if (searchtype) {
926  /* parent or rigidbody are always matching */
927  if (has_parent || has_rigidbody) {
928  return true;
929  }
930 
931  /* constraints */
932  for (; con; con = con->next) {
933  /* only consider constraint if it is not disabled, and has influence */
934  if (con->flag & CONSTRAINT_DISABLE) {
935  continue;
936  }
937  if (con->enforce == 0.0f) {
938  continue;
939  }
940 
941  /* some constraints may alter these transforms */
942  switch (con->type) {
943  /* multi-transform constraints */
946  return true;
949  return true;
951  return true;
953  return true;
954 
955  /* single-transform constraints */
957  if (searchtype == VISUALKEY_ROT) {
958  return true;
959  }
960  break;
962  if (searchtype == VISUALKEY_ROT) {
963  return true;
964  }
965  break;
967  if (searchtype == VISUALKEY_ROT) {
968  return true;
969  }
970  break;
972  if (searchtype == VISUALKEY_LOC) {
973  return true;
974  }
975  break;
977  if (searchtype == VISUALKEY_SCA) {
978  return true;
979  }
980  break;
982  if (searchtype == VISUALKEY_LOC) {
983  return true;
984  }
985  break;
987  if (searchtype == VISUALKEY_ROT) {
988  return true;
989  }
990  break;
992  if (searchtype == VISUALKEY_LOC) {
993  return true;
994  }
995  break;
997  if (searchtype == VISUALKEY_SCA) {
998  return true;
999  }
1000  break;
1002  if (searchtype == VISUALKEY_ROT) {
1003  return true;
1004  }
1005  break;
1007  if (searchtype == VISUALKEY_LOC) {
1008  return true;
1009  }
1010  break;
1011 
1012  default:
1013  break;
1014  }
1015  }
1016  }
1017 
1018  /* when some condition is met, this function returns, so that means we've got nothing */
1019  return false;
1020 }
1021 
1022 /* This helper function extracts the value to use for visual-keyframing
1023  * In the event that it is not possible to perform visual keying, try to fall-back
1024  * to using the default method. Assumes that all data it has been passed is valid.
1025  */
1026 static float *visualkey_get_values(
1027  PointerRNA *ptr, PropertyRNA *prop, float *buffer, int buffer_size, int *r_count)
1028 {
1029  BLI_assert(buffer_size >= 4);
1030 
1031  const char *identifier = RNA_property_identifier(prop);
1032  float tmat[4][4];
1033  int rotmode;
1034 
1035  /* handle for Objects or PoseChannels only
1036  * - only Location, Rotation or Scale keyframes are supported currently
1037  * - constraints can be on either Objects or PoseChannels, so we only check if the
1038  * ptr->type is RNA_Object or RNA_PoseBone, which are the RNA wrapping-info for
1039  * those structs, allowing us to identify the owner of the data
1040  * - assume that array_index will be sane
1041  */
1042  if (ptr->type == &RNA_Object) {
1043  Object *ob = ptr->data;
1044  /* Loc code is specific... */
1045  if (strstr(identifier, "location")) {
1046  copy_v3_v3(buffer, ob->obmat[3]);
1047  *r_count = 3;
1048  return buffer;
1049  }
1050 
1051  copy_m4_m4(tmat, ob->obmat);
1052  rotmode = ob->rotmode;
1053  }
1054  else if (ptr->type == &RNA_PoseBone) {
1055  bPoseChannel *pchan = ptr->data;
1056 
1057  BKE_armature_mat_pose_to_bone(pchan, pchan->pose_mat, tmat);
1058  rotmode = pchan->rotmode;
1059 
1060  /* Loc code is specific... */
1061  if (strstr(identifier, "location")) {
1062  /* only use for non-connected bones */
1063  if ((pchan->bone->parent == NULL) || !(pchan->bone->flag & BONE_CONNECTED)) {
1064  copy_v3_v3(buffer, tmat[3]);
1065  *r_count = 3;
1066  return buffer;
1067  }
1068  }
1069  }
1070  else {
1071  return setting_get_rna_values(ptr, prop, buffer, buffer_size, r_count);
1072  }
1073 
1074  /* Rot/Scale code are common! */
1075  if (strstr(identifier, "rotation_euler")) {
1076  mat4_to_eulO(buffer, rotmode, tmat);
1077 
1078  *r_count = 3;
1079  return buffer;
1080  }
1081 
1082  if (strstr(identifier, "rotation_quaternion")) {
1083  float mat3[3][3];
1084 
1085  copy_m3_m4(mat3, tmat);
1086  mat3_to_quat_is_ok(buffer, mat3);
1087 
1088  *r_count = 4;
1089  return buffer;
1090  }
1091 
1092  if (strstr(identifier, "rotation_axis_angle")) {
1093  /* w = 0, x,y,z = 1,2,3 */
1094  mat4_to_axis_angle(buffer + 1, buffer, tmat);
1095 
1096  *r_count = 4;
1097  return buffer;
1098  }
1099 
1100  if (strstr(identifier, "scale")) {
1101  mat4_to_size(buffer, tmat);
1102 
1103  *r_count = 3;
1104  return buffer;
1105  }
1106 
1107  /* as the function hasn't returned yet, read value from system in the default way */
1108  return setting_get_rna_values(ptr, prop, buffer, buffer_size, r_count);
1109 }
1110 
1111 /* ------------------------- Insert Key API ------------------------- */
1112 
1117 static float *get_keyframe_values(ReportList *reports,
1118  PointerRNA ptr,
1119  PropertyRNA *prop,
1120  int index,
1121  struct NlaKeyframingContext *nla_context,
1122  eInsertKeyFlags flag,
1123  float *buffer,
1124  int buffer_size,
1125  int *r_count,
1126  bool *r_force_all)
1127 {
1128  float *values;
1129 
1130  if ((flag & INSERTKEY_MATRIX) && (visualkey_can_use(&ptr, prop))) {
1131  /* visual-keying is only available for object and pchan datablocks, as
1132  * it works by keyframing using a value extracted from the final matrix
1133  * instead of using the kt system to extract a value.
1134  */
1135  values = visualkey_get_values(&ptr, prop, buffer, buffer_size, r_count);
1136  }
1137  else {
1138  /* read value from system */
1139  values = setting_get_rna_values(&ptr, prop, buffer, buffer_size, r_count);
1140  }
1141 
1142  /* adjust the value for NLA factors */
1144  nla_context, &ptr, prop, values, *r_count, index, r_force_all)) {
1145  BKE_report(
1146  reports, RPT_ERROR, "Could not insert keyframe due to zero NLA influence or base value");
1147 
1148  if (values != buffer) {
1149  MEM_freeN(values);
1150  }
1151  return NULL;
1152  }
1153 
1154  return values;
1155 }
1156 
1157 /* Insert the specified keyframe value into a single F-Curve. */
1158 static bool insert_keyframe_value(ReportList *reports,
1159  PointerRNA *ptr,
1160  PropertyRNA *prop,
1161  FCurve *fcu,
1162  const AnimationEvalContext *anim_eval_context,
1163  float curval,
1164  eBezTriple_KeyframeType keytype,
1165  eInsertKeyFlags flag)
1166 {
1167  /* F-Curve not editable? */
1168  if (BKE_fcurve_is_keyframable(fcu) == 0) {
1169  BKE_reportf(
1170  reports,
1171  RPT_ERROR,
1172  "F-Curve with path '%s[%d]' cannot be keyframed, ensure that it is not locked or sampled, "
1173  "and try removing F-Modifiers",
1174  fcu->rna_path,
1175  fcu->array_index);
1176  return false;
1177  }
1178 
1179  float cfra = anim_eval_context->eval_time;
1180 
1181  /* adjust frame on which to add keyframe */
1182  if ((flag & INSERTKEY_DRIVER) && (fcu->driver)) {
1183  PathResolvedRNA anim_rna;
1184 
1185  if (RNA_path_resolved_create(ptr, prop, fcu->array_index, &anim_rna)) {
1186  /* for making it easier to add corrective drivers... */
1187  cfra = evaluate_driver(&anim_rna, fcu->driver, fcu->driver, anim_eval_context);
1188  }
1189  else {
1190  cfra = 0.0f;
1191  }
1192  }
1193 
1194  /* adjust coordinates for cycle aware insertion */
1195  if (flag & INSERTKEY_CYCLE_AWARE) {
1196  if (remap_cyclic_keyframe_location(fcu, &cfra, &curval) != FCU_CYCLE_PERFECT) {
1197  /* inhibit action from insert_vert_fcurve unless it's a perfect cycle */
1198  flag &= ~INSERTKEY_CYCLE_AWARE;
1199  }
1200  }
1201 
1202  /* only insert keyframes where they are needed */
1203  if (flag & INSERTKEY_NEEDED) {
1204  short insert_mode;
1205 
1206  /* check whether this curve really needs a new keyframe */
1207  insert_mode = new_key_needed(fcu, cfra, curval);
1208 
1209  /* only return success if keyframe added */
1210  if (insert_mode == KEYNEEDED_DONTADD) {
1211  return false;
1212  }
1213 
1214  /* insert new keyframe at current frame */
1215  if (insert_vert_fcurve(fcu, cfra, curval, keytype, flag) < 0) {
1216  return false;
1217  }
1218 
1219  /* delete keyframe immediately before/after newly added */
1220  switch (insert_mode) {
1221  case KEYNEEDED_DELPREV:
1222  delete_fcurve_key(fcu, fcu->totvert - 2, 1);
1223  break;
1224  case KEYNEEDED_DELNEXT:
1225  delete_fcurve_key(fcu, 1, 1);
1226  break;
1227  }
1228 
1229  return true;
1230  }
1231 
1232  /* just insert keyframe */
1233  return insert_vert_fcurve(fcu, cfra, curval, keytype, flag) >= 0;
1234 }
1235 
1236 /* Secondary Keyframing API call:
1237  * Use this when validation of necessary animation data is not necessary,
1238  * since an RNA-pointer to the necessary data being keyframed,
1239  * and a pointer to the F-Curve to use have both been provided.
1240  *
1241  * This function can't keyframe quaternion channels on some NLA strip types.
1242  *
1243  * keytype is the "keyframe type" (eBezTriple_KeyframeType), as shown in the Dope Sheet.
1244  *
1245  * The flag argument is used for special settings that alter the behavior of
1246  * the keyframe insertion. These include the 'visual' keyframing modes, quick refresh,
1247  * and extra keyframe filtering.
1248  */
1250  PointerRNA ptr,
1251  PropertyRNA *prop,
1252  FCurve *fcu,
1253  const AnimationEvalContext *anim_eval_context,
1254  eBezTriple_KeyframeType keytype,
1255  struct NlaKeyframingContext *nla_context,
1256  eInsertKeyFlags flag)
1257 {
1258  float curval = 0.0f;
1259 
1260  /* no F-Curve to add keyframe to? */
1261  if (fcu == NULL) {
1262  BKE_report(reports, RPT_ERROR, "No F-Curve to add keyframes to");
1263  return false;
1264  }
1265 
1266  /* if no property given yet, try to validate from F-Curve info */
1267  if ((ptr.owner_id == NULL) && (ptr.data == NULL)) {
1268  BKE_report(
1269  reports, RPT_ERROR, "No RNA pointer available to retrieve values for keyframing from");
1270  return false;
1271  }
1272  if (prop == NULL) {
1273  PointerRNA tmp_ptr;
1274 
1275  /* try to get property we should be affecting */
1276  if (RNA_path_resolve_property(&ptr, fcu->rna_path, &tmp_ptr, &prop) == false) {
1277  /* property not found... */
1278  const char *idname = (ptr.owner_id) ? ptr.owner_id->name : TIP_("<No ID pointer>");
1279 
1280  BKE_reportf(reports,
1281  RPT_ERROR,
1282  "Could not insert keyframe, as RNA path is invalid for the given ID (ID = %s, "
1283  "path = %s)",
1284  idname,
1285  fcu->rna_path);
1286  return false;
1287  }
1288 
1289  /* property found, so overwrite 'ptr' to make later code easier */
1290  ptr = tmp_ptr;
1291  }
1292 
1293  /* update F-Curve flags to ensure proper behavior for property type */
1294  update_autoflags_fcurve_direct(fcu, prop);
1295 
1296  /* Obtain the value to insert. */
1297  float value_buffer[RNA_MAX_ARRAY_LENGTH];
1298  int value_count;
1299  int index = fcu->array_index;
1300 
1301  float *values = get_keyframe_values(reports,
1302  ptr,
1303  prop,
1304  index,
1305  nla_context,
1306  flag,
1307  value_buffer,
1309  &value_count,
1310  NULL);
1311 
1312  if (values == NULL) {
1313  /* This happens if NLA rejects this insertion. */
1314  return false;
1315  }
1316 
1317  if (index >= 0 && index < value_count) {
1318  curval = values[index];
1319  }
1320 
1321  if (values != value_buffer) {
1322  MEM_freeN(values);
1323  }
1324 
1325  return insert_keyframe_value(reports, &ptr, prop, fcu, anim_eval_context, curval, keytype, flag);
1326 }
1327 
1328 /* Find or create the FCurve based on the given path, and insert the specified value into it. */
1330  ReportList *reports,
1331  PointerRNA *ptr,
1332  PropertyRNA *prop,
1333  bAction *act,
1334  const char group[],
1335  const char rna_path[],
1336  int array_index,
1337  const AnimationEvalContext *anim_eval_context,
1338  float curval,
1339  eBezTriple_KeyframeType keytype,
1340  eInsertKeyFlags flag)
1341 {
1342  /* make sure the F-Curve exists
1343  * - if we're replacing keyframes only, DO NOT create new F-Curves if they do not exist yet
1344  * but still try to get the F-Curve if it exists...
1345  */
1346  bool can_create_curve = (flag & (INSERTKEY_REPLACE | INSERTKEY_AVAILABLE)) == 0;
1347  FCurve *fcu = can_create_curve ?
1348  ED_action_fcurve_ensure(bmain, act, group, ptr, rna_path, array_index) :
1349  ED_action_fcurve_find(act, rna_path, array_index);
1350 
1351  /* we may not have a F-Curve when we're replacing only... */
1352  if (fcu) {
1353  /* set color mode if the F-Curve is new (i.e. without any keyframes) */
1354  if ((fcu->totvert == 0) && (flag & INSERTKEY_XYZ2RGB)) {
1355  /* for Loc/Rot/Scale and also Color F-Curves, the color of the F-Curve in the Graph Editor,
1356  * is determined by the array index for the F-Curve
1357  */
1358  PropertySubType prop_subtype = RNA_property_subtype(prop);
1361  }
1362  else if (ELEM(prop_subtype, PROP_QUATERNION)) {
1364  }
1365  }
1366 
1367  /* update F-Curve flags to ensure proper behavior for property type */
1368  update_autoflags_fcurve_direct(fcu, prop);
1369 
1370  /* insert keyframe */
1371  return insert_keyframe_value(
1372  reports, ptr, prop, fcu, anim_eval_context, curval, keytype, flag);
1373  }
1374 
1375  return false;
1376 }
1377 
1379  PointerRNA *id_ptr,
1380  AnimData *adt,
1381  bAction *act,
1382  ListBase *nla_cache,
1383  NlaKeyframingContext **r_nla_context)
1384 {
1385  if (adt && adt->action == act) {
1386  /* Get NLA context for value remapping. */
1387  *r_nla_context = BKE_animsys_get_nla_keyframing_context(
1388  nla_cache, id_ptr, adt, anim_eval_context);
1389 
1390  /* Apply NLA-mapping to frame. */
1391  const float remapped_frame = BKE_nla_tweakedit_remap(
1392  adt, anim_eval_context->eval_time, NLATIME_CONVERT_UNMAP);
1393  return BKE_animsys_eval_context_construct_at(anim_eval_context, remapped_frame);
1394  }
1395 
1396  *r_nla_context = NULL;
1397  return *anim_eval_context;
1398 }
1399 
1414  ReportList *reports,
1415  ID *id,
1416  bAction *act,
1417  const char group[],
1418  const char rna_path[],
1419  int array_index,
1420  const AnimationEvalContext *anim_eval_context,
1421  eBezTriple_KeyframeType keytype,
1422  ListBase *nla_cache,
1423  eInsertKeyFlags flag)
1424 {
1425  PointerRNA id_ptr, ptr;
1426  PropertyRNA *prop = NULL;
1427  AnimData *adt;
1428  ListBase tmp_nla_cache = {NULL, NULL};
1429  NlaKeyframingContext *nla_context = NULL;
1430  int ret = 0;
1431 
1432  /* validate pointer first - exit if failure */
1433  if (id == NULL) {
1434  BKE_reportf(reports, RPT_ERROR, "No ID block to insert keyframe in (path = %s)", rna_path);
1435  return 0;
1436  }
1437 
1438  RNA_id_pointer_create(id, &id_ptr);
1439  if (RNA_path_resolve_property(&id_ptr, rna_path, &ptr, &prop) == false) {
1440  BKE_reportf(
1441  reports,
1442  RPT_ERROR,
1443  "Could not insert keyframe, as RNA path is invalid for the given ID (ID = %s, path = %s)",
1444  (id) ? id->name : TIP_("<Missing ID block>"),
1445  rna_path);
1446  return 0;
1447  }
1448 
1449  /* if no action is provided, keyframe to the default one attached to this ID-block */
1450  if (act == NULL) {
1451  /* get action to add F-Curve+keyframe to */
1452  act = ED_id_action_ensure(bmain, id);
1453 
1454  if (act == NULL) {
1455  BKE_reportf(reports,
1456  RPT_ERROR,
1457  "Could not insert keyframe, as this type does not support animation data (ID = "
1458  "%s, path = %s)",
1459  id->name,
1460  rna_path);
1461  return 0;
1462  }
1463  }
1464 
1465  /* apply NLA-mapping to frame to use (if applicable) */
1466  adt = BKE_animdata_from_id(id);
1467  const AnimationEvalContext remapped_context = nla_time_remap(
1468  anim_eval_context, &id_ptr, adt, act, nla_cache ? nla_cache : &tmp_nla_cache, &nla_context);
1469 
1470  /* Obtain values to insert. */
1471  float value_buffer[RNA_MAX_ARRAY_LENGTH];
1472  int value_count;
1473  bool force_all;
1474 
1475  float *values = get_keyframe_values(reports,
1476  ptr,
1477  prop,
1478  array_index,
1479  nla_context,
1480  flag,
1481  value_buffer,
1483  &value_count,
1484  &force_all);
1485 
1486  if (values != NULL) {
1487  /* Key the entire array. */
1488  if (array_index == -1 || force_all) {
1489  /* In force mode, if any of the curves succeeds, drop the replace mode and restart. */
1490  if (force_all && (flag & (INSERTKEY_REPLACE | INSERTKEY_AVAILABLE)) != 0) {
1491  int exclude = -1;
1492 
1493  for (array_index = 0; array_index < value_count; array_index++) {
1494  if (insert_keyframe_fcurve_value(bmain,
1495  reports,
1496  &ptr,
1497  prop,
1498  act,
1499  group,
1500  rna_path,
1501  array_index,
1502  &remapped_context,
1503  values[array_index],
1504  keytype,
1505  flag)) {
1506  ret++;
1507  exclude = array_index;
1508  break;
1509  }
1510  }
1511 
1512  if (exclude != -1) {
1514 
1515  for (array_index = 0; array_index < value_count; array_index++) {
1516  if (array_index != exclude) {
1518  reports,
1519  &ptr,
1520  prop,
1521  act,
1522  group,
1523  rna_path,
1524  array_index,
1525  &remapped_context,
1526  values[array_index],
1527  keytype,
1528  flag);
1529  }
1530  }
1531  }
1532  }
1533  /* Simply insert all channels. */
1534  else {
1535  for (array_index = 0; array_index < value_count; array_index++) {
1537  reports,
1538  &ptr,
1539  prop,
1540  act,
1541  group,
1542  rna_path,
1543  array_index,
1544  &remapped_context,
1545  values[array_index],
1546  keytype,
1547  flag);
1548  }
1549  }
1550  }
1551  /* Key a single index. */
1552  else {
1553  if (array_index >= 0 && array_index < value_count) {
1555  reports,
1556  &ptr,
1557  prop,
1558  act,
1559  group,
1560  rna_path,
1561  array_index,
1562  &remapped_context,
1563  values[array_index],
1564  keytype,
1565  flag);
1566  }
1567  }
1568 
1569  if (values != value_buffer) {
1570  MEM_freeN(values);
1571  }
1572  }
1573 
1575 
1576  if (ret) {
1577  if (act != NULL) {
1579  }
1580  if (adt != NULL && adt->action != NULL && adt->action != act) {
1582  }
1583  }
1584 
1585  return ret;
1586 }
1587 
1588 /* ************************************************** */
1589 /* KEYFRAME DELETION */
1590 
1591 /* Main Keyframing API call:
1592  * Use this when validation of necessary animation data isn't necessary as it
1593  * already exists. It will delete a keyframe at the current frame.
1594  *
1595  * The flag argument is used for special settings that alter the behavior of
1596  * the keyframe deletion. These include the quick refresh options.
1597  */
1598 
1603 static bool delete_keyframe_fcurve(AnimData *adt, FCurve *fcu, float cfra)
1604 {
1605  bool found;
1606  int i;
1607 
1608  /* try to find index of beztriple to get rid of */
1609  i = BKE_fcurve_bezt_binarysearch_index(fcu->bezt, cfra, fcu->totvert, &found);
1610  if (found) {
1611  /* delete the key at the index (will sanity check + do recalc afterwards) */
1612  delete_fcurve_key(fcu, i, 1);
1613 
1614  /* Only delete curve too if it won't be doing anything anymore */
1615  if (BKE_fcurve_is_empty(fcu)) {
1617  }
1618 
1619  /* return success */
1620  return true;
1621  }
1622  return false;
1623 }
1624 
1625 static void deg_tag_after_keyframe_delete(Main *bmain, ID *id, AnimData *adt)
1626 {
1627  if (adt->action == NULL) {
1628  /* In the case last f-curve was removed need to inform dependency graph
1629  * about relations update, since it needs to get rid of animation operation
1630  * for this data-block. */
1632  DEG_relations_tag_update(bmain);
1633  }
1634  else {
1636  }
1637 }
1638 
1643  ReportList *reports,
1644  ID *id,
1645  bAction *act,
1646  const char rna_path[],
1647  int array_index,
1648  float cfra)
1649 {
1650  AnimData *adt = BKE_animdata_from_id(id);
1651  PointerRNA id_ptr, ptr;
1652  PropertyRNA *prop;
1653  int array_index_max = array_index + 1;
1654  int ret = 0;
1655 
1656  /* sanity checks */
1657  if (ELEM(NULL, id, adt)) {
1658  BKE_report(reports, RPT_ERROR, "No ID block and/or AnimData to delete keyframe from");
1659  return 0;
1660  }
1661 
1662  /* validate pointer first - exit if failure */
1663  RNA_id_pointer_create(id, &id_ptr);
1664  if (RNA_path_resolve_property(&id_ptr, rna_path, &ptr, &prop) == false) {
1665  BKE_reportf(
1666  reports,
1667  RPT_ERROR,
1668  "Could not delete keyframe, as RNA path is invalid for the given ID (ID = %s, path = %s)",
1669  id->name,
1670  rna_path);
1671  return 0;
1672  }
1673 
1674  /* get F-Curve
1675  * Note: here is one of the places where we don't want new Action + F-Curve added!
1676  * so 'add' var must be 0
1677  */
1678  if (act == NULL) {
1679  /* if no action is provided, use the default one attached to this ID-block
1680  * - if it doesn't exist, then we're out of options...
1681  */
1682  if (adt->action) {
1683  act = adt->action;
1684 
1685  /* apply NLA-mapping to frame to use (if applicable) */
1687  }
1688  else {
1689  BKE_reportf(reports, RPT_ERROR, "No action to delete keyframes from for ID = %s", id->name);
1690  return 0;
1691  }
1692  }
1693 
1694  /* key entire array convenience method */
1695  if (array_index == -1) {
1696  array_index = 0;
1697  array_index_max = RNA_property_array_length(&ptr, prop);
1698 
1699  /* for single properties, increase max_index so that the property itself gets included,
1700  * but don't do this for standard arrays since that can cause corruption issues
1701  * (extra unused curves)
1702  */
1703  if (array_index_max == array_index) {
1704  array_index_max++;
1705  }
1706  }
1707 
1708  /* will only loop once unless the array index was -1 */
1709  for (; array_index < array_index_max; array_index++) {
1710  FCurve *fcu = ED_action_fcurve_find(act, rna_path, array_index);
1711 
1712  /* check if F-Curve exists and/or whether it can be edited */
1713  if (fcu == NULL) {
1714  continue;
1715  }
1716 
1717  if (BKE_fcurve_is_protected(fcu)) {
1718  BKE_reportf(reports,
1719  RPT_WARNING,
1720  "Not deleting keyframe for locked F-Curve '%s' for %s '%s'",
1721  fcu->rna_path,
1723  id->name + 2);
1724  continue;
1725  }
1726 
1727  ret += delete_keyframe_fcurve(adt, fcu, cfra);
1728  }
1729  if (ret) {
1730  deg_tag_after_keyframe_delete(bmain, id, adt);
1731  }
1732  /* return success/failure */
1733  return ret;
1734 }
1735 
1736 /* ************************************************** */
1737 /* KEYFRAME CLEAR */
1738 
1749 static int clear_keyframe(Main *bmain,
1750  ReportList *reports,
1751  ID *id,
1752  bAction *act,
1753  const char rna_path[],
1754  int array_index,
1755  eInsertKeyFlags UNUSED(flag))
1756 {
1757  AnimData *adt = BKE_animdata_from_id(id);
1758  PointerRNA id_ptr, ptr;
1759  PropertyRNA *prop;
1760  int array_index_max = array_index + 1;
1761  int ret = 0;
1762 
1763  /* sanity checks */
1764  if (ELEM(NULL, id, adt)) {
1765  BKE_report(reports, RPT_ERROR, "No ID block and/or AnimData to delete keyframe from");
1766  return 0;
1767  }
1768 
1769  /* validate pointer first - exit if failure */
1770  RNA_id_pointer_create(id, &id_ptr);
1771  if (RNA_path_resolve_property(&id_ptr, rna_path, &ptr, &prop) == false) {
1772  BKE_reportf(
1773  reports,
1774  RPT_ERROR,
1775  "Could not clear keyframe, as RNA path is invalid for the given ID (ID = %s, path = %s)",
1776  id->name,
1777  rna_path);
1778  return 0;
1779  }
1780 
1781  /* get F-Curve
1782  * Note: here is one of the places where we don't want new Action + F-Curve added!
1783  * so 'add' var must be 0
1784  */
1785  if (act == NULL) {
1786  /* if no action is provided, use the default one attached to this ID-block
1787  * - if it doesn't exist, then we're out of options...
1788  */
1789  if (adt->action) {
1790  act = adt->action;
1791  }
1792  else {
1793  BKE_reportf(reports, RPT_ERROR, "No action to delete keyframes from for ID = %s", id->name);
1794  return 0;
1795  }
1796  }
1797 
1798  /* key entire array convenience method */
1799  if (array_index == -1) {
1800  array_index = 0;
1801  array_index_max = RNA_property_array_length(&ptr, prop);
1802 
1803  /* for single properties, increase max_index so that the property itself gets included,
1804  * but don't do this for standard arrays since that can cause corruption issues
1805  * (extra unused curves)
1806  */
1807  if (array_index_max == array_index) {
1808  array_index_max++;
1809  }
1810  }
1811 
1812  /* will only loop once unless the array index was -1 */
1813  for (; array_index < array_index_max; array_index++) {
1814  FCurve *fcu = ED_action_fcurve_find(act, rna_path, array_index);
1815 
1816  /* check if F-Curve exists and/or whether it can be edited */
1817  if (fcu == NULL) {
1818  continue;
1819  }
1820 
1821  if (BKE_fcurve_is_protected(fcu)) {
1822  BKE_reportf(reports,
1823  RPT_WARNING,
1824  "Not clearing all keyframes from locked F-Curve '%s' for %s '%s'",
1825  fcu->rna_path,
1827  id->name + 2);
1828  continue;
1829  }
1830 
1832 
1833  /* return success */
1834  ret++;
1835  }
1836  if (ret) {
1837  deg_tag_after_keyframe_delete(bmain, id, adt);
1838  }
1839  /* return success/failure */
1840  return ret;
1841 }
1842 
1843 /* ******************************************* */
1844 /* KEYFRAME MODIFICATION */
1845 
1846 /* mode for commonkey_modifykey */
1847 enum {
1850 } /*eCommonModifyKey_Modes*/;
1851 
1852 /* Polling callback for use with ANIM_*_keyframe() operators
1853  * This is based on the standard ED_operator_areaactive callback,
1854  * except that it does special checks for a few spacetypes too...
1855  */
1857 {
1858  ScrArea *area = CTX_wm_area(C);
1860 
1861  /* if no area or active scene */
1862  if (ELEM(NULL, area, scene)) {
1863  return false;
1864  }
1865 
1866  /* should be fine */
1867  return true;
1868 }
1869 
1870 /* Insert Key Operator ------------------------ */
1871 
1873 {
1875  Object *obedit = CTX_data_edit_object(C);
1876  bool ob_edit_mode = false;
1877 
1878  float cfra = (float)CFRA; /* XXX for now, don't bother about all the yucky offset crap */
1879  int num_channels;
1880 
1882  if (ks == NULL) {
1883  return OPERATOR_CANCELLED;
1884  }
1885 
1886  /* exit the edit mode to make sure that those object data properties that have been
1887  * updated since the last switching to the edit mode will be keyframed correctly
1888  */
1889  if (obedit && ANIM_keyingset_find_id(ks, (ID *)obedit->data)) {
1891  ob_edit_mode = true;
1892  }
1893 
1894  /* try to insert keyframes for the channels specified by KeyingSet */
1895  num_channels = ANIM_apply_keyingset(C, NULL, NULL, ks, MODIFYKEY_MODE_INSERT, cfra);
1896  if (G.debug & G_DEBUG) {
1897  BKE_reportf(op->reports,
1898  RPT_INFO,
1899  "Keying set '%s' - successfully added %d keyframes",
1900  ks->name,
1901  num_channels);
1902  }
1903 
1904  /* restore the edit mode if necessary */
1905  if (ob_edit_mode) {
1907  }
1908 
1909  /* report failure or do updates? */
1910  if (num_channels < 0) {
1911  BKE_report(op->reports, RPT_ERROR, "No suitable context info for active keying set");
1912  return OPERATOR_CANCELLED;
1913  }
1914 
1915  if (num_channels > 0) {
1916  /* if the appropriate properties have been set, make a note that we've inserted something */
1917  if (RNA_boolean_get(op->ptr, "confirm_success")) {
1918  BKE_reportf(op->reports,
1919  RPT_INFO,
1920  "Successfully added %d keyframes for keying set '%s'",
1921  num_channels,
1922  ks->name);
1923  }
1924 
1925  /* send notifiers that keyframes have been changed */
1927  }
1928  else {
1929  BKE_report(op->reports, RPT_WARNING, "Keying set failed to insert any keyframes");
1930  }
1931 
1932  return OPERATOR_FINISHED;
1933 }
1934 
1936 {
1937  PropertyRNA *prop;
1938 
1939  /* identifiers */
1940  ot->name = "Insert Keyframe";
1941  ot->idname = "ANIM_OT_keyframe_insert";
1942  ot->description =
1943  "Insert keyframes on the current frame for all properties in the specified Keying Set";
1944 
1945  /* callbacks */
1946  ot->exec = insert_key_exec;
1948 
1949  /* flags */
1951 
1952  /* keyingset to use (dynamic enum) */
1953  prop = RNA_def_enum(
1954  ot->srna, "type", DummyRNA_DEFAULT_items, 0, "Keying Set", "The Keying Set to use");
1957  ot->prop = prop;
1958 
1959  /* confirm whether a keyframe was added by showing a popup
1960  * - by default, this is enabled, since this operator is assumed to be called independently
1961  */
1962  prop = RNA_def_boolean(ot->srna,
1963  "confirm_success",
1964  1,
1965  "Confirm Successful Insert",
1966  "Show a popup when the keyframes get successfully added");
1968 }
1969 
1970 /* Clone of 'ANIM_OT_keyframe_insert' which uses a name for the keying set instead of an enum. */
1972 {
1973  PropertyRNA *prop;
1974 
1975  /* identifiers */
1976  ot->name = "Insert Keyframe (by name)";
1977  ot->idname = "ANIM_OT_keyframe_insert_by_name";
1978  ot->description = "Alternate access to 'Insert Keyframe' for keymaps to use";
1979 
1980  /* callbacks */
1981  ot->exec = insert_key_exec;
1983 
1984  /* flags */
1986 
1987  /* keyingset to use (idname) */
1988  prop = RNA_def_string_file_path(ot->srna, "type", "Type", MAX_ID_NAME - 2, "", "");
1990  ot->prop = prop;
1991 
1992  /* confirm whether a keyframe was added by showing a popup
1993  * - by default, this is enabled, since this operator is assumed to be called independently
1994  */
1995  prop = RNA_def_boolean(ot->srna,
1996  "confirm_success",
1997  1,
1998  "Confirm Successful Insert",
1999  "Show a popup when the keyframes get successfully added");
2001 }
2002 
2003 /* Insert Key Operator (With Menu) ------------------------ */
2004 /* This operator checks if a menu should be shown for choosing the KeyingSet to use,
2005  * then calls the menu if necessary before
2006  */
2007 
2008 static int insert_key_menu_invoke(bContext *C, wmOperator *op, const wmEvent *UNUSED(event))
2009 {
2011 
2012  /* if prompting or no active Keying Set, show the menu */
2013  if ((scene->active_keyingset == 0) || RNA_boolean_get(op->ptr, "always_prompt")) {
2014  uiPopupMenu *pup;
2015  uiLayout *layout;
2016 
2017  /* call the menu, which will call this operator again, hence the canceled */
2018  pup = UI_popup_menu_begin(C, WM_operatortype_name(op->type, op->ptr), ICON_NONE);
2019  layout = UI_popup_menu_layout(pup);
2020  uiItemsEnumO(layout, "ANIM_OT_keyframe_insert_menu", "type");
2021  UI_popup_menu_end(C, pup);
2022 
2023  return OPERATOR_INTERFACE;
2024  }
2025 
2026  /* just call the exec() on the active keyingset */
2027  RNA_enum_set(op->ptr, "type", 0);
2028  RNA_boolean_set(op->ptr, "confirm_success", true);
2029 
2030  return op->type->exec(C, op);
2031 }
2032 
2034 {
2035  PropertyRNA *prop;
2036 
2037  /* identifiers */
2038  ot->name = "Insert Keyframe Menu";
2039  ot->idname = "ANIM_OT_keyframe_insert_menu";
2040  ot->description =
2041  "Insert Keyframes for specified Keying Set, with menu of available Keying Sets if undefined";
2042 
2043  /* callbacks */
2045  ot->exec = insert_key_exec;
2047 
2048  /* flags */
2050 
2051  /* keyingset to use (dynamic enum) */
2052  prop = RNA_def_enum(
2053  ot->srna, "type", DummyRNA_DEFAULT_items, 0, "Keying Set", "The Keying Set to use");
2056  ot->prop = prop;
2057 
2058  /* confirm whether a keyframe was added by showing a popup
2059  * - by default, this is disabled so that if a menu is shown, this doesn't come up too
2060  */
2061  /* XXX should this just be always on? */
2062  prop = RNA_def_boolean(ot->srna,
2063  "confirm_success",
2064  0,
2065  "Confirm Successful Insert",
2066  "Show a popup when the keyframes get successfully added");
2068 
2069  /* whether the menu should always be shown
2070  * - by default, the menu should only be shown when there is no active Keying Set (2.5 behavior),
2071  * although in some cases it might be useful to always shown (pre 2.5 behavior)
2072  */
2073  prop = RNA_def_boolean(ot->srna, "always_prompt", 0, "Always Show Menu", "");
2075 }
2076 
2077 /* Delete Key Operator ------------------------ */
2078 
2080 {
2082  float cfra = (float)CFRA; /* XXX for now, don't bother about all the yucky offset crap */
2083  int num_channels;
2084 
2086  if (ks == NULL) {
2087  return OPERATOR_CANCELLED;
2088  }
2089 
2090  const int prop_type = RNA_property_type(op->type->prop);
2091  if (prop_type == PROP_ENUM) {
2092  int type = RNA_property_enum_get(op->ptr, op->type->prop);
2094  if (ks == NULL) {
2095  BKE_report(op->reports, RPT_ERROR, "No active Keying Set");
2096  return OPERATOR_CANCELLED;
2097  }
2098  }
2099  else if (prop_type == PROP_STRING) {
2100  char type_id[MAX_ID_NAME - 2];
2101  RNA_property_string_get(op->ptr, op->type->prop, type_id);
2102  ks = ANIM_keyingset_get_from_idname(scene, type_id);
2103 
2104  if (ks == NULL) {
2105  BKE_reportf(op->reports, RPT_ERROR, "Active Keying Set '%s' not found", type_id);
2106  return OPERATOR_CANCELLED;
2107  }
2108  }
2109  else {
2110  BLI_assert(0);
2111  }
2112 
2113  /* report failure */
2114  if (ks == NULL) {
2115  BKE_report(op->reports, RPT_ERROR, "No active Keying Set");
2116  return OPERATOR_CANCELLED;
2117  }
2118 
2119  /* try to delete keyframes for the channels specified by KeyingSet */
2120  num_channels = ANIM_apply_keyingset(C, NULL, NULL, ks, MODIFYKEY_MODE_DELETE, cfra);
2121  if (G.debug & G_DEBUG) {
2122  printf("KeyingSet '%s' - Successfully removed %d Keyframes\n", ks->name, num_channels);
2123  }
2124 
2125  /* report failure or do updates? */
2126  if (num_channels < 0) {
2127  BKE_report(op->reports, RPT_ERROR, "No suitable context info for active keying set");
2128  return OPERATOR_CANCELLED;
2129  }
2130 
2131  if (num_channels > 0) {
2132  /* if the appropriate properties have been set, make a note that we've inserted something */
2133  if (RNA_boolean_get(op->ptr, "confirm_success")) {
2134  BKE_reportf(op->reports,
2135  RPT_INFO,
2136  "Successfully removed %d keyframes for keying set '%s'",
2137  num_channels,
2138  ks->name);
2139  }
2140 
2141  /* send notifiers that keyframes have been changed */
2143  }
2144  else {
2145  BKE_report(op->reports, RPT_WARNING, "Keying set failed to remove any keyframes");
2146  }
2147 
2148  return OPERATOR_FINISHED;
2149 }
2150 
2152 {
2153  PropertyRNA *prop;
2154 
2155  /* identifiers */
2156  ot->name = "Delete Keying-Set Keyframe";
2157  ot->idname = "ANIM_OT_keyframe_delete";
2158  ot->description =
2159  "Delete keyframes on the current frame for all properties in the specified Keying Set";
2160 
2161  /* callbacks */
2162  ot->exec = delete_key_exec;
2164 
2165  /* flags */
2167 
2168  /* keyingset to use (dynamic enum) */
2169  prop = RNA_def_enum(
2170  ot->srna, "type", DummyRNA_DEFAULT_items, 0, "Keying Set", "The Keying Set to use");
2173  ot->prop = prop;
2174 
2175  /* confirm whether a keyframe was added by showing a popup
2176  * - by default, this is enabled, since this operator is assumed to be called independently
2177  */
2179  "confirm_success",
2180  1,
2181  "Confirm Successful Delete",
2182  "Show a popup when the keyframes get successfully removed");
2183 }
2184 
2186 {
2187  PropertyRNA *prop;
2188 
2189  /* identifiers */
2190  ot->name = "Delete Keying-Set Keyframe (by name)";
2191  ot->idname = "ANIM_OT_keyframe_delete_by_name";
2192  ot->description = "Alternate access to 'Delete Keyframe' for keymaps to use";
2193 
2194  /* callbacks */
2195  ot->exec = delete_key_exec;
2197 
2198  /* flags */
2200 
2201  /* keyingset to use (idname) */
2202  prop = RNA_def_string_file_path(ot->srna, "type", "Type", MAX_ID_NAME - 2, "", "");
2204  ot->prop = prop;
2205 
2206  /* confirm whether a keyframe was added by showing a popup
2207  * - by default, this is enabled, since this operator is assumed to be called independently
2208  */
2210  "confirm_success",
2211  1,
2212  "Confirm Successful Delete",
2213  "Show a popup when the keyframes get successfully removed");
2214 }
2215 
2216 /* Delete Key Operator ------------------------ */
2217 /* NOTE: Although this version is simpler than the more generic version for KeyingSets,
2218  * it is more useful for animators working in the 3D view.
2219  */
2220 
2222 {
2223  bool changed = false;
2224 
2225  CTX_DATA_BEGIN (C, Object *, ob, selected_objects) {
2226  /* just those in active action... */
2227  if ((ob->adt) && (ob->adt->action)) {
2228  AnimData *adt = ob->adt;
2229  bAction *act = adt->action;
2230  FCurve *fcu, *fcn;
2231 
2232  for (fcu = act->curves.first; fcu; fcu = fcn) {
2233  bool can_delete = false;
2234 
2235  fcn = fcu->next;
2236 
2237  /* in pose mode, only delete the F-Curve if it belongs to a selected bone */
2238  if (ob->mode & OB_MODE_POSE) {
2239  if ((fcu->rna_path) && strstr(fcu->rna_path, "pose.bones[")) {
2240 
2241  /* get bone-name, and check if this bone is selected */
2242  char *bone_name = BLI_str_quoted_substrN(fcu->rna_path, "pose.bones[");
2243  if (bone_name) {
2244  bPoseChannel *pchan = BKE_pose_channel_find_name(ob->pose, bone_name);
2245  MEM_freeN(bone_name);
2246 
2247  /* delete if bone is selected*/
2248  if ((pchan) && (pchan->bone)) {
2249  if (pchan->bone->flag & BONE_SELECTED) {
2250  can_delete = true;
2251  }
2252  }
2253  }
2254  }
2255  }
2256  else {
2257  /* object mode - all of Object's F-Curves are affected */
2258  can_delete = true;
2259  }
2260 
2261  /* delete F-Curve completely */
2262  if (can_delete) {
2265  changed = true;
2266  }
2267  }
2268 
2269  /* Delete the action itself if it is empty. */
2271  changed = true;
2272  }
2273  }
2274  }
2275  CTX_DATA_END;
2276 
2277  if (!changed) {
2278  return OPERATOR_CANCELLED;
2279  }
2280 
2281  /* send updates */
2283 
2284  return OPERATOR_FINISHED;
2285 }
2286 
2288 {
2289  /* identifiers */
2290  ot->name = "Remove Animation";
2291  ot->description = "Remove all keyframe animation for selected objects";
2292  ot->idname = "ANIM_OT_keyframe_clear_v3d";
2293 
2294  /* callbacks */
2297 
2299 
2300  /* flags */
2302 }
2303 
2305 {
2307  float cfra = (float)CFRA;
2308 
2309  int selected_objects_len = 0;
2310  int selected_objects_success_len = 0;
2311  int success_multi = 0;
2312 
2313  CTX_DATA_BEGIN (C, Object *, ob, selected_objects) {
2314  ID *id = &ob->id;
2315  int success = 0;
2316 
2317  selected_objects_len += 1;
2318 
2319  /* just those in active action... */
2320  if ((ob->adt) && (ob->adt->action)) {
2321  AnimData *adt = ob->adt;
2322  bAction *act = adt->action;
2323  FCurve *fcu, *fcn;
2324  const float cfra_unmap = BKE_nla_tweakedit_remap(adt, cfra, NLATIME_CONVERT_UNMAP);
2325 
2326  for (fcu = act->curves.first; fcu; fcu = fcn) {
2327  fcn = fcu->next;
2328 
2329  /* don't touch protected F-Curves */
2330  if (BKE_fcurve_is_protected(fcu)) {
2331  BKE_reportf(op->reports,
2332  RPT_WARNING,
2333  "Not deleting keyframe for locked F-Curve '%s', object '%s'",
2334  fcu->rna_path,
2335  id->name + 2);
2336  continue;
2337  }
2338 
2339  /* Special exception for bones, as this makes this operator more convenient to use
2340  * NOTE: This is only done in pose mode.
2341  * In object mode, we're dealing with the entire object.
2342  */
2343  if ((ob->mode & OB_MODE_POSE) && strstr(fcu->rna_path, "pose.bones[\"")) {
2344  bPoseChannel *pchan = NULL;
2345 
2346  /* get bone-name, and check if this bone is selected */
2347  char *bone_name = BLI_str_quoted_substrN(fcu->rna_path, "pose.bones[");
2348  if (bone_name) {
2349  pchan = BKE_pose_channel_find_name(ob->pose, bone_name);
2350  MEM_freeN(bone_name);
2351  }
2352 
2353  /* skip if bone is not selected */
2354  if ((pchan) && (pchan->bone)) {
2355  /* bones are only selected/editable if visible... */
2356  bArmature *arm = (bArmature *)ob->data;
2357 
2358  /* skipping - not visible on currently visible layers */
2359  if ((arm->layer & pchan->bone->layer) == 0) {
2360  continue;
2361  }
2362  /* skipping - is currently hidden */
2363  if (pchan->bone->flag & BONE_HIDDEN_P) {
2364  continue;
2365  }
2366 
2367  /* selection flag... */
2368  if ((pchan->bone->flag & BONE_SELECTED) == 0) {
2369  continue;
2370  }
2371  }
2372  }
2373 
2374  /* delete keyframes on current frame
2375  * WARNING: this can delete the next F-Curve, hence the "fcn" copying
2376  */
2377  success += delete_keyframe_fcurve(adt, fcu, cfra_unmap);
2378  }
2379  DEG_id_tag_update(&ob->adt->action->id, ID_RECALC_ANIMATION_NO_FLUSH);
2380  }
2381 
2382  /* Only for reporting. */
2383  if (success) {
2384  selected_objects_success_len += 1;
2385  success_multi += success;
2386  }
2387 
2389  }
2390  CTX_DATA_END;
2391 
2392  /* report success (or failure) */
2393  if (selected_objects_success_len) {
2394  BKE_reportf(op->reports,
2395  RPT_INFO,
2396  "%d object(s) successfully had %d keyframes removed",
2397  selected_objects_success_len,
2398  success_multi);
2399  }
2400  else {
2401  BKE_reportf(
2402  op->reports, RPT_ERROR, "No keyframes removed from %d object(s)", selected_objects_len);
2403  }
2404 
2405  /* send updates */
2407 
2408  return OPERATOR_FINISHED;
2409 }
2410 
2412 {
2413  /* identifiers */
2414  ot->name = "Delete Keyframe";
2415  ot->description = "Remove keyframes on current frame for selected objects and bones";
2416  ot->idname = "ANIM_OT_keyframe_delete_v3d";
2417 
2418  /* callbacks */
2421 
2423 
2424  /* flags */
2426 }
2427 
2428 /* Insert Key Button Operator ------------------------ */
2429 
2431 {
2432  Main *bmain = CTX_data_main(C);
2435  PointerRNA ptr = {NULL};
2436  PropertyRNA *prop = NULL;
2437  char *path;
2438  uiBut *but;
2439  const AnimationEvalContext anim_eval_context = BKE_animsys_eval_context_construct(
2440  CTX_data_depsgraph_pointer(C), (float)CFRA);
2441  bool changed = false;
2442  int index;
2443  const bool all = RNA_boolean_get(op->ptr, "all");
2445 
2446  /* flags for inserting keyframes */
2447  flag = ANIM_get_keyframing_flags(scene, true);
2448 
2449  /* try to insert keyframe using property retrieved from UI */
2450  if (!(but = UI_context_active_but_prop_get(C, &ptr, &prop, &index))) {
2451  /* pass event on if no active button found */
2453  }
2454 
2455  if ((ptr.owner_id && ptr.data && prop) && RNA_property_animateable(&ptr, prop)) {
2456  if (ptr.type == &RNA_NlaStrip) {
2457  /* Handle special properties for NLA Strips, whose F-Curves are stored on the
2458  * strips themselves. These are stored separately or else the properties will
2459  * not have any effect.
2460  */
2461  NlaStrip *strip = ptr.data;
2462  FCurve *fcu = BKE_fcurve_find(&strip->fcurves, RNA_property_identifier(prop), index);
2463 
2464  if (fcu) {
2465  changed = insert_keyframe_direct(
2466  op->reports, ptr, prop, fcu, &anim_eval_context, ts->keyframe_type, NULL, 0);
2467  }
2468  else {
2469  BKE_report(op->reports,
2470  RPT_ERROR,
2471  "This property cannot be animated as it will not get updated correctly");
2472  }
2473  }
2474  else if (UI_but_flag_is_set(but, UI_BUT_DRIVEN)) {
2475  /* Driven property - Find driver */
2476  FCurve *fcu;
2477  bool driven, special;
2478 
2479  fcu = BKE_fcurve_find_by_rna_context_ui(C, &ptr, prop, index, NULL, NULL, &driven, &special);
2480 
2481  if (fcu && driven) {
2482  changed = insert_keyframe_direct(op->reports,
2483  ptr,
2484  prop,
2485  fcu,
2486  &anim_eval_context,
2487  ts->keyframe_type,
2488  NULL,
2490  }
2491  }
2492  else {
2493  /* standard properties */
2494  path = RNA_path_from_ID_to_property(&ptr, prop);
2495 
2496  if (path) {
2497  const char *identifier = RNA_property_identifier(prop);
2498  const char *group = NULL;
2499 
2500  /* Special exception for keyframing transforms:
2501  * Set "group" for this manually, instead of having them appearing at the bottom
2502  * (ungrouped) part of the channels list.
2503  * Leaving these ungrouped is not a nice user behavior in this case.
2504  *
2505  * TODO: Perhaps we can extend this behavior in future for other properties...
2506  */
2507  if (ptr.type == &RNA_PoseBone) {
2508  bPoseChannel *pchan = ptr.data;
2509  group = pchan->name;
2510  }
2511  else if ((ptr.type == &RNA_Object) &&
2512  (strstr(identifier, "location") || strstr(identifier, "rotation") ||
2513  strstr(identifier, "scale"))) {
2514  /* NOTE: Keep this label in sync with the "ID" case in
2515  * keyingsets_utils.py :: get_transform_generators_base_info()
2516  */
2517  group = "Object Transforms";
2518  }
2519 
2520  if (all) {
2521  /* -1 indicates operating on the entire array (or the property itself otherwise) */
2522  index = -1;
2523  }
2524 
2525  changed = (insert_keyframe(bmain,
2526  op->reports,
2527  ptr.owner_id,
2528  NULL,
2529  group,
2530  path,
2531  index,
2532  &anim_eval_context,
2533  ts->keyframe_type,
2534  NULL,
2535  flag) != 0);
2536 
2537  MEM_freeN(path);
2538  }
2539  else {
2540  BKE_report(op->reports,
2541  RPT_WARNING,
2542  "Failed to resolve path to property, "
2543  "try manually specifying this using a Keying Set instead");
2544  }
2545  }
2546  }
2547  else {
2548  if (prop && !RNA_property_animateable(&ptr, prop)) {
2549  BKE_reportf(op->reports,
2550  RPT_WARNING,
2551  "\"%s\" property cannot be animated",
2552  RNA_property_identifier(prop));
2553  }
2554  else {
2555  BKE_reportf(op->reports,
2556  RPT_WARNING,
2557  "Button doesn't appear to have any property information attached (ptr.data = "
2558  "%p, prop = %p)",
2559  ptr.data,
2560  (void *)prop);
2561  }
2562  }
2563 
2564  if (changed) {
2565  ID *id = ptr.owner_id;
2566  AnimData *adt = BKE_animdata_from_id(id);
2567  if (adt->action != NULL) {
2569  }
2571 
2572  /* send updates */
2574 
2575  /* send notifiers that keyframes have been changed */
2577  }
2578 
2579  return (changed) ? OPERATOR_FINISHED : OPERATOR_CANCELLED;
2580 }
2581 
2583 {
2584  /* identifiers */
2585  ot->name = "Insert Keyframe (Buttons)";
2586  ot->idname = "ANIM_OT_keyframe_insert_button";
2587  ot->description = "Insert a keyframe for current UI-active property";
2588 
2589  /* callbacks */
2592 
2593  /* flags */
2595 
2596  /* properties */
2597  RNA_def_boolean(ot->srna, "all", 1, "All", "Insert a keyframe for all element of the array");
2598 }
2599 
2600 /* Delete Key Button Operator ------------------------ */
2601 
2603 {
2605  PointerRNA ptr = {NULL};
2606  PropertyRNA *prop = NULL;
2607  Main *bmain = CTX_data_main(C);
2608  char *path;
2609  float cfra = (float)CFRA; /* XXX for now, don't bother about all the yucky offset crap */
2610  bool changed = false;
2611  int index;
2612  const bool all = RNA_boolean_get(op->ptr, "all");
2613 
2614  /* try to insert keyframe using property retrieved from UI */
2615  if (!UI_context_active_but_prop_get(C, &ptr, &prop, &index)) {
2616  /* pass event on if no active button found */
2618  }
2619 
2620  if (ptr.owner_id && ptr.data && prop) {
2622  /* Handle special properties for NLA Strips, whose F-Curves are stored on the
2623  * strips themselves. These are stored separately or else the properties will
2624  * not have any effect.
2625  */
2626  ID *id = ptr.owner_id;
2627  NlaStrip *strip = ptr.data;
2628  FCurve *fcu = BKE_fcurve_find(&strip->fcurves, RNA_property_identifier(prop), 0);
2629 
2630  if (fcu) {
2631  if (BKE_fcurve_is_protected(fcu)) {
2632  BKE_reportf(
2633  op->reports,
2634  RPT_WARNING,
2635  "Not deleting keyframe for locked F-Curve for NLA Strip influence on %s - %s '%s'",
2636  strip->name,
2638  id->name + 2);
2639  }
2640  else {
2641  /* remove the keyframe directly
2642  * NOTE: cannot use delete_keyframe_fcurve(), as that will free the curve,
2643  * and delete_keyframe() expects the FCurve to be part of an action
2644  */
2645  bool found = false;
2646  int i;
2647 
2648  /* try to find index of beztriple to get rid of */
2649  i = BKE_fcurve_bezt_binarysearch_index(fcu->bezt, cfra, fcu->totvert, &found);
2650  if (found) {
2651  /* delete the key at the index (will sanity check + do recalc afterwards) */
2652  delete_fcurve_key(fcu, i, 1);
2653  changed = true;
2654  }
2655  }
2656  }
2657  }
2658  else {
2659  /* standard properties */
2660  path = RNA_path_from_ID_to_property(&ptr, prop);
2661 
2662  if (path) {
2663  if (all) {
2664  /* -1 indicates operating on the entire array (or the property itself otherwise) */
2665  index = -1;
2666  }
2667 
2668  changed = delete_keyframe(bmain, op->reports, ptr.owner_id, NULL, path, index, cfra) != 0;
2669  MEM_freeN(path);
2670  }
2671  else if (G.debug & G_DEBUG) {
2672  printf("Button Delete-Key: no path to property\n");
2673  }
2674  }
2675  }
2676  else if (G.debug & G_DEBUG) {
2677  printf("ptr.data = %p, prop = %p\n", ptr.data, (void *)prop);
2678  }
2679 
2680  if (changed) {
2681  /* send updates */
2683 
2684  /* send notifiers that keyframes have been changed */
2686  }
2687 
2688  return (changed) ? OPERATOR_FINISHED : OPERATOR_CANCELLED;
2689 }
2690 
2692 {
2693  /* identifiers */
2694  ot->name = "Delete Keyframe (Buttons)";
2695  ot->idname = "ANIM_OT_keyframe_delete_button";
2696  ot->description = "Delete current keyframe of current UI-active property";
2697 
2698  /* callbacks */
2701 
2702  /* flags */
2704 
2705  /* properties */
2706  RNA_def_boolean(ot->srna, "all", 1, "All", "Delete keyframes from all elements of the array");
2707 }
2708 
2709 /* Clear Key Button Operator ------------------------ */
2710 
2712 {
2713  PointerRNA ptr = {NULL};
2714  PropertyRNA *prop = NULL;
2715  Main *bmain = CTX_data_main(C);
2716  char *path;
2717  bool changed = false;
2718  int index;
2719  const bool all = RNA_boolean_get(op->ptr, "all");
2720 
2721  /* try to insert keyframe using property retrieved from UI */
2722  if (!UI_context_active_but_prop_get(C, &ptr, &prop, &index)) {
2723  /* pass event on if no active button found */
2725  }
2726 
2727  if (ptr.owner_id && ptr.data && prop) {
2728  path = RNA_path_from_ID_to_property(&ptr, prop);
2729 
2730  if (path) {
2731  if (all) {
2732  /* -1 indicates operating on the entire array (or the property itself otherwise) */
2733  index = -1;
2734  }
2735 
2736  changed |= (clear_keyframe(bmain, op->reports, ptr.owner_id, NULL, path, index, 0) != 0);
2737  MEM_freeN(path);
2738  }
2739  else if (G.debug & G_DEBUG) {
2740  printf("Button Clear-Key: no path to property\n");
2741  }
2742  }
2743  else if (G.debug & G_DEBUG) {
2744  printf("ptr.data = %p, prop = %p\n", ptr.data, (void *)prop);
2745  }
2746 
2747  if (changed) {
2748  /* send updates */
2750 
2751  /* send notifiers that keyframes have been changed */
2753  }
2754 
2755  return (changed) ? OPERATOR_FINISHED : OPERATOR_CANCELLED;
2756 }
2757 
2759 {
2760  /* identifiers */
2761  ot->name = "Clear Keyframe (Buttons)";
2762  ot->idname = "ANIM_OT_keyframe_clear_button";
2763  ot->description = "Clear all keyframes on the currently active property";
2764 
2765  /* callbacks */
2768 
2769  /* flags */
2771 
2772  /* properties */
2773  RNA_def_boolean(ot->srna, "all", 1, "All", "Clear keyframes from all elements of the array");
2774 }
2775 
2776 /* ******************************************* */
2777 /* AUTO KEYFRAME */
2778 
2780 {
2781  float cfra = (float)CFRA; /* XXX for now, this will do */
2782 
2783  /* only filter if auto-key mode requires this */
2784  if (IS_AUTOKEY_ON(scene) == 0) {
2785  return false;
2786  }
2787 
2788  if (IS_AUTOKEY_MODE(scene, EDITKEYS)) {
2789  /* Replace Mode:
2790  * For whole block, only key if there's a keyframe on that frame already
2791  * This is a valid assumption when we're blocking + tweaking
2792  */
2793  return id_frame_has_keyframe(id, cfra, ANIMFILTER_KEYS_LOCAL);
2794  }
2795 
2796  /* Normal Mode (or treat as being normal mode):
2797  *
2798  * Just in case the flags aren't set properly (i.e. only on/off is set, without a mode)
2799  * let's set the "normal" flag too, so that it will all be sane everywhere...
2800  */
2802 
2803  /* Can insert anytime we like... */
2804  return true;
2805 }
2806 
2807 /* ******************************************* */
2808 /* KEYFRAME DETECTION */
2809 
2810 /* --------------- API/Per-Datablock Handling ------------------- */
2811 
2812 /* Checks if some F-Curve has a keyframe for a given frame */
2813 bool fcurve_frame_has_keyframe(FCurve *fcu, float frame, short filter)
2814 {
2815  /* quick sanity check */
2816  if (ELEM(NULL, fcu, fcu->bezt)) {
2817  return false;
2818  }
2819 
2820  /* we either include all regardless of muting, or only non-muted */
2821  if ((filter & ANIMFILTER_KEYS_MUTED) || (fcu->flag & FCURVE_MUTED) == 0) {
2822  bool replace;
2823  int i = BKE_fcurve_bezt_binarysearch_index(fcu->bezt, frame, fcu->totvert, &replace);
2824 
2825  /* BKE_fcurve_bezt_binarysearch_index will set replace to be 0 or 1
2826  * - obviously, 1 represents a match
2827  */
2828  if (replace) {
2829  /* sanity check: 'i' may in rare cases exceed arraylen */
2830  if ((i >= 0) && (i < fcu->totvert)) {
2831  return true;
2832  }
2833  }
2834  }
2835 
2836  return false;
2837 }
2838 
2839 /* Returns whether the current value of a given property differs from the interpolated value. */
2841  PropertyRNA *prop,
2842  FCurve *fcu,
2843  const AnimationEvalContext *anim_eval_context)
2844 {
2845  PathResolvedRNA anim_rna;
2846  anim_rna.ptr = ptr;
2847  anim_rna.prop = prop;
2848  anim_rna.prop_index = fcu->array_index;
2849 
2851  int count, index = fcu->array_index;
2852  float *values = setting_get_rna_values(&ptr, prop, buffer, RNA_MAX_ARRAY_LENGTH, &count);
2853 
2854  float fcurve_val = calculate_fcurve(&anim_rna, fcu, anim_eval_context);
2855  float cur_val = (index >= 0 && index < count) ? values[index] : 0.0f;
2856 
2857  if (values != buffer) {
2858  MEM_freeN(values);
2859  }
2860 
2861  return !compare_ff_relative(fcurve_val, cur_val, FLT_EPSILON, 64);
2862 }
2863 
2869 static bool action_frame_has_keyframe(bAction *act, float frame, short filter)
2870 {
2871  FCurve *fcu;
2872 
2873  /* can only find if there is data */
2874  if (act == NULL) {
2875  return false;
2876  }
2877 
2878  /* if only check non-muted, check if muted */
2879  if ((filter & ANIMFILTER_KEYS_MUTED) || (act->flag & ACT_MUTED)) {
2880  return false;
2881  }
2882 
2883  /* loop over F-Curves, using binary-search to try to find matches
2884  * - this assumes that keyframes are only beztriples
2885  */
2886  for (fcu = act->curves.first; fcu; fcu = fcu->next) {
2887  /* only check if there are keyframes (currently only of type BezTriple) */
2888  if (fcu->bezt && fcu->totvert) {
2889  if (fcurve_frame_has_keyframe(fcu, frame, filter)) {
2890  return true;
2891  }
2892  }
2893  }
2894 
2895  /* nothing found */
2896  return false;
2897 }
2898 
2899 /* Checks whether an Object has a keyframe for a given frame */
2900 static bool object_frame_has_keyframe(Object *ob, float frame, short filter)
2901 {
2902  /* error checking */
2903  if (ob == NULL) {
2904  return false;
2905  }
2906 
2907  /* check own animation data - specifically, the action it contains */
2908  if ((ob->adt) && (ob->adt->action)) {
2909  /* T41525 - When the active action is a NLA strip being edited,
2910  * we need to correct the frame number to "look inside" the
2911  * remapped action
2912  */
2913  float ob_frame = BKE_nla_tweakedit_remap(ob->adt, frame, NLATIME_CONVERT_UNMAP);
2914 
2915  if (action_frame_has_keyframe(ob->adt->action, ob_frame, filter)) {
2916  return true;
2917  }
2918  }
2919 
2920  /* try shapekey keyframes (if available, and allowed by filter) */
2922  Key *key = BKE_key_from_object(ob);
2923 
2924  /* shapekeys can have keyframes ('Relative Shape Keys')
2925  * or depend on time (old 'Absolute Shape Keys')
2926  */
2927 
2928  /* 1. test for relative (with keyframes) */
2929  if (id_frame_has_keyframe((ID *)key, frame, filter)) {
2930  return true;
2931  }
2932 
2933  /* 2. test for time */
2934  /* TODO... yet to be implemented (this feature may evolve before then anyway) */
2935  }
2936 
2937  /* try materials */
2939  /* if only active, then we can skip a lot of looping */
2941  Material *ma = BKE_object_material_get(ob, (ob->actcol + 1));
2942 
2943  /* we only retrieve the active material... */
2944  if (id_frame_has_keyframe((ID *)ma, frame, filter)) {
2945  return true;
2946  }
2947  }
2948  else {
2949  int a;
2950 
2951  /* loop over materials */
2952  for (a = 0; a < ob->totcol; a++) {
2953  Material *ma = BKE_object_material_get(ob, a + 1);
2954 
2955  if (id_frame_has_keyframe((ID *)ma, frame, filter)) {
2956  return true;
2957  }
2958  }
2959  }
2960  }
2961 
2962  /* nothing found */
2963  return false;
2964 }
2965 
2966 /* --------------- API ------------------- */
2967 
2968 /* Checks whether a keyframe exists for the given ID-block one the given frame */
2969 bool id_frame_has_keyframe(ID *id, float frame, short filter)
2970 {
2971  /* sanity checks */
2972  if (id == NULL) {
2973  return false;
2974  }
2975 
2976  /* perform special checks for 'macro' types */
2977  switch (GS(id->name)) {
2978  case ID_OB: /* object */
2979  return object_frame_has_keyframe((Object *)id, frame, filter);
2980 #if 0
2981  /* XXX TODO... for now, just use 'normal' behavior */
2982  case ID_SCE: /* scene */
2983  break;
2984 #endif
2985  default: /* 'normal type' */
2986  {
2987  AnimData *adt = BKE_animdata_from_id(id);
2988 
2989  /* only check keyframes in active action */
2990  if (adt) {
2991  return action_frame_has_keyframe(adt->action, frame, filter);
2992  }
2993  break;
2994  }
2995  }
2996 
2997  /* no keyframe found */
2998  return false;
2999 }
3000 
3001 /* ************************************************** */
3002 
3004 {
3005  /* auto keyframing */
3006  if (autokeyframe_cfra_can_key(scene, &ob->id)) {
3007  ListBase dsources = {NULL, NULL};
3008 
3009  /* Now insert the key-frame(s) using the Keying Set:
3010  * 1) Add data-source override for the Object.
3011  * 2) Insert key-frames.
3012  * 3) Free the extra info.
3013  */
3014  ANIM_relative_keyingset_add_source(&dsources, &ob->id, NULL, NULL);
3015  ANIM_apply_keyingset(C, &dsources, NULL, ks, MODIFYKEY_MODE_INSERT, (float)CFRA);
3016  BLI_freelistN(&dsources);
3017 
3018  return true;
3019  }
3020  return false;
3021 }
3022 
3024  bContext *C, Scene *scene, Object *ob, bPoseChannel *pchan, KeyingSet *ks)
3025 {
3026  if (autokeyframe_cfra_can_key(scene, &ob->id)) {
3027  ListBase dsources = {NULL, NULL};
3028 
3029  /* Now insert the keyframe(s) using the Keying Set:
3030  * 1) Add data-source override for the pose-channel.
3031  * 2) Insert key-frames.
3032  * 3) Free the extra info.
3033  */
3034  ANIM_relative_keyingset_add_source(&dsources, &ob->id, &RNA_PoseBone, pchan);
3035  ANIM_apply_keyingset(C, &dsources, NULL, ks, MODIFYKEY_MODE_INSERT, (float)CFRA);
3036  BLI_freelistN(&dsources);
3037 
3038  return true;
3039  }
3040 
3041  return false;
3042 }
3043 
3048  bContext *C, Scene *scene, PointerRNA *ptr, PropertyRNA *prop, int rnaindex, float cfra)
3049 {
3050  Main *bmain = CTX_data_main(C);
3053  cfra);
3054  ID *id;
3055  bAction *action;
3056  FCurve *fcu;
3057  bool driven;
3058  bool special;
3059  bool changed = false;
3060 
3061  /* for entire array buttons we check the first component, it's not perfect
3062  * but works well enough in typical cases */
3063  const int rnaindex_check = (rnaindex == -1) ? 0 : rnaindex;
3065  C, ptr, prop, rnaindex_check, NULL, &action, &driven, &special);
3066 
3067  if (fcu == NULL) {
3068  return changed;
3069  }
3070 
3071  if (special) {
3072  /* NLA Strip property */
3073  if (IS_AUTOKEY_ON(scene)) {
3074  ReportList *reports = CTX_wm_reports(C);
3076 
3077  changed = insert_keyframe_direct(
3078  reports, *ptr, prop, fcu, &anim_eval_context, ts->keyframe_type, NULL, 0);
3080  }
3081  }
3082  else if (driven) {
3083  /* Driver - Try to insert keyframe using the driver's input as the frame,
3084  * making it easier to set up corrective drivers
3085  */
3086  if (IS_AUTOKEY_ON(scene)) {
3087  ReportList *reports = CTX_wm_reports(C);
3089 
3090  changed = insert_keyframe_direct(
3091  reports, *ptr, prop, fcu, &anim_eval_context, ts->keyframe_type, NULL, INSERTKEY_DRIVER);
3093  }
3094  }
3095  else {
3096  id = ptr->owner_id;
3097 
3098  /* TODO: this should probably respect the keyingset only option for anim */
3099  if (autokeyframe_cfra_can_key(scene, id)) {
3100  ReportList *reports = CTX_wm_reports(C);
3102  const eInsertKeyFlags flag = ANIM_get_keyframing_flags(scene, true);
3103 
3104  /* Note: We use rnaindex instead of fcu->array_index,
3105  * because a button may control all items of an array at once.
3106  * E.g., color wheels (see T42567). */
3107  BLI_assert((fcu->array_index == rnaindex) || (rnaindex == -1));
3108  changed = insert_keyframe(bmain,
3109  reports,
3110  id,
3111  action,
3112  ((fcu->grp) ? (fcu->grp->name) : (NULL)),
3113  fcu->rna_path,
3114  rnaindex,
3115  &anim_eval_context,
3116  ts->keyframe_type,
3117  NULL,
3118  flag) != 0;
3119 
3121  }
3122  }
3123  return changed;
3124 }
3125 
3126 /* -------------------------------------------------------------------- */
3132 {
3133  KeyingSet *ks = NULL;
3134  const int prop_type = RNA_property_type(prop);
3135  if (prop_type == PROP_ENUM) {
3136  int type = RNA_property_enum_get(op->ptr, prop);
3138  if (ks == NULL) {
3139  BKE_report(op->reports, RPT_ERROR, "No active Keying Set");
3140  }
3141  }
3142  else if (prop_type == PROP_STRING) {
3143  char type_id[MAX_ID_NAME - 2];
3144  RNA_property_string_get(op->ptr, prop, type_id);
3145  ks = ANIM_keyingset_get_from_idname(scene, type_id);
3146 
3147  if (ks == NULL) {
3148  BKE_reportf(op->reports, RPT_ERROR, "Keying set '%s' not found", type_id);
3149  }
3150  }
3151  else {
3152  BLI_assert(0);
3153  }
3154  return ks;
3155 }
3156 
typedef float(TangentPoint)[2]
Blender kernel action and pose functionality.
struct bActionGroup * action_groups_add_new(struct bAction *act, const char name[])
Definition: action.c:402
struct bPoseChannel * BKE_pose_channel_find_name(const struct bPose *pose, const char *name)
void action_group_colors_sync(struct bActionGroup *grp, const struct bActionGroup *ref_grp)
struct bActionGroup * BKE_action_group_find_name(struct bAction *act, const char name[])
Definition: action.c:579
struct bAction * BKE_action_add(struct Main *bmain, const char name[])
Definition: action.c:320
void action_groups_add_channel(struct bAction *act, struct bActionGroup *agrp, struct FCurve *fcurve)
Definition: action.c:431
bool BKE_animdata_action_ensure_idroot(const struct ID *owner, struct bAction *action)
struct AnimData * BKE_animdata_from_id(struct ID *id)
Definition: anim_data.c:96
struct AnimData * BKE_animdata_add_id(struct ID *id)
Definition: anim_data.c:113
void BKE_animsys_free_nla_keyframing_context_cache(struct ListBase *cache)
Definition: anim_sys.c:2756
bool BKE_animsys_nla_remap_keyframe_values(struct NlaKeyframingContext *context, struct PointerRNA *prop_ptr, struct PropertyRNA *prop, float *values, int count, int index, bool *r_force_all)
Definition: anim_sys.c:2648
AnimationEvalContext BKE_animsys_eval_context_construct(struct Depsgraph *depsgraph, float eval_time)
Definition: anim_sys.c:637
struct NlaKeyframingContext * BKE_animsys_get_nla_keyframing_context(struct ListBase *cache, struct PointerRNA *ptr, struct AnimData *adt, const struct AnimationEvalContext *anim_eval_context)
AnimationEvalContext BKE_animsys_eval_context_construct_at(const AnimationEvalContext *anim_eval_context, float eval_time)
Definition: anim_sys.c:647
void BKE_armature_mat_pose_to_bone(struct bPoseChannel *pchan, const float inmat[4][4], float outmat[4][4])
Definition: armature.c:1828
struct ScrArea * CTX_wm_area(const bContext *C)
Definition: context.c:714
struct Scene * CTX_data_scene(const bContext *C)
Definition: context.c:1034
struct Object * CTX_data_edit_object(const bContext *C)
Definition: context.c:1296
#define CTX_DATA_BEGIN(C, Type, instance, member)
Definition: BKE_context.h:252
struct ReportList * CTX_wm_reports(const bContext *C)
Definition: context.c:751
struct Depsgraph * CTX_data_depsgraph_pointer(const bContext *C)
Definition: context.c:1401
struct Main * CTX_data_main(const bContext *C)
Definition: context.c:1018
#define CTX_DATA_END
Definition: BKE_context.h:260
void BKE_fcurve_active_keyframe_set(struct FCurve *fcu, const struct BezTriple *active_bezt)
float evaluate_fcurve(struct FCurve *fcu, float evaltime)
Definition: fcurve.c:2186
bool BKE_fcurve_bezt_subdivide_handles(struct BezTriple *bezt, struct BezTriple *prev, struct BezTriple *next, float *r_pdelta)
Definition: fcurve.c:1714
float calculate_fcurve(struct PathResolvedRNA *anim_rna, struct FCurve *fcu, const struct AnimationEvalContext *anim_eval_context)
eFCU_Cycle_Type
Definition: BKE_fcurve.h:289
@ FCU_CYCLE_OFFSET
Definition: BKE_fcurve.h:294
@ FCU_CYCLE_NONE
Definition: BKE_fcurve.h:290
@ FCU_CYCLE_PERFECT
Definition: BKE_fcurve.h:292
bool BKE_fcurve_is_empty(struct FCurve *fcu)
Definition: fcurve.c:2250
struct FCurve * BKE_fcurve_find_by_rna_context_ui(struct bContext *C, struct PointerRNA *ptr, struct PropertyRNA *prop, int rnaindex, struct AnimData **r_animdata, struct bAction **r_action, bool *r_driven, bool *r_special)
Definition: fcurve.c:390
bool BKE_fcurve_is_keyframable(struct FCurve *fcu)
Definition: fcurve.c:1031
bool BKE_fcurve_is_protected(struct FCurve *fcu)
Definition: fcurve.c:1023
struct FCurve * BKE_fcurve_find(ListBase *list, const char rna_path[], const int array_index)
Definition: fcurve.c:274
eFCU_Cycle_Type BKE_fcurve_get_cycle_type(struct FCurve *fcu)
Definition: fcurve.c:1232
void calchandles_fcurve(struct FCurve *fcu)
Definition: fcurve.c:1391
struct FCurve * BKE_fcurve_create(void)
Definition: fcurve.c:68
int BKE_fcurve_bezt_binarysearch_index(struct BezTriple array[], float frame, int arraylen, bool *r_replace)
Definition: fcurve.c:600
float evaluate_driver(struct PathResolvedRNA *anim_rna, struct ChannelDriver *driver, struct ChannelDriver *driver_orig, const struct AnimationEvalContext *anim_eval_context)
@ G_DEBUG
Definition: BKE_global.h:133
const char * BKE_idtype_idcode_to_name(const short idcode)
Definition: idtype.c:168
struct Key * BKE_key_from_object(const struct Object *ob)
General operations, lookup, etc. for materials.
struct Material * BKE_object_material_get(struct Object *ob, short act)
Definition: material.c:697
bool BKE_nlastrip_has_curves_for_property(const struct PointerRNA *ptr, const struct PropertyRNA *prop)
@ NLATIME_CONVERT_UNMAP
Definition: BKE_nla.h:153
float BKE_nla_tweakedit_remap(struct AnimData *adt, float cframe, short mode)
Definition: nla.c:582
void BKE_report(ReportList *reports, ReportType type, const char *message)
Definition: report.c:104
void BKE_reportf(ReportList *reports, ReportType type, const char *format,...) ATTR_PRINTF_FORMAT(3
#define BLI_assert(a)
Definition: BLI_assert.h:58
BLI_INLINE bool BLI_listbase_is_empty(const struct ListBase *lb)
Definition: BLI_listbase.h:124
void void BLI_freelistN(struct ListBase *listbase) ATTR_NONNULL(1)
Definition: listbase.c:547
void BLI_addtail(struct ListBase *listbase, void *vlink) ATTR_NONNULL(1)
Definition: listbase.c:110
void * BLI_findlink(const struct ListBase *listbase, int number) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1)
MINLINE int compare_ff_relative(float a, float b, const float max_diff, const int max_ulps)
void copy_m3_m4(float m1[3][3], const float m2[4][4])
Definition: math_matrix.c:105
void copy_m4_m4(float m1[4][4], const float m2[4][4])
Definition: math_matrix.c:95
void mat4_to_size(float size[3], const float M[4][4])
Definition: math_matrix.c:2145
void mat4_to_axis_angle(float axis[3], float *angle, const float M[4][4])
void mat3_to_quat_is_ok(float q[4], const float mat[3][3])
void mat4_to_eulO(float eul[3], const short order, const float mat[4][4])
MINLINE void copy_v3_v3(float r[3], const float a[3])
char * BLI_strdup(const char *str) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL() ATTR_MALLOC
Definition: string.c:70
char * BLI_str_quoted_substrN(const char *__restrict str, const char *__restrict prefix) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL() ATTR_MALLOC
Definition: string.c:432
size_t BLI_snprintf(char *__restrict dst, size_t maxncpy, const char *__restrict format,...) ATTR_NONNULL(1
unsigned int uint
Definition: BLI_sys_types.h:83
#define UNUSED(x)
#define ELEM(...)
#define IS_EQF(a, b)
#define TIP_(msgid)
struct Depsgraph Depsgraph
Definition: DEG_depsgraph.h:51
void DEG_id_tag_update_ex(struct Main *bmain, struct ID *id, int flag)
void DEG_id_tag_update(struct ID *id, int flag)
void DEG_relations_tag_update(struct Main *bmain)
@ ID_RECALC_TRANSFORM
Definition: DNA_ID.h:599
@ ID_RECALC_ANIMATION_NO_FLUSH
Definition: DNA_ID.h:690
#define MAX_ID_NAME
Definition: DNA_ID.h:269
@ ID_SCE
Definition: DNA_ID_enums.h:57
@ ID_OB
Definition: DNA_ID_enums.h:59
@ ACT_MUTED
@ FCM_EXTRAPOLATE_CYCLIC_OFFSET
@ FCURVE_COLOR_AUTO_RGB
@ FCURVE_COLOR_AUTO_YRGB
eInsertKeyFlags
@ INSERTKEY_FAST
@ INSERTKEY_CYCLE_AWARE
@ INSERTKEY_OVERWRITE_FULL
@ INSERTKEY_REPLACE
@ INSERTKEY_MATRIX
@ INSERTKEY_NEEDED
@ INSERTKEY_XYZ2RGB
@ INSERTKEY_NO_USERPREF
@ INSERTKEY_AVAILABLE
@ INSERTKEY_DRIVER
@ INSERTKEY_NOFLAGS
@ FCURVE_MUTED
@ FCURVE_INT_VALUES
@ FCURVE_ACTIVE
@ FCURVE_SELECTED
@ FCURVE_DISCRETE_VALUES
@ FCURVE_VISIBLE
@ FCURVE_SMOOTH_CONT_ACCEL
@ BONE_SELECTED
@ BONE_HIDDEN_P
@ BONE_CONNECTED
@ CONSTRAINT_DISABLE
@ CONSTRAINT_TYPE_TRACKTO
@ CONSTRAINT_TYPE_CHILDOF
@ CONSTRAINT_TYPE_TRANSFORM
@ CONSTRAINT_TYPE_ARMATURE
@ CONSTRAINT_TYPE_LOCLIKE
@ CONSTRAINT_TYPE_MINMAX
@ CONSTRAINT_TYPE_ROTLIMIT
@ CONSTRAINT_TYPE_ROTLIKE
@ CONSTRAINT_TYPE_KINEMATIC
@ CONSTRAINT_TYPE_DISTLIMIT
@ CONSTRAINT_TYPE_TRANSLIKE
@ CONSTRAINT_TYPE_LOCLIMIT
@ CONSTRAINT_TYPE_LOCKTRACK
@ CONSTRAINT_TYPE_SIZELIMIT
@ CONSTRAINT_TYPE_FOLLOWPATH
@ CONSTRAINT_TYPE_SIZELIKE
@ CONSTRAINT_TYPE_DAMPTRACK
#define BEZT_IS_AUTOH(bezt)
@ HD_AUTO_ANIM
@ HD_VECT
@ HD_ALIGN
@ BEZT_IPO_CONST
@ BEZT_IPO_BEZ
@ BEZT_IPO_LIN
eBezTriple_KeyframeType
@ OB_MODE_EDIT
@ OB_MODE_POSE
@ OB_MODE_OBJECT
Object is a sort of wrapper for general info.
Types and defines for representing Rigid Body entities.
@ RBO_TYPE_ACTIVE
#define CFRA
@ AUTOKEY_MODE_NORMAL
@ OPERATOR_CANCELLED
@ OPERATOR_INTERFACE
@ OPERATOR_FINISHED
@ OPERATOR_PASS_THROUGH
#define BEZKEYTYPE(bezt)
Definition: ED_anim_api.h:789
@ ANIMFILTER_KEYS_NOSKEY
@ ANIMFILTER_KEYS_MUTED
@ ANIMFILTER_KEYS_LOCAL
@ ANIMFILTER_KEYS_ACTIVE
@ ANIMFILTER_KEYS_NOMAT
#define IS_AUTOKEY_FLAG(scene, flag)
#define IS_AUTOKEY_MODE(scene, mode)
@ MODIFYKEY_MODE_INSERT
@ MODIFYKEY_MODE_DELETE
#define IS_AUTOKEY_ON(scene)
bool ED_object_mode_set(struct bContext *C, eObjectMode mode)
Definition: object_modes.c:235
bool ED_operator_areaactive(struct bContext *C)
Definition: screen_ops.c:119
_GL_VOID GLfloat value _GL_VOID_RET _GL_VOID const GLuint GLboolean *residences _GL_BOOL_RET _GL_VOID GLsizei GLfloat GLfloat GLfloat GLfloat const GLubyte *bitmap _GL_VOID_RET _GL_VOID GLenum type
_GL_VOID GLfloat value _GL_VOID_RET _GL_VOID const GLuint GLboolean *residences _GL_BOOL_RET _GL_VOID GLsizei GLfloat GLfloat GLfloat GLfloat const GLubyte *bitmap _GL_VOID_RET _GL_VOID GLenum const void *lists _GL_VOID_RET _GL_VOID const GLdouble *equation _GL_VOID_RET _GL_VOID GLdouble GLdouble blue _GL_VOID_RET _GL_VOID GLfloat GLfloat blue _GL_VOID_RET _GL_VOID GLint GLint blue _GL_VOID_RET _GL_VOID GLshort GLshort blue _GL_VOID_RET _GL_VOID GLubyte GLubyte blue _GL_VOID_RET _GL_VOID GLuint GLuint blue _GL_VOID_RET _GL_VOID GLushort GLushort blue _GL_VOID_RET _GL_VOID GLbyte GLbyte GLbyte alpha _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble alpha _GL_VOID_RET _GL_VOID GLfloat GLfloat GLfloat alpha _GL_VOID_RET _GL_VOID GLint GLint GLint alpha _GL_VOID_RET _GL_VOID GLshort GLshort GLshort alpha _GL_VOID_RET _GL_VOID GLubyte GLubyte GLubyte alpha _GL_VOID_RET _GL_VOID GLuint GLuint GLuint alpha _GL_VOID_RET _GL_VOID GLushort GLushort GLushort alpha _GL_VOID_RET _GL_VOID GLenum mode _GL_VOID_RET _GL_VOID GLint y
Read Guarded memory(de)allocation.
StructRNA RNA_PoseBone
StructRNA RNA_Object
StructRNA RNA_NlaStrip
#define RNA_MAX_ARRAY_LENGTH
Definition: RNA_define.h:39
@ PROP_FLOAT
Definition: RNA_types.h:75
@ PROP_BOOLEAN
Definition: RNA_types.h:73
@ PROP_ENUM
Definition: RNA_types.h:77
@ PROP_INT
Definition: RNA_types.h:74
@ PROP_STRING
Definition: RNA_types.h:76
@ PROP_HIDDEN
Definition: RNA_types.h:202
PropertySubType
Definition: RNA_types.h:112
@ PROP_XYZ
Definition: RNA_types.h:148
@ PROP_COLOR
Definition: RNA_types.h:139
@ PROP_EULER
Definition: RNA_types.h:145
@ PROP_COORDS
Definition: RNA_types.h:153
@ PROP_TRANSLATION
Definition: RNA_types.h:140
@ PROP_QUATERNION
Definition: RNA_types.h:146
#define C
Definition: RandGen.cpp:39
@ UI_BUT_DRIVEN
Definition: UI_interface.h:203
struct uiLayout * UI_popup_menu_layout(uiPopupMenu *pup)
void uiItemsEnumO(uiLayout *layout, const char *opname, const char *propname)
uiBut * UI_context_active_but_prop_get(const struct bContext *C, struct PointerRNA *r_ptr, struct PropertyRNA **r_prop, int *r_index)
void UI_popup_menu_end(struct bContext *C, struct uiPopupMenu *pup)
void UI_context_update_anim_flag(const struct bContext *C)
uiPopupMenu * UI_popup_menu_begin(struct bContext *C, const char *title, int icon) ATTR_NONNULL()
bool UI_but_flag_is_set(uiBut *but, int flag)
Definition: interface.c:6087
@ OPTYPE_INTERNAL
Definition: WM_types.h:175
@ OPTYPE_UNDO
Definition: WM_types.h:155
@ OPTYPE_REGISTER
Definition: WM_types.h:153
#define NC_ANIMATION
Definition: WM_types.h:289
#define NA_ADDED
Definition: WM_types.h:464
#define NA_EDITED
Definition: WM_types.h:462
#define NA_REMOVED
Definition: WM_types.h:465
#define ND_KEYS
Definition: WM_types.h:364
#define ND_KEYFRAME
Definition: WM_types.h:394
#define NC_OBJECT
Definition: WM_types.h:280
bool ANIM_remove_empty_action_from_animdata(struct AnimData *adt)
void ANIM_fcurve_delete_from_animdata(bAnimContext *ac, AnimData *adt, FCurve *fcu)
unsigned int U
Definition: btGjkEpa3.h:78
SIMD_FORCE_INLINE btScalar length(const btQuaternion &q)
Return the length of a quaternion.
Definition: btQuaternion.h:895
#define SELECT
Scene scene
const Depsgraph * depsgraph
DO_INLINE void filter(lfVector *V, fmatrix3x3 *S)
int count
#define GS(x)
Definition: iris.c:241
#define floorf(x)
#define fabsf(x)
__kernel void ccl_constant KernelData ccl_global void ccl_global char ccl_global int ccl_global char ccl_global unsigned int ccl_global float * buffer
void delete_fcurve_key(FCurve *fcu, int index, bool do_recalc)
static void replace_bezt_keyframe_ypos(BezTriple *dst, const BezTriple *bezt)
Definition: keyframing.c:379
void ANIM_OT_keyframe_insert_menu(wmOperatorType *ot)
Definition: keyframing.c:2033
static void deg_tag_after_keyframe_delete(Main *bmain, ID *id, AnimData *adt)
Definition: keyframing.c:1625
bool fcurve_is_changed(PointerRNA ptr, PropertyRNA *prop, FCurve *fcu, const AnimationEvalContext *anim_eval_context)
Definition: keyframing.c:2840
static bool visualkey_can_use(PointerRNA *ptr, PropertyRNA *prop)
Definition: keyframing.c:860
int delete_keyframe(Main *bmain, ReportList *reports, ID *id, bAction *act, const char rna_path[], int array_index, float cfra)
Definition: keyframing.c:1642
static int insert_key_exec(bContext *C, wmOperator *op)
Definition: keyframing.c:1872
static int delete_key_exec(bContext *C, wmOperator *op)
Definition: keyframing.c:2079
static float * visualkey_get_values(PointerRNA *ptr, PropertyRNA *prop, float *buffer, int buffer_size, int *r_count)
Definition: keyframing.c:1026
static int insert_key_button_exec(bContext *C, wmOperator *op)
Definition: keyframing.c:2430
bool ED_autokeyframe_object(bContext *C, Scene *scene, Object *ob, KeyingSet *ks)
Definition: keyframing.c:3003
int insert_vert_fcurve(FCurve *fcu, float x, float y, eBezTriple_KeyframeType keyframe_type, eInsertKeyFlags flag)
Definition: keyframing.c:547
void ANIM_OT_keyframe_insert(wmOperatorType *ot)
Definition: keyframing.c:1935
static eFCU_Cycle_Type remap_cyclic_keyframe_location(FCurve *fcu, float *px, float *py)
Definition: keyframing.c:338
@ VISUALKEY_LOC
Definition: keyframing.c:849
@ VISUALKEY_NONE
Definition: keyframing.c:848
@ VISUALKEY_SCA
Definition: keyframing.c:851
@ VISUALKEY_ROT
Definition: keyframing.c:850
bAction * ED_id_action_ensure(Main *bmain, ID *id)
Definition: keyframing.c:136
bool fcurve_frame_has_keyframe(FCurve *fcu, float frame, short filter)
Definition: keyframing.c:2813
static int delete_key_button_exec(bContext *C, wmOperator *op)
Definition: keyframing.c:2602
static bool object_frame_has_keyframe(Object *ob, float frame, short filter)
Definition: keyframing.c:2900
void ANIM_OT_keyframe_clear_button(wmOperatorType *ot)
Definition: keyframing.c:2758
bool insert_keyframe_direct(ReportList *reports, PointerRNA ptr, PropertyRNA *prop, FCurve *fcu, const AnimationEvalContext *anim_eval_context, eBezTriple_KeyframeType keytype, struct NlaKeyframingContext *nla_context, eInsertKeyFlags flag)
Definition: keyframing.c:1249
void ANIM_OT_keyframe_insert_by_name(wmOperatorType *ot)
Definition: keyframing.c:1971
static int clear_key_button_exec(bContext *C, wmOperator *op)
Definition: keyframing.c:2711
void ANIM_OT_keyframe_delete(wmOperatorType *ot)
Definition: keyframing.c:2151
static int insert_key_menu_invoke(bContext *C, wmOperator *op, const wmEvent *UNUSED(event))
Definition: keyframing.c:2008
static float * get_keyframe_values(ReportList *reports, PointerRNA ptr, PropertyRNA *prop, int index, struct NlaKeyframingContext *nla_context, eInsertKeyFlags flag, float *buffer, int buffer_size, int *r_count, bool *r_force_all)
Definition: keyframing.c:1117
bool id_frame_has_keyframe(ID *id, float frame, short filter)
Definition: keyframing.c:2969
static float * setting_get_rna_values(PointerRNA *ptr, PropertyRNA *prop, float *buffer, int buffer_size, int *r_count)
Definition: keyframing.c:780
void ANIM_OT_keyframe_clear_v3d(wmOperatorType *ot)
Definition: keyframing.c:2287
@ COMMONKEY_MODE_INSERT
Definition: keyframing.c:1848
@ COMMONKEY_MODE_DELETE
Definition: keyframing.c:1849
static bool delete_keyframe_fcurve(AnimData *adt, FCurve *fcu, float cfra)
Definition: keyframing.c:1603
static void update_autoflags_fcurve_direct(FCurve *fcu, PropertyRNA *prop)
Definition: keyframing.c:273
FCurve * ED_action_fcurve_ensure(struct Main *bmain, struct bAction *act, const char group[], struct PointerRNA *ptr, const char rna_path[], const int array_index)
Definition: keyframing.c:194
static void subdivide_nonauto_handles(const FCurve *fcu, BezTriple *bezt, BezTriple *prev, BezTriple *next)
Definition: keyframing.c:496
static int clear_anim_v3d_exec(bContext *C, wmOperator *UNUSED(op))
Definition: keyframing.c:2221
int insert_bezt_fcurve(FCurve *fcu, const BezTriple *bezt, eInsertKeyFlags flag)
Definition: keyframing.c:403
void ANIM_OT_keyframe_insert_button(wmOperatorType *ot)
Definition: keyframing.c:2582
bool ED_autokeyframe_property(bContext *C, Scene *scene, PointerRNA *ptr, PropertyRNA *prop, int rnaindex, float cfra)
Definition: keyframing.c:3047
static bool insert_keyframe_fcurve_value(Main *bmain, ReportList *reports, PointerRNA *ptr, PropertyRNA *prop, bAction *act, const char group[], const char rna_path[], int array_index, const AnimationEvalContext *anim_eval_context, float curval, eBezTriple_KeyframeType keytype, eInsertKeyFlags flag)
Definition: keyframing.c:1329
@ KEYNEEDED_DONTADD
Definition: keyframing.c:656
@ KEYNEEDED_DELPREV
Definition: keyframing.c:658
@ KEYNEEDED_JUSTADD
Definition: keyframing.c:657
@ KEYNEEDED_DELNEXT
Definition: keyframing.c:659
static KeyingSet * keyingset_get_from_op_with_error(wmOperator *op, PropertyRNA *prop, Scene *scene)
Definition: keyframing.c:3131
static int clear_keyframe(Main *bmain, ReportList *reports, ID *id, bAction *act, const char rna_path[], int array_index, eInsertKeyFlags UNUSED(flag))
Definition: keyframing.c:1749
static AnimationEvalContext nla_time_remap(const AnimationEvalContext *anim_eval_context, PointerRNA *id_ptr, AnimData *adt, bAction *act, ListBase *nla_cache, NlaKeyframingContext **r_nla_context)
Definition: keyframing.c:1378
void update_autoflags_fcurve(FCurve *fcu, bContext *C, ReportList *reports, PointerRNA *ptr)
Definition: keyframing.c:298
static short new_key_needed(FCurve *fcu, float cFrame, float nValue)
Definition: keyframing.c:668
bool autokeyframe_cfra_can_key(const Scene *scene, ID *id)
Definition: keyframing.c:2779
static bool modify_key_op_poll(bContext *C)
Definition: keyframing.c:1856
bool ED_autokeyframe_pchan(bContext *C, Scene *scene, Object *ob, bPoseChannel *pchan, KeyingSet *ks)
Definition: keyframing.c:3023
void ANIM_OT_keyframe_delete_v3d(wmOperatorType *ot)
Definition: keyframing.c:2411
eInsertKeyFlags ANIM_get_keyframing_flags(Scene *scene, const bool use_autokey_mode)
Definition: keyframing.c:92
static bool action_frame_has_keyframe(bAction *act, float frame, short filter)
Definition: keyframing.c:2869
static bool insert_keyframe_value(ReportList *reports, PointerRNA *ptr, PropertyRNA *prop, FCurve *fcu, const AnimationEvalContext *anim_eval_context, float curval, eBezTriple_KeyframeType keytype, eInsertKeyFlags flag)
Definition: keyframing.c:1158
int insert_keyframe(Main *bmain, ReportList *reports, ID *id, bAction *act, const char group[], const char rna_path[], int array_index, const AnimationEvalContext *anim_eval_context, eBezTriple_KeyframeType keytype, ListBase *nla_cache, eInsertKeyFlags flag)
Definition: keyframing.c:1413
void ANIM_OT_keyframe_delete_button(wmOperatorType *ot)
Definition: keyframing.c:2691
void ANIM_OT_keyframe_delete_by_name(wmOperatorType *ot)
Definition: keyframing.c:2185
static int delete_key_v3d_exec(bContext *C, wmOperator *op)
Definition: keyframing.c:2304
FCurve * ED_action_fcurve_find(struct bAction *act, const char rna_path[], const int array_index)
Definition: keyframing.c:181
int ANIM_apply_keyingset(bContext *C, ListBase *dsources, bAction *act, KeyingSet *ks, short mode, float cfra)
Definition: keyingsets.c:1028
KeyingSet * ANIM_keyingset_get_from_enum_type(Scene *scene, int type)
Definition: keyingsets.c:819
KeyingSet * ANIM_keyingset_get_from_idname(Scene *scene, const char *idname)
Definition: keyingsets.c:836
void ANIM_relative_keyingset_add_source(ListBase *dsources, ID *id, StructRNA *srna, void *data)
Definition: keyingsets.c:898
bool ANIM_keyingset_find_id(KeyingSet *ks, ID *id)
Definition: keyingsets.c:658
const EnumPropertyItem * ANIM_keying_sets_enum_itemf(bContext *C, PointerRNA *UNUSED(ptr), PropertyRNA *UNUSED(prop), bool *r_free)
Definition: keyingsets.c:743
void *(* MEM_malloc_arrayN)(size_t len, size_t size, const char *str)
Definition: mallocn.c:48
void(* MEM_freeN)(void *vmemh)
Definition: mallocn.c:41
void *(* MEM_callocN)(size_t len, const char *str)
Definition: mallocn.c:45
static ulong * next
static unsigned a[3]
Definition: RandGen.cpp:92
static void area(int d1, int d2, int e1, int e2, float weights[2])
return ret
float RNA_property_float_get(PointerRNA *ptr, PropertyRNA *prop)
Definition: rna_access.c:2941
bool RNA_property_array_check(PropertyRNA *prop)
Definition: rna_access.c:1223
void RNA_property_float_get_array(PointerRNA *ptr, PropertyRNA *prop, float *values)
Definition: rna_access.c:3033
bool RNA_property_animateable(PointerRNA *ptr, PropertyRNA *prop)
Definition: rna_access.c:2168
void RNA_id_pointer_create(ID *id, PointerRNA *r_ptr)
Definition: rna_access.c:122
const char * RNA_property_identifier(const PropertyRNA *prop)
Definition: rna_access.c:1145
void RNA_boolean_set(PointerRNA *ptr, const char *name, bool value)
Definition: rna_access.c:6272
void RNA_property_boolean_get_array(PointerRNA *ptr, PropertyRNA *prop, bool *values)
Definition: rna_access.c:2420
PropertyType RNA_property_type(PropertyRNA *prop)
Definition: rna_access.c:1155
char * RNA_path_from_ID_to_property(PointerRNA *ptr, PropertyRNA *prop)
Definition: rna_access.c:6027
bool RNA_property_boolean_get(PointerRNA *ptr, PropertyRNA *prop)
Definition: rna_access.c:2331
int RNA_property_int_get(PointerRNA *ptr, PropertyRNA *prop)
Definition: rna_access.c:2607
void RNA_property_string_get(PointerRNA *ptr, PropertyRNA *prop, char *value)
Definition: rna_access.c:3310
int RNA_property_array_length(PointerRNA *ptr, PropertyRNA *prop)
Definition: rna_access.c:1218
int RNA_property_enum_get(PointerRNA *ptr, PropertyRNA *prop)
Definition: rna_access.c:3543
void RNA_property_int_get_array(PointerRNA *ptr, PropertyRNA *prop, int *values)
Definition: rna_access.c:2690
PropertySubType RNA_property_subtype(PropertyRNA *prop)
Definition: rna_access.c:1160
bool RNA_path_resolve_property(PointerRNA *ptr, const char *path, PointerRNA *r_ptr, PropertyRNA **r_prop)
Definition: rna_access.c:5434
bool RNA_boolean_get(PointerRNA *ptr, const char *name)
Definition: rna_access.c:6261
void RNA_enum_set(PointerRNA *ptr, const char *name, int value)
Definition: rna_access.c:6413
bool RNA_path_resolved_create(PointerRNA *ptr, struct PropertyRNA *prop, const int prop_index, PathResolvedRNA *r_anim_rna)
Definition: rna_access.c:8170
PropertyRNA * RNA_def_boolean(StructOrFunctionRNA *cont_, const char *identifier, bool default_value, const char *ui_name, const char *ui_description)
Definition: rna_define.c:3481
PropertyRNA * RNA_def_string_file_path(StructOrFunctionRNA *cont_, const char *identifier, const char *default_value, int maxlen, const char *ui_name, const char *ui_description)
Definition: rna_define.c:3699
void RNA_def_property_flag(PropertyRNA *prop, PropertyFlag flag)
Definition: rna_define.c:1512
void RNA_def_enum_funcs(PropertyRNA *prop, EnumPropertyItemFunc itemfunc)
Definition: rna_define.c:3819
PropertyRNA * RNA_def_enum(StructOrFunctionRNA *cont_, const char *identifier, const EnumPropertyItem *items, int default_value, const char *ui_name, const char *ui_description)
Definition: rna_define.c:3771
const EnumPropertyItem DummyRNA_DEFAULT_items[]
Definition: rna_rna.c:45
bAction * action
float vec[3][3]
struct Bone * parent
struct FCurve * next
bActionGroup * grp
int color_mode
char * rna_path
FPoint * fpt
ChannelDriver * driver
BezTriple * bezt
int array_index
short flag
unsigned int totvert
char auto_smoothing
ListBase modifiers
Definition: DNA_ID.h:273
char name[66]
Definition: DNA_ID.h:283
char name[64]
void * first
Definition: DNA_listBase.h:47
Definition: BKE_main.h:116
ListBase fcurves
char name[64]
ListBase constraints
struct bPose * pose
struct RigidBodyOb * rigidbody_object
float obmat[4][4]
short rotmode
struct AnimData * adt
struct Object * parent
void * data
struct PropertyRNA * prop
Definition: RNA_types.h:65
struct PointerRNA ptr
Definition: RNA_types.h:64
struct StructRNA * type
Definition: RNA_types.h:51
void * data
Definition: RNA_types.h:52
struct ID * owner_id
Definition: RNA_types.h:50
int active_keyingset
struct ToolSettings * toolsettings
ListBase curves
unsigned int layer
struct bConstraint * next
ListBase constraints
struct Bone * bone
struct bPoseChannel * parent
float pose_mat[4][4]
int(* invoke)(struct bContext *, struct wmOperator *, const struct wmEvent *) ATTR_WARN_UNUSED_RESULT
Definition: WM_types.h:752
const char * name
Definition: WM_types.h:721
const char * idname
Definition: WM_types.h:723
bool(* poll)(struct bContext *) ATTR_WARN_UNUSED_RESULT
Definition: WM_types.h:776
struct StructRNA * srna
Definition: WM_types.h:802
const char * description
Definition: WM_types.h:726
int(* exec)(struct bContext *, struct wmOperator *) ATTR_WARN_UNUSED_RESULT
Definition: WM_types.h:736
PropertyRNA * prop
Definition: WM_types.h:814
struct ReportList * reports
struct wmOperatorType * type
struct PointerRNA * ptr
__forceinline bool all(const avxb &b)
Definition: util_avxb.h:214
#define G(x, y, z)
void WM_event_add_notifier(const bContext *C, uint type, void *reference)
PointerRNA * ptr
Definition: wm_files.c:3157
wmOperatorType * ot
Definition: wm_files.c:3156
const char * WM_operatortype_name(struct wmOperatorType *ot, struct PointerRNA *properties)
int WM_operator_confirm(bContext *C, wmOperator *op, const wmEvent *UNUSED(event))