Majeed Siddiqui

How to group multiple small boxes under one big box?

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. 

Share this post


Link to post
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

Share this post


Link to post
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.

Share this post


Link to post
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.

Share this post


Link to post
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

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Recently Browsing   0 members

    No registered users viewing this page.