Rotation to rotationQuaternion

Hi,

We can set either rotation or rotationQuaternion for a mesh.
I have implemented my logic with an assumption that all meshes will have rotationQuaternion (Because all the exporters are exporting meshes with rotationQuaternion set). Now I come across few models where rotation is specified. Not rotationQuaternion.

How can I compute rotationQuaternion from rotation?

Thanks in advance.

Here in the docs Euler Angles and Quaternions - Babylon.js Documentation

2 Likes

(Necro-posting because this is a top search result, and the documentation doesn’t quite answer it.)

You can convert an existing mesh.rotation directly to mesh.rotationQuaternion as follows:

mesh1.rotationQuaternion = BABYLON.Quaternion.RotationYawPitchRoll(mesh1.rotation.y, mesh1.rotation.x, mesh1.rotation.z);

Note that the order is y,x,z – not x,y,z!

Playground example