In my case the great simplification is that case sizes are all multiple of a base tile of 10x10x10. Then I do not need true collision detection but work with an imaginary 3D array. Each cell of this array keeps track if it is occupied and which box occupies it.

Then its all about position calculation and projection on the Z index. For example the calculation of the position of the projection box (that imaginary thingie which appears red or green on the floor) is done with something like this:

```
// currentMesh is the floating mesh you are moving
// projectionBox is the projected box on the floor
let currentPosition = currentMesh.position.clone();
// Make projectionBox fit into our grid
currentPosition.x = Math.round(currentPosition.x);
currentPosition.y = Math.round(currentPosition.y);
currentPosition.z = Math.round(currentPosition.z);
let canDrop = false;
// Start on same height as currentMesh, find which is the last height where mesh could be dropped
do {
currentPosition.y -= 0.5;
canDrop = CasePiler.checkCanDropAtPosition(projectionBox, currentPosition);
if (!canDrop) {
currentPosition.y += 0.5;
break;
}
} while (currentPosition.y > 0);
projectionBox.position = currentPosition;
```

And when I need the placed box to appear in the selected position just clone the floating box and position it adequately:

```
let placedBox = currentMesh.clone();
placedBox.position = new BABYLON.Vector3(projectionBox.position.x, projectionBox.position.y, projectionBox.position.z);
CasePiler.addToCasesMap(placedBox);
projectionBox.dispose();
```

A function I use in some key places in the code which was most hard to understand was “getGroundPosition” which as far as I can remember calculates the projection of a point on a plane. I used another example from the playground which I can’t find, but the most similar I can see is this one:

https://www.babylonjs-playground.com/#060K58#8

Try to move a chair around …

Peli products are great !!! Each time I have a meeting with them I cross my fingers to see if they give me a laptop case but still no luck !!

I hope it was useful. If you have any more things you would like to clarify go on or just message me.