用raycaster控制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
}

谢谢


标志可能会在这里派上用场。 如果鼠标移动,您可以防止发生选择。 就像是:

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;
};
链接地址: http://www.djcxy.com/p/83229.html

上一篇: three.js orbit control with raycaster

下一篇: How can I move the camera in ThreeJS relative to perspective?