pichou Posted September 14, 2018 Share Posted September 14, 2018 Hello everybody! Hope everyone is going well in the Babylon community ! My issue is simple : I use the mesh.rotate() function in order to rotate a mesh in the BABYLON.Space.WORLD. The function works great and my mesh rotate exactly how I want. The mesh.rotate() function use quaternion and so the rotation attribute is set to Vector0. But when the rotation is hover I would like to have the euler rotation back! To do so I use the mesh.rotationQuaternion.toEulerAngles() function But if I set the mesh.rotation = mesh.rotationQuaternion.toEulerAngles(); Then the mesh is rotating again on my screen like if the euler angles I get from the quaternion wasn't right. There is a lot of topics in this forum concerning this toEulerAngles function but after hours of reading and testing (even changing ZYX, YXZ orders), nothing is working! Is there an other way to get the euler rotation vector back from the quaternion? Or maybe a simplier way to rotate mesh around a world axis? Thanks for your help! Quote Link to comment Share on other sites More sharing options...
JohnK Posted September 14, 2018 Share Posted September 14, 2018 Whenever the rotationQuaternion is set for a mesh then rotation values are ignored and setting a value for mesh.rotation will have unpredictable results. So set a variable to mesh. rotationQuaternion.toEulerAngles() , null the rotationQuaternion and then set the rotation to the stored value. See the difference when you comment out line 48 is http://www.babylonjs-playground.com/#1ST43U#77 kcoley, Wingnut and coolroar 3 Quote Link to comment Share on other sites More sharing options...
coolroar Posted September 14, 2018 Share Posted September 14, 2018 (edited) I speculate that mesh's rotation state is held in either mesh.rotation or mesh.rotationQuaternion. mesh.rotate source Apparently the first use of mesh.rotate() creates mesh.rotationQuaternion to hold the rotation state. Then mesh.rotation is no longer valid. So now ALL rotations must be done with mesh.rotate() and reading rotation must be done with mesh.rotationQuaternion.toEulerAngles(). If this is true, why doesn't the rendering engine now ignore mesh.rotation? So when you mesh.rotate(a,b,c) and then mesh.rotation = mesh.rotationQuaternion.toEulerAngles(), maybe you are getting a double rotation effect. (?) Possible work-a-round: mesh.rotate(a/2, b/2, c/2) and then mesh.rotation = mesh.rotationQuaternion.toEulerAngles(). (?) Good luck! ☘️ Edit: Oops! JohnK posted as I was writing this. Edited September 14, 2018 by coolroar JohnK might have made my post mute! Wingnut 1 Quote Link to comment Share on other sites More sharing options...
pichou Posted September 14, 2018 Author Share Posted September 14, 2018 Thanks a lot for you answers. @JohnK your solution was perfect for my needs. I indeed didn't know that we had to set the rotationQuaternion to null before setting new rotation values. But now I get the exact result I want! Cheers! Wingnut 1 Quote Link to comment Share on other sites More sharing options...
pichou Posted September 14, 2018 Author Share Posted September 14, 2018 I have another question link to quaternion calculation. I am sure there is not a straight answer but how hard will rotationQuaternion be on CPU/GPU compare to basic rotation? I feel like maybe my last changes with quaternions made my computer less happy! Quote Link to comment Share on other sites More sharing options...
coolroar Posted September 14, 2018 Share Posted September 14, 2018 I have a program that makes several quaternion function calls per engine.runRenderLoop(). See it here: It runs smoothly (60 fps) on my machine (an older e-machines (AMD Athlon II X2 235e 2.7GHz, Radeon RX460 card). How about googling "babylonjs profiling"? Good luck with your app! ? pichou 1 Quote Link to comment Share on other sites More sharing options...
pichou Posted September 14, 2018 Author Share Posted September 14, 2018 Very nice simulation! Indeed it hasn't change much my computer performance eventually. I think this is more my curiosity which has pushed me to ask! coolroar 1 Quote Link to comment Share on other sites More sharing options...
Guest Posted September 17, 2018 Share Posted September 17, 2018 No worry, the cost is the same (like no difference over 30000 iterations) 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.