Can't get Three.js onDocumentMouseDown to work correctly

后端 未结 2 1781
再見小時候
再見小時候 2020-12-22 05:57

I\'ve looked at a lot of examples -- and borrowed from some -- and can\'t seem to get this to work right. What I want is for the raycaster in onDocumentMouseDown to pick up

2条回答
  •  长情又很酷
    2020-12-22 06:19

    Your Three.js canvas probably isn't at the top left of the screen, and you're not taking into account the offset from 0,0 on the page. To fix it, adjust the mouse position to subtract the offset.

    var rect = container.getBoundingClientRect();
    mouse.x = ((event.clientX - rect.left) / renderer.domElement.clientWidth) * 2 - 1;
    mouse.y = -((event.clientY - rect.top) / renderer.domElement.clientHeight) * 2 + 1;
    

提交回复
热议问题