Reset angle of an axis

What’s the best way to set an axis rotation to a number other than what it is without the axis moving?

So, after positioning an item in a scene the z axis shows to be at 270 degrees but I would like it reset to 0 degrees and the axis position to remain in the same spot. I can probably use an offset but first I like to try to reset it. Can’t seem to find an example playground that does this type of reset.

Thanks!

–Rob

Hi @rmorgan001,

The best way to achieve this is by using the bakeCurrentTransformIntoVertices() method. This “reset” the current rotation to the mesh geometry and resets the rotation values to zero without moving the object visually.

Check out the example in the Playground to demonstrate this, in which a small trick was added to ensure that the pivot point stays at the center of the mesh during the reset.

Bake Transform Into Vertices Example

Let me check it out. Thanks for the information! When attached to a parent do the rules change?

–Rob

Not really! The method works on local space, so it will reset the child’s rotation to zero relative to its parent while maintaining its visual orientation. The logic remains the same.

Thanks for the information. I’ve just about got it all working but I’ll ask another question.

bakeCurrentTransformIntoVertices() basically zeros out all axes without visually moving them. If I wanted to do this then set one of the axis to something other than 0 can this be done without a visual change? Maybe something like this…

bakeCurrentTransformIntoVertices() rotation set to 0,0,0

bakeCurrentTransformIntoVertices.y = BABYLON.Angle.FromDegrees(90).radians();

I end up with 0,90,0 converted and no visual change.

thanks

–Rob

Hi,

To do this, subtract your target angle from the current rotation before baking, then set it back:

mesh.rotation.y -= BABYLON.Angle.FromDegrees(90).radians();
mesh.bakeCurrentTransformIntoVertices();
mesh.rotation.y = BABYLON.Angle.FromDegrees(90).radians();

Yes, that was my backup plan :slight_smile:

Thanks!

1 Like