Blender  V2.93
BKE_animsys.h
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 
20 #pragma once
21 
26 #include "BLI_sys_types.h" /* for bool */
27 
28 #ifdef __cplusplus
29 extern "C" {
30 #endif
31 
32 struct AnimData;
33 struct BlendDataReader;
34 struct BlendExpander;
35 struct BlendLibReader;
36 struct BlendWriter;
37 struct Depsgraph;
38 struct FCurve;
39 struct ID;
40 struct KS_Path;
41 struct KeyingSet;
43 struct ListBase;
44 struct Main;
46 struct PathResolvedRNA;
47 struct PointerRNA;
48 struct PropertyRNA;
49 struct bAction;
50 struct bActionGroup;
51 struct bContext;
52 
53 /* Container for data required to do FCurve and Driver evaluation. */
54 typedef struct AnimationEvalContext {
55  /* For drivers, so that they have access to the dependency graph and the current view layer. See
56  * T77086. */
58 
59  /* FCurves and Drivers can be evaluated at a different time than the current scene time, for
60  * example when evaluating NLA strips. This means that, even though the current time is stored in
61  * the dependency graph, we need an explicit evaluation time. */
62  float eval_time;
64 
66  float eval_time);
68  const AnimationEvalContext *anim_eval_context, float eval_time);
69 
70 /* ************************************* */
71 /* KeyingSets API */
72 
73 /* Used to create a new 'custom' KeyingSet for the user,
74  * that will be automatically added to the stack */
76  struct ListBase *list, const char idname[], const char name[], short flag, short keyingflag);
77 
78 /* Add a path to a KeyingSet */
79 struct KS_Path *BKE_keyingset_add_path(struct KeyingSet *ks,
80  struct ID *id,
81  const char group_name[],
82  const char rna_path[],
83  int array_index,
84  short flag,
85  short groupmode);
86 
87 /* Find the destination matching the criteria given */
89  struct ID *id,
90  const char group_name[],
91  const char rna_path[],
92  int array_index,
93  int group_mode);
94 
95 /* Copy all KeyingSets in the given list */
96 void BKE_keyingsets_copy(struct ListBase *newlist, const struct ListBase *list);
97 
99 void BKE_keyingsets_foreach_id(struct LibraryForeachIDData *data, const struct ListBase *keyingsets);
100 
101 /* Free the given Keying Set path */
102 void BKE_keyingset_free_path(struct KeyingSet *ks, struct KS_Path *ksp);
103 
104 /* Free data for KeyingSet but not set itself */
105 void BKE_keyingset_free(struct KeyingSet *ks);
106 
107 /* Free all the KeyingSets in the given list */
108 void BKE_keyingsets_free(struct ListBase *list);
109 
110 void BKE_keyingsets_blend_write(struct BlendWriter *writer, struct ListBase *list);
111 void BKE_keyingsets_blend_read_data(struct BlendDataReader *reader, struct ListBase *list);
113  struct ID *id,
114  struct ListBase *list);
115 void BKE_keyingsets_blend_read_expand(struct BlendExpander *expander, struct ListBase *list);
116 
117 /* ************************************* */
118 /* Path Fixing API */
119 
120 /* Get a "fixed" version of the given path (oldPath) */
121 char *BKE_animsys_fix_rna_path_rename(struct ID *owner_id,
122  char *old_path,
123  const char *prefix,
124  const char *oldName,
125  const char *newName,
126  int oldSubscript,
127  int newSubscript,
128  bool verify_paths);
129 
130 /* Fix all the paths for the given ID + Action */
131 void BKE_action_fix_paths_rename(struct ID *owner_id,
132  struct bAction *act,
133  const char *prefix,
134  const char *oldName,
135  const char *newName,
136  int oldSubscript,
137  int newSubscript,
138  bool verify_paths);
139 
140 /* Fix all the paths for the given ID+AnimData */
141 void BKE_animdata_fix_paths_rename(struct ID *owner_id,
142  struct AnimData *adt,
143  struct ID *ref_id,
144  const char *prefix,
145  const char *oldName,
146  const char *newName,
147  int oldSubscript,
148  int newSubscript,
149  bool verify_paths);
150 
151 /* Fix all the paths for the entire database... */
152 void BKE_animdata_fix_paths_rename_all(struct ID *ref_id,
153  const char *prefix,
154  const char *oldName,
155  const char *newName);
156 
157 /* Fix all the paths for the entire bmain with extra parameters. */
158 void BKE_animdata_fix_paths_rename_all_ex(struct Main *bmain,
159  struct ID *ref_id,
160  const char *prefix,
161  const char *oldName,
162  const char *newName,
163  const int oldSubscript,
164  const int newSubscript,
165  const bool verify_paths);
166 
167 /* Fix the path after removing elements that are not ID (e.g., node).
168  * Return true if any animation data was affected. */
169 bool BKE_animdata_fix_paths_remove(struct ID *id, const char *path);
170 
171 /* -------------------------------------- */
172 
173 typedef struct AnimationBasePathChange {
175  const char *src_basepath;
176  const char *dst_basepath;
178 
179 /* Move animation data from src to destination if its paths are based on basepaths */
180 void BKE_animdata_transfer_by_basepath(struct Main *bmain,
181  struct ID *srcID,
182  struct ID *dstID,
183  struct ListBase *basepaths);
184 
186  struct PointerRNA *ptr,
187  struct PropertyRNA *prop,
188  char *base_path);
189 
190 /* ************************************* */
191 /* Batch AnimData API */
192 
193 /* Define for callback looper used in BKE_animdata_main_cb */
194 typedef void (*ID_AnimData_Edit_Callback)(struct ID *id, struct AnimData *adt, void *user_data);
195 
196 /* Define for callback looper used in BKE_fcurves_main_cb */
197 typedef void (*ID_FCurve_Edit_Callback)(struct ID *id, struct FCurve *fcu, void *user_data);
198 
199 /* Loop over all datablocks applying callback */
200 void BKE_animdata_main_cb(struct Main *bmain, ID_AnimData_Edit_Callback func, void *user_data);
201 
202 /* Loop over all datablocks applying callback to all its F-Curves */
203 void BKE_fcurves_main_cb(struct Main *bmain, ID_FCurve_Edit_Callback func, void *user_data);
204 
205 /* Look over all f-curves of a given ID. */
207 
208 /* ************************************* */
209 // TODO: overrides, remapping, and path-finding api's
210 
211 /* ------------ NLA Keyframing --------------- */
212 
214 
216  struct ListBase *cache,
217  struct PointerRNA *ptr,
218  struct AnimData *adt,
219  const struct AnimationEvalContext *anim_eval_context);
221  struct PointerRNA *prop_ptr,
222  struct PropertyRNA *prop,
223  float *values,
224  int count,
225  int index,
226  bool *r_force_all);
228 
229 /* ************************************* */
230 /* Evaluation API */
231 
232 /* ------------- Main API -------------------- */
233 /* In general, these ones should be called to do all animation evaluation */
234 
235 /* Flags for recalc parameter, indicating which part to recalculate. */
236 typedef enum eAnimData_Recalc {
237  ADT_RECALC_DRIVERS = (1 << 0),
238  ADT_RECALC_ANIM = (1 << 1),
241 
243  const char *rna_path,
244  const int array_index,
245  struct PathResolvedRNA *r_result);
246 bool BKE_animsys_read_from_rna_path(struct PathResolvedRNA *anim_rna, float *r_value);
247 bool BKE_animsys_write_to_rna_path(struct PathResolvedRNA *anim_rna, const float value);
248 
249 /* Evaluation loop for evaluating animation data */
251  struct AnimData *adt,
252  const struct AnimationEvalContext *anim_eval_context,
253  eAnimData_Recalc recalc,
254  const bool flush_to_original);
255 
256 /* Evaluation of all ID-blocks with Animation Data blocks - Animation Data Only */
258  struct Depsgraph *depsgraph,
259  float ctime);
260 
261 /* ------------ Specialized API --------------- */
262 /* There are a few special tools which require these following functions. They are NOT to be used
263  * for standard animation evaluation UNDER ANY CIRCUMSTANCES!
264  *
265  * i.e. Pose Library (PoseLib) uses some of these for selectively applying poses, but
266  * Particles/Sequencer performing funky time manipulation is not ok.
267  */
268 
269 /* Evaluate Action (F-Curve Bag) */
271  struct bAction *act,
272  const struct AnimationEvalContext *anim_eval_context,
273  bool flush_to_original);
274 
275 /* Evaluate Action Group */
277  struct bAction *act,
278  struct bActionGroup *agrp,
279  const struct AnimationEvalContext *anim_eval_context);
280 
281 /* ************************************* */
282 
283 /* ------------ Evaluation API --------------- */
284 
285 struct Depsgraph;
286 
287 void BKE_animsys_eval_animdata(struct Depsgraph *depsgraph, struct ID *id);
289  struct ID *id,
290  int driver_index,
291  struct FCurve *fcu_orig);
292 
293 void BKE_animsys_update_driver_array(struct ID *id);
294 
295 /* ************************************* */
296 
297 #ifdef __cplusplus
298 }
299 #endif
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
struct KS_Path * BKE_keyingset_add_path(struct KeyingSet *ks, struct ID *id, const char group_name[], const char rna_path[], int array_index, short flag, short groupmode)
Definition: anim_sys.c:178
void BKE_keyingsets_free(struct ListBase *list)
Definition: anim_sys.c:304
void(* ID_AnimData_Edit_Callback)(struct ID *id, struct AnimData *adt, void *user_data)
Definition: BKE_animsys.h:194
void BKE_keyingsets_copy(struct ListBase *newlist, const struct ListBase *list)
char * BKE_animdata_driver_path_hack(struct bContext *C, struct PointerRNA *ptr, struct PropertyRNA *prop, char *base_path)
Definition: anim_data.c:732
void BKE_fcurves_main_cb(struct Main *bmain, ID_FCurve_Edit_Callback func, void *user_data)
Definition: anim_data.c:1288
char * BKE_animsys_fix_rna_path_rename(struct ID *owner_id, char *old_path, const char *prefix, const char *oldName, const char *newName, int oldSubscript, int newSubscript, bool verify_paths)
Definition: anim_data.c:969
void BKE_animdata_fix_paths_rename_all(struct ID *ref_id, const char *prefix, const char *oldName, const char *newName)
Definition: anim_data.c:1414
void BKE_animsys_evaluate_all_animation(struct Main *main, struct Depsgraph *depsgraph, float ctime)
Definition: anim_sys.c:2887
struct KeyingSet * BKE_keyingset_add(struct ListBase *list, const char idname[], const char name[], short flag, short keyingflag)
Definition: anim_sys.c:144
void animsys_evaluate_action(struct PointerRNA *ptr, struct bAction *act, const struct AnimationEvalContext *anim_eval_context, bool flush_to_original)
bool BKE_animsys_write_to_rna_path(struct PathResolvedRNA *anim_rna, const float value)
Definition: anim_sys.c:501
AnimationEvalContext BKE_animsys_eval_context_construct(struct Depsgraph *depsgraph, float eval_time)
Definition: anim_sys.c:637
void BKE_keyingsets_blend_read_lib(struct BlendLibReader *reader, struct ID *id, struct ListBase *list)
Definition: anim_sys.c:354
void BKE_keyingsets_blend_read_data(struct BlendDataReader *reader, struct ListBase *list)
Definition: anim_sys.c:341
void BKE_keyingsets_blend_write(struct BlendWriter *writer, struct ListBase *list)
Definition: anim_sys.c:323
void BKE_action_fix_paths_rename(struct ID *owner_id, struct bAction *act, const char *prefix, const char *oldName, const char *newName, int oldSubscript, int newSubscript, bool verify_paths)
Definition: anim_data.c:1032
void BKE_keyingsets_foreach_id(struct LibraryForeachIDData *data, const struct ListBase *keyingsets)
struct AnimationBasePathChange AnimationBasePathChange
void BKE_fcurves_id_cb(struct ID *id, ID_FCurve_Edit_Callback func, void *user_data)
Definition: anim_data.c:1278
void BKE_animdata_transfer_by_basepath(struct Main *bmain, struct ID *srcID, struct ID *dstID, struct ListBase *basepaths)
Definition: anim_data.c:656
bool BKE_animdata_fix_paths_remove(struct ID *id, const char *path)
Definition: anim_data.c:1188
eAnimData_Recalc
Definition: BKE_animsys.h:236
@ ADT_RECALC_ANIM
Definition: BKE_animsys.h:238
@ ADT_RECALC_ALL
Definition: BKE_animsys.h:239
@ ADT_RECALC_DRIVERS
Definition: BKE_animsys.h:237
void BKE_animdata_fix_paths_rename_all_ex(struct Main *bmain, struct ID *ref_id, const char *prefix, const char *oldName, const char *newName, const int oldSubscript, const int newSubscript, const bool verify_paths)
Definition: anim_data.c:1428
struct KS_Path * BKE_keyingset_find_path(struct KeyingSet *ks, struct ID *id, const char group_name[], const char rna_path[], int array_index, int group_mode)
void BKE_animsys_eval_animdata(struct Depsgraph *depsgraph, struct ID *id)
Definition: anim_sys.c:3038
void BKE_animdata_fix_paths_rename(struct ID *owner_id, struct AnimData *adt, struct ID *ref_id, const char *prefix, const char *oldName, const char *newName, int oldSubscript, int newSubscript, bool verify_paths)
Definition: anim_data.c:1079
bool BKE_animsys_rna_path_resolve(struct PointerRNA *ptr, const char *rna_path, const int array_index, struct PathResolvedRNA *r_result)
Definition: anim_sys.c:389
void BKE_keyingsets_blend_read_expand(struct BlendExpander *expander, struct ListBase *list)
Definition: anim_sys.c:363
bool BKE_animsys_read_from_rna_path(struct PathResolvedRNA *anim_rna, float *r_value)
Definition: anim_sys.c:438
void(* ID_FCurve_Edit_Callback)(struct ID *id, struct FCurve *fcu, void *user_data)
Definition: BKE_animsys.h:197
void BKE_keyingset_free(struct KeyingSet *ks)
Definition: anim_sys.c:287
void BKE_keyingset_free_path(struct KeyingSet *ks, struct KS_Path *ksp)
Definition: anim_sys.c:242
void animsys_evaluate_action_group(struct PointerRNA *ptr, struct bAction *act, struct bActionGroup *agrp, const struct AnimationEvalContext *anim_eval_context)
void BKE_animsys_update_driver_array(struct ID *id)
Definition: anim_sys.c:3052
void BKE_animsys_eval_driver(struct Depsgraph *depsgraph, struct ID *id, int driver_index, struct FCurve *fcu_orig)
Definition: anim_sys.c:3072
struct AnimationEvalContext AnimationEvalContext
void BKE_animdata_main_cb(struct Main *bmain, ID_AnimData_Edit_Callback func, void *user_data)
Definition: anim_data.c:1300
void BKE_animsys_evaluate_animdata(struct ID *id, struct AnimData *adt, const struct AnimationEvalContext *anim_eval_context, eAnimData_Recalc recalc, const bool flush_to_original)
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
struct Depsgraph Depsgraph
Definition: DEG_depsgraph.h:51
#define C
Definition: RandGen.cpp:39
const Depsgraph * depsgraph
void * user_data
int count
int main(int argc, char **argv)
Definition: msgfmt.c:457
struct SELECTID_Context context
Definition: select_engine.c:47
const char * dst_basepath
Definition: BKE_animsys.h:176
const char * src_basepath
Definition: BKE_animsys.h:175
struct AnimationBasePathChange * next
Definition: BKE_animsys.h:174
struct AnimationBasePathChange * prev
Definition: BKE_animsys.h:174
struct Depsgraph * depsgraph
Definition: BKE_animsys.h:57
Definition: DNA_ID.h:273
short flag
int array_index
short groupmode
char * rna_path
char name[64]
char idname[64]
short keyingflag
Definition: BKE_main.h:116
struct AnimData * adt
Definition: nla_private.h:152
PointerRNA * ptr
Definition: wm_files.c:3157