How to detect intersections of two faces of two bufferGeometryBox?

I used it for simplicity and to show the conception, but it’s not the ultimate solution. If you’ve read How to find wall thickness of 3d models (STL) files? carefully, then at the end of it you could find the link to the SO answer with the solution of how to get a random point on a face (triangle).

You say, that you just copied a piece of code. But it’s irrelevant. It’s just a concept of how to get origin and direction for a raycaster. And in your case, you have to convert them from local coordinates to world coordinates. After that you have to find intersection with the cube that is opposite to the current one and use that concept with flags for sides. Thus, each cube you add to the scene already has to have .userData.sides property.

Please, read about .intersectObjects method of raycaster.