How to rotate/position meshes independently

Hello,

I’m stuck doing something that seems like it should be kind of simple:
I want to set the absolute position and rotation (about that position) of a given mesh. That is the position should determine the center point of the mesh, and the rotation should determine rotation around that position.

I have read:
https://babylonjsguide.github.io/intermediate/Translate
https://doc.babylonjs.com/features/position,_rotation,_scaling
https://doc.babylonjs.com/how_to/rotate

but honestly none of them have made this any clearer.

Setting position is as easy as:
mesh.position = new Vector3(x,y,z)

I have tried applying the rotation with all of the following methods:
mesh.rotate()
mesh.addRotation()
mesh.rotationQuaternion = …

But none of them rotate around the position, instead they rotate around 0,0,0. Switching between local and global space doesn’t help either.

What is the ‘right’ approach to doing this? I tried saving the position elsewhere and then applying the inverse rotation to the position but this doesn’t have the desired results at all.

These may help
https://doc.babylonjs.com/how_to/pivots
https://doc.babylonjs.com/how_to/pivot

Thanks!

It turned out my problem was a bit simpler than that.

The way I was handling meshes was I would load the glb file then add all the meshes into a list. When I wanted to rotate/position that model I would apply the same rotation/position to all the meshes. This caused havok because some of the meshes were children of the parent and position/rotation propagate. I fixed my code to only add parent meshes to the list.

The other minor note was my surprise that:
mesh.rotation.x = …; // Does nothing
mesh.rotation = new Vector3(…); // Works

I suspect the answer is pretty simple, the first line probably works like this: (mesh.rotation).x = …; // Gets the rotation, changes one of the vector properties and then dumps the temporary vector.

Still it wasn’t what I’d expected initially.

I expect it is because of this https://doc.babylonjs.com/resources/rotation_conventions#historical-warning

Setting the rotation as a full Vector3 applies the null value to the rotationquaternion, just setting a x, y or z property directly will not trigger the null