Eelis Posted September 16, 2016 Share Posted September 16, 2016 Consider: var s = new BABYLON.Vector3(); var r = new BABYLON.Quaternion(); var t = new BABYLON.Vector3(); if (BABYLON.Matrix.Scaling(1, -1, 1).decompose(s, r, t)) { console.log("scale: " + s); } I get the following output: scale: {X: 1 Y:1 Z:1} Naively I expected to get {1, -1, 1} back out again. What am I missing here? Thanks Quote Link to comment Share on other sites More sharing options...
GameMonetize Posted September 16, 2016 Share Posted September 16, 2016 What are the values of t and r? Quote Link to comment Share on other sites More sharing options...
Eelis Posted September 16, 2016 Author Share Posted September 16, 2016 56 minutes ago, Deltakosh said: What are the values of t and r? r: {X: 0 Y:0 Z:0 W:0.7071067811865476} r.toEulerAngles(): {X: 0 Y:0 Z:0} t: {X: 0 Y:0 Z:0} I wonder what that nonzero W component in r is doing. From the Euler angles it looks like it's not doing anything. Quote Link to comment Share on other sites More sharing options...
Nockawa Posted September 16, 2016 Share Posted September 16, 2016 I'm not 100% sure about what I'm going to tell, but this reminds me old things. If I remember correctly most of the matrix decomposition routines can't extract non uniform scale (i.e. not the same scale value for x, y & z). I think it has something to do with finding the matrix determinant which is needed after. Well can't remember exactly but googling will tell you if I'm right or not. Quote Link to comment Share on other sites More sharing options...
Eelis Posted September 16, 2016 Author Share Posted September 16, 2016 Hmm, well if the decompose function only yields correct outputs for certain inputs, it would be useful if the documentation stated these preconditions. Quote Link to comment Share on other sites More sharing options...
Nockawa Posted September 16, 2016 Share Posted September 16, 2016 1 hour ago, Eelis said: Hmm, well if the decompose function only yields correct outputs for certain inputs, it would be useful if the documentation stated these preconditions. Well, mixing 3 different matrices into one may lead to information loss, which means you can't decompose to get back what you had initially in some cases. There's no mystery, the decomposition only works if some specific conditions are met. But we, you're right, documentation should state the limitations of this methods. Overall if you deal with non uniform scale be aware there could be other "issues" like that. A good general rule is to allow non uniform scaling only for final stage animation (vertex blending/bones/etc.). If you still need to get it back I suggest you to work with a custom structure I used to call PRS: Position (Vector3), Rotation (Quaternion) and Scale (Vector3), you can easily create a matrix from it and you will always have each info stored specifically. Quote Link to comment Share on other sites More sharing options...
GameMonetize Posted September 19, 2016 Share Posted September 19, 2016 The problem is that the decomposition is not unique. Several matrices can lead to same transform. Here the scale is positive because the quaternion will then rotate the mesh to achieve the same result as scaling to 1, -1, 1 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.