我试图检测鼠标何时悬停在我的粒子系统中的粒子上。我正在做的检测是这样的,并且在每一帧上运行:
function check_intersections() {
var vect = new THREE.Vector3(
mouse.x,
mouse.y,
0.5
);
projectr.unprojectVector( vect, camera );
var raycaster = new THREE.Ray( camera.position, vect.subSelf( camera.position ).normalize() );
var intersects = raycaster.intersectObjects( particleSystem );
if ( intersects.length > 0 ) {
//intersects[ 0 ].object.materials[ 0 ].color.setHex( Math.random() * 0xffffff );
noticeDiv.text('Intersection');
}
}`
varparticleSystem 是我的粒子系统,其中包含数千个粒子,鼠标在移动时定义为:
function onDocumentMouseMove( event ) {
// update the mouse variable
mouse.x = ( event.clientX / window.innerWidth ) * 2 - 1;
mouse.y = - ( event.clientY / window.innerHeight ) * 2 + 1;
}
我看过几个例子,但似乎无法正确理解这一点。