three.jsbounding-boxocclusion-culling

How to retrieve a bounding box's meshes in three js?


I am actually working on implementing some occlusion culling on three.js , and I want to know if there's a way ,from a THREE.Box3 , to retrieve all corresponding meshes that are inside this bounding box ?
does the bounding box in three.js keeps track of the meshes it contains ?
Thank you all .


Solution

  • Answering you questions in reverse order:

    No, a Box3 has no "sense of surroundings" If you want to keep a list of the meshes a Box3 contains, you'd need to build that list when you create the Box3, and maintain it as your scene and Box3 change.

    You can, however, GET all of those meshes by checking for bounding box intersections. One major caveat is that the boxes must be translated to their world transformations. This can make the intersection less accurate, because the bounding box will expand in order to contain the transformed part while remaining world-aligned.

    myMesh.geometry.computeBoundingBox(); // computes a LOCAL bounding box
    var tmpBox = new THREE.Box3().copy(myMesh.boundingBox);
    tmpBox.applyMatrix4(myMesh.matrixWorld); // converts tmpBox into a WORLD bounding box
    console.log("Boxes intersect:", someOtherWorldBox.intersectsBox(tmpBox)); // true/false