Blender  V3.3
deg_eval_runtime_backup_animation.cc
Go to the documentation of this file.
1 /* SPDX-License-Identifier: GPL-2.0-or-later
2  * Copyright 2019 Blender Foundation. All rights reserved. */
3 
9 
10 #include "DNA_anim_types.h"
11 
12 #include "BKE_animsys.h"
13 
14 #include "RNA_access.h"
15 #include "RNA_types.h"
16 
17 #include "intern/depsgraph.h"
18 
19 namespace blender::deg {
20 
21 namespace {
22 
23 struct AnimatedPropertyStoreCalbackData {
24  AnimationBackup *backup;
25 
26  /* ID which needs to be stored.
27  * Is used to check possibly nested IDs which f-curves are pointing to. */
28  ID *id;
29 
31 };
32 
33 void animated_property_store_cb(ID *id, FCurve *fcurve, void *data_v)
34 {
35  AnimatedPropertyStoreCalbackData *data = reinterpret_cast<AnimatedPropertyStoreCalbackData *>(
36  data_v);
37  if (fcurve->rna_path == nullptr || fcurve->rna_path[0] == '\0') {
38  return;
39  }
40  if (id != data->id) {
41  return;
42  }
43 
44  /* Resolve path to the property. */
45  PathResolvedRNA resolved_rna;
47  &data->id_pointer_rna, fcurve->rna_path, fcurve->array_index, &resolved_rna)) {
48  return;
49  }
50 
51  /* Read property value. */
52  float value;
53  if (!BKE_animsys_read_from_rna_path(&resolved_rna, &value)) {
54  return;
55  }
56 
57  data->backup->values_backup.append({fcurve->rna_path, fcurve->array_index, value});
58 }
59 
60 } // namespace
61 
62 AnimationValueBackup::AnimationValueBackup(const string &rna_path, int array_index, float value)
63  : rna_path(rna_path), array_index(array_index), value(value)
64 {
65 }
66 
68 {
69  meed_value_backup = !depsgraph->is_active;
70  reset();
71 }
72 
74 {
75 }
76 
78 {
79  /* NOTE: This animation backup nicely preserves values which are animated and
80  * are not touched by frame/depsgraph post_update handler.
81  *
82  * But it makes it impossible to have user edits to animated properties: for
83  * example, translation of object with animated location will not work with
84  * the current version of backup. */
85  return;
86 
87  AnimatedPropertyStoreCalbackData data;
88  data.backup = this;
89  data.id = id;
90  RNA_id_pointer_create(id, &data.id_pointer_rna);
91  BKE_fcurves_id_cb(id, animated_property_store_cb, &data);
92 }
93 
95 {
96  return;
97 
100  for (const AnimationValueBackup &value_backup : values_backup) {
101  /* Resolve path to the property.
102  *
103  * NOTE: Do it again (after storing), since the sub-data pointers might be
104  * changed after copy-on-write. */
105  PathResolvedRNA resolved_rna;
107  value_backup.rna_path.c_str(),
108  value_backup.array_index,
109  &resolved_rna)) {
110  return;
111  }
112 
113  /* Write property value. */
114  if (!BKE_animsys_write_to_rna_path(&resolved_rna, value_backup.value)) {
115  return;
116  }
117  }
118 }
119 
120 } // namespace blender::deg
void BKE_fcurves_id_cb(struct ID *id, ID_FCurve_Edit_Callback func, void *user_data)
Definition: anim_data.c:1157
bool BKE_animsys_rna_path_resolve(struct PointerRNA *ptr, const char *rna_path, int array_index, struct PathResolvedRNA *r_result)
Definition: anim_sys.c:367
bool BKE_animsys_read_from_rna_path(struct PathResolvedRNA *anim_rna, float *r_value)
Definition: anim_sys.c:416
bool BKE_animsys_write_to_rna_path(struct PathResolvedRNA *anim_rna, float value)
Definition: anim_sys.c:478
Vector< AnimationValueBackup > values_backup
const Depsgraph * depsgraph
AnimationBackup * backup
PointerRNA id_pointer_rna
void RNA_id_pointer_create(ID *id, PointerRNA *r_ptr)
Definition: rna_access.c:112
char * rna_path
int array_index
Definition: DNA_ID.h:368