diff options
author | K. S. Ernest (iFire) Lee <ernest.lee@chibifire.com> | 2018-08-27 14:51:54 -0700 |
---|---|---|
committer | K. S. Ernest (iFire) Lee <ernest.lee@chibifire.com> | 2018-08-27 14:59:28 -0700 |
commit | fa62037ff6f1f49510a5e907edaa42da8889b27b (patch) | |
tree | 61c33f5ef184901cdcb587c83e0bfdb7fc9de244 /editor | |
parent | 6b10e3750e8f7fe64abd3024b7cc2265e544f521 (diff) |
In the GLTF importer normalize Quaternions after every operation and when reading from the format.
Diffstat (limited to 'editor')
-rw-r--r-- | editor/import/editor_scene_importer_gltf.cpp | 18 |
1 files changed, 13 insertions, 5 deletions
diff --git a/editor/import/editor_scene_importer_gltf.cpp b/editor/import/editor_scene_importer_gltf.cpp index 4d5c292847..3d3dc978bc 100644 --- a/editor/import/editor_scene_importer_gltf.cpp +++ b/editor/import/editor_scene_importer_gltf.cpp @@ -793,7 +793,7 @@ Vector<Quat> EditorSceneImporterGLTF::_decode_accessor_as_quat(GLTFState &state, ret.resize(ret_size); { for (int i = 0; i < ret_size; i++) { - ret.write[i] = Quat(attribs_ptr[i * 4 + 0], attribs_ptr[i * 4 + 1], attribs_ptr[i * 4 + 2], attribs_ptr[i * 4 + 3]); + ret.write[i] = Quat(attribs_ptr[i * 4 + 0], attribs_ptr[i * 4 + 1], attribs_ptr[i * 4 + 2], attribs_ptr[i * 4 + 3]).normalized(); } } return ret; @@ -1793,17 +1793,24 @@ template <> struct EditorSceneImporterGLTFInterpolate<Quat> { Quat lerp(const Quat &a, const Quat &b, float c) const { + ERR_FAIL_COND_V(a.is_normalized() == false, Quat()); + ERR_FAIL_COND_V(b.is_normalized() == false, Quat()); - return a.slerp(b, c); + return a.slerp(b, c).normalized(); } Quat catmull_rom(const Quat &p0, const Quat &p1, const Quat &p2, const Quat &p3, float c) { + ERR_FAIL_COND_V(p1.is_normalized() == false, Quat()); + ERR_FAIL_COND_V(p2.is_normalized() == false, Quat()); - return p1.slerp(p2, c); + return p1.slerp(p2, c).normalized(); } Quat bezier(Quat start, Quat control_1, Quat control_2, Quat end, float t) { - return start.slerp(end, t); + ERR_FAIL_COND_V(start.is_normalized() == false, Quat()); + ERR_FAIL_COND_V(end.is_normalized() == false, Quat()); + + return start.slerp(end, t).normalized(); } }; @@ -1945,7 +1952,7 @@ void EditorSceneImporterGLTF::_import_animation(GLTFState &state, AnimationPlaye Vector3 base_scale = Vector3(1, 1, 1); if (!track.rotation_track.values.size()) { - base_rot = state.nodes[E->key()]->rotation; + base_rot = state.nodes[E->key()]->rotation.normalized(); } if (!track.translation_track.values.size()) { @@ -1991,6 +1998,7 @@ void EditorSceneImporterGLTF::_import_animation(GLTFState &state, AnimationPlaye xform = skeleton->get_bone_rest(bone).affine_inverse() * xform; rot = xform.basis.get_rotation_quat(); + rot.normalize(); scale = xform.basis.get_scale(); pos = xform.origin; } |