Three.js THREE.Projector has been moved to

后端 未结 5 606
萌比男神i
萌比男神i 2020-12-09 17:47

I understand there is no THREE.projector in version 71 (see the deprecated list), but I don\'t understand how to replace it, particularly in this code that dete

5条回答
  •  一向
    一向 (楼主)
    2020-12-09 18:35

    https://github.com/mrdoob/three.js/issues/5587

    var vector = new THREE.Vector3();
    var raycaster = new THREE.Raycaster();
    var dir = new THREE.Vector3();
    
    ...
    
    if ( camera instanceof THREE.OrthographicCamera ) {
    
        vector.set( ( event.clientX / window.innerWidth ) * 2 - 1, - ( event.clientY / window.innerHeight ) * 2 + 1, - 1 ); // z = - 1 important!
    
        vector.unproject( camera );
    
        dir.set( 0, 0, - 1 ).transformDirection( camera.matrixWorld );
    
        raycaster.set( vector, dir );
    
    } else if ( camera instanceof THREE.PerspectiveCamera ) {
    
        vector.set( ( event.clientX / window.innerWidth ) * 2 - 1, - ( event.clientY / window.innerHeight ) * 2 + 1, 0.5 ); // z = 0.5 important!
    
        vector.unproject( camera );
    
        raycaster.set( camera.position, vector.sub( camera.position ).normalize() );
    
    }
    
    var intersects = raycaster.intersectObjects( objects, recursiveFlag );
    

提交回复
热议问题