22#include "RNA_prototypes.hh"
28#include "testing/testing.h"
32using namespace blender::animrig::internal;
72 const int array_index,
73 const float eval_time)
80 if (!parsed_rna_path) {
89 return loc0_result->
value;
94 const int array_index,
95 const float2 eval_time__expect_value)
97 const float eval_time = eval_time__expect_value[0];
98 const float expect_value = eval_time__expect_value[1];
102 if (!opt_eval_value) {
103 return testing::AssertionFailure()
104 <<
rna_path <<
"[" << array_index <<
"] should have been animated";
107 const float eval_value = *opt_eval_value;
109 if (diff_ulps >= 4) {
110 return testing::AssertionFailure()
112 <<
" " <<
rna_path <<
"[" << array_index
113 <<
"] evaluation did not produce the expected result:" << std::endl
114 <<
" evaluated to: " << testing::PrintToString(eval_value) << std::endl
115 <<
" expected : " << testing::PrintToString(expect_value) << std::endl;
118 return testing::AssertionSuccess();
123 const int array_index,
124 const float eval_time)
129 return testing::AssertionFailure()
131 <<
" " <<
rna_path <<
"[" << array_index
132 <<
"] evaluation should NOT produce a value:" << std::endl
133 <<
" evaluated to: " << testing::PrintToString(*eval_value) << std::endl;
136 return testing::AssertionSuccess();
146 strip_data.
keyframe_insert(bmain, *slot, {
"location", 0}, {1.0f, 47.1f}, settings);
147 strip_data.
keyframe_insert(bmain, *slot, {
"location", 0}, {5.0f, 47.5f}, settings);
148 strip_data.
keyframe_insert(bmain, *slot, {
"rotation_euler", 1}, {1.0f, 0.0f}, settings);
149 strip_data.
keyframe_insert(bmain, *slot, {
"rotation_euler", 1}, {5.0f, 3.14f}, settings);
161 anim_eval_context.eval_time = 3.0f;
163 cube_rna_ptr, *action, *
layer, slot->handle, anim_eval_context);
169 ASSERT_FALSE(
result.is_empty());
171 ASSERT_NE(
nullptr, loc0_result) <<
"location[0] should have been animated";
174 EXPECT_EQ(3.0f, cube->loc[0]) <<
"Evaluation should not modify the animated ID";
175 EXPECT_EQ(2.0f, cube->loc[1]) <<
"Evaluation should not modify the animated ID";
176 EXPECT_EQ(7.0f, cube->loc[2]) <<
"Evaluation should not modify the animated ID";
177 EXPECT_EQ(3.0f, cube->rot[0]) <<
"Evaluation should not modify the animated ID";
178 EXPECT_EQ(2.0f, cube->rot[1]) <<
"Evaluation should not modify the animated ID";
179 EXPECT_EQ(7.0f, cube->rot[2]) <<
"Evaluation should not modify the animated ID";
185 constexpr int vertex_count = 200;
186 mesh->verts_num = vertex_count;
198 for (
const int vertex_index :
IndexRange(vertex_count)) {
199 const std::string
rna_path =
"vertices[" + std::to_string(vertex_index) +
"].co";
202 bmain, mesh_slot, {
rna_path, component}, {1.0f,
float(vertex_index)}, settings);
207 anim_eval_context.eval_time = 1.0f;
210 mesh_rna_ptr, *mesh_action, mesh_layer, mesh_slot.
handle, anim_eval_context);
212 ASSERT_FALSE(
result.is_empty());
214 for (
const int vertex_index :
IndexRange(vertex_count)) {
215 const std::string
rna_path =
"vertices[" + std::to_string(vertex_index) +
"].co";
217 ASSERT_TRUE(parsed_rna_path.has_value());
222 ASSERT_NE(
nullptr, property);
223 EXPECT_EQ(
float(vertex_index), property->value);
232 strip.
resize(1.0f, 10.0f);
236 strip_data.
keyframe_insert(bmain, *slot, {
"location", 0}, {1.0f, 47.0f}, settings);
237 strip_data.
keyframe_insert(bmain, *slot, {
"location", 0}, {5.0f, 327.0f}, settings);
238 strip_data.
keyframe_insert(bmain, *slot, {
"location", 0}, {10.0f, 48.0f}, settings);
241 EXPECT_TRUE(test_evaluate_layer(
"location", 0, {1.0f, 47.0f}));
242 EXPECT_TRUE(test_evaluate_layer(
"location", 0, {3.0f, 187.0f}));
243 EXPECT_TRUE(test_evaluate_layer(
"location", 0, {10.0f, 48.0f}));
245 EXPECT_TRUE(test_evaluate_layer_no_result(
"location", 0, 10.001f));
253 strip1.
resize(1.0f, 10.0f);
254 strip2.
resize(11.0f, 20.0f);
260 strip_data1.
keyframe_insert(bmain, *slot, {
"location", 0}, {1.0f, 47.0f}, settings);
261 strip_data1.
keyframe_insert(bmain, *slot, {
"location", 0}, {5.0f, 327.0f}, settings);
262 strip_data1.
keyframe_insert(bmain, *slot, {
"location", 0}, {10.0f, 48.0f}, settings);
266 strip_data2.
keyframe_insert(bmain, *slot, {
"location", 0}, {1.0f, 47.0f}, settings);
267 strip_data2.
keyframe_insert(bmain, *slot, {
"location", 0}, {5.0f, 327.0f}, settings);
268 strip_data2.
keyframe_insert(bmain, *slot, {
"location", 0}, {10.0f, 48.0f}, settings);
272 EXPECT_TRUE(test_evaluate_layer(
"location", 0, {1.0f, 47.0f}));
273 EXPECT_TRUE(test_evaluate_layer(
"location", 0, {3.0f, 187.0f}));
274 EXPECT_TRUE(test_evaluate_layer(
"location", 0, {10.0f, 48.0f}));
277 EXPECT_TRUE(test_evaluate_layer(
"location", 0, {11.0f, 47.0f}));
278 EXPECT_TRUE(test_evaluate_layer(
"location", 0, {13.0f, 187.0f}));
279 EXPECT_TRUE(test_evaluate_layer(
"location", 0, {20.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, 10.001f));
284 EXPECT_TRUE(test_evaluate_layer_no_result(
"location", 0, 10.999f));
285 EXPECT_TRUE(test_evaluate_layer_no_result(
"location", 0, 20.001f));
293 strip1.
resize(1.0f, 10.0f);
294 strip2.
resize(10.0f, 19.0f);
300 strip_data1.
keyframe_insert(bmain, *slot, {
"location", 0}, {1.0f, 47.0f}, settings);
301 strip_data1.
keyframe_insert(bmain, *slot, {
"location", 0}, {5.0f, 327.0f}, settings);
302 strip_data1.
keyframe_insert(bmain, *slot, {
"location", 0}, {10.0f, 48.0f}, settings);
306 strip_data2.
keyframe_insert(bmain, *slot, {
"location", 0}, {1.0f, 47.0f}, settings);
307 strip_data2.
keyframe_insert(bmain, *slot, {
"location", 0}, {5.0f, 327.0f}, settings);
308 strip_data2.
keyframe_insert(bmain, *slot, {
"location", 0}, {10.0f, 48.0f}, settings);
312 EXPECT_TRUE(test_evaluate_layer(
"location", 0, {1.0f, 47.0f}));
313 EXPECT_TRUE(test_evaluate_layer(
"location", 0, {3.0f, 187.0f}));
316 EXPECT_TRUE(test_evaluate_layer(
"location", 0, {10.0f, 47.0f}))
317 <<
"On the overlapping frame, only Strip 2 should be evaluated.";
320 EXPECT_TRUE(test_evaluate_layer(
"location", 0, {12.0f, 187.0f}));
321 EXPECT_TRUE(test_evaluate_layer(
"location", 0, {19.0f, 48.0f}));
324 EXPECT_TRUE(test_evaluate_layer_no_result(
"location", 0, 0.999f));
325 EXPECT_TRUE(test_evaluate_layer_no_result(
"location", 0, 19.001f));
344 const char *rna_path_1 =
"pose.bones[\"Root\"].location";
345 const std::string rna_path_2(rna_path_1);
346 ASSERT_NE(rna_path_1, rna_path_2.c_str())
347 <<
"This test requires different addresses for the RNA path strings";
353 result.store(*parsed_rna_path_1, 0, 1.0f, fake_resolved_rna);
354 result.store(*parsed_rna_path_2, 0, 2.0f, fake_resolved_rna);
356 <<
"Storing a result for the same property twice should just overwrite the previous value";
361 EXPECT_EQ(2.0f, anim_prop->
value) <<
"The last-stored result should survive.";
366 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.
General operations, lookup, etc. for blender objects.
Object is a sort of wrapper for general info.
constexpr IndexRange()=default
static std::optional< ParsedRNAPath > from_string(StringRefNull path)
Layer & layer_add(std::optional< StringRefNull > name)
EvaluationResult()=default
Map< PropIdentifier, AnimatedProperty > EvaluationMap
Strip & strip_add(Action &owning_action, Strip::Type strip_type)
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
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)
#define EXPECT_TRUE(result)
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)
KeyframeSettings get_keyframe_settings(bool from_userprefs)
ActionSlotAssignmentResult assign_action_and_slot(Action *action, Slot *slot_to_assign, ID &animated_id)
void mesh_ensure_required_data_layers(Mesh &mesh)
PointerRNA RNA_id_pointer_create(ID *id)
MINLINE uint ulp_diff_ff(float a, float b)
VecBase< float, 2 > float2
PointerRNA RNA_pointer_create_discrete(ID *id, StructRNA *type, void *data)
void BKE_main_free(Main *bmain)
EXPECT_EQ(BLI_expr_pylike_eval(expr, nullptr, 0, &result), EXPR_PYLIKE_INVALID)
Object * BKE_object_add_only_object(Main *bmain, ObjectType type, const char *name) ATTR_RETURNS_NONNULL
Mesh * BKE_mesh_add(Main *bmain, const char *name)
void * BKE_id_new(Main *bmain, short type, const char *name)
KERNEL_FEATURE_LIGHT_PASSES KERNEL_FEATURE_PATH_GUIDING float
eBezTriple_Interpolation interpolation