Recently, I've been delving into the world of three.js to determine if a ray intersects with an object.
My scene is all set up and looking great!
I tried clicking on the sphere that I created using the following code:
var intersected_objects = [];
//Setting up the scene, objects, and events
scene = new THREE.Scene();
group = new THREE.Object3D();
sphere = new THREE.SphereGeometry(23.8, 60, 60);
//Adding meshes, textures, etc.
intersected_objects.push(group);
function onDocumentMouseUp(event) {
event.preventDefault();
var mouseX = (event.clientX / window.innerWidth)*2-1;
var mouseY = -(event.clientY /window.innerHeight)*2+1;
var vector = new THREE.Vector3(mouseX, mouseY, 0.5);
projector.unprojectVector(vector, camera);
var ray = new THREE.Raycaster(camera.position, vector.sub(camera.position).normalize());
var intersections = ray.intersectObjects(intersected_objects);
console.log(intersections.length); //Always returning 0
}
Despite my efforts, the length of intersections array always remains at 0. Isn't it supposed to intersect with the sphere?