Save current rotation and apply the rotation stored to mesh

I’m implementing a Undo button. I need to save the current rotation of a mesh and then on Undo apply the stored value.

I tried saving this

var objRot= mesh.rotationQuaternion;

Then on Undo I do this:

selectedObj.rotationQuaternion = new BABYLON.Quaternion(objRot.x, objRot.y, objRot.z, objRot.w);

I see some values, but the rotation results always in a 0,0,0,0 rotation.

Any ideas how to save correctly a mesh quaternion and apply it after?


Hi. I would prefer to use rotation instead of quaternion.
Get the rotation from quaternion with


and on undo simply set mesh rotation, and set rotationQuaternion to null.
Or if you still want to try it with quaternions, then maybe this will help you,_rotation,_scaling#rotationquaternion

1 Like

In this PG

All three boxes are set to the same rotation using quaternions.

The top two are given further random rotations. Click on either of the top two followed by the update button and they are reset to their original rotation matching the lowest box.


rotationQuaternion is a JavaScript object. There are no value type structures in JavaScript and thus they don’t copy by value. I’m not exactly sure why you end up with all zeros (send a PG if you really want to find out), but you probably should create a new Quaternion for your “stored” backup value:

var objRot = new Quaternion();

Then, set it back by:



Thank you for your replies, I’ll work on your recommendations and let you know how it goes.


I have the same question, can you share any new progress?

Are you having problems with what has been suggested? If so would you please provide a playground showing your problem.

Some time ago we created “Undo position” (origin topic). Might be useful for you

Sorry, please forgive me,
I have solved it, please ignore