From 3c9dc7ab87071c329cb2f15917111813bb998a6d Mon Sep 17 00:00:00 2001 From: pissang Date: Fri, 9 Jun 2017 14:06:06 +0800 Subject: [PATCH] Fix matrix decompose wrong when has negative scale component --- src/math/Matrix4.js | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/math/Matrix4.js b/src/math/Matrix4.js index 044628d44..11b3f8c15 100644 --- a/src/math/Matrix4.js +++ b/src/math/Matrix4.js @@ -349,11 +349,15 @@ define(function(require) { var sx = vec3.length(x); var sy = vec3.length(y); var sz = vec3.length(z); + + // if determine is negative, we need to invert one scale + var det = this.determinant(); + if (det < 0) { + sx = -sx; + } + if (scale) { - scale.x = sx; - scale.y = sy; - scale.z = sz; - scale._dirty = true; + scale.set(sx, sy, sz); } position.set(el[12], el[13], el[14]);