Performance problem when using raycaster

Hi to all!

It is necessary to put html tags disappearing behind the edge.
On small models work ( click mouse on model ):

But on big model ( 25mb ) works very slow ( click mouse on model ):

If disable disappear - norm ( click mouse on model ):

var raycaster = new THREE.Raycaster();

 function checkPointVisible(point, targetList) {
    let posLabel = point.clone();
    let posCam = camera.position.clone();
    let lenToLabel = posLabel.sub(posCam).length();
    raycaster.set(posCam, posLabel.normalize());
    let intersects = raycaster.intersectObjects(targetList, false);
    if ( intersects.length > 0 ) {
      if( intersects[0].distance < lenToLabel ) {
        return false;
    return true

Is there any other way to know object is displayed or behind and not visible… ?

IN JSFiddle … wait few seconds … ( click on sphere ):

137 line… :roll_eyes:

The problem is that your sphere geometry is way too complex. If you define it like so, the performance is much better.

var geometry = new THREE.SphereBufferGeometry( 10, 32, 32 );

Representing your geometry just as a THREE.Sphere will further increase the performance.

Besides, you should avoid object creation in code which is called from your animation loop. So define objects like posLabel or posCam once and reuse them in checkPointVisible(). Moreover, a for loop is better than foreach since you avoid the creation of an anonymous function per execution.

Working demo:


I put the example on the list for the sample collection.
Collection of examples from

Unfortunately it only works with Opera, Chrom but not with Firefox.:slightly_frowning_face:

1 Like

I searching for a long time - maybe there is some other way to determine whether the object is visible or not.
Big size model working fast without check visibility:

But not find. I will disable labels for large models.

Thanks for the recommendations!!!

Small mistake: e/event in mouse listener ( not working in firefox ). Corrected: