Blender V5.0
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
8
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
29
35
37
39{
40 /* NOTE: This animation backup nicely preserves values which are animated and
41 * are not touched by frame/depsgraph post_update handler.
42 *
43 * But it makes it impossible to have user edits to animated properties: for
44 * example, translation of object with animated location will not work with
45 * the current version of backup. */
46 return;
47
48 PointerRNA id_pointer_rna = RNA_id_pointer_create(id);
49 BKE_fcurves_id_cb(id, [&](ID *cb_id, FCurve *fcurve) {
50 if (fcurve->rna_path == nullptr || fcurve->rna_path[0] == '\0') {
51 return;
52 }
53 if (id != cb_id) {
54 return;
55 }
56
57 /* Resolve path to the property. */
58 PathResolvedRNA resolved_rna;
60 &id_pointer_rna, fcurve->rna_path, fcurve->array_index, &resolved_rna))
61 {
62 return;
63 }
64
65 /* Read property value. */
66 float value;
67 if (!BKE_animsys_read_from_rna_path(&resolved_rna, &value)) {
68 return;
69 }
70
71 this->values_backup.append({fcurve->rna_path, fcurve->array_index, value});
72 });
73}
74
76{
77 return;
78
79 PointerRNA id_pointer_rna = RNA_id_pointer_create(id);
80 for (const AnimationValueBackup &value_backup : values_backup) {
81 /* Resolve path to the property.
82 *
83 * NOTE: Do it again (after storing), since the sub-data pointers might be
84 * changed after copy-on-evaluation. */
85 PathResolvedRNA resolved_rna;
86 if (!BKE_animsys_rna_path_resolve(&id_pointer_rna,
87 value_backup.rna_path.c_str(),
88 value_backup.array_index,
89 &resolved_rna))
90 {
91 return;
92 }
93
94 /* Write property value. */
95 if (!BKE_animsys_write_to_rna_path(&resolved_rna, value_backup.value)) {
96 return;
97 }
98 }
99}
100
101} // namespace blender::deg
void BKE_fcurves_id_cb(struct ID *id, blender::FunctionRef< void(ID *, FCurve *)> func)
bool BKE_animsys_write_to_rna_path(struct PathResolvedRNA *anim_rna, float value, bool force_write=false)
Definition anim_sys.cc:460
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
BPy_StructRNA * depsgraph
Vector< AnimationValueBackup > values_backup
PointerRNA RNA_id_pointer_create(ID *id)
char * rna_path
int array_index
Definition DNA_ID.h:414