[Bf-blender-cvs] [848d3f8e094] temp-sybren-alembic: Alembic: rotation mode issue in copy_m44_axis_swap, and added unit tests.

Sybren A. Stüvel noreply at git.blender.org
Thu Apr 6 15:21:14 CEST 2017


Commit: 848d3f8e094ec7ca2c9c2b946fb5b97dcf5d6990
Author: Sybren A. Stüvel
Date:   Wed Apr 5 17:07:24 2017 +0200
Branches: temp-sybren-alembic
https://developer.blender.org/rB848d3f8e094ec7ca2c9c2b946fb5b97dcf5d6990

Alembic: rotation mode issue in copy_m44_axis_swap, and added unit tests.

===================================================================

M	source/blender/alembic/intern/abc_util.cc
M	tests/gtests/alembic/abc_matrix_test.cc

===================================================================

diff --git a/source/blender/alembic/intern/abc_util.cc b/source/blender/alembic/intern/abc_util.cc
index 1a212ce34c0..61c8ddcf20b 100644
--- a/source/blender/alembic/intern/abc_util.cc
+++ b/source/blender/alembic/intern/abc_util.cc
@@ -200,7 +200,7 @@ void copy_m44_axis_swap(float dst_mat[4][4], float src_mat[4][4], AbcAxisSwapMod
 	mat4_to_loc_rot_size(src_trans, src_rot, src_scale, src_mat);
 
 	/* Get euler angles from rotation matrix. */
-	mat3_to_eulO(euler, ROT_MODE_XYZ, src_rot);
+	mat3_to_eulO(euler, ROT_MODE_XZY, src_rot);
 
 	/* Create X, Y, Z rotation matrices from euler angles. */
 	create_swapped_rotation_matrix(rot_x_mat, rot_y_mat, rot_z_mat, euler, mode);
@@ -210,7 +210,7 @@ void copy_m44_axis_swap(float dst_mat[4][4], float src_mat[4][4], AbcAxisSwapMod
 	mul_m3_m3m3(dst_rot, dst_rot, rot_y_mat);
 	mul_m3_m3m3(dst_rot, dst_rot, rot_x_mat);
 
-	mat3_to_eulO(euler, ROT_MODE_XYZ, dst_rot);
+	mat3_to_eulO(euler, ROT_MODE_XZY, dst_rot);
 
 	/* Start construction of dst_mat from rotation matrix */
 	unit_m4(dst_mat);
diff --git a/tests/gtests/alembic/abc_matrix_test.cc b/tests/gtests/alembic/abc_matrix_test.cc
index c9a79a73f60..b17ef098ba9 100644
--- a/tests/gtests/alembic/abc_matrix_test.cc
+++ b/tests/gtests/alembic/abc_matrix_test.cc
@@ -142,3 +142,115 @@ TEST(abc_matrix, CreateRotationMatrixXYZ_ZfromY) {
 	EXPECT_M3_NEAR(rot_y_mat, rot_y_m30, 1e-5f);
 	EXPECT_M3_NEAR(rot_z_mat, rot_z_p20, 1e-5f);
 }
+
+TEST(abc_matrix, CopyM44AxisSwap_YfromZ) {
+	float result[4][4];
+
+	/* Construct an input matrix that performs a rotation like the tests
+	 * above. This matrix was created by rotating a cube in Blender over
+	 * (X=10, Y=20, Z=30 degrees in XYZ order) and translating over (1, 2, 3) */
+	float input[4][4] = {
+	    {0.813797652721405, 0.46984633803367615, -0.3420201241970062, 0.0},
+	    {-0.4409696161746979, 0.882564127445221, 0.16317591071128845, 0.0},
+	    {0.3785223066806793, 0.018028317019343376, 0.9254165887832642, 0.0},
+	    {1.0, 2.0, 3.0, 1.0},
+	};
+
+	copy_m44_axis_swap(result, input, ABC_YUP_FROM_ZUP);
+
+	/* Check the resulting rotation & translation. */
+	float trans[4] = {1.f, 3.f, -2.f, 1.f};
+	EXPECT_V4_NEAR(trans, result[3], 1e-5f);
+
+	/* This matrix was created by rotating a cube in Blender over
+	 * (X=10, Y=30, Z=-20 degrees in XZY order) and translating over (1, 3, -2) */
+	float expect[4][4] = {
+	    {0.813797652721405, -0.3420201241970062, -0.46984633803367615, 0.0},
+	    {0.3785223066806793, 0.9254165887832642, -0.018028317019343376, 0.0},
+	    {0.4409696161746979, -0.16317591071128845, 0.882564127445221, 0.0},
+	    {1.0, 3.0, -2.0, 1.0},
+	};
+	EXPECT_M4_NEAR(expect, result, 1e-5f);
+}
+
+TEST(abc_matrix, CopyM44AxisSwapWithScale_YfromZ) {
+	float result[4][4];
+
+	/* Construct an input matrix that performs a rotation like the tests
+	 * above. This matrix was created by rotating a cube in Blender over
+	 * (X=10, Y=20, Z=30 degrees in XYZ order), translating over (1, 2, 3),
+	 * and scaling by (4, 5, 6). */
+	float input[4][4] = {
+	            {3.25519061088562, 1.8793853521347046, -1.368080496788025, 0.0},
+		        {-2.204848051071167, 4.412820816040039, 0.8158795833587646, 0.0},
+		        {2.2711338996887207, 0.10816989839076996, 5.552499771118164, 0.0},
+		        {1.0, 2.0, 3.0, 1.0},
+	};
+
+	copy_m44_axis_swap(result, input, ABC_YUP_FROM_ZUP);
+
+	/* This matrix was created by rotating a cube in Blender over
+	 * (X=10, Y=30, Z=-20 degrees in XZY order), translating over (1, 3, -2)
+	 * and scaling over (4, 6, 5). */
+	float expect[4][4] = {
+	    {3.25519061088562, -1.368080496788025, -1.8793853521347046, 0.0},
+		{2.2711338996887207, 5.552499771118164, -0.10816989839076996, 0.0},
+		{2.204848051071167, -0.8158795833587646, 4.412820816040039, 0.0},
+		{1.0, 3.0, -2.0, 1.0},
+	};
+	EXPECT_M4_NEAR(expect, result, 1e-5f);
+}
+
+TEST(abc_matrix, CopyM44AxisSwap_ZfromY) {
+	float result[4][4];
+
+	/* This matrix was created by rotating a cube in Blender over
+	 * (X=10, Y=30, Z=-20 degrees in XZY order) and translating over (1, 3, -2) */
+	float input[4][4] = {
+	    {0.813797652721405, -0.3420201241970062, -0.46984633803367615, 0.0},
+	    {0.3785223066806793, 0.9254165887832642, -0.018028317019343376, 0.0},
+	    {0.4409696161746979, -0.16317591071128845, 0.882564127445221, 0.0},
+	    {1.0, 3.0, -2.0, 1.0},
+	};
+
+	copy_m44_axis_swap(result, input, ABC_ZUP_FROM_YUP);
+
+	/* This matrix was created by rotating a cube in Blender over
+	 * (X=10, Y=20, Z=30 degrees in XYZ order) and translating over (1, 2, 3) */
+	float expect[4][4] = {
+	    {0.813797652721405, 0.46984633803367615, -0.3420201241970062, 0.0},
+	    {-0.4409696161746979, 0.882564127445221, 0.16317591071128845, 0.0},
+	    {0.3785223066806793, 0.018028317019343376, 0.9254165887832642, 0.0},
+	    {1.0, 2.0, 3.0, 1.0},
+	};
+
+	EXPECT_M4_NEAR(expect, result, 1e-5f);
+}
+
+TEST(abc_matrix, CopyM44AxisSwapWithScale_ZfromY) {
+	float result[4][4];
+
+	/* This matrix was created by rotating a cube in Blender over
+	 * (X=10, Y=30, Z=-20 degrees in XZY order), translating over (1, 3, -2)
+	 * and scaling over (4, 6, 5). */
+	float input[4][4] = {
+	    {3.25519061088562, -1.368080496788025, -1.8793853521347046, 0.0},
+		{2.2711338996887207, 5.552499771118164, -0.10816989839076996, 0.0},
+		{2.204848051071167, -0.8158795833587646, 4.412820816040039, 0.0},
+		{1.0, 3.0, -2.0, 1.0},
+	};
+
+	copy_m44_axis_swap(result, input, ABC_ZUP_FROM_YUP);
+
+	/* This matrix was created by rotating a cube in Blender over
+	 * (X=10, Y=20, Z=30 degrees in XYZ order), translating over (1, 2, 3),
+	 * and scaling by (4, 5, 6). */
+	float expect[4][4] = {
+	            {3.25519061088562, 1.8793853521347046, -1.368080496788025, 0.0},
+		        {-2.204848051071167, 4.412820816040039, 0.8158795833587646, 0.0},
+		        {2.2711338996887207, 0.10816989839076996, 5.552499771118164, 0.0},
+		        {1.0, 2.0, 3.0, 1.0},
+	};
+
+	EXPECT_M4_NEAR(expect, result, 1e-5f);
+}




More information about the Bf-blender-cvs mailing list