Blender V4.3
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 "DNA_anim_types.h"
16
17#include "RNA_access.hh"
18
19#include "ANIM_action.hh"
20
21namespace blender::animrig {
22
23/* Identifies the property that an evaluated animation value is for.
24 *
25 * This could be replaced with either `FCurveIdentifier` or `RNAPath`. However,
26 * `FCurveIdentifier` is semantically meant to represent an fcurve itself rather
27 * than the property an fcurve might be for, and moreover not all animation will
28 * necessarily come from fcurves in the future anyway. `RNAPath` would be more
29 * semantically appropriate, but it stores a full copy of the string component
30 * of the path, and here we want to be lighter than that and use a string
31 * reference.
32 */
34 public:
42
43 PropIdentifier() = default;
44
49
50 bool operator==(const PropIdentifier &other) const
51 {
52 return rna_path == other.rna_path && array_index == other.array_index;
53 }
54 bool operator!=(const PropIdentifier &other) const
55 {
56 return !(*this == other);
57 }
58
59 uint64_t hash() const
60 {
62 }
63};
64
69 public:
70 float value;
72
73 AnimatedProperty(const float value, const PathResolvedRNA &prop_rna)
74 : value(value), prop_rna(prop_rna)
75 {
76 }
77};
78
79/* Result of FCurve evaluation for an action slot.
80 * Mapping from property identifier to its float value.
81 *
82 * Can be fed to the evaluation of the next layer, mixed with another strip, or
83 * used to modify actual RNA properties.
84 *
85 * TODO: see if this is efficient, and contains enough info, for mixing. For now
86 * this just captures the FCurve evaluation result, but doesn't have any info
87 * about how to do the mixing (LERP, quaternion SLERP, etc.).
88 */
90 protected:
93
94 public:
95 EvaluationResult() = default;
96 EvaluationResult(const EvaluationResult &other) = default;
97 ~EvaluationResult() = default;
98
99 public:
100 operator bool() const
101 {
102 return !this->is_empty();
103 }
104 bool is_empty() const
105 {
106 return result_.is_empty();
107 }
108
109 void store(const StringRefNull rna_path,
110 const int array_index,
111 const float value,
112 const PathResolvedRNA &prop_rna)
113 {
114 PropIdentifier key(rna_path, array_index);
115 AnimatedProperty anim_prop(value, prop_rna);
116 result_.add_overwrite(key, anim_prop);
117 }
118
119 AnimatedProperty value(const StringRefNull rna_path, const int array_index) const
120 {
121 PropIdentifier key(rna_path, array_index);
122 return result_.lookup(key);
123 }
124
126 {
127 return result_.lookup_ptr(key);
128 }
130 {
131 return result_.lookup_ptr(key);
132 }
133
134 EvaluationMap::ItemIterator items() const
135 {
136 return result_.items();
137 }
138};
139
146EvaluationResult evaluate_action(PointerRNA &animated_id_ptr,
147 Action &action,
148 slot_handle_t slot_handle,
149 const AnimationEvalContext &anim_eval_context);
150
159void evaluate_and_apply_action(PointerRNA &animated_id_ptr,
160 Action &action,
161 slot_handle_t slot_handle,
162 const AnimationEvalContext &anim_eval_context,
163 bool flush_to_original);
164
165} // namespace blender::animrig
Functions and classes to work with Actions.
const Value * lookup_ptr(const Key &key) const
Definition BLI_map.hh:484
bool add_overwrite(const Key &key, const Value &value)
Definition BLI_map.hh:301
const Value & lookup(const Key &key) const
Definition BLI_map.hh:506
ItemIterator items() const
Definition BLI_map.hh:864
bool is_empty() const
Definition BLI_map.hh:937
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
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:73
EvaluationResult evaluate_action(PointerRNA &animated_id_ptr, Action &action, slot_handle_t slot_handle, const AnimationEvalContext &anim_eval_context)
Definition evaluation.cc:38
decltype(::ActionSlot::handle) slot_handle_t
uint64_t get_default_hash(const T &v)
Definition BLI_hash.hh:219
unsigned __int64 uint64_t
Definition stdint.h:90