three.jshelperintersectionsceneraycasting

How To exclude helper objects from intersection check by raycaster in threejs?


I have a threejs scene with intersection checking on objects. I'm adding every scene object to the array which is then checked by the raycaster.

var intersects = raycaster.intersectObjects( scene.children );

I then check the color of an object and change it on contact with the mouse pointer.

INTERSECTED.material.emissive.setHex( 0xff0000 );

If I add a helper object, like CameraHelper or GridHelper, to the scene I get constant errors because .getHex .setHex is not possible with the helper objects.

Is it possible to exclude the helper objects from this check and how would I do this?

It has to be something like scene.children - scene.helpers but I cannot come up with a way to do this. Thanks for the help.


Solution

  • Create an array of objects that you want Raycaster to process.

    var objects = [];
    
    objects.push( mesh1 );
    objects.push( mesh2 );
    
    ---
    
    var intersects = raycaster.intersectObjects( objects, recursiveFlag );
    

    three.js r.73