Detecting collisions in the Forge viewer

In a recent post we saw that switching to use THREE.BufferGeometry brought some unexpected benefits when it came to rendering robots inside Dasher. I wasn’t very happy about the fact that said robots were spinning destructively on the MX3D bridge, so I started looking into options for collision detection inside a Forge viewer application.

From the start I should say that the approach that I ended up choosing is fairly rudimentary in nature: a much better solution would be to integrate a physics engine such as Ammo.js or perhaps even a voxelization engine such as VASA. But I figured that providing this simpler technique might still be of benefit for certain simpler situations.

The basic approach is outlined in this StackOverflow response and this GitHub example. The idea is to take the various vertices of your source mesh and then fire rays from the mesh’s position to each vertex: if the rays intersect the scene somewhere closer than the distance from the position to the vertex…

Read more