satguru Posted January 19, 2018 Share Posted January 19, 2018 @Deltakosh The matrix decompose returns wrong scale value when scale is negative see https://www.babylonjs-playground.com/#ZXZI83 Here scling.z is being set to -2, decompose returns +2 I think the bug got introduced by this change https://github.com/BabylonJS/Babylon.js/commit/8d1b546a20b3398556f0fe98f6d57329bce92687#diff-ccd6f7b0cc7c001d6fdf41cff591c6a6 Fixed matrix decomposition with negative scaling Quote Link to comment Share on other sites More sharing options...
GameMonetize Posted January 19, 2018 Share Posted January 19, 2018 You can also notice that scale.y === -1. Do you have an idea to fix it? Quote Link to comment Share on other sites More sharing options...
satguru Posted January 20, 2018 Author Share Posted January 20, 2018 @Deltakosh I am not sure how to fix it. Don't think the previous solution would have worked either. That relied on the signs of each co-ordinates of the unit vectors. I think that would only be reliable if the rotation was zero. We might also have a similar issue with getRotationMatrixToRef(). https://github.com/BabylonJS/Babylon.js/blob/0d75ccca5ce75ae46b19adf3aab5078706c5a07a/src/Math/babylon.math.ts#L3444 Won't m[3],m[7],m[11] always be zero? Anyway It is an interesting problem and I will keep looking into it. Quote Link to comment Share on other sites More sharing options...
GameMonetize Posted January 22, 2018 Share Posted January 22, 2018 Thanks for your help! Quote Link to comment Share on other sites More sharing options...
bghgary Posted January 22, 2018 Share Posted January 22, 2018 I don't think decompose is wrong. Once a scale is composed into a matrix, the information on which component is negative is lost as there are multiple ways to represent the same transformation. If you change your playground to output all the values, you'll notice the y component of the scale is negative and note that rotation is not identity. https://www.babylonjs-playground.com/#ZXZI83#1 Quote Link to comment Share on other sites More sharing options...
satguru Posted January 23, 2018 Author Share Posted January 23, 2018 @bghgary The more I think about it the more I believe you are right about "Once a scale is composed into a matrix, the information on which component is negative is lost ". It seems you can find that one of the component is negative but not which one and maybe just knowing that one of the component is negative is good enough to figure out the correct rotation. what about getRotationMatrixToRef()? needs to be corrected? Quote Link to comment Share on other sites More sharing options...
satguru Posted January 24, 2018 Author Share Posted January 24, 2018 @Deltakosh @bghgary check this playground example wherein I am printing out the rotationQuaternion using different methods https://www.babylonjs-playground.com/#ZXZI83#3 I get different results If i comment out line 12 (thus removing the negative scaling), I get correct results. Quote Link to comment Share on other sites More sharing options...
GameMonetize Posted January 24, 2018 Share Posted January 24, 2018 The math are correct but having a negative scale is something we cannot detect as the extracted scale is always positive (we consider it as a vector length) I can easily fix the computation with : https://www.babylonjs-playground.com/#ZXZI83#4 But it is a trick as I switch scale.z because I know that initial scling was negative on z I see no solution to this problem Quote Link to comment Share on other sites More sharing options...
satguru Posted January 25, 2018 Author Share Posted January 25, 2018 @Deltakosh 23 hours ago, Deltakosh said: I see no solution to this problem Me too it seems that based on just the matrix the only conclusion one can definitely arrive at is i) one scale is -negative or all scales are negative or ii) one scale is positive or all scales are positive but not which scale exactly. This would be based on taking cross product of two vectors and then dot product with the third vector So if (Vector3.Cross(ux,uy).Dot(uz))<0 then one scale is negative or all scales are negative else one scale is positive or all scales are positive Maybe mathematically impossible to determine the sign of the original scale? If that is the case then should the user provide the information ? as optional params? Matrix.Decompose(scale,rotation,translation,signX?,signY?,signZ?); where signX,signY,signZ would be 1 or -1 Quote Link to comment Share on other sites More sharing options...
GameMonetize Posted January 25, 2018 Share Posted January 25, 2018 That's a good option ! Quote Link to comment Share on other sites More sharing options...
satguru Posted January 26, 2018 Author Share Posted January 26, 2018 I will work on a pr Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.