Reset a models rotation which has been rotated via the pointer

Hello,
i would like to reset the transformations done by a pointer input to a model via an animation but I cant seem to figure out which properties of the scene are being used for the pointer based rotation.
Here is playground example:
https://www.babylonjs-playground.com/#BYNTRS
After loading the model, a rotation animation starts.
when the user drags the object around the animation stops and starts again after the POINTERUP event.
However I would like the model to rotate back also on each axis to the initial view.

I guess the pointer drags and rotates a different object then the one i am animating?

a simple would adding a parent, where the rotation happen so that you know you simply need to rotate back to 0 0 0 work ?

Thank you.
Well I am actually trying to figure out what I am rotating :slight_smile:
In my code I use the scene.meshes[0] as the target for the auto-rotation.
But What element is rotated by the pointer? the scene itself?

Ohhhhhhhhhhh I see, the camera is rotating not the object with the pointers

is it? I thought I was rotating the mesh? :thinking:

1 Like

You are cause you call in attachControl so by default the camera answers to the pointers. If you want to use the mesh manually, you can disable the attachControl like here:

https://www.babylonjs-playground.com/#BYNTRS#1

And then integrate your custom code.

Thanks, but I a not quite sure if I follow you.

This PG rotates the box not the camera https://www.babylonjs-playground.com/#K4UGI8#9

See line 8 the camera is not attached to the canvas, ie pointer events on the canvas are not sent to the camera.

2 Likes

great. thank you!

Hello:
this is a follow up to my question:
The rotation works nicely and now i am trying to reset the model’s rotation via an animation when the user is idle for a certain time.
For that I create an animation with:

new BABYLON.Animation('rotation_animation', 'rotation', 60, BABYLON.Animation.ANIMATIONTYPE_VECTOR3, BABYLON.Animation.ANIMATIONLOOPMODE_RELATIVE);

What confuses me a bit:
In the pointer code the rotation is done with:

ani_body.rotate(BABYLON.Axis.X, angleX, BABYLON.Space.WORLD);
ani_body.rotate(BABYLON.Axis.Y, angleY, BABYLON.Space.WORLD);

however when I check for the body’s current rotation with

console.info(ani_body.rotation);

I always get:

Object { x: 0, y: 0, z: 0 }

Are there two different kinds of rotation involved here?

The model is probably using quaternions you should check console.info(ani_body.rotationQuaternion);

Thank you.
It does indeed.
Do I need to convert the units, or can I animate rotationQuaternion?
Since in the final version there will be different models can the behaviour be changed, or is it embedded in the model?

The rotate function will animate the rotationQuaternion without any issues.

You could the behavior by setting rotation to rotationQuaternion.toEulerAngles() and then setting the rotationQuaternion to null but I would advise against it if you could end up in gimbal lock situations: Gimbal lock - Wikipedia

2 Likes