How to get absolute rotation of a parented mesh?

How do I get the “absolute rotation” after I remove the parent? When I no longer want a parent attached to the mesh, I want to remove the parent attribute but keep the position and rotation its currently at prior to its parent set to null. Cloning the “rotation” attribute doesn’t work correctly. I need the absolute rotation.

this.entity.mesh.parent = box;
// entity moves around randomly at this time.

setTimeout(() => {
 const oldPos = this.entity.mesh.getAbsolutePosition().clone();
    const oldAngle = this.entity.mesh.rotation.clone();

    this.entity.mesh.parent = null;

    this.entity.mesh.position = oldPos;

    // doesnt work correctly.
    this.entity.mesh.rotation = oldAngle;
}, 10000)

Old forum Get absolute rotation of child mesh... - Questions & Answers - HTML5 Game Devs Forum

1 Like

Beautiful, and for anyone who also has this question, this still works in Babylon.js 4

var rotation = Quaternion.Identity()
var position = Vector3.Zero()

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

if (child.rotationQuaternion) {
} else {

child.parent = undefined

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