19#include "RNA_prototypes.hh"
26#include "testing/testing.h"
30using namespace blender::animrig::internal;
84 const int array_index,
85 const float eval_time)
95 return loc0_result->
value;
100 const int array_index,
101 const float2 eval_time__expect_value)
103 const float eval_time = eval_time__expect_value[0];
104 const float expect_value = eval_time__expect_value[1];
107 rna_path, array_index, eval_time);
108 if (!opt_eval_value) {
109 return testing::AssertionFailure()
110 << rna_path <<
"[" << array_index <<
"] should have been animated";
113 const float eval_value = *opt_eval_value;
115 if (diff_ulps >= 4) {
116 return testing::AssertionFailure()
118 <<
" " << rna_path <<
"[" << array_index
119 <<
"] evaluation did not produce the expected result:" << std::endl
120 <<
" evaluated to: " << testing::PrintToString(eval_value) << std::endl
121 <<
" expected : " << testing::PrintToString(expect_value) << std::endl;
124 return testing::AssertionSuccess();
129 const int array_index,
130 const float eval_time)
133 rna_path, array_index, eval_time);
135 return testing::AssertionFailure()
137 <<
" " << rna_path <<
"[" << array_index
138 <<
"] evaluation should NOT produce a value:" << std::endl
139 <<
" evaluated to: " << testing::PrintToString(*eval_value) << std::endl;
142 return testing::AssertionSuccess();
148 Strip &strip = layer->strip_add(*action, Strip::Type::Keyframe);
152 strip_data.
keyframe_insert(bmain, *slot, {
"location", 0}, {1.0f, 47.1f}, settings);
153 strip_data.
keyframe_insert(bmain, *slot, {
"location", 0}, {5.0f, 47.5f}, settings);
154 strip_data.
keyframe_insert(bmain, *slot, {
"rotation_euler", 1}, {1.0f, 0.0f}, settings);
155 strip_data.
keyframe_insert(bmain, *slot, {
"rotation_euler", 1}, {5.0f, 3.14f}, settings);
167 anim_eval_context.eval_time = 3.0f;
169 cube_rna_ptr, *action, *layer, slot->handle, anim_eval_context);
172 ASSERT_FALSE(
result.is_empty());
174 ASSERT_NE(
nullptr, loc0_result) <<
"location[0] should have been animated";
177 EXPECT_EQ(3.0f, cube->loc[0]) <<
"Evaluation should not modify the animated ID";
178 EXPECT_EQ(2.0f, cube->loc[1]) <<
"Evaluation should not modify the animated ID";
179 EXPECT_EQ(7.0f, cube->loc[2]) <<
"Evaluation should not modify the animated ID";
180 EXPECT_EQ(3.0f, cube->rot[0]) <<
"Evaluation should not modify the animated ID";
181 EXPECT_EQ(2.0f, cube->rot[1]) <<
"Evaluation should not modify the animated ID";
182 EXPECT_EQ(7.0f, cube->rot[2]) <<
"Evaluation should not modify the animated ID";
188 Strip &strip = layer->strip_add(*action, Strip::Type::Keyframe);
189 strip.
resize(1.0f, 10.0f);
193 strip_data.
keyframe_insert(bmain, *slot, {
"location", 0}, {1.0f, 47.0f}, settings);
194 strip_data.
keyframe_insert(bmain, *slot, {
"location", 0}, {5.0f, 327.0f}, settings);
195 strip_data.
keyframe_insert(bmain, *slot, {
"location", 0}, {10.0f, 48.0f}, settings);
198 EXPECT_TRUE(test_evaluate_layer(
"location", 0, {1.0f, 47.0f}));
199 EXPECT_TRUE(test_evaluate_layer(
"location", 0, {3.0f, 187.0f}));
200 EXPECT_TRUE(test_evaluate_layer(
"location", 0, {10.0f, 48.0f}));
202 EXPECT_TRUE(test_evaluate_layer_no_result(
"location", 0, 10.001f));
208 Strip &strip1 = layer->strip_add(*action, Strip::Type::Keyframe);
209 Strip &strip2 = layer->strip_add(*action, Strip::Type::Keyframe);
210 strip1.
resize(1.0f, 10.0f);
211 strip2.
resize(11.0f, 20.0f);
217 strip_data1.
keyframe_insert(bmain, *slot, {
"location", 0}, {1.0f, 47.0f}, settings);
218 strip_data1.
keyframe_insert(bmain, *slot, {
"location", 0}, {5.0f, 327.0f}, settings);
219 strip_data1.
keyframe_insert(bmain, *slot, {
"location", 0}, {10.0f, 48.0f}, settings);
223 strip_data2.
keyframe_insert(bmain, *slot, {
"location", 0}, {1.0f, 47.0f}, settings);
224 strip_data2.
keyframe_insert(bmain, *slot, {
"location", 0}, {5.0f, 327.0f}, settings);
225 strip_data2.
keyframe_insert(bmain, *slot, {
"location", 0}, {10.0f, 48.0f}, settings);
229 EXPECT_TRUE(test_evaluate_layer(
"location", 0, {1.0f, 47.0f}));
230 EXPECT_TRUE(test_evaluate_layer(
"location", 0, {3.0f, 187.0f}));
231 EXPECT_TRUE(test_evaluate_layer(
"location", 0, {10.0f, 48.0f}));
234 EXPECT_TRUE(test_evaluate_layer(
"location", 0, {11.0f, 47.0f}));
235 EXPECT_TRUE(test_evaluate_layer(
"location", 0, {13.0f, 187.0f}));
236 EXPECT_TRUE(test_evaluate_layer(
"location", 0, {20.0f, 48.0f}));
239 EXPECT_TRUE(test_evaluate_layer_no_result(
"location", 0, 0.999f));
240 EXPECT_TRUE(test_evaluate_layer_no_result(
"location", 0, 10.001f));
241 EXPECT_TRUE(test_evaluate_layer_no_result(
"location", 0, 10.999f));
242 EXPECT_TRUE(test_evaluate_layer_no_result(
"location", 0, 20.001f));
248 Strip &strip1 = layer->strip_add(*action, Strip::Type::Keyframe);
249 Strip &strip2 = layer->strip_add(*action, Strip::Type::Keyframe);
250 strip1.
resize(1.0f, 10.0f);
251 strip2.
resize(10.0f, 19.0f);
257 strip_data1.
keyframe_insert(bmain, *slot, {
"location", 0}, {1.0f, 47.0f}, settings);
258 strip_data1.
keyframe_insert(bmain, *slot, {
"location", 0}, {5.0f, 327.0f}, settings);
259 strip_data1.
keyframe_insert(bmain, *slot, {
"location", 0}, {10.0f, 48.0f}, settings);
263 strip_data2.
keyframe_insert(bmain, *slot, {
"location", 0}, {1.0f, 47.0f}, settings);
264 strip_data2.
keyframe_insert(bmain, *slot, {
"location", 0}, {5.0f, 327.0f}, settings);
265 strip_data2.
keyframe_insert(bmain, *slot, {
"location", 0}, {10.0f, 48.0f}, settings);
269 EXPECT_TRUE(test_evaluate_layer(
"location", 0, {1.0f, 47.0f}));
270 EXPECT_TRUE(test_evaluate_layer(
"location", 0, {3.0f, 187.0f}));
273 EXPECT_TRUE(test_evaluate_layer(
"location", 0, {10.0f, 47.0f}))
274 <<
"On the overlapping frame, only Strip 2 should be evaluated.";
277 EXPECT_TRUE(test_evaluate_layer(
"location", 0, {12.0f, 187.0f}));
278 EXPECT_TRUE(test_evaluate_layer(
"location", 0, {19.0f, 48.0f}));
281 EXPECT_TRUE(test_evaluate_layer_no_result(
"location", 0, 0.999f));
282 EXPECT_TRUE(test_evaluate_layer_no_result(
"location", 0, 19.001f));
293TEST(AnimationEvaluationResultTest, prop_identifier_hashing)
299 const char *rna_path_1 =
"pose.bones['Root'].location";
300 const std::string rna_path_2(rna_path_1);
301 ASSERT_NE(rna_path_1, rna_path_2.c_str())
302 <<
"This test requires different addresses for the RNA path strings";
305 result.store(rna_path_1, 0, 1.0f, fake_resolved_rna);
306 result.store(rna_path_2, 0, 2.0f, fake_resolved_rna);
308 <<
"Storing a result for the same property twice should just overwrite the previous value";
313 EXPECT_EQ(2.0f, anim_prop->
value) <<
"The last-stored result should survive.";
318 EXPECT_EQ(2.0f, anim_prop->
value) <<
"The last-stored result should survive.";
Functions and classes to work with Actions.
Layered Action evaluation.
Blender kernel action and pose functionality.
void * BKE_id_new(Main *bmain, short type, const char *name)
void BKE_main_free(Main *bmain)
General operations, lookup, etc. for blender objects.
Object * BKE_object_add_only_object(Main *bmain, int type, const char *name) ATTR_RETURNS_NONNULL
EXPECT_EQ(BLI_expr_pylike_eval(expr, nullptr, 0, &result), EXPR_PYLIKE_INVALID)
MINLINE uint ulp_diff_ff(float a, float b)
Object is a sort of wrapper for general info.
EvaluationResult()=default
Map< PropIdentifier, AnimatedProperty > EvaluationMap
SingleKeyingResult keyframe_insert(Main *bmain, const Slot &slot, const FCurveDescriptor &fcurve_descriptor, float2 time_value, const KeyframeSettings &settings, eInsertKeyFlags insert_key_flags=INSERTKEY_NOFLAGS, std::optional< float2 > cycle_range=std::nullopt)
void resize(float frame_start, float frame_end)
const T & data(const Action &owning_action) const
EvaluationMap & get_map()
AnimationEvalContext anim_eval_context
static void TearDownTestSuite()
static void SetUpTestSuite()
testing::AssertionResult test_evaluate_layer(const StringRefNull rna_path, const int array_index, const float2 eval_time__expect_value)
std::optional< float > evaluate_single_property(const StringRefNull rna_path, const int array_index, const float eval_time)
KeyframeSettings settings
testing::AssertionResult test_evaluate_layer_no_result(const StringRefNull rna_path, const int array_index, const float eval_time)
EvaluationResult evaluate_layer(PointerRNA &animated_id_ptr, Action &owning_action, Layer &layer, const slot_handle_t slot_handle, const AnimationEvalContext &anim_eval_context)
TEST_F(ActionIteratorsTest, iterate_all_fcurves_of_slot)
TEST(action, low_level_initialisation)
KeyframeSettings get_keyframe_settings(bool from_userprefs)
ActionSlotAssignmentResult assign_action_and_slot(Action *action, Slot *slot_to_assign, ID &animated_id)
VecBase< float, 2 > float2
PointerRNA RNA_pointer_create_discrete(ID *id, StructRNA *type, void *data)