Raycast is not working properly in three.js

I load the gltf model in scene and when I raycast the model then sometimes it works and sometime its now work even if I click surrounded the model then it give me the intersect object .So is there any way to handle which give me proper intersect where I click on the model or not give me the intersect value where I click on the scene .Thanks

mouseMove(event)
{   
    pointer.x =  (( event.clientX )/ window.innerWidth ) * 2 - 1;
    pointer.y = -(( event.clientY )/ window.innerHeight ) * 2 + 1;
}

pickModel()
{          
    
        raycaster.setFromCamera(pointer, camera);
        let intersects = raycaster.intersectObjects(scene.children,true);
        
        if (intersects.length>0 && intersects[0].object.name!=''){ 
            console.log(intersects[0].object);

        }
}

/cc

As mentioned at stackoverflow, please share a complete live example that demonstrates the issue.

1 Like