用raycaster控制三个轨道

时间:2017-07-17 08:46:00

标签: javascript three.js

我正在使用three.js。要在我的场景中移动,我正在使用轨道控制并选择我使用raycaster的对象。 Raycaster是通过点击和轨道控制发送的。因此,如果选择了一个对象并且我在鼠标释放时移动相机,则将选择另一个对象。有没有办法检查轨道控制中的摄像机运动。

或者防止意外选择的常用方法是什么?

这是我的选择处理程序:

function onMouseClick( event ) {

    // calculate mouse position in normalized device coordinates
    // (-1 to +1) for both components
    mouse.x = ( event.clientX / canvasWidth) * 2 - 1;
    mouse.y = - ( event.clientY / window.innerHeight ) * 2 + 1;

    // update the picking ray with the camera and mouse position
    raycaster.setFromCamera( mouse, camera );

    // calculate objects intersecting the picking ray
    var intersects = raycaster.intersectObjects( CentroLite.children, true );
    if (intersects.length === 0){
    intersects = raycaster.intersectObjects( millingTable.children, true );
    }

    SELECTED = intersects[0].object;
    // DO SOMETHING
}

感谢

1 个答案:

答案 0 :(得分:0)

旗帜可能会派上用场。如果移动鼠标,则可以防止发生选择。类似的东西:

var doClickOnRelease = false;

document.onmousedown = function() {
    // Get ready to see if the user wants to select something
    doClickOnRelease = true
};

document.onmouseup = function() {
    if (doClickOnRelease) {
        // Your select function
    };

document.onmousemove = function() {
    // Since you're dragging, that must be because you
    // didn't intend to select something in the first place
    doClickOnRelease = false;
};