# Get absolute rotation of child mesh...

## Recommended Posts

Is it possible to get the absolute rotation of a child mesh, in the same way it is possible to get the absolute position of a child mesh via mesh.getAbsolutePosition?

I think yes.

##### Share on other sites

@Deltakosh Awesome, thank you so much!

##### Share on other sites

Deltakosh has the answer, but just wanted to add that in case you are trying to unparent a child mesh and keep rotation, in BJS 3.0 there is a setParent(mesh) in AbstractMesh - pass in null to unparent.
https://github.com/BabylonJS/Babylon.js/blob/master/src/Mesh/babylon.abstractMesh.ts

If not then here is a code sample of using decompose - don't forget to check if rotationQuaternion has been set, because otherwise rotation will have no effect:

``````// here is how you could unparent a child mesh, while keep rotation and position.
var rotation = Quaternion.Identity()
var position = Vector3.Zero()

child.getWorldMatrix().decompose(Vector3.Zero(), rotation, position)

if (child.rotationQuaternion) {
child.rotationQuaternion.copyFrom(rotation)
} else {
rotation.toEulerAnglesToRef(child.rotation)
}

child.parent = undefined

child.position.x = position.x
child.position.y = position.y
child.position.z = position.z``````

##### Share on other sites

Hi,

Just found this thread. @DeltakoshWhat if wanted to SET the absolute rotation of a matrix?

What I thought of doing was decomposing the worldMatrix, updating the rotation quaternion and then "recomposing" the world matrix with the updated rotation quaternion. I'm not sure how to do that though, or even if that really makes sense... Is there a simpler way?

Thanks!

##### Share on other sites

if the object has no parent then your code will work. If the mesh has a parent then it will be tougher as you need to compensate. Best option: call setParent(null), do your change and call setParent(parent) again

##### Share on other sites

@DeltakoshThat works, thanks!