Three.js通过Gui阻止Raycast [英] Three.js prevent Raycast through Gui
问题描述
我想通过光线投射选择对象,但是每次我想在three.js gui上选择某个对象时,都会触发Mousdownevent。
我该怎么说:如果Gui在对象的前面,不要触发
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);
函数onDocumentMouseDown(event){
if(event){}
gui是一个普通的three.js gui的用法如下:
the gui is a normal three.js gui made like this:
gui = new GUI( { width: 330 } );
推荐答案
一种解决方法是使用 jQuery
和其他控制变量:
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;
} );
然后您可以使用 enableRaycasting
确定是否应该进行射线广播。
You can then use enableRaycasting
in order to determine if raycasting should happen.
演示: https:// jsfiddle.net/gnwz5ae7/
这篇关于Three.js通过Gui阻止Raycast的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!