Set "Absolute Orientation" of a Mesh?


Is there a way to reset the “absolute orientation” lets call it of a mesh? For example I imported a gun mesh but it was all out of wack so I had to scale and rotate it to be in the starting position I wanted. Is there a way to set this new scaling/rotation as the starting scaling/rotation (aka zeroed out)?


you can simply set mesh.rotationQuaternion = null and mesh.rotation = BABYLON.Vector3.Zero()

That will cancel all rotation. but you may end up finding that the rotation is actually baked into the geometry then and in this case you will have to bake the counter part (I can show you how if you create a repro in the PG)

1 Like

The other thing which could complicate / explain things is the origin of the mesh might not be where you think it is. In the case of a gun, you might think all the vertices would be based from the trigger for ease of attachment, but it also could be end of the stock, center, or elsewhere. It does not even need to be on the surface of the mesh.

That can affect rotation greatly. An easy to find is to create a very small sphere, and place at the same position as the gun.

1 Like

You can use mesh.bakeCurrentTransformIntoVertices() to apply the current transformation matrix to the vertices.

Hmm. It seems I need a new Quarternion(0, 1, 0, 0) to be applied to the mesh upon it being loaded into the scene in order to get the gun to face the same direction the is facing . I am just wondering if its possible to tell Babylon "Hey that new Quarternion(0, 1, 0, 0) position is actually now the guns new Quarternion(0, 0, 0, 0)

Thankyou! This is what i needed!

Thanks for the help. This got me on the right track to understanding rotations better :slight_smile:

I have discovered that the center of rotation is indeed the center of the mesh. Just curious is it possible to update the origin of rotation? Might need to learn this for future use

You should be able to use setPivotPoint / setPivotMatrix for that.

1 Like