Jump to content

Get absolute rotation of child mesh...


nicktendo
 Share

Recommended Posts

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

 

Link to comment
Share on other sites

  • 7 months later...

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!

Link to comment
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

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...