如何在三个js上为精灵添加事件监听器?

时间:2018-02-19 13:29:26

标签: events three.js

我在三个JS中的三维地球上有几个标记。我试过这个

function onDocumentMouseDown( event ) {

  event.preventDefault();

  mouse.x = ( event.clientX / renderer.domElement.clientWidth ) * 2 - 1;
  mouse.y = - ( event.clientY / renderer.domElement.clientHeight ) * 2 + 1;

  raycaster.setFromCamera( mouse, camera );

  var intersects = raycaster.intersectObjects( objects );

  console.log('outside');

  if ( intersects.length > 0 ) {

    console.log('inside');

      intersects[0].object.callback();

  }

}

document.addEventListener( 'click', onDocumentMouseDown, false );

但它总是印在“外面”。我应该将事件添加到精灵本身吗?或者到父网格?感谢。

仅供参考,callback来自marker.callback = function() { console.log( 'HERE !!!' ); }

0 个答案:

没有答案