It looks that "raycaster.intersectObjects" does not react (using Three.js r54). The extraction from the code (with the important parts) is the following:
var renderer = new THREE.WebGLRenderer();
renderer.setSize( window.innerWidth, window.innerHeight );
document.body.appendChild( renderer.domElement );
var camera = new THREE.PerspectiveCamera( 45, window.innerWidth / window.innerHeight, 1, 1000 );
camera.position.z = 75;
scene = new THREE.Scene();
document.addEventListener( 'mousedown', onDocumentMouseDown, false );
var raycaster = new THREE.Raycaster();
var mouseVector = new THREE.Vector2();
function onDocumentMouseDown( e ) {
e.preventDefault();
mouseVector.x = ( e.clientX / window.innerWidth ) * 2 - 1;
mouseVector.y = - ( e.clientY / window.innerHeight ) * 2 + 1;
var intersects = raycaster.intersectObjects(scene.children, true);
console.log(intersects);
if (intersects.length>0){
intersects[ 0 ].object.material.color.setHex( Math.random() * 0xffffff );
}
}
function render() {
requestAnimationFrame(render);
mesh.rotation.y += 0.005;
renderer.render(scene, camera);
}
I put inside the code "console.log" to debug the problem, and found that it outputs the empty array in the console. Between, I get the output of the empty array, not depending whether I clicked the certain object or just the background.