Three.js prevent Raycast through Gui

你说的曾经没有我的故事 提交于 2020-02-25 03:44:07

问题


I want to select objects with raycasting, but everytime i want to select something on the three.js gui, the Mousdownevent get triggered. How can i say something like "if the Gui is in front of the object, dont trigger"

document.addEventListener( 'mousedown', onDocumentMouseDown, false ); function onDocumentMouseDown( event ) { if (event){}

the gui is a normal three.js gui made like this:

gui = new GUI( { width: 330 } );

回答1:


One way to solve this is with jQuery and an additional control variable:

$( gui.domElement ).mouseenter(function(evt) {

    enableRaycasting = false;

} );

$( gui.domElement ).mouseleave(function() {

    enableRaycasting = true;

} );

You can then use enableRaycasting in order to determine if raycasting should happen.

Demo: https://jsfiddle.net/gnwz5ae7/



来源:https://stackoverflow.com/questions/58202842/three-js-prevent-raycast-through-gui

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!