There is a function in my prototype system which detects intersections when you click on a Collada file. The intersect function is below:
function Intersectfun ( event ) {
mouse.x = ( event.clientX / window.innerWidth ) * 2 - 1;
mouse.y = - ( event.clientY / window.innerHeight ) * 2 + 1;
var vector = new THREE.Vector3( mouse.x, mouse.y, 1 );
var toIntersect = [];
THREE.SceneUtils.traverseHierarchy(scene, function (child) {
if (child instanceof THREE.Mesh) {
toIntersect.push(child);
}
});
// Unproject the vector
projector.unprojectVector(vector, camera);
var ray = new THREE.Ray( camera.position, vector.subSelf(camera.position).normalize());
var intersects = ray.intersectObjects( toIntersect );
if(intersects.length){
target = intersects[0].object;
}
}
But when I use the:
controls = new THREE.TrackballControls( camera, renderer.domElement );
The intersects matrix is empty and cannot detect intersections!!!
But when I use:
controls = new THREE.TrackballControls( camera );
I can get the intersects matrix and it works very well, but another problem is revealed (look at here: Three.JS -- conflict Camera controls with a textbox in a scene)
Is there any code in the above function? For your information, I have used a simple camera:
camera = new THREE.PerspectiveCamera( 40, window.innerWidth / window.innerHeight, 1, 10000 );
Thanks.