19#include "RNA_prototypes.hh"
27#include "testing/testing.h"
85 const int array_index,
86 const float eval_time)
96 return loc0_result->
value;
101 const int array_index,
102 const float2 eval_time__expect_value)
104 const float eval_time = eval_time__expect_value[0];
105 const float expect_value = eval_time__expect_value[1];
108 rna_path, array_index, eval_time);
109 if (!opt_eval_value) {
110 return testing::AssertionFailure()
111 << rna_path <<
"[" << array_index <<
"] should have been animated";
114 const float eval_value = *opt_eval_value;
116 if (diff_ulps >= 4) {
117 return testing::AssertionFailure()
119 <<
" " << rna_path <<
"[" << array_index
120 <<
"] evaluation did not produce the expected result:" << std::endl
121 <<
" evaluted to: " << testing::PrintToString(eval_value) << std::endl
122 <<
" expected : " << testing::PrintToString(expect_value) << std::endl;
125 return testing::AssertionSuccess();
130 const int array_index,
131 const float eval_time)
134 rna_path, array_index, eval_time);
136 return testing::AssertionFailure()
138 <<
" " << rna_path <<
"[" << array_index
139 <<
"] evaluation should NOT produce a value:" << std::endl
140 <<
" evaluted to: " << testing::PrintToString(*eval_value) << std::endl;
143 return testing::AssertionSuccess();
149 Strip &strip = layer->strip_add(*action, Strip::Type::Keyframe);
153 strip_data.
keyframe_insert(bmain, *slot, {
"location", 0}, {1.0f, 47.1f}, settings);
154 strip_data.
keyframe_insert(bmain, *slot, {
"location", 0}, {5.0f, 47.5f}, settings);
155 strip_data.
keyframe_insert(bmain, *slot, {
"rotation_euler", 1}, {1.0f, 0.0f}, settings);
156 strip_data.
keyframe_insert(bmain, *slot, {
"rotation_euler", 1}, {5.0f, 3.14f}, settings);
168 anim_eval_context.eval_time = 3.0f;
170 cube_rna_ptr, *action, *layer, slot->handle, anim_eval_context);
173 ASSERT_FALSE(result.is_empty());
175 ASSERT_NE(
nullptr, loc0_result) <<
"location[0] should have been animated";
178 EXPECT_EQ(3.0f, cube->loc[0]) <<
"Evaluation should not modify the animated ID";
179 EXPECT_EQ(2.0f, cube->loc[1]) <<
"Evaluation should not modify the animated ID";
180 EXPECT_EQ(7.0f, cube->loc[2]) <<
"Evaluation should not modify the animated ID";
181 EXPECT_EQ(3.0f, cube->rot[0]) <<
"Evaluation should not modify the animated ID";
182 EXPECT_EQ(2.0f, cube->rot[1]) <<
"Evaluation should not modify the animated ID";
183 EXPECT_EQ(7.0f, cube->rot[2]) <<
"Evaluation should not modify the animated ID";
189 Strip &strip = layer->strip_add(*action, Strip::Type::Keyframe);
190 strip.
resize(1.0f, 10.0f);
194 strip_data.
keyframe_insert(bmain, *slot, {
"location", 0}, {1.0f, 47.0f}, settings);
195 strip_data.
keyframe_insert(bmain, *slot, {
"location", 0}, {5.0f, 327.0f}, settings);
196 strip_data.
keyframe_insert(bmain, *slot, {
"location", 0}, {10.0f, 48.0f}, settings);
199 EXPECT_TRUE(test_evaluate_layer(
"location", 0, {1.0f, 47.0f}));
200 EXPECT_TRUE(test_evaluate_layer(
"location", 0, {3.0f, 187.0f}));
201 EXPECT_TRUE(test_evaluate_layer(
"location", 0, {10.0f, 48.0f}));
203 EXPECT_TRUE(test_evaluate_layer_no_result(
"location", 0, 10.001f));
209 Strip &strip1 = layer->strip_add(*action, Strip::Type::Keyframe);
210 Strip &strip2 = layer->strip_add(*action, Strip::Type::Keyframe);
211 strip1.
resize(1.0f, 10.0f);
212 strip2.
resize(11.0f, 20.0f);
218 strip_data1.
keyframe_insert(bmain, *slot, {
"location", 0}, {1.0f, 47.0f}, settings);
219 strip_data1.
keyframe_insert(bmain, *slot, {
"location", 0}, {5.0f, 327.0f}, settings);
220 strip_data1.
keyframe_insert(bmain, *slot, {
"location", 0}, {10.0f, 48.0f}, settings);
224 strip_data2.
keyframe_insert(bmain, *slot, {
"location", 0}, {1.0f, 47.0f}, settings);
225 strip_data2.
keyframe_insert(bmain, *slot, {
"location", 0}, {5.0f, 327.0f}, settings);
226 strip_data2.
keyframe_insert(bmain, *slot, {
"location", 0}, {10.0f, 48.0f}, settings);
230 EXPECT_TRUE(test_evaluate_layer(
"location", 0, {1.0f, 47.0f}));
231 EXPECT_TRUE(test_evaluate_layer(
"location", 0, {3.0f, 187.0f}));
232 EXPECT_TRUE(test_evaluate_layer(
"location", 0, {10.0f, 48.0f}));
235 EXPECT_TRUE(test_evaluate_layer(
"location", 0, {11.0f, 47.0f}));
236 EXPECT_TRUE(test_evaluate_layer(
"location", 0, {13.0f, 187.0f}));
237 EXPECT_TRUE(test_evaluate_layer(
"location", 0, {20.0f, 48.0f}));
240 EXPECT_TRUE(test_evaluate_layer_no_result(
"location", 0, 0.999f));
241 EXPECT_TRUE(test_evaluate_layer_no_result(
"location", 0, 10.001f));
242 EXPECT_TRUE(test_evaluate_layer_no_result(
"location", 0, 10.999f));
243 EXPECT_TRUE(test_evaluate_layer_no_result(
"location", 0, 20.001f));
249 Strip &strip1 = layer->strip_add(*action, Strip::Type::Keyframe);
250 Strip &strip2 = layer->strip_add(*action, Strip::Type::Keyframe);
251 strip1.
resize(1.0f, 10.0f);
252 strip2.
resize(10.0f, 19.0f);
258 strip_data1.
keyframe_insert(bmain, *slot, {
"location", 0}, {1.0f, 47.0f}, settings);
259 strip_data1.
keyframe_insert(bmain, *slot, {
"location", 0}, {5.0f, 327.0f}, settings);
260 strip_data1.
keyframe_insert(bmain, *slot, {
"location", 0}, {10.0f, 48.0f}, settings);
264 strip_data2.
keyframe_insert(bmain, *slot, {
"location", 0}, {1.0f, 47.0f}, settings);
265 strip_data2.
keyframe_insert(bmain, *slot, {
"location", 0}, {5.0f, 327.0f}, settings);
266 strip_data2.
keyframe_insert(bmain, *slot, {
"location", 0}, {10.0f, 48.0f}, settings);
270 EXPECT_TRUE(test_evaluate_layer(
"location", 0, {1.0f, 47.0f}));
271 EXPECT_TRUE(test_evaluate_layer(
"location", 0, {3.0f, 187.0f}));
274 EXPECT_TRUE(test_evaluate_layer(
"location", 0, {10.0f, 47.0f}))
275 <<
"On the overlapping frame, only Strip 2 should be evaluated.";
278 EXPECT_TRUE(test_evaluate_layer(
"location", 0, {12.0f, 187.0f}));
279 EXPECT_TRUE(test_evaluate_layer(
"location", 0, {19.0f, 48.0f}));
282 EXPECT_TRUE(test_evaluate_layer_no_result(
"location", 0, 0.999f));
283 EXPECT_TRUE(test_evaluate_layer_no_result(
"location", 0, 19.001f));
294TEST(AnimationEvaluationResultTest, prop_identifier_hashing)
300 const char *rna_path_1 =
"pose.bones['Root'].location";
301 const std::string rna_path_2(rna_path_1);
302 ASSERT_NE(rna_path_1, rna_path_2.c_str())
303 <<
"This test requires different addresses for the RNA path strings";
306 result.store(rna_path_1, 0, 1.0f, fake_resolved_rna);
307 result.store(rna_path_2, 0, 2.0f, fake_resolved_rna);
309 <<
"Storing a result for the same property twice should just overwrite the previous value";
314 EXPECT_EQ(2.0f, anim_prop->
value) <<
"The last-stored result should survive.";
319 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)
Main * BKE_main_new(void)
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.
Layer & layer_add(std::optional< StringRefNull > name)
SingleKeyingResult keyframe_insert(Main *bmain, const Slot &slot, FCurveDescriptor fcurve_descriptor, float2 time_value, const KeyframeSettings &settings, eInsertKeyFlags insert_key_flags=INSERTKEY_NOFLAGS)
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)
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(ANIM_bone_collections, bonecoll_new_free)
KeyframeSettings get_keyframe_settings(bool from_userprefs)
ActionSlotAssignmentResult assign_action_and_slot(Action *action, Slot *slot_to_assign, ID &animated_id)
PointerRNA RNA_pointer_create(ID *id, StructRNA *type, void *data)