digEmAll Posted January 4, 2018 Share Posted January 4, 2018 Hi All, the issue I'm facing is probably trivial to solve but I couldn't find a solution. Basically I need to set the parent of a mesh (used as rotation pivot) to null after a rotation, because I need to use that pivot again for another group of meshes. I tried to use the following approach: var pos = box.getAbsolutePosition(); var rot = box.rotation; box.parent = null; box.setAbsolutePosition(pos); box.rotation = rot; but it seem to keep only the position, but not the rotation. I have created a simple playground to reproduce the problem : https://www.babylonjs-playground.com/#S13YXG#2 As you can see, when the animation is completed the bigger box returns to the original rotation. Any suggestion ? Thanks a lot in advance Quote Link to comment Share on other sites More sharing options...
aWeirdo Posted January 4, 2018 Share Posted January 4, 2018 Hi @digEmAll As you're using rotationQuaternion, box.rotation won't do anything. furthermore, you should clone the values instead of referencing them (reference will change as the box.parent is removed) var pos = box.getAbsolutePosition().clone(); var rot = box.parent.rotationQuaternion.clone(); box.parent = null; box.setAbsolutePosition(pos); box.rotationQuaternion = rot; https://www.babylonjs-playground.com/#S13YXG#4 dbawel and digEmAll 2 Quote Link to comment Share on other sites More sharing options...
digEmAll Posted January 4, 2018 Author Share Posted January 4, 2018 Thanks a lot! It was easy after all Quote Link to comment Share on other sites More sharing options...
brianzinn Posted January 4, 2018 Share Posted January 4, 2018 That code might work in your case, but I think a better way to do it is in one line with mesh.setParent(null):https://github.com/BabylonJS/Babylon.js/blob/master/src/Mesh/babylon.transformNode.ts#L464https://www.babylonjs-playground.com/#S13YXG#6 digEmAll 1 Quote Link to comment Share on other sites More sharing options...
digEmAll Posted January 5, 2018 Author Share Posted January 5, 2018 Thanks @brianzinn, that's great ! 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.