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) {
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
1 Like

hey There!
looking for parented mesh world rotation at the moment…
do you happend to have a playground using that technique?

cheers!

Waking up a 4 years old topic might not work as expected :slight_smile:
The method, however, should still work correctly. Have you tried it?

1 Like

yeah! that is actually true…

I couldn’t understand how to apply it. I’m not such a great coder
But found a differnte solution one minute ago!

mesh.rotationQuaternion = nestedMesh.absoluteRotationQuaternion;

That solved what i wanted to do :slight_smile:

1 Like