Jump to content

How to group multiple small boxes under one big box?


Majeed Siddiqui
 Share

Recommended Posts

I have few small boxes which I want to fit in big box. e.g I have 4x3, 4x4, 4x8 small boxes. And one big box of 4x(3 + 4 + 8 = 15) => 4x15. I want all these small boxes to be aligned in one line. Which are covered by big box. This big box is not visible at very close distance from camera only small boxes are. But it hides all the small and displays it self only at large distance from camera. How do I achieve this?

Edit 1: I have drag and drop functionality thanks to @Wingnut, so doing drag and drop on big box should affect small boxes. 

Link to comment
Share on other sites

Hi @Majeed Siddiqui 

I made a simple PG with a custom create box function for you to start experimenting, you can create a new box by typing;

var box1 = newBox(sizeX, sizeY, sizeZ, scene);

check it out, and play around with it, if you need further help, don't hesitate to ask :)

everything needed to know, should be commented in the code.

http://www.babylonjs-playground.com/#1KH9RY#2

Link to comment
Share on other sites

Thanks @aWeirdo! I know how to create basic boxes. How do I club all small boxes into big one?

Solution I tried: Creating small boxes and setting their parent as big box. This fails miserably! The big box acts as pivot instead of covering these small boxes. I know I can achieve the view of mesh through LOD.

I want a simpler mechanism. Like big box acting as container for small boxes.

Link to comment
Share on other sites

Hi again @Majeed Siddiqui

Take a look at what i did here: http://www.babylonjs-playground.com/#1KH9RY#3

depending on where i want the box, I offset the little box by half it's own scaling(size) either minus or plus, aswell as the bigBox position, and then half the bigbox's scaling(size), again, either plus or minus depending on where i want the box :)

 

Note that using scaling as a mesh's size only works "out of the box" when the mesh is created with a size of 1 and then scaled to the wanted size.

Link to comment
Share on other sites

Hi @Majeed Siddiqui et al. First of all if you want to create boxes of specific sizes use MeshBuilder, then there is no problem with scaling affecting  children. Also 4 x 3 is the dimensions of a rectangle not a box, so what is the other dimension?

This PG may not be exactly what you want but it shows how MeshBuilder can be used to align boxes in a box.

 

http://www.babylonjs-playground.com/#1KH9RY#5

Edited by JohnK
missing link added
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...