Blender V5.0
ANIM_evaluation.hh
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2023 Blender Developers
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
10#pragma once
11
12#include "BLI_map.hh"
13#include "BLI_string_ref.hh"
14
15#include "ANIM_action.hh"
16
17namespace blender::animrig {
18
19/* Identifies the property that an evaluated animation value is for.
20 *
21 * This could be replaced with either `FCurveIdentifier` or `RNAPath`. However,
22 * `FCurveIdentifier` is semantically meant to represent an fcurve itself rather
23 * than the property an fcurve might be for, and moreover not all animation will
24 * necessarily come from fcurves in the future anyway. `RNAPath` would be more
25 * semantically appropriate, but it stores a full copy of the string component
26 * of the path, and here we want to be lighter than that and use a string
27 * reference.
28 */
30 public:
38
39 PropIdentifier() = default;
40
45
46 bool operator==(const PropIdentifier &other) const
47 {
48 return rna_path == other.rna_path && array_index == other.array_index;
49 }
50 bool operator!=(const PropIdentifier &other) const
51 {
52 return !(*this == other);
53 }
54
55 uint64_t hash() const
56 {
58 }
59};
60
65 public:
66 float value;
68
73};
74
75/* Result of FCurve evaluation for an action slot.
76 * Mapping from property identifier to its float value.
77 *
78 * Can be fed to the evaluation of the next layer, mixed with another strip, or
79 * used to modify actual RNA properties.
80 *
81 * TODO: see if this is efficient, and contains enough info, for mixing. For now
82 * this just captures the FCurve evaluation result, but doesn't have any info
83 * about how to do the mixing (LERP, quaternion SLERP, etc.).
84 */
86 protected:
89
90 public:
91 EvaluationResult() = default;
92 EvaluationResult(const EvaluationResult &other) = default;
93 ~EvaluationResult() = default;
94
95 operator bool() const
96 {
97 return !this->is_empty();
98 }
99 bool is_empty() const
100 {
101 return result_.is_empty();
102 }
103
104 void store(const StringRefNull rna_path,
105 const int array_index,
106 const float value,
107 const PathResolvedRNA &prop_rna)
108 {
109 PropIdentifier key(rna_path, array_index);
110 AnimatedProperty anim_prop(value, prop_rna);
111 result_.add_overwrite(key, anim_prop);
112 }
113
114 AnimatedProperty value(const StringRefNull rna_path, const int array_index) const
115 {
116 PropIdentifier key(rna_path, array_index);
117 return result_.lookup(key);
118 }
119
121 {
122 return result_.lookup_ptr(key);
123 }
125 {
126 return result_.lookup_ptr(key);
127 }
128
129 EvaluationMap::ItemIterator items() const
130 {
131 return result_.items();
132 }
133};
134
141EvaluationResult evaluate_action(PointerRNA &animated_id_ptr,
142 Action &action,
143 slot_handle_t slot_handle,
144 const AnimationEvalContext &anim_eval_context);
145
154void evaluate_and_apply_action(PointerRNA &animated_id_ptr,
155 Action &action,
156 slot_handle_t slot_handle,
157 const AnimationEvalContext &anim_eval_context,
158 bool flush_to_original);
159
160} // namespace blender::animrig
Functions and classes to work with Actions.
unsigned long long int uint64_t
bool is_empty() const
Definition BLI_map.hh:986
AnimatedProperty(const float value, const PathResolvedRNA &prop_rna)
AnimatedProperty value(const StringRefNull rna_path, const int array_index) const
AnimatedProperty * lookup_ptr(const PropIdentifier &key)
EvaluationResult(const EvaluationResult &other)=default
void store(const StringRefNull rna_path, const int array_index, const float value, const PathResolvedRNA &prop_rna)
EvaluationMap::ItemIterator items() const
Map< PropIdentifier, AnimatedProperty > EvaluationMap
const AnimatedProperty * lookup_ptr(const PropIdentifier &key) const
PropIdentifier(const StringRefNull rna_path, const int array_index)
bool operator==(const PropIdentifier &other) const
bool operator!=(const PropIdentifier &other) const
void evaluate_and_apply_action(PointerRNA &animated_id_ptr, Action &action, slot_handle_t slot_handle, const AnimationEvalContext &anim_eval_context, bool flush_to_original)
Definition evaluation.cc:76
EvaluationResult evaluate_action(PointerRNA &animated_id_ptr, Action &action, slot_handle_t slot_handle, const AnimationEvalContext &anim_eval_context)
Definition evaluation.cc:41
decltype(::ActionSlot::handle) slot_handle_t
uint64_t get_default_hash(const T &v, const Args &...args)
Definition BLI_hash.hh:233