nicktendo Posted June 26, 2017 Share Posted June 26, 2017 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? Borislav 1 Quote Link to comment Share on other sites More sharing options...
Borislav Posted June 26, 2017 Share Posted June 26, 2017 I think yes. nicktendo 1 Quote Link to comment Share on other sites More sharing options...
GameMonetize Posted June 26, 2017 Share Posted June 26, 2017 Yes it is possible. just get mesh.getWorldMatrix() then you can use matrix.decompose: https://github.com/BabylonJS/Babylon.js/blob/master/src/Math/babylon.math.ts#L3281 nicktendo 1 Quote Link to comment Share on other sites More sharing options...
nicktendo Posted June 27, 2017 Author Share Posted June 27, 2017 @Deltakosh Awesome, thank you so much! Quote Link to comment Share on other sites More sharing options...
brianzinn Posted June 27, 2017 Share Posted June 27, 2017 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 Quote Link to comment Share on other sites More sharing options...
Art Vandelay Posted February 6, 2018 Share Posted February 6, 2018 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! Quote Link to comment Share on other sites More sharing options...
Guest Posted February 6, 2018 Share Posted February 6, 2018 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 Quote Link to comment Share on other sites More sharing options...
Art Vandelay Posted February 8, 2018 Share Posted February 8, 2018 @DeltakoshThat works, thanks! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.