From 7fdf720fb164e448703c7d9f6103a3b59178189d Mon Sep 17 00:00:00 2001 From: Gaia Clary Date: Fri, 16 Feb 2018 12:37:36 +0100 Subject: Fix rotation issues due to matrix to quaternion ambiguities Reviewers: mont29 Reviewed By: mont29 Subscribers: mont29 Differential Revision: https://developer.blender.org/D3066 --- source/blender/collada/AnimationImporter.cpp | 14 ++++++++++++-- source/blender/collada/collada_utils.cpp | 29 ++++++++++++++++++++++++++++ source/blender/collada/collada_utils.h | 1 + 3 files changed, 42 insertions(+), 2 deletions(-) (limited to 'source') diff --git a/source/blender/collada/AnimationImporter.cpp b/source/blender/collada/AnimationImporter.cpp index fec8d62933a..bc91b94afd9 100644 --- a/source/blender/collada/AnimationImporter.cpp +++ b/source/blender/collada/AnimationImporter.cpp @@ -780,6 +780,9 @@ void AnimationImporter::apply_matrix_curves(Object *ob, std::vector& a std::vector::iterator it; + float qref[4]; + unit_qt(qref); + // sample values at each frame for (it = frames.begin(); it != frames.end(); it++) { float fra = *it; @@ -815,7 +818,9 @@ void AnimationImporter::apply_matrix_curves(Object *ob, std::vector& a float rot[4], loc[3], scale[3]; - mat4_to_quat(rot, mat); + bc_rotate_from_reference_quat(rot, qref, mat); + copy_qt_qt(qref, rot); + #if 0 for (int i = 0 ; i < 4; i++) { rot[i] = RAD2DEGF(rot[i]); @@ -1190,6 +1195,9 @@ void AnimationImporter::add_bone_animation_sampled(Object *ob, std::vector::iterator it; // sample values at each frame @@ -1223,7 +1231,9 @@ void AnimationImporter::add_bone_animation_sampled(Object *ob, std::vector *objects_done, UnitConverter &unit_converter, bool scale_to_scene); extern void bc_decompose(float mat[4][4], float *loc, float eul[3], float quat[4], float *size); +extern void bc_rotate_from_reference_quat(float quat_to[4], float quat_from[4], float mat_to[4][4]); extern void bc_triangulate_mesh(Mesh *me); extern bool bc_is_leaf_bone(Bone *bone); -- cgit v1.2.3 From e1a686e44448e8345d45041631fda84d4ee0d2fa Mon Sep 17 00:00:00 2001 From: Gaia Clary Date: Fri, 16 Feb 2018 16:53:16 +0100 Subject: fix: limit precision also for animation matrixes if the limit option is set (gives nicer output for inspection) --- source/blender/collada/AnimationExporter.cpp | 3 +++ source/blender/collada/collada_utils.cpp | 7 +++++++ source/blender/collada/collada_utils.h | 1 + 3 files changed, 11 insertions(+) (limited to 'source') diff --git a/source/blender/collada/AnimationExporter.cpp b/source/blender/collada/AnimationExporter.cpp index d4f434d56fd..bd5cb05a1fa 100644 --- a/source/blender/collada/AnimationExporter.cpp +++ b/source/blender/collada/AnimationExporter.cpp @@ -988,6 +988,9 @@ std::string AnimationExporter::create_4x4_source(std::vector &frames, Obj double outmat[4][4]; converter.mat4_to_dae_double(outmat, mat); + if (this->export_settings->limit_precision) + bc_sanitize_mat(outmat, 6); + source.appendValues(outmat); j++; diff --git a/source/blender/collada/collada_utils.cpp b/source/blender/collada/collada_utils.cpp index c13757fa2a4..35bc643d3c7 100644 --- a/source/blender/collada/collada_utils.cpp +++ b/source/blender/collada/collada_utils.cpp @@ -864,6 +864,13 @@ void bc_sanitize_mat(float mat[4][4], int precision) mat[i][j] = double_round(mat[i][j], precision); } +void bc_sanitize_mat(double mat[4][4], int precision) +{ + for (int i = 0; i < 4; i++) + for (int j = 0; j < 4; j++) + mat[i][j] = double_round(mat[i][j], precision); +} + /* * Returns name of Active UV Layer or empty String if no active UV Layer defined. * Assuming the Object is of type MESH diff --git a/source/blender/collada/collada_utils.h b/source/blender/collada/collada_utils.h index ad274777e8d..e9066d7db46 100644 --- a/source/blender/collada/collada_utils.h +++ b/source/blender/collada/collada_utils.h @@ -100,6 +100,7 @@ extern EditBone *bc_get_edit_bone(bArmature * armature, char *name); extern int bc_set_layer(int bitfield, int layer, bool enable); extern int bc_set_layer(int bitfield, int layer); extern void bc_sanitize_mat(float mat[4][4], int precision); +extern void bc_sanitize_mat(double mat[4][4], int precision); extern IDProperty *bc_get_IDProperty(Bone *bone, std::string key); extern void bc_set_IDProperty(EditBone *ebone, const char *key, float value); -- cgit v1.2.3 From 5bc2c17161cfc23ca2d8c58e7e24458c277100ae Mon Sep 17 00:00:00 2001 From: Gaia Clary Date: Fri, 16 Feb 2018 16:58:20 +0100 Subject: fix:T50079 collada matrix and blender matrix are transposed. This was not regarded by the animation importer, so it was creating very odd results --- source/blender/collada/AnimationImporter.cpp | 1 + source/blender/collada/collada_utils.cpp | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) (limited to 'source') diff --git a/source/blender/collada/AnimationImporter.cpp b/source/blender/collada/AnimationImporter.cpp index bc91b94afd9..95543b2dc18 100644 --- a/source/blender/collada/AnimationImporter.cpp +++ b/source/blender/collada/AnimationImporter.cpp @@ -817,6 +817,7 @@ void AnimationImporter::apply_matrix_curves(Object *ob, std::vector& a } float rot[4], loc[3], scale[3]; + transpose_m4(mat); bc_rotate_from_reference_quat(rot, qref, mat); copy_qt_qt(qref, rot); diff --git a/source/blender/collada/collada_utils.cpp b/source/blender/collada/collada_utils.cpp index 35bc643d3c7..415daccfa3d 100644 --- a/source/blender/collada/collada_utils.cpp +++ b/source/blender/collada/collada_utils.cpp @@ -403,7 +403,7 @@ void bc_rotate_from_reference_quat(float quat_to[4], float quat_from[4], float m mat4_to_quat(qd, matd); - mul_qt_qtqt(quat_to, quat_from, qd); // rot is the final rotation corresponding to mat_to + mul_qt_qtqt(quat_to, qd, quat_from); // rot is the final rotation corresponding to mat_to } void bc_triangulate_mesh(Mesh *me) -- cgit v1.2.3