mrdoob/three.js — Issue #1479: projector
Author: chkpk
Created: 2012-03-09 14:35:08+00:00
State: open

i added some	cubes and particles with image textures to the scene,
but i cannot interact with the particles while there is no problem interacting with the cubes.
is there any way to interact	with particles? the particles are all textured with a image. what i need to realize is that when the mouse move pass the image(stands for a particle), the color of the image changes.
Or maybe it is just impossible and i have to replace all the particles with cubes?
thank you very much!

my code was copied from this demo: three.js / examples / webgl_interactive_cubes.html

projector = new THREE.Projector();

// find intersections
var vector = new THREE.Vector3( mouse.x, mouse.y, 1 );
projector.unprojectVector( vector, camera );

var ray = new THREE.Ray( camera.position, vector.subSelf( camera.position ).normalize() );

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

//console.log("length:"+intersects.length);
if ( intersects.length > 0 ) {

console.log("length:"+intersects.length);
if ( INTERSECTED != intersects[ 0 ].object ) {

if ( INTERSECTED ) INTERSECTED.material.color.setHex( INTERSECTED.currentHex );

INTERSECTED = intersects[ 0 ].object;
INTERSECTED.currentHex = INTERSECTED.material.color.getHex();
INTERSECTED.material.color.setHex( 0xff0000 );

}

} else {

if ( INTERSECTED ) INTERSECTED.material.color.setHex( INTERSECTED.currentHex );

//console.log("no object: " + mouse.x + ' ' + mouse.y);
INTERSECTED = null;

}