Prevent two mesh from overlapping on eachother

I have used ExtrudeGeometry to create the boxes given in the below image. When I drag and drop the box over other box then it merge into one and doesn’t get separate. I need to drag each box individually.I have used MeshStandardMaterial for the box’s side.


You can use Box3 collision detection on the bounding box computed for each mesh. Box3 is axis aligned. If you need precise collision when boxes are rotated, used OBB collision. The OBB example can help with understanding OBB.

I wrote a helper class for performing collisions between boxes and spheres that might also be useful. demo is here