27#include "testing/testing.h"
65 float unit_matrix[3][3];
72 EXPECT_FLOAT_EQ(0.0f, roll);
75 EXPECT_FLOAT_EQ(0.0f, roll);
78 EXPECT_FLOAT_EQ(0.0f, roll);
82 float vector[3] = {1.0f, 1.0f, 1.0f};
95 float rotation_matrix[3][3];
98 const float rot_around_x[3] = {1.234f, 0.0f, 0.0f};
102 const float unit_axis_x[3] = {1.0f, 0.0f, 0.0f};
108 const float unit_axis_y[3] = {0.0f, 1.0f, 0.0f};
114 const float unit_axis_z[3] = {0.0f, 0.0f, 1.0f};
120 const float between_x_and_y[3] = {1.0f, 1.0f, 0.0f};
129 const float expected_roll_mat[3][3],
132 float input_normalized[3];
133 float roll_mat[3][3];
145 EXPECT_V3_NEAR(roll_mat[1], input_normalized,
FLT_EPSILON);
147 if (expected_roll_mat) {
148 EXPECT_M3_NEAR(roll_mat, expected_roll_mat,
FLT_EPSILON);
160 double theta =
x *
x +
z *
z;
161 double minv = 0, maxv = 1
e-2;
164 double mid = (minv + maxv) / 2;
166 float roll_mat[3][3];
175 if (roll_mat[0][0] == -1 && roll_mat[0][1] == 0 && roll_mat[2][1] == 0) {
183 return sqrt(theta) * (minv + maxv) * 0.5;
200 const float input[3] = {0.0f, -1.0f, 0.0f};
201 const float expected_roll_mat[3][3] = {
202 {-1.0f, 0.0f, 0.0f}, {0.0f, -1.0f, 0.0f}, {0.0f, 0.0f, 1.0f}};
211 const float input[3] = {1
e-24, -0.999999881, 0};
212 const float expected_roll_mat[3][3] = {
213 {-1.0f, 0.0f, 0.0f}, {0.0f, -1.0f, 0.0f}, {0.0f, 0.0f, 1.0f}};
220 const float input[3] = {2.5e-4f, -0.999999881f, 2.5e-4f};
221 const float expected_roll_mat[3][3] = {{0.000000f, -2.5e-4f, -1.000000f},
222 {2.5e-4f, -0.999999881f, 2.5e-4f},
223 {-1.000000f, -2.5e-4f, 0.000000f}};
231 const float input[3] = {1, 0, 0};
232 const float expected_roll_mat[3][3] = {{0, -1, 0}, {1, 0, 0}, {0, 0, 1}};
239 const float input[3] = {-1, 0, 0};
240 const float expected_roll_mat[3][3] = {{0, 1, 0}, {-1, 0, 0}, {0, 0, 1}};
247 const float input[3] = {0, 0, -1};
248 const float expected_roll_mat[3][3] = {{1, 0, 0}, {0, 0, -1}, {0, 1, 0}};
255 const float input[3] = {0, 0, 1};
256 const float expected_roll_mat[3][3] = {{1, 0, 0}, {0, 0, 1}, {0, -1, 0}};
263 const float input[3] = {1.0f, 1.0f, 1.0f};
264 const float expected_roll_mat[3][3] = {{0.788675129f, -0.577350259f, -0.211324856f},
265 {0.577350259f, 0.577350259f, 0.577350259f},
266 {-0.211324856f, -0.577350259f, 0.788675129f}};
272 const float input[3] = {1.0f, -1.0f, 1.0f};
273 const float expected_roll_mat[3][3] = {{0.211324856f, -0.577350259f, -0.788675129f},
274 {0.577350259f, -0.577350259f, 0.577350259f},
275 {-0.788675129f, -0.577350259f, 0.211324856f}};
281 const float input[3] = {-1.0f, -1.0f, 1.0f};
282 const float expected_roll_mat[3][3] = {{0.211324856f, 0.577350259f, 0.788675129f},
283 {-0.577350259f, -0.577350259f, 0.577350259f},
284 {0.788675129f, -0.577350259f, 0.211324856f}};
290 const float input[3] = {-1.0f, -1.0f, -1.0f};
291 const float expected_roll_mat[3][3] = {{0.211324856f, 0.577350259f, -0.788675129f},
292 {-0.577350259f, -0.577350259f, -0.577350259f},
293 {-0.788675129f, 0.577350259f, 0.211324856f}};
300 const float input[3] = {1.0f, 1.0f, 1.0f};
301 const float expected_roll_mat[3][3] = {{0.211324856f, 0.577350259f, -0.788675129f},
302 {0.577350259f, 0.577350259f, 0.577350259f},
303 {0.788675129f, -0.577350259f, -0.211324856f}};
318 const int count = 5000;
322 for (
int i = 0; i <= count; i++) {
323 double t = double(i) / count;
327 double curdelta =
abs(det - 1);
328 if (curdelta > delta) {
334 printf(
" Max determinant deviation %.10f at %f.\n", delta, tmax);
337#define TEST_VEC_ROLL_TO_MAT3_ORTHOGONAL(name, s, x1, x2, y1, y2) \
338 TEST(vec_roll_to_mat3_normalized, name) \
340 test_vec_roll_to_mat3_orthogonal(s, x1, x2, y1, y2); \
389 std::vector<Bone *> seen_bones;
390 auto callback = [&](
Bone *bone) { seen_bones.push_back(bone); };
394 ASSERT_EQ(seen_bones.size(), 2) <<
"Expected 2 selected bones, got " << seen_bones.size();
404 bone1.flag = bone2.flag = bone3.flag =
eBone_Flag{};
406 std::vector<Bone *> seen_bones;
407 auto callback = [&](
Bone *bone) { seen_bones.push_back(bone); };
411 EXPECT_TRUE(seen_bones.empty()) <<
"Expected no selected bones, got " << seen_bones.size();
420 std::vector<Bone *> seen_bones;
421 auto callback = [&](
Bone *bone) { seen_bones.push_back(bone); };
425 ASSERT_EQ(seen_bones.size(), 3) <<
"Expected 3 selected bones, got " << seen_bones.size();
480 EXPECT_EQ(0, armature->runtime->bones.size())
481 <<
"After low-level bone adding, the runtime array should be empty.";
482 ASSERT_NE(0, armature->id.session_uid);
483 EXPECT_EQ(
uint64_t(armature->id.session_uid) << 32, armature->runtime->bones_generation_count);
485 EXPECT_EQ(bone_root, armature->bone_get_indexed(0));
486 EXPECT_EQ(3, armature->runtime->bones.size())
487 <<
"After calling bone_get_index(), the runtime array should be filled.";
489 EXPECT_EQ(bone_child1, armature->bone_get_indexed(1));
491 armature->runtime->bones_tag_rebuild();
492 EXPECT_EQ(bone_child2, armature->bone_get_indexed(2));
493 EXPECT_EQ(3, armature->runtime->bones.size())
494 <<
"After clearing the bone array, calling bone_get_index() should rebuild it.";
500 EXPECT_EQ(bone_root, armature->bone_get_indexed(0));
504 ASSERT_NE(0, armature->id.session_uid);
505 EXPECT_NE(armature->runtime->bones_generation_count, copy->
runtime->bones_generation_count);
509 Bone *copybone_root = copy->bonebase.first();
510 EXPECT_EQ(copybone_root, copy->bone_get_indexed(0));
513 bArmature *cow_copy = id_cast<bArmature *>(
520 ASSERT_NE(0, armature->id.session_uid);
556 EXPECT_EQ(bone_root, pchan_root->bone_get(*
object));
557 EXPECT_EQ(bone_child1, pchan_child1->bone_get(*
object));
558 EXPECT_EQ(bone_child2, pchan_child2->bone_get(*
object));
577 ASSERT_NE(bone_root, copybone_root);
578 ASSERT_NE(bone_child1, copybone_child1);
579 ASSERT_NE(bone_child2, copybone_child2);
582 Array<Bone *> expected_bones = {copybone_root, copybone_child1, copybone_child2};
583 ASSERT_EQ(expected_bones, copy->
runtime->bones);
588 object->data = ©->id;
591 EXPECT_EQ(copybone_root, pchan_root->bone_get(*
object));
592 EXPECT_EQ(copybone_child1, pchan_child1->bone_get(*
object));
593 EXPECT_EQ(copybone_child2, pchan_child2->bone_get(*
object));
596 EXPECT_EQ(bone_root, pchan_root->bone_get(*armature));
597 EXPECT_EQ(bone_child1, pchan_child1->bone_get(*armature));
598 EXPECT_EQ(bone_child2, pchan_child2->bone_get(*armature));
614 MEM_delete(bone_child2);
615 bone_child2 =
nullptr;
616 armature->runtime->bones_tag_rebuild();
618 EXPECT_EQ(bone_root, pchan_root->bone_get(*
object));
619 EXPECT_EQ(bone_child1, pchan_child1->bone_get(*
object));
623 const uint64_t armature_generation_count = armature->runtime->bones_generation_count;
624 const uint64_t object_generation_count =
object->runtime->pose_bones_generation_count;
625 EXPECT_EQ(armature_generation_count, object_generation_count);
Blender kernel action and pose functionality.
General operations, lookup, etc. for blender objects.
ID and Library types, which are fundamental for SDNA.
Object is a sort of wrapper for general info.
Read Blender memory allocation and freeing.
#define TEST_VEC_ROLL_TO_MAT3_ORTHOGONAL(name, s, x1, x2, y1, y2)
SIMD_FORCE_INLINE const btScalar & z() const
Return the z value.
b[1] b &&[1] b &&[1] b &&[1] b &&[1] b[3] b &&[1] b[3] float determinant(MatBase< C, R >) RET
VecBase< float, D > normalize(VecOp< float, D >) RET
float3x3 scale(float3x3 mat, float2 scale)
#define EXPECT_FALSE(result)
#define EXPECT_NE(result, expect)
#define EXPECT_TRUE(result)
#define EXPECT_NEAR(result, expect, threshold)
static double find_flip_boundary(double x, double z)
TEST(mat3_vec_to_roll, UnitMatrix)
static const float SCALE_EPSILON
static double test_vec_roll_to_mat3_orthogonal(double s, double x, double z)
static double EXPECT_M3_ORTHOGONAL(const float mat[3][3], double epsilon_scale, double epsilon_ortho)
static const float ORTHO_EPSILON
static const float FLOAT_EPSILON
static double test_vec_roll_to_mat3_normalized(const float input[3], float roll, const float expected_roll_mat[3][3], bool normalize=true)
TEST_F(AnimDataTest, BKE_fcurves_id_cb_test)
SelectedBonesResult BKE_armature_find_selected_bones(const bArmature *armature, SelectedBoneCallback callback)
T length(const VecBase< T, Size > &a)
T determinant(const MatBase< T, Size, Size > &mat)
void mat3_vec_to_roll(const float mat[3][3], const float vec[3], float *r_roll)
unsigned __int64 uint64_t
void eul_to_mat3(float mat[3][3], const float eul[3])
bArmature * BKE_armature_add(Main *bmain, const char *name)
char * STRNCPY(char(&dst)[N], const char *src)
void BKE_pose_rebuild(Main *bmain, Object *ob, bArmature *arm, bool do_id_user)
MINLINE double dot_v3v3_db(const double a[3], const double b[3]) ATTR_WARN_UNUSED_RESULT
MINLINE void copy_v3_v3(float r[3], const float a[3])
MINLINE double interpd(double target, double origin, double t)
MatBase< double, 3, 3 > double3x3
@ LIB_ID_COPY_SET_COPIED_ON_WRITE
void BLI_remlink(ListBase *listbase, void *vlink) ATTR_NONNULL(1)
void copy_m3d_m3(double m1[3][3], const float m2[3][3])
MINLINE float normalize_v3_v3(float r[3], const float a[3])
void BKE_main_free(Main *bmain)
EXPECT_EQ(BLI_expr_pylike_eval(expr, nullptr, 0, &result), EXPR_PYLIKE_INVALID)
MINLINE float normalize_v3(float n[3])
void BLI_addtail(ListBase *listbase, void *vlink) ATTR_NONNULL(1)
void unit_m3(float m[3][3])
void vec_roll_to_mat3_normalized(const float nor[3], float roll, float r_mat[3][3])
Object * BKE_object_add_only_object(Main *bmain, ObjectType type, const char *name) ATTR_RETURNS_NONNULL
ID * BKE_id_copy(Main *bmain, const ID *id)
Bone * BKE_armature_find_bone_name(bArmature *arm, const char *name)
bPoseChannel * BKE_pose_channel_find_name(const bPose *pose, const char *name)
struct ID * BKE_id_copy_in_lib(Main *bmain, std::optional< Library * > owner_library, const ID *id, std::optional< const ID * > new_owner_id, ID **new_id_p, int flag)
ATTR_WARN_UNUSED_RESULT const BMVert const BMEdge * e
KERNEL_FEATURE_LIGHT_PASSES KERNEL_FEATURE_PATH_GUIDING float
ListBaseT< Bone > childbase
const c_style_mat & ptr() const
bke::bArmature_Runtime * runtime
ListBaseT< Bone > bonebase
bke::motionpath::Runtime * runtime
uint64_t bones_generation_count