gamefan Posted April 14, 2017 Share Posted April 14, 2017 Hi, I am in a situation in which I want to add a parent to a mesh without changing the mesh's world rotation. For that I subtracted the parent's rotation from child before parenting. Sometimes the meshes have rotations as Quaternions (for both parent and child) , so to make the subtraction I convert them to euler using Quaternion.toEulerAngles(). This works perfectly for some orientation but not for others. Is this logic right? I want to know if there is some other way of doing this. Quote Link to comment Share on other sites More sharing options...
gamefan Posted April 14, 2017 Author Share Posted April 14, 2017 I have a playground http://www.babylonjs-playground.com/#KK6J9I#2 Quote Link to comment Share on other sites More sharing options...
adam Posted April 14, 2017 Share Posted April 14, 2017 You can use setParent or addChild for this: https://github.com/BabylonJS/Babylon.js/blob/master/src/Mesh/babylon.abstractMesh.ts#L1823 with keepWorldPositionRotation set to true. gamefan 1 Quote Link to comment Share on other sites More sharing options...
gamefan Posted April 14, 2017 Author Share Posted April 14, 2017 Works like magic. Thanks a lot . I have updated the playground : http://www.babylonjs-playground.com/#KK6J9I#4 Quote Link to comment Share on other sites More sharing options...
adam Posted April 14, 2017 Share Posted April 14, 2017 I just want to make sure you realize you don't need to use that makeParent function. You can do this: http://www.babylonjs-playground.com/#KK6J9I#5 Quote Link to comment Share on other sites More sharing options...
gamefan Posted April 14, 2017 Author Share Posted April 14, 2017 Yeah. Well, I am on 2.4. When I first saw your post, I searched for setParent in my babylon file. I wanted to use that but I didn't find it , so I thought its probably a new addition. adam 1 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.