Help is there difference from intersectsBox vs intersectsSphere

im getting false positives when im doing this, is there ay difference, the visual error is a lag beetween one frame and and another, sometimes the instance should appear but take one frame to appear and other time a instance should dissapear but still show one frame, box is being corrrectly calculated from object position plus half of object size

if (this.frustum.intersectsBox(data.collider.box)) { //intersectsSphere
    //console.log("showing instance",data.instance)
    this.showInstance(data.instance);
} else {
    //console.log("hiding instance",data.instance)
    this.hideInstance(data.instance);
}

on the other loop i have this and i checked with logs that vox is correctly beign updated always

data.collider.box = new THREE.Box3(

new THREE.Vector3(data.movement.position.x-data.collider.userData.size.x/2, data.movement.position.y, data.movement.position.z-data.collider.userData.size.z/2),
 
new THREE.Vector3( data.movement.position.x+data.collider.userData.size.x/2,  data.movement.position.y+data.collider.userData.size.y, data.movement.position.z+data.collider.userData.size.z/2 )
)

is it true that intersectsSphere is faster than intersectsBox?

Do your raycast after renderer.render.

Yes sphere intersect is faster than box intersect.

i actually moved away from raycasting im usign heighmap to calculate the position of any object in the terrain , what i found is that if i remove the part about checkign if camera has changed the code work, maybe its becuase the code is being executign many times in the same frame make the fix to itself

if (this.world.camera) {
const value = this.world.camera.rotation.changed || this.world.camera.position.changed || this.world.camera.zoom.changed
if (value) {
this.projScreenMatrix.multiplyMatrices(this.world.camera.getObject().projectionMatrix, this.world.camera.getObject().matrixWorldInverse);
this.frustum.setFromProjectionMatrix(this.projScreenMatrix);
//console.log(“visible tiles”,this.visibleTiles)
for (const key of this.visibleTiles) {
const bucket = this.tileBuckets.get(key);
if (!bucket) continue;
for (let i = 0; i < bucket.length; i++) {

            const data = bucket\[i\];
            //console.log("data",data)

            if (this.frustum.intersectsBox(data.collider.box)) { //intersectsSphere
                //console.log("showing instance",data.instance)
                this.showInstance(data.instance);
            } else {
                //console.log("hiding instance",data.instance)
                this.hideInstance(data.instance);
            }
        }
    }
    this.instancedMesh.instanceMatrix.needsUpdate = true;

}

} does it make any difference to run this.projScreenMatrix.multiplyMatrices(this.world.camera.getObject().projectionMatrix, this.world.camera.getObject().matrixWorldInverse);
this.frustum.setFromProjectionMatrix(this.projScreenMatrix);

all the time, im worried it consume too much resources

It depends how often you call it. Calling it 100 times in a frame is no big deal. Calling it 1 million times, might be a lot worse. :smiley:

It’s hard to know without seeing what/why you’re raycasting, to get a sense of how much the numbers will affect you.

what i did is to make the sphere 1.1 bigger so by the time the mesh bounding is visible it get evaluated once just before the real mesh is visible, seems to work fine