Blender V4.3
deg_eval_runtime_backup_animation.cc
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2019 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
10
11#include "DNA_anim_types.h"
12
13#include "BKE_anim_data.hh"
14#include "BKE_animsys.h"
15
16#include "RNA_access.hh"
17#include "RNA_types.hh"
18
19#include "intern/depsgraph.hh"
20
21namespace blender::deg {
22
23AnimationValueBackup::AnimationValueBackup(const string &rna_path, int array_index, float value)
24 : rna_path(rna_path), array_index(array_index), value(value)
25{
26}
27
33
35
37{
38 /* NOTE: This animation backup nicely preserves values which are animated and
39 * are not touched by frame/depsgraph post_update handler.
40 *
41 * But it makes it impossible to have user edits to animated properties: for
42 * example, translation of object with animated location will not work with
43 * the current version of backup. */
44 return;
45
46 PointerRNA id_pointer_rna = RNA_id_pointer_create(id);
47 BKE_fcurves_id_cb(id, [&](ID *cb_id, FCurve *fcurve) {
48 if (fcurve->rna_path == nullptr || fcurve->rna_path[0] == '\0') {
49 return;
50 }
51 if (id != cb_id) {
52 return;
53 }
54
55 /* Resolve path to the property. */
56 PathResolvedRNA resolved_rna;
58 &id_pointer_rna, fcurve->rna_path, fcurve->array_index, &resolved_rna))
59 {
60 return;
61 }
62
63 /* Read property value. */
64 float value;
65 if (!BKE_animsys_read_from_rna_path(&resolved_rna, &value)) {
66 return;
67 }
68
69 this->values_backup.append({fcurve->rna_path, fcurve->array_index, value});
70 });
71}
72
74{
75 return;
76
77 PointerRNA id_pointer_rna = RNA_id_pointer_create(id);
78 for (const AnimationValueBackup &value_backup : values_backup) {
79 /* Resolve path to the property.
80 *
81 * NOTE: Do it again (after storing), since the sub-data pointers might be
82 * changed after copy-on-evaluation. */
83 PathResolvedRNA resolved_rna;
84 if (!BKE_animsys_rna_path_resolve(&id_pointer_rna,
85 value_backup.rna_path.c_str(),
86 value_backup.array_index,
87 &resolved_rna))
88 {
89 return;
90 }
91
92 /* Write property value. */
93 if (!BKE_animsys_write_to_rna_path(&resolved_rna, value_backup.value)) {
94 return;
95 }
96 }
97}
98
99} // namespace blender::deg
void BKE_fcurves_id_cb(struct ID *id, blender::FunctionRef< void(ID *, FCurve *)> func)
bool BKE_animsys_rna_path_resolve(struct PointerRNA *ptr, const char *rna_path, int array_index, struct PathResolvedRNA *r_result)
Definition anim_sys.cc:350
bool BKE_animsys_read_from_rna_path(struct PathResolvedRNA *anim_rna, float *r_value)
Definition anim_sys.cc:399
bool BKE_animsys_write_to_rna_path(struct PathResolvedRNA *anim_rna, float value)
Definition anim_sys.cc:460
Vector< AnimationValueBackup > values_backup
const Depsgraph * depsgraph
PointerRNA RNA_id_pointer_create(ID *id)
char * rna_path
int array_index
Definition DNA_ID.h:413