Dad72 Posted January 10, 2017 Share Posted January 10, 2017 hello, When I put a parent has an object, it is moved. Why ? I would like objects to stay in their place when an object is added as parent to another. http://www.babylonjs-playground.com/#L2MN5#0 (Pick on object to create parent and child. The object child is moved ?) Quote Link to comment Share on other sites More sharing options...
adam Posted January 10, 2017 Share Posted January 10, 2017 You need to do something like this if you want to maintain the global position and rotation of the child: http://www.babylonjs-playground.com/#L2MN5#1 another example: http://www.babylonjs-playground.com/#28IXSE#17 Dad72 1 Quote Link to comment Share on other sites More sharing options...
Dad72 Posted January 10, 2017 Author Share Posted January 10, 2017 Thank you Adam. I did not think we should have done so much to avoid this inconvenience. Is this a bug with mesh.parent = xmesh; ? Quote Link to comment Share on other sites More sharing options...
JCPalmer Posted January 10, 2017 Share Posted January 10, 2017 Assigning .parent is a setter not a direct assignment, so in theory you could adjust. Changing behavior could be an issue for pre-existing code. Not sure if you can add additional optional args onto a setter. Quote Link to comment Share on other sites More sharing options...
Dad72 Posted January 10, 2017 Author Share Posted January 10, 2017 Ok, I see. Thanks JSP Quote Link to comment Share on other sites More sharing options...
adam Posted January 10, 2017 Share Posted January 10, 2017 3 hours ago, Dad72 said: Is this a bug with mesh.parent = xmesh; It's not a bug. I was thinking about adding an addChild method to AbstractMesh. It would be pretty easy to add this as an option to that function. Dad72 1 Quote Link to comment Share on other sites More sharing options...
Dad72 Posted January 10, 2017 Author Share Posted January 10, 2017 Cool, thank you Adam Quote Link to comment Share on other sites More sharing options...
Dad72 Posted January 10, 2017 Author Share Posted January 10, 2017 Adam, the unparentMesh() function has a problem. The selection point of the child object is no longer in the center of the object but outside. parentMesh work perfectly. [edit] I believe that the problem comes from my code and not from the unparentMesh function that seems to be perfect too. Quote Link to comment Share on other sites More sharing options...
Numa Posted January 10, 2017 Share Posted January 10, 2017 I think the best way to go would be to have a setParent(parent, keepWorldPosition) function on AbstractMesh, with keepWorldPosition defaulting to TRUE, seems like what most people would expect when parenting. .parent should be a getter to avoid people setting it without doing any of the required calculations. Dad72 1 Quote Link to comment Share on other sites More sharing options...
Dad72 Posted January 10, 2017 Author Share Posted January 10, 2017 Completely agree with Numa. Quote Link to comment Share on other sites More sharing options...
adam Posted January 11, 2017 Share Posted January 11, 2017 PR submitted Dad72 1 Quote Link to comment Share on other sites More sharing options...
Dad72 Posted January 11, 2017 Author Share Posted January 11, 2017 Thanks Adam Quote Link to comment Share on other sites More sharing options...
adam Posted January 11, 2017 Share Posted January 11, 2017 No problem. I've seen this issue a few times and I'm glad there is now an easy solution. Numa 1 Quote Link to comment Share on other sites More sharing options...
Dad72 Posted January 11, 2017 Author Share Posted January 11, 2017 Yes, me to 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.