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 
20 /** \file
21  * \ingroup DNA
22  */
23 
24 #pragma once
25 
26 #include "DNA_ID.h"
27 #include "DNA_action_types.h"
28 #include "DNA_curve_types.h"
29 #include "DNA_listBase.h"
30 
31 #ifdef __cplusplus
32 extern "C" {
33 #endif
34 
35 /* ************************************************ */
36 /* F-Curve DataTypes */
37 
38 /* Modifiers -------------------------------------- */
39 
40 /**
41  * F-Curve Modifiers (fcm)
42  *
43  * These alter the way F-Curves behave, by altering the value that is returned
44  * when evaluating the curve's data at some time (t).
45  */
46 typedef struct FModifier {
47   struct FModifier *next, *prev;
48 
49   /** Containing curve, only used for updates to CYCLES. */
50   struct FCurve *curve;
51   /** Pointer to modifier data. */
52   void *data;
53 
54   /** User-defined description for the modifier - MAX_ID_NAME-2. */
55   char name[64];
56   /** Type of f-curve modifier. */
57   short type;
58   /** Settings for the modifier. */
59   short flag;
60 
61   /** The amount that the modifier should influence the value. */
62   float influence;
63 
64   /** Start frame of restricted frame-range. */
65   float sfra;
66   /** End frame of restricted frame-range. */
67   float efra;
68   /** Number of frames from sfra before modifier takes full influence. */
69   float blendin;
70   /** Number of frames from efra before modifier fades out. */
71   float blendout;
72 } FModifier;
73 
74 /**
75  * Types of F-Curve modifier
76  * WARNING: order here is important!
77  */
78 typedef enum eFModifier_Types {
79   FMODIFIER_TYPE_NULL = 0,
80   FMODIFIER_TYPE_GENERATOR = 1,
81   FMODIFIER_TYPE_FN_GENERATOR = 2,
82   FMODIFIER_TYPE_ENVELOPE = 3,
83   FMODIFIER_TYPE_CYCLES = 4,
84   FMODIFIER_TYPE_NOISE = 5,
85   /** Unimplemented - for applying: fft, high/low pass filters, etc. */
86   FMODIFIER_TYPE_FILTER = 6,
87   FMODIFIER_TYPE_PYTHON = 7,
88   FMODIFIER_TYPE_LIMITS = 8,
89   FMODIFIER_TYPE_STEPPED = 9,
90 
91   /* NOTE: all new modifiers must be added above this line */
92   FMODIFIER_NUM_TYPES,
93 } eFModifier_Types;
94 
95 /** F-Curve Modifier Settings. */
96 typedef enum eFModifier_Flags {
97   /** Modifier is not able to be evaluated for some reason, and should be skipped (internal). */
98   FMODIFIER_FLAG_DISABLED = (1 << 0),
99   /** Modifier's data is expanded (in UI). */
100   FMODIFIER_FLAG_EXPANDED = (1 << 1),
101   /** Modifier is active one (in UI) for editing purposes. */
102   FMODIFIER_FLAG_ACTIVE = (1 << 2),
103   /** User wants modifier to be skipped. */
104   FMODIFIER_FLAG_MUTED = (1 << 3),
105   /** Restrict range that F-Modifier can be considered over. */
106   FMODIFIER_FLAG_RANGERESTRICT = (1 << 4),
107   /** Use influence control. */
108   FMODIFIER_FLAG_USEINFLUENCE = (1 << 5),
109 } eFModifier_Flags;
110 
111 /* --- */
112 
113 /* Generator modifier data */
114 typedef struct FMod_Generator {
115   /* general generator information */
116   /** Coefficients array. */
117   float *coefficients;
118   /** Size of the coefficients array. */
119   unsigned int arraysize;
120 
121   /** Order of polynomial generated (i.e. 1 for linear, 2 for quadratic). */
122   int poly_order;
123   /** Which 'generator' to use eFMod_Generator_Modes. */
124   int mode;
125 
126   /** Settings. */
127   int flag;
128 } FMod_Generator;
129 
130 /* generator modes */
131 typedef enum eFMod_Generator_Modes {
132   FCM_GENERATOR_POLYNOMIAL = 0,
133   FCM_GENERATOR_POLYNOMIAL_FACTORISED = 1,
134 } eFMod_Generator_Modes;
135 
136 /* generator flags
137  * - shared by Generator and Function Generator
138  */
139 typedef enum eFMod_Generator_Flags {
140   /* generator works in conjunction with other modifiers (i.e. doesn't replace those before it) */
141   FCM_GENERATOR_ADDITIVE = (1 << 0),
142 } eFMod_Generator_Flags;
143 
144 /**
145  * 'Built-In Function' Generator modifier data
146  *
147  * This uses the general equation for equations:
148  * y = amplitude * fn(phase_multiplier*x + phase_offset) + y_offset
149  *
150  * where amplitude, phase_multiplier/offset, y_offset are user-defined coefficients,
151  * x is the evaluation 'time', and 'y' is the resultant value
152  */
153 typedef struct FMod_FunctionGenerator {
154   /** Coefficients for general equation (as above). */
155   float amplitude;
156   float phase_multiplier;
157   float phase_offset;
158   float value_offset;
159 
160   /* flags */
161   /** #eFMod_Generator_Functions. */
162   int type;
163   /** #eFMod_Generator_flags. */
164   int flag;
165 } FMod_FunctionGenerator;
166 
167 /* 'function' generator types */
168 typedef enum eFMod_Generator_Functions {
169   FCM_GENERATOR_FN_SIN = 0,
170   FCM_GENERATOR_FN_COS = 1,
171   FCM_GENERATOR_FN_TAN = 2,
172   FCM_GENERATOR_FN_SQRT = 3,
173   FCM_GENERATOR_FN_LN = 4,
174   FCM_GENERATOR_FN_SINC = 5,
175 } eFMod_Generator_Functions;
176 
177 /* envelope modifier - envelope data */
178 typedef struct FCM_EnvelopeData {
179   /** Min/max values for envelope at this point (absolute values) . */
180   float min, max;
181   /** Time for that this sample-point occurs. */
182   float time;
183 
184   /** Settings for 'min' control point. */
185   short f1;
186   /** Settings for 'max' control point. */
187   short f2;
188 } FCM_EnvelopeData;
189 
190 /* envelope-like adjustment to values (for fade in/out) */
191 typedef struct FMod_Envelope {
192   /** Data-points defining envelope to apply (array) . */
193   FCM_EnvelopeData *data;
194   /** Number of envelope points. */
195   int totvert;
196 
197   /** Value that envelope's influence is centered around / based on. */
198   float midval;
199   /** Distances from 'middle-value' for 1:1 envelope influence. */
200   float min, max;
201 } FMod_Envelope;
202 
203 /* cycling/repetition modifier data */
204 // TODO: we can only do complete cycles...
205 typedef struct FMod_Cycles {
206   /** Extrapolation mode to use before first keyframe. */
207   short before_mode;
208   /** Extrapolation mode to use after last keyframe. */
209   short after_mode;
210   /** Number of 'cycles' before first keyframe to do. */
211   short before_cycles;
212   /** Number of 'cycles' after last keyframe to do. */
213   short after_cycles;
214 } FMod_Cycles;
215 
216 /* cycling modes */
217 typedef enum eFMod_Cycling_Modes {
218   /** don't do anything */
219   FCM_EXTRAPOLATE_NONE = 0,
220   /** repeat keyframe range as-is */
221   FCM_EXTRAPOLATE_CYCLIC,
222   /** repeat keyframe range, but with offset based on gradient between values */
223   FCM_EXTRAPOLATE_CYCLIC_OFFSET,
224   /** alternate between forward and reverse playback of keyframe range */
225   FCM_EXTRAPOLATE_MIRROR,
226 } eFMod_Cycling_Modes;
227 
228 /* Python-script modifier data */
229 typedef struct FMod_Python {
230   /** Text buffer containing script to execute. */
231   struct Text *script;
232   /** ID-properties to provide 'custom' settings. */
233   IDProperty *prop;
234 } FMod_Python;
235 
236 /* limits modifier data */
237 typedef struct FMod_Limits {
238   /** Rect defining the min/max values. */
239   rctf rect;
240   /** Settings for limiting. */
241   int flag;
242   char _pad[4];
243 } FMod_Limits;
244 
245 /* limiting flags */
246 typedef enum eFMod_Limit_Flags {
247   FCM_LIMIT_XMIN = (1 << 0),
248   FCM_LIMIT_XMAX = (1 << 1),
249   FCM_LIMIT_YMIN = (1 << 2),
250   FCM_LIMIT_YMAX = (1 << 3),
251 } eFMod_Limit_Flags;
252 
253 /* noise modifier data */
254 typedef struct FMod_Noise {
255   float size;
256   float strength;
257   float phase;
258   float offset;
259 
260   short depth;
261   short modification;
262 } FMod_Noise;
263 
264 /* modification modes */
265 typedef enum eFMod_Noise_Modifications {
266   /** Modify existing curve, matching its shape. */
267   FCM_NOISE_MODIF_REPLACE = 0,
268   /** Add noise to the curve. */
269   FCM_NOISE_MODIF_ADD,
270   /** Subtract noise from the curve. */
271   FCM_NOISE_MODIF_SUBTRACT,
272   /** Multiply the curve by noise. */
273   FCM_NOISE_MODIF_MULTIPLY,
274 } eFMod_Noise_Modifications;
275 
276 /* stepped modifier data */
277 typedef struct FMod_Stepped {
278   /** Number of frames each interpolated value should be held. */
279   float step_size;
280   /** Reference frame number that stepping starts from. */
281   float offset;
282 
283   /** Start frame of the frame range that modifier works in. */
284   float start_frame;
285   /** End frame of the frame range that modifier works in. */
286   float end_frame;
287 
288   /** Various settings. */
289   int flag;
290 } FMod_Stepped;
291 
292 /* stepped modifier range flags */
293 typedef enum eFMod_Stepped_Flags {
294   /** Don't affect frames before the start frame. */
295   FCM_STEPPED_NO_BEFORE = (1 << 0),
296   /** Don't affect frames after the end frame. */
297   FCM_STEPPED_NO_AFTER = (1 << 1),
298 } eFMod_Stepped_Flags;
299 
300 /* Drivers -------------------------------------- */
301 
302 /* Driver Target (dtar)
303  *
304  * Defines how to access a dependency needed for a driver variable.
305  */
306 typedef struct DriverTarget {
307   /** ID-block which owns the target, no user count. */
308   ID *id;
309 
310   /** RNA path defining the setting to use (for DVAR_TYPE_SINGLE_PROP). */
311   char *rna_path;
312 
313   /**
314    * Name of the posebone to use
315    * (for vars where DTAR_FLAG_STRUCT_REF is used) - MAX_ID_NAME-2.
316    */
317   char pchan_name[64];
318   /** Transform channel index (for DVAR_TYPE_TRANSFORM_CHAN.)*/
319   short transChan;
320 
321   /** Rotation channel calculation type. */
322   char rotation_mode;
323   char _pad[7];
324 
325   /**
326    * Flags for the validity of the target
327    * (NOTE: these get reset every time the types change).
328    */
329   short flag;
330   /** Type of ID-block that this target can use. */
331   int idtype;
332 } DriverTarget;
333 
334 /** Driver Target flags. */
335 typedef enum eDriverTarget_Flag {
336   /** used for targets that use the pchan_name instead of RNA path
337    * (i.e. rotation difference) */
338   DTAR_FLAG_STRUCT_REF = (1 << 0),
339   /** idtype can only be 'Object' */
340   DTAR_FLAG_ID_OB_ONLY = (1 << 1),
341 
342   /* "localspace" flags */
343   /** base flag - basically "pre parent+constraints" */
344   DTAR_FLAG_LOCALSPACE = (1 << 2),
345   /** include constraints transformed to space including parents */
346   DTAR_FLAG_LOCAL_CONSTS = (1 << 3),
347 
348   /** error flags */
349   DTAR_FLAG_INVALID = (1 << 4),
350 } eDriverTarget_Flag;
351 
352 /* Transform Channels for Driver Targets */
353 typedef enum eDriverTarget_TransformChannels {
354   DTAR_TRANSCHAN_LOCX = 0,
355   DTAR_TRANSCHAN_LOCY,
356   DTAR_TRANSCHAN_LOCZ,
357   DTAR_TRANSCHAN_ROTX,
358   DTAR_TRANSCHAN_ROTY,
359   DTAR_TRANSCHAN_ROTZ,
360   DTAR_TRANSCHAN_SCALEX,
361   DTAR_TRANSCHAN_SCALEY,
362   DTAR_TRANSCHAN_SCALEZ,
363   DTAR_TRANSCHAN_SCALE_AVG,
364   DTAR_TRANSCHAN_ROTW,
365 
366   MAX_DTAR_TRANSCHAN_TYPES,
367 } eDriverTarget_TransformChannels;
368 
369 /* Rotation channel mode for Driver Targets */
370 typedef enum eDriverTarget_RotationMode {
371   /** Automatic euler mode. */
372   DTAR_ROTMODE_AUTO = 0,
373 
374   /** Explicit euler rotation modes - must sync with BLI_math_rotation.h defines. */
375   DTAR_ROTMODE_EULER_XYZ = 1,
376   DTAR_ROTMODE_EULER_XZY,
377   DTAR_ROTMODE_EULER_YXZ,
378   DTAR_ROTMODE_EULER_YZX,
379   DTAR_ROTMODE_EULER_ZXY,
380   DTAR_ROTMODE_EULER_ZYX,
381 
382   DTAR_ROTMODE_QUATERNION,
383 
384   /** Implements the very common Damped Track + child trick to decompose
385    *  rotation into bending followed by twist around the remaining axis. */
386   DTAR_ROTMODE_SWING_TWIST_X,
387   DTAR_ROTMODE_SWING_TWIST_Y,
388   DTAR_ROTMODE_SWING_TWIST_Z,
389 
390   DTAR_ROTMODE_EULER_MIN = DTAR_ROTMODE_EULER_XYZ,
391   DTAR_ROTMODE_EULER_MAX = DTAR_ROTMODE_EULER_ZYX,
392 } eDriverTarget_RotationMode;
393 
394 /* --- */
395 
396 /* maximum number of driver targets per variable */
397 #define MAX_DRIVER_TARGETS 8
398 
399 /**
400  * Driver Variable (dvar)
401  *
402  * A 'variable' for use as an input for the driver evaluation.
403  * Defines a way of accessing some channel to use, that can be
404  * referred to in the expression as a variable, thus simplifying
405  * expressions and also Depsgraph building.
406  */
407 typedef struct DriverVar {
408   struct DriverVar *next, *prev;
409 
410   /**
411    * Name of the variable to use in py-expression
412    * (must be valid python identifier) - MAX_ID_NAME-2.
413    */
414   char name[64];
415 
416   /** MAX_DRIVER_TARGETS, target slots. */
417   DriverTarget targets[8];
418 
419   /** Number of targets actually used by this variable. */
420   char num_targets;
421   /** Type of driver variable (eDriverVar_Types). */
422   char type;
423 
424   /** Validation tags, etc. (eDriverVar_Flags). */
425   short flag;
426   /** Result of previous evaluation. */
427   float curval;
428 } DriverVar;
429 
430 /** Driver Variable Types.* */
431 typedef enum eDriverVar_Types {
432   /** single RNA property */
433   DVAR_TYPE_SINGLE_PROP = 0,
434   /** rotation difference (between 2 bones) */
435   DVAR_TYPE_ROT_DIFF,
436   /** distance between objects/bones */
437   DVAR_TYPE_LOC_DIFF,
438   /** 'final' transform for object/bones */
439   DVAR_TYPE_TRANSFORM_CHAN,
440 
441   /** Maximum number of variable types.
442    *
443    * \note This must always be th last item in this list,
444    * so add new types above this line.
445    */
446   MAX_DVAR_TYPES,
447 } eDriverVar_Types;
448 
449 /* Driver Variable Flags */
450 typedef enum eDriverVar_Flags {
451   /* variable is not set up correctly */
452   DVAR_FLAG_ERROR = (1 << 0),
453 
454   /* variable name doesn't pass the validation tests */
455   DVAR_FLAG_INVALID_NAME = (1 << 1),
456   /* name starts with a number */
457   DVAR_FLAG_INVALID_START_NUM = (1 << 2),
458   /* name starts with a special character (!, $, @, #, _, etc.) */
459   DVAR_FLAG_INVALID_START_CHAR = (1 << 3),
460   /* name contains a space */
461   DVAR_FLAG_INVALID_HAS_SPACE = (1 << 4),
462   /* name contains a dot */
463   DVAR_FLAG_INVALID_HAS_DOT = (1 << 5),
464   /* name contains invalid chars */
465   DVAR_FLAG_INVALID_HAS_SPECIAL = (1 << 6),
466   /* name is a reserved keyword */
467   DVAR_FLAG_INVALID_PY_KEYWORD = (1 << 7),
468   /* name is zero-length */
469   DVAR_FLAG_INVALID_EMPTY = (1 << 8),
470 } eDriverVar_Flags;
471 
472 /* All invalid dvar name flags */
473 #define DVAR_ALL_INVALID_FLAGS \
474   (DVAR_FLAG_INVALID_NAME | DVAR_FLAG_INVALID_START_NUM | DVAR_FLAG_INVALID_START_CHAR | \
475    DVAR_FLAG_INVALID_HAS_SPACE | DVAR_FLAG_INVALID_HAS_DOT | DVAR_FLAG_INVALID_HAS_SPECIAL | \
476    DVAR_FLAG_INVALID_PY_KEYWORD | DVAR_FLAG_INVALID_EMPTY)
477 
478 /* --- */
479 
480 /**
481  * Channel Driver (i.e. Drivers / Expressions) (driver)
482  *
483  * Channel Drivers are part of the dependency system, and are executed in addition to
484  * normal user-defined animation. They take the animation result of some channel(s), and
485  * use that (optionally combined with its own F-Curve for modification of results) to define
486  * the value of some setting semi-procedurally.
487  *
488  * Drivers are stored as part of F-Curve data, so that the F-Curve's RNA-path settings (for storing
489  * what setting the driver will affect). The order in which they are stored defines the order that
490  * they're evaluated in. This order is set by the Depsgraph's sorting stuff.
491  */
492 typedef struct ChannelDriver {
493   /** Targets for this driver (i.e. list of DriverVar). */
494   ListBase variables;
495 
496   /* python expression to execute (may call functions defined in an accessory file)
497    * which relates the target 'variables' in some way to yield a single usable value
498    */
499   /** Expression to compile for evaluation. */
500   char expression[256];
501   /** PyObject - compiled expression, don't save this. */
502   void *expr_comp;
503 
504   /** Compiled simple arithmetic expression. */
505   struct ExprPyLike_Parsed *expr_simple;
506 
507   /** Result of previous evaluation. */
508   float curval;
509   /* XXX to be implemented... this is like the constraint influence setting. */
510   /** Influence of driver on result. */
511   float influence;
512 
513   /* general settings */
514   /** Type of driver. */
515   int type;
516   /** Settings of driver. */
517   int flag;
518 } ChannelDriver;
519 
520 /** Driver type. */
521 typedef enum eDriver_Types {
522   /** target values are averaged together. */
523   DRIVER_TYPE_AVERAGE = 0,
524   /** python expression/function relates targets. */
525   DRIVER_TYPE_PYTHON,
526   /** sum of all values. */
527   DRIVER_TYPE_SUM,
528   /** smallest value. */
529   DRIVER_TYPE_MIN,
530   /** largest value. */
531   DRIVER_TYPE_MAX,
532 } eDriver_Types;
533 
534 /** Driver flags. */
535 typedef enum eDriver_Flags {
536   /** Driver has invalid settings (internal flag)  */
537   DRIVER_FLAG_INVALID = (1 << 0),
538   DRIVER_FLAG_DEPRECATED = (1 << 1),
539   /** Driver does replace value, but overrides (for layering of animation over driver) */
540   /* TODO: this needs to be implemented at some stage or left out... */
541   // DRIVER_FLAG_LAYERING  = (1 << 2),
542   /** Use when the expression needs to be recompiled. */
543   DRIVER_FLAG_RECOMPILE = (1 << 3),
544   /** The names are cached so they don't need have python unicode versions created each time */
545   DRIVER_FLAG_RENAMEVAR = (1 << 4),
546   // DRIVER_FLAG_UNUSED_5 = (1 << 5),
547   /** Include 'self' in the drivers namespace. */
548   DRIVER_FLAG_USE_SELF = (1 << 6),
549 } eDriver_Flags;
550 
551 /* F-Curves -------------------------------------- */
552 
553 /** When #active_keyframe_index is set to this, the FCurve does not have an active keyframe. */
554 #define FCURVE_ACTIVE_KEYFRAME_NONE -1
555 
556 /**
557  * FPoint (fpt)
558  *
559  * This is the bare-minimum data required storing motion samples. Should be more efficient
560  * than using BPoints, which contain a lot of other unnecessary data...
561  */
562 typedef struct FPoint {
563   /** Time + value. */
564   float vec[2];
565   /** Selection info. */
566   int flag;
567   char _pad[4];
568 } FPoint;
569 
570 /* 'Function-Curve' - defines values over time for a given setting (fcu) */
571 typedef struct FCurve {
572   struct FCurve *next, *prev;
573 
574   /* group */
575   /** Group that F-Curve belongs to. */
576   bActionGroup *grp;
577 
578   /* driver settings */
579   /** Only valid for drivers (i.e. stored in AnimData not Actions). */
580   ChannelDriver *driver;
581   /* evaluation settings */
582   /** FCurve Modifiers. */
583   ListBase modifiers;
584 
585   /* motion data */
586   /** User-editable keyframes (array). */
587   BezTriple *bezt;
588   /** 'baked/imported' motion samples (array). */
589   FPoint *fpt;
590   /** Total number of points which define the curve (i.e. size of arrays in FPoints). */
591   unsigned int totvert;
592 
593   /**
594    * Index of active keyframe in #bezt for numerical editing in the interface. A value of
595    * #FCURVE_ACTIVE_KEYFRAME_NONE indicates that the FCurve has no active keyframe.
596    *
597    * Do not access directly, use #BKE_fcurve_active_keyframe_index() and
598    * #BKE_fcurve_active_keyframe_set() instead.
599    */
600   int active_keyframe_index;
601 
602   /* value cache + settings */
603   /** Value stored from last time curve was evaluated (not threadsafe, debug display only!). */
604   float curval;
605   /** User-editable settings for this curve. */
606   short flag;
607   /** Value-extending mode for this curve (does not cover). */
608   short extend;
609   /** Auto-handle smoothing mode. */
610   char auto_smoothing;
611 
612   char _pad[3];
613 
614   /* RNA - data link */
615   /** If applicable, the index of the RNA-array item to get. */
616   int array_index;
617   /** RNA-path to resolve data-access. */
618   char *rna_path;
619 
620   /* curve coloring (for editor) */
621   /** Coloring method to use (eFCurve_Coloring). */
622   int color_mode;
623   /** The last-color this curve took. */
624   float color[3];
625 
626   float prev_norm_factor, prev_offset;
627 } FCurve;
628 
629 /* user-editable flags/settings */
630 typedef enum eFCurve_Flags {
631   /** curve/keyframes are visible in editor */
632   FCURVE_VISIBLE = (1 << 0),
633   /** curve is selected for editing  */
634   FCURVE_SELECTED = (1 << 1),
635   /** curve is active one */
636   FCURVE_ACTIVE = (1 << 2),
637   /** keyframes (beztriples) cannot be edited */
638   FCURVE_PROTECTED = (1 << 3),
639   /** fcurve will not be evaluated for the next round */
640   FCURVE_MUTED = (1 << 4),
641 
642   /** fcurve uses 'auto-handles', which stay horizontal... */
643   // DEPRECATED
644   FCURVE_AUTO_HANDLES = (1 << 5),
645   FCURVE_MOD_OFF = (1 << 6),
646   /** skip evaluation, as RNA-path cannot be resolved
647    * (similar to muting, but cannot be set by user) */
648   FCURVE_DISABLED = (1 << 10),
649   /** curve can only have whole-number values (integer types) */
650   FCURVE_INT_VALUES = (1 << 11),
651   /** curve can only have certain discrete-number values
652    * (no interpolation at all, for enums/booleans) */
653   FCURVE_DISCRETE_VALUES = (1 << 12),
654 
655   /** temporary tag for editing */
656   FCURVE_TAGGED = (1 << 15),
657 } eFCurve_Flags;
658 
659 /* extrapolation modes (only simple value 'extending') */
660 typedef enum eFCurve_Extend {
661   /** just extend min/max keyframe value  */
662   FCURVE_EXTRAPOLATE_CONSTANT = 0,
663   /** just extend gradient of segment between first segment keyframes */
664   FCURVE_EXTRAPOLATE_LINEAR,
665 } eFCurve_Extend;
666 
667 /* curve coloring modes */
668 typedef enum eFCurve_Coloring {
669   /** automatically determine color using rainbow (calculated at drawtime) */
670   FCURVE_COLOR_AUTO_RAINBOW = 0,
671   /** automatically determine color using XYZ (array index) <-> RGB */
672   FCURVE_COLOR_AUTO_RGB = 1,
673   /** automatically determine color where XYZ <-> RGB, but index(X) != 0 */
674   FCURVE_COLOR_AUTO_YRGB = 3,
675   /** custom color */
676   FCURVE_COLOR_CUSTOM = 2,
677 } eFCurve_Coloring;
678 
679 /* curve smoothing modes */
680 typedef enum eFCurve_Smoothing {
681   /** legacy mode: auto handles only consider adjacent points */
682   FCURVE_SMOOTH_NONE = 0,
683   /** maintain continuity of the acceleration */
684   FCURVE_SMOOTH_CONT_ACCEL = 1,
685 } eFCurve_Smoothing;
686 
687 /* ************************************************ */
688 /* 'Action' Datatypes */
689 
690 /* NOTE: Although these are part of the Animation System,
691  * they are not stored here... see DNA_action_types.h instead
692  */
693 
694 /* ************************************************ */
695 /* NLA - Non-Linear Animation */
696 
697 /* NLA Strips ------------------------------------- */
698 
699 /**
700  * NLA Strip (strip)
701  *
702  * A NLA Strip is a container for the reuse of Action data, defining parameters
703  * to control the remapping of the Action data to some destination.
704  */
705 typedef struct NlaStrip {
706   struct NlaStrip *next, *prev;
707 
708   /** 'Child' strips (used for 'meta' strips). */
709   ListBase strips;
710   /** Action that is referenced by this strip (strip is 'user' of the action). */
711   bAction *act;
712 
713   /** F-Curves for controlling this strip's influence and timing */ /* TODO: move out? */
714   ListBase fcurves;
715   /** F-Curve modifiers to be applied to the entire strip's referenced F-Curves. */
716   ListBase modifiers;
717 
718   /** User-Visible Identifier for Strip - MAX_ID_NAME-2. */
719   char name[64];
720 
721   /** Influence of strip. */
722   float influence;
723   /** Current 'time' within action being used (automatically evaluated, but can be overridden). */
724   float strip_time;
725 
726   /** Extents of the strip. */
727   float start, end;
728   /** Range of the action to use. */
729   float actstart, actend;
730 
731   /** The number of times to repeat the action range (only when no F-Curves). */
732   float repeat;
733   /** The amount the action range is scaled by (only when no F-Curves). */
734   float scale;
735 
736   /** Strip blending length (only used when there are no F-Curves). */
737   float blendin, blendout;
738   /** Strip blending mode (layer-based mixing). */
739   short blendmode;
740 
741   /** Strip extrapolation mode (time-based mixing). */
742   short extendmode;
743   char _pad1[2];
744 
745   /** Type of NLA strip. */
746   short type;
747 
748   /** Handle for speaker objects. */
749   void *speaker_handle;
750 
751   /** Settings. */
752   int flag;
753   char _pad2[4];
754 
755   /* Pointer to an original NLA strip. */
756   struct NlaStrip *orig_strip;
757 
758   void *_pad3;
759 } NlaStrip;
760 
761 /* NLA Strip Blending Mode */
762 typedef enum eNlaStrip_Blend_Mode {
763   NLASTRIP_MODE_REPLACE = 0,
764   NLASTRIP_MODE_ADD,
765   NLASTRIP_MODE_SUBTRACT,
766   NLASTRIP_MODE_MULTIPLY,
767   NLASTRIP_MODE_COMBINE,
768 } eNlaStrip_Blend_Mode;
769 
770 /** NLA Strip Extrpolation Mode. */
771 typedef enum eNlaStrip_Extrapolate_Mode {
772   /* extend before first frame if no previous strips in track,
773    * and always hold+extend last frame */
774   NLASTRIP_EXTEND_HOLD = 0,
775   /* only hold+extend last frame */
776   NLASTRIP_EXTEND_HOLD_FORWARD = 1,
777   /* don't contribute at all */
778   NLASTRIP_EXTEND_NOTHING = 2,
779 } eNlaStrip_Extrapolate_Mode;
780 
781 /** NLA Strip Settings. */
782 typedef enum eNlaStrip_Flag {
783   /* UI selection flags */
784   /** NLA strip is the active one in the track (also indicates if strip is being tweaked) */
785   NLASTRIP_FLAG_ACTIVE = (1 << 0),
786   /* NLA strip is selected for editing */
787   NLASTRIP_FLAG_SELECT = (1 << 1),
788   // NLASTRIP_FLAG_SELECT_L      = (1 << 2),   /* left handle selected. */
789   // NLASTRIP_FLAG_SELECT_R      = (1 << 3),   /* right handle selected. */
790 
791   /** NLA strip uses the same action that the action being tweaked uses
792    * (not set for the tweaking one though). */
793   NLASTRIP_FLAG_TWEAKUSER = (1 << 4),
794 
795   /* controls driven by local F-Curves */
796   /** strip influence is controlled by local F-Curve */
797   NLASTRIP_FLAG_USR_INFLUENCE = (1 << 5),
798   NLASTRIP_FLAG_USR_TIME = (1 << 6),
799   NLASTRIP_FLAG_USR_TIME_CYCLIC = (1 << 7),
800 
801   /** NLA strip length is synced to the length of the referenced action */
802   NLASTRIP_FLAG_SYNC_LENGTH = (1 << 9),
803 
804   /* playback flags (may be overridden by F-Curves) */
805   /** NLA strip blendin/out values are set automatically based on overlaps */
806   NLASTRIP_FLAG_AUTO_BLENDS = (1 << 10),
807   /** NLA strip is played back in reverse order */
808   NLASTRIP_FLAG_REVERSE = (1 << 11),
809   /** NLA strip is muted (i.e. doesn't contribute in any way) */
810   NLASTRIP_FLAG_MUTED = (1 << 12),
811   /** NLA Strip is played back in 'ping-pong' style */
812   /* NLASTRIP_FLAG_MIRROR = (1 << 13), */ /* UNUSED */
813 
814   /* temporary editing flags */
815   /** NLA strip should ignore frame range and hold settings, and evaluate at global time. */
816   NLASTRIP_FLAG_NO_TIME_MAP = (1 << 29),
817   /** NLA-Strip is really just a temporary meta used to facilitate easier transform code */
818   NLASTRIP_FLAG_TEMP_META = (1 << 30),
819   NLASTRIP_FLAG_EDIT_TOUCHED = (1u << 31),
820 } eNlaStrip_Flag;
821 
822 /* NLA Strip Type */
823 typedef enum eNlaStrip_Type {
824   /* 'clip' - references an Action */
825   NLASTRIP_TYPE_CLIP = 0,
826   /* 'transition' - blends between the adjacent strips */
827   NLASTRIP_TYPE_TRANSITION,
828   /* 'meta' - a strip which acts as a container for a few others */
829   NLASTRIP_TYPE_META,
830 
831   /* 'emit sound' - a strip which is used for timing when speaker emits sounds */
832   NLASTRIP_TYPE_SOUND,
833 } eNlaStrip_Type;
834 
835 /* NLA Tracks ------------------------------------- */
836 
837 /**
838  * NLA Track (nlt)
839  *
840  * A track groups a bunch of 'strips', which should form a continuous set of
841  * motion, on top of which other such groups can be layered. This should allow
842  * for animators to work in a non-destructive manner, layering tweaks, etc. over
843  * 'rough' blocks of their work.
844  */
845 typedef struct NlaTrack {
846   struct NlaTrack *next, *prev;
847 
848   /** BActionStrips in this track. */
849   ListBase strips;
850 
851   /** Settings for this track. */
852   int flag;
853   /** Index of the track in the stack
854    * \note not really useful, but we need a '_pad' var anyways! */
855   int index;
856 
857   /** Short user-description of this track - MAX_ID_NAME-2. */
858   char name[64];
859 } NlaTrack;
860 
861 /* settings for track */
862 typedef enum eNlaTrack_Flag {
863   /** track is the one that settings can be modified on,
864    * also indicates if track is being 'tweaked' */
865   NLATRACK_ACTIVE = (1 << 0),
866   /** track is selected in UI for relevant editing operations */
867   NLATRACK_SELECTED = (1 << 1),
868   /** track is not evaluated */
869   NLATRACK_MUTED = (1 << 2),
870   /** track is the only one evaluated (must be used in conjunction with adt->flag) */
871   NLATRACK_SOLO = (1 << 3),
872   /** track's settings (and strips) cannot be edited (to guard against unwanted changes) */
873   NLATRACK_PROTECTED = (1 << 4),
874 
875   /** track is not allowed to execute,
876    * usually as result of tweaking being enabled (internal flag) */
877   NLATRACK_DISABLED = (1 << 10),
878 } eNlaTrack_Flag;
879 
880 /* ************************************ */
881 /* KeyingSet Datatypes */
882 
883 /**
884  * Path for use in KeyingSet definitions (ksp)
885  *
886  * Paths may be either specific (specifying the exact sub-ID
887  * dynamic data-block - such as PoseChannels - to act upon, ala
888  * Maya's 'Character Sets' and XSI's 'Marking Sets'), or they may
889  * be generic (using various placeholder template tags that will be
890  * replaced with appropriate information from the context).
891  */
892 typedef struct KS_Path {
893   struct KS_Path *next, *prev;
894 
895   /** ID block that keyframes are for. */
896   ID *id;
897   /** Name of the group to add to - MAX_ID_NAME-2. */
898   char group[64];
899 
900   /** ID-type that path can be used on. */
901   int idtype;
902 
903   /** Group naming (eKSP_Grouping). */
904   short groupmode;
905   /** Various settings, etc. */
906   short flag;
907 
908   /** Dynamically (or statically in the case of predefined sets) path. */
909   char *rna_path;
910   /** Index that path affects. */
911   int array_index;
912 
913   /** (eInsertKeyFlags) settings to supply insertkey() with. */
914   short keyingflag;
915   /** (eInsertKeyFlags) for each flag set, the relevant keyingflag bit overrides the default. */
916   short keyingoverride;
917 } KS_Path;
918 
919 /* KS_Path->flag */
920 typedef enum eKSP_Settings {
921   /* entire array (not just the specified index) gets keyframed */
922   KSP_FLAG_WHOLE_ARRAY = (1 << 0),
923 } eKSP_Settings;
924 
925 /* KS_Path->groupmode */
926 typedef enum eKSP_Grouping {
927   /** Path should be grouped using group name stored in path. */
928   KSP_GROUP_NAMED = 0,
929   /** Path should not be grouped at all. */
930   KSP_GROUP_NONE,
931   /** Path should be grouped using KeyingSet's name. */
932   KSP_GROUP_KSNAME,
933   /** Path should be grouped using name of inner-most context item from templates
934    * - this is most useful for relative KeyingSets only. */
935   /* KSP_GROUP_TEMPLATE_ITEM, */ /* UNUSED */
936 } eKSP_Grouping;
937 
938 /* ---------------- */
939 
940 /**
941  * KeyingSet definition (ks)
942  *
943  * A KeyingSet defines a group of properties that should
944  * be keyframed together, providing a convenient way for animators
945  * to insert keyframes without resorting to Auto-Keyframing.
946  *
947  * A few 'generic' (non-absolute and dependent on templates) KeyingSets
948  * are defined 'built-in' to facilitate easy animating for the casual
949  * animator without the need to add extra steps to the rigging process.
950  */
951 typedef struct KeyingSet {
952   struct KeyingSet *next, *prev;
953 
954   /** (KS_Path) paths to keyframe to. */
955   ListBase paths;
956 
957   /** Unique name (for search, etc.) - MAX_ID_NAME-2 . */
958   char idname[64];
959   /** User-viewable name for KeyingSet (for menus, etc.) - MAX_ID_NAME-2. */
960   char name[64];
961   /** (RNA_DYN_DESCR_MAX) short help text. */
962   char description[240];
963   /** Name of the typeinfo data used for the relative paths - MAX_ID_NAME-2. */
964   char typeinfo[64];
965 
966   /** Index of the active path. */
967   int active_path;
968 
969   /** Settings for KeyingSet. */
970   short flag;
971 
972   /** (eInsertKeyFlags) settings to supply insertkey() with. */
973   short keyingflag;
974   /** (eInsertKeyFlags) for each flag set, the relevant keyingflag bit overrides the default. */
975   short keyingoverride;
976 
977   char _pad[6];
978 } KeyingSet;
979 
980 /* KeyingSet settings */
981 typedef enum eKS_Settings {
982   /** Keyingset cannot be removed (and doesn't need to be freed). */
983   /* KEYINGSET_BUILTIN = (1 << 0), */ /* UNUSED */
984   /** Keyingset does not depend on context info (i.e. paths are absolute). */
985   KEYINGSET_ABSOLUTE = (1 << 1),
986 } eKS_Settings;
987 
988 /* Flags for use by keyframe creation/deletion calls */
989 typedef enum eInsertKeyFlags {
990   INSERTKEY_NOFLAGS = 0,
991   /** only insert keyframes where they're needed */
992   INSERTKEY_NEEDED = (1 << 0),
993   /** insert 'visual' keyframes where possible/needed */
994   INSERTKEY_MATRIX = (1 << 1),
995   /** don't recalculate handles,etc. after adding key */
996   INSERTKEY_FAST = (1 << 2),
997   /** don't realloc mem (or increase count, as array has already been set out) */
998   /* INSERTKEY_FASTR = (1 << 3), */ /* UNUSED */
999   /** only replace an existing keyframe (this overrides INSERTKEY_NEEDED) */
1000   INSERTKEY_REPLACE = (1 << 4),
1001   /** transform F-Curves should have XYZ->RGB color mode */
1002   INSERTKEY_XYZ2RGB = (1 << 5),
1003   /** ignore user-prefs (needed for predictable API use) */
1004   INSERTKEY_NO_USERPREF = (1 << 6),
1005   /** Allow to make a full copy of new key into existing one, if any,
1006    * instead of 'reusing' existing handles.
1007    * Used by copy/paste code. */
1008   INSERTKEY_OVERWRITE_FULL = (1 << 7),
1009   /** for driver FCurves, use driver's "input" value - for easier corrective driver setup */
1010   INSERTKEY_DRIVER = (1 << 8),
1011   /** for cyclic FCurves, adjust key timing to preserve the cycle period and flow */
1012   INSERTKEY_CYCLE_AWARE = (1 << 9),
1013   /** don't create new F-Curves (implied by INSERTKEY_REPLACE) */
1014   INSERTKEY_AVAILABLE = (1 << 10),
1015 } eInsertKeyFlags;
1016 
1017 /* ************************************************ */
1018 /* Animation Data */
1019 
1020 /* AnimOverride ------------------------------------- */
1021 
1022 /**
1023  * Animation Override (aor)
1024  *
1025  * This is used to as temporary storage of values which have been changed by the user, but not
1026  * yet keyframed (thus, would get overwritten by the animation system before the user had a chance
1027  * to see the changes that were made).
1028  *
1029  * It is probably not needed for overriding keyframed values in most cases, as those will only get
1030  * evaluated on frame-change now. That situation may change in future.
1031  */
1032 typedef struct AnimOverride {
1033   struct AnimOverride *next, *prev;
1034 
1035   /** RNA-path to use to resolve data-access. */
1036   char *rna_path;
1037   /** If applicable, the index of the RNA-array item to get. */
1038   int array_index;
1039 
1040   /** Value to override setting with. */
1041   float value;
1042 } AnimOverride;
1043 
1044 /* AnimData ------------------------------------- */
1045 
1046 /**
1047  * Animation data for some ID block (adt)
1048  *
1049  * This block of data is used to provide all of the necessary animation data for a data-block.
1050  * Currently, this data will not be reusable, as there shouldn't be any need to do so.
1051  *
1052  * This information should be made available for most if not all ID-blocks, which should
1053  * enable all of its settings to be animatable locally. Animation from 'higher-up' ID-AnimData
1054  * blocks may override local settings.
1055  *
1056  * This data-block should be placed immediately after the ID block where it is used, so that
1057  * the code which retrieves this data can do so in an easier manner.
1058  * See blenkernel/intern/anim_sys.c for details.
1059  */
1060 typedef struct AnimData {
1061   /**
1062    * Active action - acts as the 'tweaking track' for the NLA.
1063    * Either use BKE_animdata_set_action() to set this, or call BKE_animdata_action_ensure_idroot()
1064    * after setting. */
1065   bAction *action;
1066 
1067   /** temp-storage for the 'real' active action (i.e. the one used before the tweaking-action
1068    * took over to be edited in the Animation Editors)
1069    */
1070   bAction *tmpact;
1071 
1072   /* nla-tracks */
1073   ListBase nla_tracks;
1074   /**
1075    * Active NLA-track
1076    * (only set/used during tweaking, so no need to worry about dangling pointers).
1077    */
1078   NlaTrack *act_track;
1079   /**
1080    * Active NLA-strip
1081    * (only set/used during tweaking, so no need to worry about dangling pointers).
1082    */
1083   NlaStrip *actstrip;
1084 
1085   /* 'drivers' for this ID-block's settings - FCurves, but are completely
1086    * separate from those for animation data
1087    */
1088   /** Standard user-created Drivers/Expressions (used as part of a rig). */
1089   ListBase drivers;
1090   /** Temp storage (AnimOverride) of values for settings that are animated
1091    * (but the value hasn't been keyframed). */
1092   ListBase overrides;
1093 
1094   /** Runtime data, for depsgraph evaluation. */
1095   FCurve **driver_array;
1096 
1097   /* settings for animation evaluation */
1098   /** User-defined settings. */
1099   int flag;
1100   char _pad[4];
1101 
1102   /* settings for active action evaluation (based on NLA strip settings) */
1103   /** Accumulation mode for active action. */
1104   short act_blendmode;
1105   /** Extrapolation mode for active action. */
1106   short act_extendmode;
1107   /** Influence for active action. */
1108   float act_influence;
1109 } AnimData;
1110 
1111 /* Animation Data settings (mostly for NLA) */
1112 typedef enum eAnimData_Flag {
1113   /** Only evaluate a single track in the NLA. */
1114   ADT_NLA_SOLO_TRACK = (1 << 0),
1115   /** Don't use NLA */
1116   ADT_NLA_EVAL_OFF = (1 << 1),
1117   /** NLA is being 'tweaked' (i.e. in EditMode). */
1118   ADT_NLA_EDIT_ON = (1 << 2),
1119   /** Active Action for 'tweaking' does not have mapping applied for editing. */
1120   ADT_NLA_EDIT_NOMAP = (1 << 3),
1121   /** NLA-Strip F-Curves are expanded in UI. */
1122   ADT_NLA_SKEYS_COLLAPSED = (1 << 4),
1123 
1124   /** Drivers expanded in UI. */
1125   ADT_DRIVERS_COLLAPSED = (1 << 10),
1126   /** Don't execute drivers. */
1127   /* ADT_DRIVERS_DISABLED = (1 << 11), */ /* UNUSED */
1128 
1129   /** AnimData block is selected in UI. */
1130   ADT_UI_SELECTED = (1 << 14),
1131   /** AnimData block is active in UI. */
1132   ADT_UI_ACTIVE = (1 << 15),
1133 
1134   /** F-Curves from this AnimData block are not visible in the Graph Editor. */
1135   ADT_CURVES_NOT_VISIBLE = (1 << 16),
1136 
1137   /** F-Curves from this AnimData block are always visible. */
1138   ADT_CURVES_ALWAYS_VISIBLE = (1 << 17),
1139 } eAnimData_Flag;
1140 
1141 /* Base Struct for Anim ------------------------------------- */
1142 
1143 /**
1144  * Used for #BKE_animdata_from_id()
1145  * All ID-data-blocks which have their own 'local' AnimData
1146  * should have the same arrangement in their structs.
1147  */
1148 typedef struct IdAdtTemplate {
1149   ID id;
1150   AnimData *adt;
1151 } IdAdtTemplate;
1152 
1153 /* ************************************************ */
1154 
1155 #ifdef __cplusplus
1156 };
1157 #endif
1158