Sometimes you may know the final orientation you want to give to a mesh in terms of alignment with distant axes, but you don't know what rotation to apply to it to achieve this wanted orientation.
There is a way to compute an Euler rotation from a set of axes :
var rot = BABYLON.Vector3.RotationFromAxis(axis1, axis2, axis3);
mesh.rotation = rot;
where axis1, axis2 and axis3 are three left-handed oriented orthogonal vectors.
With this code, the mesh will be aligned thus :
example : http://www.babylonjs-playground.com/#VYM1E#28 -
RotationFromAxis()
computes the required rotation value (Vector3) to assign to the mesh property .rotation
in order to rotate it along the passed axes.RotationQuaternionFromAxis()
computes the required rotation value (Quaternion) to assign to the mesh property .rotationQuaternion
in order to rotate it along the passed axes.toRef()
version.
Vector3.RotationFromAxis()
Vector3.RotationFromAxisToRef()
Quaternion.RotationQuaternionFromAxis()
Quaternion.RotationQuaternionFromAxisToRef()