Changing Raycaster position dynamically

前端 未结 1 1754
说谎
说谎 2021-01-15 22:40

I have a canvas, inside that I have several cubes. I use Raycaster to select them and change their colors. But the canvas is inside of a draggable object and w

相关标签:
1条回答
  • 2021-01-15 23:13

    try to change a code as follows:

    function onDocumentMouseDown( event ) {
    
        event.preventDefault();
    
        var x = event.offsetX == undefined ? event.layerX : event.offsetX;
        var y = event.offsetY == undefined ? event.layerY : event.offsetY;
    
        var vector = new THREE.Vector3();
        vector.set( ( x / renderer.domElement.width ) * 2 - 1, - ( y / renderer.domElement.height ) * 2 + 1, 0.5 );
        vector.unproject( camera );
    
        raycaster.ray.set( camera.position, vector.sub( camera.position ).normalize() );
    ...
    
    0 讨论(0)
提交回复
热议问题