Jump to content

Grouping objects


luka_friend
 Share

Recommended Posts

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;

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

  • 2 years later...
  • 5 months later...

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.

Link to comment
Share on other sites

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.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...