Need some help with something. Any ideas are welcome. I’m making an app where you can configure a room and move around objects using Transform Controls.
Need to ensure that objects do not go through walls/floors and other objects in the scene (collisions).
When using TransformControls, l found out that you can actually actually translate through other meshes, it just goes through. BUT l need functionality for translate/rotate/scaling in my scene.
Issue: In the screenshots below, you can see how a translated chair can go through the table.
Ideally: Need to stop the prevent this in an intuitive way. Same will go for walls/floors
Anyone with any idea on how to approach this…
The jankiest way is to use the raycaster to cast rays out in the 8 directions from the center of the object, and then stop the drag if any of the rays hit closer than the mesh bounds min/max.
or to cast 12 rays along the edges of the bounding box, and stop the drag if any of those hit anything.
These schemes break if dragging you drag the thing into something small/skinny enough to fit between the rays/edges etc.
A more robust way is to the use the excellent mesh-bvh library:
and do a shapecast of the bounding box against the bvh tree of the scene. The bvh tree can end up having other useful things too, so I recommend checking it out at least to familiarize yourself with what it can do. there are some good examples/demos on the page:
Specifically: three-mesh-bvh - Geometry Lasso Selection
and perhaps this one if you think of your chair as the character in the sample and instead of a capsule you use a box: three-mesh-bvh - Character Movement