luka_friend Posted December 7, 2014 Share Posted December 7, 2014 Hello!I am trying to create a grid of bar elements (to form some kind of net) and I was wondering if there is a way to group these bars, so when I want to move the net, all of the children objects would move also. EXAMPLE:var bar1 = new BABYLON.Mesh.CreateBox(name, 1, scene);var bar2 = new BABYLON.Mesh.CreateBox(name, 1, scene);var bar3 = new BABYLON.Mesh.CreateBox(name, 1, scene); <-- how do I group bar1, bar2, bar3 so that I could use :group.position.x = 10; Quote Link to comment Share on other sites More sharing options...
Wingnut Posted December 7, 2014 Share Posted December 7, 2014 Hi LF! In this system, you group things with .parent // make a parent object...var myparent = new BABYLON.Mesh.CreateBox("myparent", 1, scene); // make kids and set their .parent properties...var bar1 = new BABYLON.Mesh.CreateBox(name, 1, scene);bar1.parent = myparent; var bar2 = new BABYLON.Mesh.CreateBox(name, 1, scene);bar2.parent = myparent; var bar3 = new BABYLON.Mesh.CreateBox(name, 1, scene);bar3.parent = myparent; [ position and rotate the children... in this area ] // now you can move them as a group...myparent.position.x = 2; // and hide the parent if you wish...myparent.isVisible = false; From then-on, you can position, rotate or scale myparent, and the children will come along. Notice that it is important to position and rotate the children... AFTER they have been parented to the "gizmo" parent. Any rotations, positioning or scaling of the child, prior to setting a parent on them, will get "nulled out". Experiment. Good luck. Quote Link to comment Share on other sites More sharing options...
luka_friend Posted December 8, 2014 Author Share Posted December 8, 2014 Almost forgot to thank you - - > THANK YOU WINGNUT Wingnut 1 Quote Link to comment Share on other sites More sharing options...
anurag Posted December 11, 2014 Share Posted December 11, 2014 In this case, only parent dictates the position and scaling. Is it possible to group them in a way that even if a child is moved, all the group members should also reflect the same? Quote Link to comment Share on other sites More sharing options...
reddozen Posted December 11, 2014 Share Posted December 11, 2014 you could assign a tag then search for tags. Quote Link to comment Share on other sites More sharing options...
anurag Posted December 12, 2014 Share Posted December 12, 2014 yeah that can be done.In my case as there are fixed number of models, I ended up removing the parent child relationship and applied the scaling and position for all models simultaneoulsy on mouse action. Quote Link to comment Share on other sites More sharing options...
securet Posted December 19, 2016 Share Posted December 19, 2016 is there a way to access the children of a parent? Like parent.getArrayOfChildren()? Quote Link to comment Share on other sites More sharing options...
Kesshi Posted December 19, 2016 Share Posted December 19, 2016 1 hour ago, securet said: is there a way to access the children of a parent? Like parent.getArrayOfChildren()? you can use parent.getChildMeshes() or parent.getDescendants() Quote Link to comment Share on other sites More sharing options...
securet Posted December 19, 2016 Share Posted December 19, 2016 k, ty Quote Link to comment Share on other sites More sharing options...
pepelito Posted May 28, 2017 Share Posted May 28, 2017 On 12/11/2014 at 11:09 PM, reddozen said: you could assign a tag then search for tags. what this means? is it sarcastic or i am not understanding? Quote Link to comment Share on other sites More sharing options...
Wingnut Posted May 30, 2017 Share Posted May 30, 2017 Hi @pepelito The tags system is an advanced search-for-scene-items system. It allows advanced searching thru scene.meshes, scene.lights, scene.cameras... using wildcards and pattern matching, etc. Some common tags might be... tree, bush, building, bridge, road, etc. These searches would allow you to "derive" a group of ALL TREES. Then you could use the meshMover code we talked about... to iterate thru all the trees, and move them as a group. Not many people use the Babylon tags system, but it is quite powerful... SUPER handy for scene layout of large scenes. In a way, tags allow you to build your own personal database[keys] for scene items. You could build your own interface to scene... like world.trees.pine.small... etc. *shrug* Hope this helps. Other commenters might have better words. Quote Link to comment Share on other sites More sharing options...
reddozen Posted May 31, 2017 Share Posted May 31, 2017 You can see how I used tags in this loader. I define sub regions on the map with tags to control visibility. http://red12.studio/Demos/Web/Include/Loaders/map_loader.php?region=1&zone=1 Wingnut 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.