Jump to content

Align randomly created boxes with grid on plane


Majeed Siddiqui
 Share

Recommended Posts

I would like to create boxes of random size that should align with grid squares. For example, if grid is 8x8 square and there is a box of size 2x3 then it should exactly take 2x3=6 square on grid. Is there any way to force this? Actually I want have drag and drop for those boxes that's why this restriction is needed. Or do I have to do maths stuff to force this? Something like shown in image. http://www.babylonjs-playground.com/#26LMDE#0

I am using one of these to implement grid: 

 

Screen Shot 2016-08-08 at 11.41.09 AM.png

Link to comment
Share on other sites

Hi guys!

http://playground.babylonjs.com/#HHFBT#2

I modified our drag'n'drop playground demo... added a little value-rounding.  I used a 500x500 grid divided 50 times, so each cell is 10x10.

Lines 89-92 are the rounding function, of course.

Line 109 is where we use the rounding on our X and Z values, but leave Y value alone. Diff is the AMOUNT of change, and it is added to the current mesh.position... in line 112.

Looks like it works.  This is only for dragging.  You will still need to position your mesh at proper places on the grid.... when you CREATE the mesh.  Some might call that initial positioning... "calibration-to" or "synchronizing-with" ...the grid.  :)  You need to "sync-up", first thing, after mesh creation/import.

There's still one minor problem.  The wireframe grid (called ground2) also let's you drag IT around, and ground2.isPickable = false doesn't stop it from being so.  Oh well, a good secondary challenge.  :)

Hope this helps.  Party on!

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...