Sign in to follow this  

issues with toEulerAngles

Recommended Posts

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! ;)

Share this post

Link to post
Share on other sites

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

Share this post

Link to post
Share on other sites

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 by coolroar
JohnK might have made my post mute!

Share this post

Link to post
Share on other sites

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! ;)

Share this post

Link to post
Share on other sites

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!  💡

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.