Blender V5.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
8
10
11#include "DNA_anim_types.h"
12
13#include "BKE_anim_data.hh"
14#include "BKE_animsys.hh"
15
16#include "RNA_access.hh"
17#include "RNA_path.hh"
18#include "RNA_types.hh"
19
20#include "intern/depsgraph.hh"
21
22namespace blender::deg {
23
28
30{
31 meed_value_backup = !depsgraph->is_active;
32 reset();
33}
34
36
38{
39 /* NOTE: This animation backup nicely preserves values which are animated and
40 * are not touched by frame/depsgraph post_update handler.
41 *
42 * But it makes it impossible to have user edits to animated properties: for
43 * example, translation of object with animated location will not work with
44 * the current version of backup. */
45 return;
46
47 PointerRNA id_pointer_rna = RNA_id_pointer_create(id);
48 BKE_fcurves_id_cb(id, [&](ID *cb_id, FCurve *fcurve) {
49 const ParsedRNAPathRef rna_path = fcurve->rna_path_parsed();
50 if (rna_path.is_empty()) {
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, 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({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;
87 &id_pointer_rna, value_backup.rna_path, value_backup.array_index, &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
Vector< AnimationValueBackup > values_backup
PointerRNA RNA_id_pointer_create(ID *id)
void BKE_fcurves_id_cb(struct ID *id, FunctionRef< void(ID *, FCurve *)> func)
Span< rna_path::Item > ParsedRNAPathRef
Definition RNA_path.hh:113
bool BKE_animsys_read_from_rna_path(PathResolvedRNA *anim_rna, float *r_value)
Definition anim_sys.cc:400
bool BKE_animsys_write_to_rna_path(PathResolvedRNA *anim_rna, float value, bool force_write=false)
Definition anim_sys.cc:461
bool BKE_animsys_rna_path_resolve(PointerRNA *ptr, ParsedRNAPathRef rna_path, int array_index, PathResolvedRNA *r_result)
Definition anim_sys.cc:356