How to generate random box inside camera frustrum?

I’m trying to randomly generate a box inside the camera frustrum. Currently I’m just manually doing the trig+geometry to figure out where to generate the box. Is there an easier way to do this? I also have issues with the box just barely clipping outside the frustrum

There is not easier way to do this, I think you are must write frustum volume calculation function, after that u must calculate random center positions for your box to inside of your frustum, that must dynamically changed from your box geometry sizes. If you want i can take example of frustum volume calculation function and random positions calculation function

I had a more or less similar problem to yours, needing a back side sphere to fit the most of the camera frustum and avoid clipping artefacts. In the end skipped the geometry / trigonometry calculations and just set camera.near to 0.01, camera.far to 720000 and the sphere radius to 200000 and it works fine. So, in my case, the trial and error method was the easiest way to do that.

In your case, calculating things manually is feasible, but since you’re looking for an easier way, you might want to look into the Three.js Frustum class, I believe there are a couple of methods there that suit your scenario. You’d probably have to do a .setFromProjectionMatrix() using the camera’s projection matrix first (along the lines of frustum.setFromMatrix(new THREE.Matrix4().multiplyMatrices(camera.projectionMatrix, camera.matrixWorldInverse));), then choose whichever of the .containsPoint(), .intersectsBox() or .intersectsObject() matches your objective best and work on from there.

Now that I think of, maybe I could have used some similar approach in my case as well … if I only knew about it at the time.