2017-07-17 8 views
0

私はthree.jsを使用しています。私のシーンで移動するには、軌道制御を使用していて、私はレイキャスターを使用しているオブジェクトを選択しています。 Raycasterは、クリックだけでなく、軌道制御で送信されます。したがって、オブジェクトが選択され、マウスリリース時にカメラを動かすと、別のオブジェクトが選択されます。軌道制御でカメラの動きを確認する方法はありますか?raycasterとthree.js軌道制御

や不要な選択を防止するための一般的な方法は何ですか?

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 
} 

おかげ

+0

私は正しく理解しています。左クリックでオブジェクトを選択し、左クリックでカメラを移動します。そうですか? –

+0

はいそうです。私はマウスのリリースとマウスのリリースの間のカメラの変更を確認することができます。これは、マウスのリリース時に選択がトリガーされるためですが、軌道コントロール内のメソッドを期待していたためです。 – tinytree

答えて

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; 
}; 
関連する問題