Maxence Posted January 17, 2014 Share Posted January 17, 2014 Hi, I am working on decomposing the world matrix of a mesh,I need it in order to keep rotation, scale and position of a mesh in world space (because these parameters are relative to the parent) if you import it without importing its parents. By testing different codes to decompose the matrix and to transform it into a quaternion, I notice that when you create a BABYLON.quaternion.RotationYawPitchRoll(yaw, pitch, roll) and you call the toEulerAngles() method on this quaternion, it does not return the passed yaw, pitch and roll. I wonder if this behavior is normal ? if yes can you explain me why ? I made a JsFiddle to explain my question. http://jsfiddle.net/Gc7n8/1/ Please look at the console line to see the log. Quote Link to comment Share on other sites More sharing options...
GameMonetize Posted January 17, 2014 Share Posted January 17, 2014 This is due to either:- a bug - or because decomposing a quaternion to euler can lead to different values but same final rotation Quote Link to comment Share on other sites More sharing options...
gwenael Posted January 19, 2014 Share Posted January 19, 2014 Looks like a bug for me http://jsfiddle.net/gwenaelhagenmuller/cM7uN/ Quote Link to comment Share on other sites More sharing options...
GameMonetize Posted January 20, 2014 Share Posted January 20, 2014 If someone is motivated to have a look to ToEulerAngles(), feel free as I'm pretty busy right now Quote Link to comment Share on other sites More sharing options...
JulienGobin Posted January 21, 2014 Share Posted January 21, 2014 I try something using math and conventions from here : http://www.euclideanspace.com/maths/geometry/rotations/euler/index.htmEuler to Quaternion : http://www.euclideanspace.com/maths/geometry/rotations/euler/index.htmQuaternion to Euler : http://www.euclideanspace.com/maths/geometry/rotations/conversions/quaternionToEuler/index.htm I get right Euler to Quaternion and Quaternion to Euler conversions but ... i got also some issues with the world matrix. http://jsfiddle.net/JulienGobin/BZ4A4/42/ It seems that the quaternion compute currently with the babylon js way are wrong (i hope it's not and i'm wrong, but after double-triple check the math and the convention ...). Quote Link to comment Share on other sites More sharing options...
gwenael Posted January 21, 2014 Share Posted January 21, 2014 If you're right, it means some changes may be needed in other places of the code to correct the maths but unfortunately the exporters may need to be updated too to get the right quaternions stored in the .babylon file. Moreover old scenes may not load as before (different rotations) and may need to be exported again. Quote Link to comment Share on other sites More sharing options...
GameMonetize Posted January 22, 2014 Share Posted January 22, 2014 The quaternion code should be good because they works well with quaternion exported from blender for instance. Could you precise where could be the error? Quote Link to comment Share on other sites More sharing options...
JulienGobin Posted January 22, 2014 Share Posted January 22, 2014 I'm not absolutely sure. Here my test : First on babylon js using BABYLON.Quaternion.YawPitchRoll with yaw = 0.1, pitch = 0.2, roll = 0.3 (assuming it's in radians) q = (x: 0.10602051106179562, y: 0.034270798550482096, z: 0.1435721750273919, w: 0.9833474432563558). Second using the Calculator on this page http://www.euclideanspace.com/maths/geometry/rotations/conversions/eulerToQuaternion/index.htm (at "Angle Calculator and Further examples"): - with heading = yaw, attitude = -roll, bank = pitch cause of the two differents conventions using by BabylonJS and euclideanspace.com (http://www.euclideanspace.com/maths/geometry/rotations/euler/index.htm)- after radian to degree conversion (using this : http://www.unitjuggler.com/convertir-angle-de-rad-en-deg.html) heading = 5.7295779513082, attitude = -17.188733853925, bank = 11.459155902616. q = (real: 0.9833474432563557, i: 0.0911575493429866, j: 0.034270798550482165, k: -0.153439302024225).If w = real and y = j (sounds logical) x != i and z != k (sounds a bit less logical). Did i miss something ? (wrong conversion maybe ?) Quote Link to comment Share on other sites More sharing options...
gwenael Posted January 22, 2014 Share Posted January 22, 2014 Deltakosh, could we imagine that the quaternion in the .babylon file (using BabylonJS exporter for Blender) is wrong and that the functions to compute the matrices correct it? Something like: a multiplication of two negative numbers gives a positive number but they should have been positive from the beginning. I haven't looked deeper in the exporter code neither in the functions to compute the matrices so it's just a suggestion. Quote Link to comment Share on other sites More sharing options...
gwenael Posted January 22, 2014 Share Posted January 22, 2014 The quaternion code should be good because they works well with quaternion exported from blender for instance. Could you precise where could be the error? I had a look to https://raw.github.com/BabylonJS/Babylon.js/master/Exporters/Blender/io_export_babylon.py. Apparently you always store rotation (euler angles) and not rotationQuaternion. My previous answer should be: "Deltakosh, could we imagine that the rotation (euler angles) in the .babylon file (using BabylonJS exporter for Blender) is wrong and that the functions to compute the matrices correct it? Something like: a multiplication of two negative numbers gives a positive number but they should have been positive from the beginning" Quote Link to comment Share on other sites More sharing options...
gwenael Posted January 22, 2014 Share Posted January 22, 2014 Blender doesn't use the same convention. It's right handed and Z-up (according to axis drawn on the viewports) Quote Link to comment Share on other sites More sharing options...
GameMonetize Posted January 23, 2014 Share Posted January 23, 2014 Everything is possible and I think that the error is somewhere into the Quaternion.YawPitchRoll function If there is a bug there, this is not a problem because this function is rarely used Quote Link to comment Share on other sites More sharing options...
JulienGobin Posted January 23, 2014 Share Posted January 23, 2014 I found something else when i look deeper in the blender exprot to babylon (maybe not really realated to this problem i made a fork) : http://www.html5gamedevs.com/topic/3293-amera-rotation-error-during-blender-export/ Quote Link to comment Share on other sites More sharing options...
GameMonetize Posted January 23, 2014 Share Posted January 23, 2014 Don't think so Quote Link to comment Share on other sites More sharing options...
JulienGobin Posted February 4, 2014 Share Posted February 4, 2014 (Sorry for the long time past)I've got something right now : http://jsfiddle.net/JulienGobin/BZ4A4/Some improvement still has to be done. And I'm not sure why it's needed to multiply by -2 instead of 2 during the quaternion to matrix conversion. I'll look deeper as soon as possible. Quote Link to comment Share on other sites More sharing options...
GameMonetize Posted February 4, 2014 Share Posted February 4, 2014 If it is working I suggest you to propose a pull request in order to be credited for your great work! Quote Link to comment Share on other sites More sharing options...
JulienGobin Posted February 5, 2014 Share Posted February 5, 2014 It works (according to many test) but ... i'm not 101% sure that no math-mistake have slipped themself into my code.Prefer double-triple check before send a pull request ^^' (maybe today). Quote Link to comment Share on other sites More sharing options...
GameMonetize Posted February 5, 2014 Share Posted February 5, 2014 good news And welcome onboard so! Quote Link to comment Share on other sites More sharing options...
GameMonetize Posted February 17, 2014 Share Posted February 17, 2014 Some news? Quote Link to comment Share on other sites More sharing options...
JulienGobin Posted March 3, 2014 Share Posted March 3, 2014 (Sorry, again, for the long time past)I still have some issue.I got the good euler -> quaternion and quaternion -> euler conversion (and the good quaternion -> matrix and matrix -> quaternion conversions)But, currently my math use a XYZ and not a YXZ euler order rotation, i'm working on it. Quote Link to comment Share on other sites More sharing options...
GameMonetize Posted March 3, 2014 Share Posted March 3, 2014 Keep the faith:) Quote Link to comment Share on other sites More sharing options...
JulienGobin Posted March 4, 2014 Share Posted March 4, 2014 Here my problem : http://jsfiddle.net/JulienGobin/BZ4A4/As i said I got the good euler <-> quat <-> matrix conversions, you can see that trying to use these commands in the console after clicking on the "Use euclideanspace conversions" button : euler <-> quatvar e = new BABYLON.Vector3(0.1, 0.2, 0.3);var q = BABYLON.Quaternion.RotationYawPitchRoll(e.y, e.x, e.z); console.log(e); // BABYLON.Vector3 {x: 0.1, y: 0.2, z: 0.3}console.log(q.toEulerAngles()); // BABYLON.Vector3 {x: 0.09999999999999999, y: 0.2, z: 0.30000000000000004} quat <-> mat var m = BABYLON.Matrix.Identity();q.toRotationMatrix(m); console.log(q); // BABYLON.Quaternion {x: 0.06407134770607098, y: 0.09115754934299045, z: 0.14357217502739153, w: 0.983347443256353}console.log(m.toQuaternion); // BABYLON.Quaternion {x: 0.06407134770607098, y: 0.09115754934299045, z: 0.14357217502739153, w: 0.983347443256353} But i don't got the good rotation (euler order are wrong). I'm working trying to fixe that. GameMonetize 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.